file

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultStorageRoot = "/data"
)

Variables

This section is empty.

Functions

func NewStorageImpl

func NewStorageImpl(appFs afero.Fs, root string) storage.Interface

Types

type StorageImpl

type StorageImpl struct {
	// contains filtered or unexported fields
}

StorageImpl offers a common interface for object marshaling/unmarshaling operations and hides all the storage-related operations behind it.

func (*StorageImpl) Count

func (s *StorageImpl) Count(key string) (int64, error)

Count returns number of different entries under the key (generally being path prefix).

func (*StorageImpl) Create

func (s *StorageImpl) Create(ctx context.Context, key string, obj, out runtime.Object, _ uint64) error

Create adds a new object at a key even when it already exists. 'ttl' is time-to-live in seconds (and is ignored). If no error is returned and out is not nil, out will be set to the read value from database.

func (*StorageImpl) Delete

Delete removes the specified key and returns the value that existed at that spot. If key didn't exist, it will return NotFound storage error. If 'cachedExistingObject' is non-nil, it can be used as a suggestion about the current version of the object to avoid read operation from storage to get it. However, the implementations have to retry in case suggestion is stale.

func (*StorageImpl) Get

func (s *StorageImpl) Get(ctx context.Context, key string, opts storage.GetOptions, objPtr runtime.Object) error

Get unmarshals object found at key into objPtr. On a not found error, will either return a zero object of the requested type, or an error, depending on 'opts.ignoreNotFound'. Treats empty responses and nil response nodes exactly like a not found error. The returned contents may be delayed, but it is guaranteed that they will match 'opts.ResourceVersion' according 'opts.ResourceVersionMatch'.

func (*StorageImpl) GetList

func (s *StorageImpl) GetList(ctx context.Context, key string, _ storage.ListOptions, listObj runtime.Object) error

GetList unmarshalls objects found at key into a *List api object (an object that satisfies runtime.IsList definition). If 'opts.Recursive' is false, 'key' is used as an exact match. If `opts.Recursive' is true, 'key' is used as a prefix. The returned contents may be delayed, but it is guaranteed that they will match 'opts.ResourceVersion' according 'opts.ResourceVersionMatch'.

func (*StorageImpl) GuaranteedUpdate

func (s *StorageImpl) GuaranteedUpdate(
	ctx context.Context, key string, destination runtime.Object, ignoreNotFound bool,
	preconditions *storage.Preconditions, tryUpdate storage.UpdateFunc, cachedExistingObject runtime.Object) error

GuaranteedUpdate keeps calling 'tryUpdate()' to update key 'key' (of type 'destination') retrying the update until success if there is index conflict. Note that object passed to tryUpdate may change across invocations of tryUpdate() if other writers are simultaneously updating it, so tryUpdate() needs to take into account the current contents of the object when deciding how the update object should look. If the key doesn't exist, it will return NotFound storage error if ignoreNotFound=false else `destination` will be set to the zero value of it's type. If the eventual successful invocation of `tryUpdate` returns an output with the same serialized contents as the input, it won't perform any update, but instead set `destination` to an object with those contents. If 'cachedExistingObject' is non-nil, it can be used as a suggestion about the current version of the object to avoid read operation from storage to get it. However, the implementations have to retry in case suggestion is stale.

Example:

s := /* implementation of Interface */ err := s.GuaranteedUpdate(

 "myKey", &MyType{}, true, preconditions,
 func(input runtime.Object, res ResponseMeta) (runtime.Object, *uint64, error) {
   // Before each invocation of the user defined function, "input" is reset to
   // current contents for "myKey" in database.
   curr := input.(*MyType)  // Guaranteed to succeed.

   // Make the modification
   curr.Counter++

   // Return the modified object - return an error to stop iterating. Return
   // a uint64 to alter the TTL on the object, or nil to keep it the same value.
   return cur, nil, nil
}, cachedExistingObject

)

func (*StorageImpl) Versioner

func (s *StorageImpl) Versioner() storage.Versioner

Versioner Returns Versioner associated with this interface.

func (*StorageImpl) Watch

Watch begins watching the specified key. Events are decoded into API objects, and any items selected by 'p' are sent down to returned watch.Interface. resourceVersion may be used to specify what version to begin watching, which should be the current resourceVersion, and no longer rv+1 (e.g. reconnecting without missing any updates). If resource version is "0", this interface will get current object at given key and send it in an "ADDED" event, before watch starts.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL