dynamostore

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 21 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dynamostore is the flag source of a DynamoDB table: a flag file is one table, read with Scan, and the store answers with a virtual flag file that it builds from the items of the table (one flag for each item: the attribute flag names it, the other attributes are the definition). It is the only package of the flag sources that imports the DynamoDB client.

Index

Constants

View Source
const KeySuffix = ".json"

KeySuffix ends the key of a flag set: the table is the key without it.

View Source
const OverallFactor = 10

OverallFactor is the number of request timeouts that the read of a whole table may take: with the default of 30 seconds the read ends after 5 minutes, whatever the pages are.

Variables

View Source
var (
	// ErrAccessRefused is the cause of an answer that refuses the credentials or the permission.
	ErrAccessRefused = errors.New("objectstore: DynamoDB access refused")
	// ErrRequestRefused is the cause of any other answer that refuses the request (a name or a setting is wrong).
	ErrRequestRefused = errors.New("objectstore: DynamoDB refused the request")
	// ErrThrottled is the cause of an answer that throttles the request.
	ErrThrottled = errors.New("objectstore: DynamoDB throttled the request")
	// ErrUnavailable is the cause of every other failure: no answer, a lost connection, a server error.
	ErrUnavailable = errors.New("objectstore: DynamoDB is not available")
)

The causes of a failed read. None of them holds an endpoint, a table, an account, a role or a request id: the text of the SDK error has them and is dropped; only the short error code of the service is kept.

View Source
var ErrKeyRefused = errors.New("objectstore: the key is no table name with the .json suffix")

ErrKeyRefused is the cause of a key that is no table name followed by ".json".

Functions

func TableOf

func TableOf(key string) (string, bool)

TableOf is the table of a key, and false for a key that names none: the key is the name of the table and KeySuffix.

Types

type Option

type Option func(*Store)

Option adjusts a Store.

func WithRequestTimeout

func WithRequestTimeout(timeout time.Duration) Option

WithRequestTimeout bounds each request of a read: one Scan call, a page, with all the attempts of the SDK and the waits between them. The read as a whole has a deadline of OverallFactor times that, and the context of the caller. Zero or less keeps storekit.DefaultCloudRequestTimeout.

type Provider

type Provider interface {
	DynamoDB(ctx context.Context, name string) (*dynamodb.Client, error)
}

Provider gives the DynamoDB client of a named connection. The connection factory (internal/connection) implements it. The store asks on every call, so a client the factory replaced after a reload is picked up and there is never a second client for the connection.

type Store

type Store struct {
	objectstore.NoLifecycle
	// contains filtered or unexported fields
}

Store is an objectstore.ObjectStore on the tables of the DynamoDB client of a connection. A key is the name of a table and ".json" (flags.json reads the table flags); the store answers with one JSON document, the flag file, built from every item of the table. See Store.Get for the rules.

func New

func New(provider Provider, connectionName string, logger *slog.Logger, opts ...Option) *Store

New returns the store of the tables of the connection named connectionName. The logger receives the one line about items that are not flags; nil discards it.

func (*Store) Format

func (s *Store) Format(f fmt.State, _ rune)

Format implements fmt.Formatter: every verb prints the name of the connection and nothing else.

func (*Store) Get

Get implements objectstore.ObjectStore. The answer is the flag file of the table.

  • The ETag is the SHA-256 of that document, so an unchanged table is objectstore.ErrNotModified. The document is rebuilt with its names in order: items that are read in another order give the same ETag.
  • DynamoDB keeps no modification time for a table: Modified is the zero time.
  • A table that does not exist is objectstore.ErrNotFound; one that exists and holds no item is the empty flag set.
  • The table is read with Scan, page after page, with consistent reads, and the read stops with objectstore.ErrTooLarge as soon as the file would be over the limit. The pages are not one snapshot: a change while they are read can tear the answer, and the next poll reads the new state.
  • Each Scan has its own request timeout (see WithRequestTimeout); the read as a whole ends after OverallFactor request timeouts, or with the context of the caller.
  • The size of the items that are left out counts toward the limit.
  • The items that are left out are logged at every read.
  • The SDK retries a throttled or failed page by its own retryer, set on the connection (retry.maxAttempts); the store adds no retry of its own.

Jump to

Keyboard shortcuts

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