dynamodb

package
v0.0.0-...-0183129 Latest Latest
Warning

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

Go to latest
Published: May 25, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultRegion     = "us-west-1"
	DefaultTableName  = "rules"
	DefaultConsistent = false
)
View Source
var CheckLastUpdated = true

CheckLastUpdated enables the experimental optimistic locking (sort of) of locations in DynamoDB.

The idea: The last updated timestamp, if any, is read from DynamoDB at location load time. We remember that timestamp (in 'Location.lastUpdated', which is accessed via 'Location.Updated()' and 'Location.Update()'. When we attempt to change the location's state, we verify that the timestamp hasn't changed in DynamoDB. If it has, we return a 'ConcurrentStateChange' error. Otherwise, we atomically update the timestamp with a new one.

ToDo: This code needs test cases badly.

View Source
var ConcurrentStateChange = &Condition{"concurrent state change", "nonfatal"}

ConcurrentStateChange is a non-fatal error resulting from two concurrent attempts to modify a location's state.

This error can only occur if CheckLastUpdated is true.

Not currently used!

View Source
var LastUpdatedKey = "LAST_UPDATED"

LastUpdatedKey is the attribute name for a timestamp (augmented with an IP address maybe) of the last state update.

ToDo: Create a space for internal ids.

Functions

func ConditionalCheckFailedException

func ConditionalCheckFailedException(err error) bool

Types

type Dialer

type Dialer struct {
	net.Dialer
}

Instrumented Dialer.

func NewDialer

func NewDialer(d *net.Dialer) Dialer

func (*Dialer) Dial

func (d *Dialer) Dial(network string, address string) (net.Conn, error)

type DynamoDBConfig

type DynamoDBConfig struct {
	Region    string
	TableName string
	// Consistent determines GetItemConsistent(cy).
	Consistent bool
}

DynamoDBConfig does what'd you'd think.

This name stutters because it's convenient to dot-import core, which defines 'Storage'.

func ParseConfig

func ParseConfig(config string) (*DynamoDBConfig, error)

ParseConfig generates a DynamoDBConfig from a string.

Input should look like region[:tableName[:(true|false)]], where the boolean indicates whether to do consistent reads. Defaults: the vars DefaultRegion, DefaultTableName, DefaultConsistent.

type DynamoDBStorage

type DynamoDBStorage struct {

	// Consistent determines we we call GetItemConsistent or just GetItem.
	//
	// Note that DynamoDBStorage isn't synchronized, so beware.
	//
	// ToDo: Ideally we move this property elsewhere, but changing
	// the Storage interface just for this capabitity is
	// questionable.  Perhaps generalize Storage to support
	// arbitrary properties (including transaction id)?  Or
	// perhaps this property is part of a DynamoDBConfig.
	Consistent bool
	// contains filtered or unexported fields
}

DynamoDBStorage implements Storage using DynamoDB. Duh.

This name stutters because it's convenient to dot-import core, which defines 'Storage'.

func GetStorage

func GetStorage(ctx *Context, config DynamoDBConfig) (*DynamoDBStorage, error)

GetStorage will return a DynamoDBStorage, creating one if necessary.

func NewStorage

func NewStorage(ctx *Context, config DynamoDBConfig) (*DynamoDBStorage, error)

func (*DynamoDBStorage) Add

func (s *DynamoDBStorage) Add(ctx *Context, loc string, m *Pair) error

Add writes the given additional state to DynamoDB.

If 'CheckLastUpdated' is true, this function attempts to verify that the state in DynamoDB hasn't changed since we last loaded it or changed it. If the state has changed unexpectedly, you get an error (which should be ConcurrentStateChange, but currently is just the error returned by the SDK).

func (*DynamoDBStorage) Clear

func (s *DynamoDBStorage) Clear(ctx *Context, loc string) (int64, error)

func (*DynamoDBStorage) Close

func (ms *DynamoDBStorage) Close(ctx *Context) error

func (*DynamoDBStorage) Delete

func (s *DynamoDBStorage) Delete(ctx *Context, loc string) error

func (*DynamoDBStorage) GetStats

func (s *DynamoDBStorage) GetStats(ctx *Context, loc string) (StorageStats, error)

func (*DynamoDBStorage) Health

func (s *DynamoDBStorage) Health(ctx *Context) error

func (*DynamoDBStorage) Load

func (s *DynamoDBStorage) Load(ctx *Context, loc string) ([]Pair, error)

Load queries DynamoDB to get a location's state.

This function also calls the location's 'Update()' function to remember the time the state was last updated (and when we read that state).

func (*DynamoDBStorage) Purge

func (ms *DynamoDBStorage) Purge(ctx *Context, loc string, t int64) (int64, error)

Purge should never be called. ToDo: Remove this method from the interface, and kill the old mutation code.

func (*DynamoDBStorage) Remove

func (s *DynamoDBStorage) Remove(ctx *Context, loc string, id []byte) (int64, error)

Remove removes the given data from DynamoDB.

If 'CheckLastUpdated' is true, this function attempts to verify that the state in DynamoDB hasn't changed since we last loaded it or changed it. If the state has changed unexpectedly, you get an error (which should be ConcurrentStateChange, but currently is just the error returned by the SDK).

func (*DynamoDBStorage) Server

func (s *DynamoDBStorage) Server(ctx *Context) *dynamodb.Server

func (*DynamoDBStorage) Table

func (s *DynamoDBStorage) Table(ctx *Context) *dynamodb.Table

Jump to

Keyboard shortcuts

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