Documentation
¶
Index ¶
Constants ¶
const NoLeaseId = 0
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Lease ¶
type Lease interface { // Id returns the lease Id Id() LeaseId // TTL is time to the lease expiration TTL() time.Duration // Release terminates (releases) the lease immediately Release() error }
Lease allows to control a lease. Lease is an abstraction which identifies a time interval where the lease is valid - ttl. Storage records could be associated with the lease by its Id.
type LeaseId ¶
type LeaseId int64
LeaseId is a record lease identifier. Every record in the storage can have a lease id or has NoLeaseId. Records that have a lease will be automatically deleted if the lease is expired.
type Lessor ¶
type Lessor interface { // NewLease creates a new lease with ttl provided. The keepAlive flag // indicates that the the lease must be kept alive until the current process // is done. NewLease(ctx context.Context, ttl time.Duration, keepAlive bool) (Lease, error) // GetLease returns a Lease object by it's Id GetLease(lid LeaseId) (Lease, error) }
Lessor is an interface which allows to manage leases in conjuction with the Storage
type Record ¶
type Record struct { // Key is a key for the record Key Key // Value is a value for the record Value Value // A version that identifies the record. It is managed by the Storage and // it is ignored in Create and update operations Version Version // Lease contains the record leaseId. If the lease is not empty // (Lease != NoLeaseId), the record availability is defined by the // lease TTL. As soon as the lease becomes invalid, the record is // Removed from the storage permanently // // Records with NoLeaseId should be deleted explicitly. The value // can be set only when the record is created and cannot be changed // (it will be ignored) during updates. Lease LeaseId }
A record that can be stored in a KV
type Storage ¶
type Storage interface { // Lessor returns Lessor implementation for the storage Lessor() Lessor // Create adds a new record into the storage. It returns existing record with // ErrAlreadyExists error if it already exists in the storage. // Create returns version of the new record with error=nil Create(ctx context.Context, record Record) (Version, error) // Get retrieves the record by its key. It will return nil and an error, // which will indicate the reason why the operation was not succesful. // ErrNotFound is returned if the key is not found in the storage Get(ctx context.Context, key Key) (Record, error) // GetRange returns the list of records for the range of keys (inclusively) // if there is no keys found, it returns empty slice with no error. GetRange(ctx context.Context, startKey, endKey Key) (Records, error) // CasByVersion compares-and-sets the record Value if the record stored // version is same as in the provided record. The record version will be updated // too and returned in the result. // // the record lease WILL NOT BE CHANGED, so the record will be associated // with the lease, that it has been done before. // // an error will contain the reason if the operation was not successful, or // the new version will be returned otherwise // ErrWrongVersion - indicates that the version is changed // ErrNotFound - indicates that the record does not exist CasByVersion(ctx context.Context, record Record) (Version, error) // Delete removes the record from the storage by its key. It returns // an error if the operation was not successful. Delete(ctx context.Context, key Key) error // WaitForVersionChange will wait for the record version change. The // version param contans an expected record version. The call returns // immediately if the record is not found together with ErrNotFound, or // if the record version is different than expected (no error this case // is returned). // // the call will block the current go-routine until one of the following // things happens: // - context is closed // - the record version is changed // - the record is deleted // // If the record is deleted during the call (nil, nil) is returned WaitForVersionChange(ctx context.Context, key Key, version Version) (Record, error) }
Storage interface defines some operations over the record storage. The record storage allows to keep key-value pairs, and supports a set of operations that allow to implement some distributed (if supported) primitives