dynamo

package
v0.2.18 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NULLValue = "%NULL%"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Storage

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

Storage is a struct that saves all necessary information to access the database, in this case the session for DynamoDB and the table name. The DynamoDB table is set up with the following attributes: Keygroup (S) | Key (S) | Value (Document) | Expiry (N) | Trigger (Document) where "Keygroup" is the partition key and "Key" is the sort key (both together form the primary key). Set this up with the following aws-cli command (table name in this case is "fred"):

aws dynamodb create-table --table-name fred \
	--attribute-definitions "AttributeName=Keygroup,AttributeType=S AttributeName=Key,AttributeType=S" \
	--key-schema "AttributeName=Keygroup,KeyType=HASH AttributeName=Key,KeyType=RANGE" \
	--provisioned-throughput "ReadCapacityUnits=1,WriteCapacityUnits=1"

The "Expiry" attribute is used to expire data items automatically in DynamoDB. Set this up with this command:

aws dynamodb update-time-to-live --table-name fred \
	--time-to-live-specification "Enabled=true, AttributeName=Expiry"

Two types of items are stored here:

  • Keygroup configuration is stored with the NULL "Key" and the keygroup name: this has the "Trigger" attribute that stores a map of trigger nodes for that keygroup
  • Keys are stored with a "Keygroup" and unique "Key", where the Value is a list of version vectors and values - the additional "Expiry" attribute can be set to let the keys expire, and it is updated with each update to the data item (note that this means that in DynamoDB, all versions of an item expire at the same time, not necessarily in the order in which they appeared)

func New

func New(table string, region string, endpoint string, create bool) (*Storage, error)

func (*Storage) AddKeygroupTrigger

func (s *Storage) AddKeygroupTrigger(kg string, tid string, host string) error

AddKeygroupTrigger stores a trigger node in the dynamodb database.

func (*Storage) Append

func (s *Storage) Append(kg string, id string, val string, expiry int) error

Append appends the item to the specified keygroup by incrementing the latest key by one.

func (*Storage) Close

func (s *Storage) Close() error

Close closes the underlying DynamoDB connection (no cleanup needed at the moment).

func (*Storage) CreateKeygroup

func (s *Storage) CreateKeygroup(kg string) error

CreateKeygroup creates the given keygroup in the DynamoDB database.

func (*Storage) Delete

func (s *Storage) Delete(kg string, id string, vvector vclock.VClock) error

Delete deletes the item with the specified id from the specified keygroup.

func (*Storage) DeleteKeygroup

func (s *Storage) DeleteKeygroup(kg string) error

DeleteKeygroup deletes the given keygroup from the DynamoDB database.

func (*Storage) DeleteKeygroupTrigger

func (s *Storage) DeleteKeygroupTrigger(kg string, tid string) error

DeleteKeygroupTrigger removes a trigger node from the dynamodb database.

func (*Storage) Exists

func (s *Storage) Exists(kg string, id string) bool

Exists checks if the given data item exists in the dynamodb database.

func (*Storage) ExistsKeygroup

func (s *Storage) ExistsKeygroup(kg string) bool

ExistsKeygroup checks if the given keygroup exists in the DynamoDB database.

func (*Storage) GetKeygroupTrigger

func (s *Storage) GetKeygroupTrigger(kg string) (map[string]string, error)

GetKeygroupTrigger returns a map of all trigger nodes from the dynamodb database.

func (*Storage) IDs

func (s *Storage) IDs(kg string) ([]string, error)

IDs returns the keys of all items in the specified keygroup.

func (*Storage) Read

func (s *Storage) Read(kg string, id string) ([]string, []vclock.VClock, bool, error)

Read returns an item with the specified id from the specified keygroup.

func (*Storage) ReadAll

func (s *Storage) ReadAll(kg string) ([]string, []string, []vclock.VClock, error)

ReadAll returns all items in the specified keygroup.

func (*Storage) ReadSome

func (s *Storage) ReadSome(kg string, id string, count uint64) ([]string, []string, []vclock.VClock, error)

func (*Storage) Update

func (s *Storage) Update(kg string, id string, val string, expiry int, vvector vclock.VClock) error

Update updates the item with the specified id in the specified keygroup.

Jump to

Keyboard shortcuts

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