Documentation
¶
Overview ¶
Package strata provides an embeddable, S3-durable key-value store.
Index ¶
- Variables
- type Config
- type Event
- type EventType
- type KeyValue
- type Node
- func (n *Node) Close() error
- func (n *Node) Compact(ctx context.Context, revision int64) error
- func (n *Node) CompactRevision() int64
- func (n *Node) Config() Config
- func (n *Node) Count(prefix string) (int64, error)
- func (n *Node) Create(ctx context.Context, key string, value []byte, lease int64) (int64, error)
- func (n *Node) CurrentRevision() int64
- func (n *Node) Delete(ctx context.Context, key string) (int64, error)
- func (n *Node) DeleteIfRevision(ctx context.Context, key string, revision int64) (int64, *KeyValue, bool, error)
- func (n *Node) Get(key string) (*KeyValue, error)
- func (n *Node) HandleForward(ctx context.Context, req *peer.ForwardRequest) (*peer.ForwardResponse, error)
- func (n *Node) IsLeader() bool
- func (n *Node) List(prefix string) ([]*KeyValue, error)
- func (n *Node) Put(ctx context.Context, key string, value []byte, lease int64) (int64, error)
- func (n *Node) Update(ctx context.Context, key string, value []byte, revision, lease int64) (int64, *KeyValue, bool, error)
- func (n *Node) WaitForRevision(ctx context.Context, rev int64) error
- func (n *Node) Watch(ctx context.Context, prefix string, startRev int64) (<-chan Event, error)
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrKeyExists = errors.New("strata: key already exists") ErrNotLeader = errors.New("strata: this node is not the leader; writes are rejected") )
Sentinel errors.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// DataDir is the directory used for local Pebble data and WAL segments.
// Required.
DataDir string
// ObjectStore is used to archive WAL segments and checkpoints and to run
// leader election. If nil the node runs in single-node mode.
ObjectStore object.Store
// SegmentMaxSize is the byte threshold that triggers WAL segment rotation.
// Default: 50 MB.
SegmentMaxSize int64
// SegmentMaxAge is the time threshold that triggers WAL segment rotation.
// Default: 10 s.
SegmentMaxAge time.Duration
// CheckpointInterval controls how often the leader writes a checkpoint.
// Default: 15 minutes.
CheckpointInterval time.Duration
// CheckpointEntries triggers a checkpoint after this many WAL entries
// regardless of time. 0 means disabled.
CheckpointEntries int64
// NodeID is a stable, unique identifier for this node.
// Defaults to the machine hostname.
NodeID string
// PeerListenAddr is the address on which the peer WAL-streaming gRPC
// server listens (e.g. "0.0.0.0:2380"). Empty → single-node mode.
PeerListenAddr string
// AdvertisePeerAddr is the address followers use to reach this node's peer
// server. Defaults to PeerListenAddr.
AdvertisePeerAddr string
// LeaderWatchInterval is how often the leader reads the lock from S3 to
// detect if it has been superseded. Read-only; no renewals.
// Default: 5 minutes.
LeaderWatchInterval time.Duration
// FollowerMaxRetries is the number of consecutive stream failures a follower
// tolerates before attempting a TakeOver election.
// Default: 5.
FollowerMaxRetries int
// PeerBufferSize is the number of WAL entries the leader buffers for
// follower catch-up. Default: 10 000.
PeerBufferSize int
// PeerServerTLS is the transport credentials used by the leader's peer
// gRPC server. Nil means plaintext (only safe inside a trusted network).
PeerServerTLS credentials.TransportCredentials
// PeerClientTLS is the transport credentials used by a follower's peer
// gRPC client. Must be set when PeerServerTLS is set on the leader.
PeerClientTLS credentials.TransportCredentials
// MetricsAddr is the TCP address for the Prometheus /metrics, /healthz,
// and /readyz HTTP endpoints (e.g. "0.0.0.0:9090"). Empty means disabled.
MetricsAddr string
}
Config holds all configuration for a Node.
type KeyValue ¶
type KeyValue struct {
Key string
Value []byte
Revision int64
CreateRevision int64
PrevRevision int64
Lease int64
}
KeyValue is a versioned key-value pair.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node is the top-level Strata instance.
Single-node mode (PeerListenAddr == ""):
Writes: WAL.Append (fsync) → store.Apply → notify watchers Background: WAL segments uploaded to S3, periodic checkpoints
Leader mode:
Same as single-node, plus fan-out to followers via peer gRPC stream. Holds the S3 leader lock; watches it infrequently for supersession.
Follower mode:
Reads are served locally. Writes are forwarded to the leader via the peer gRPC channel and the response is returned transparently to the caller. After persistent stream failure, attempts a TakeOver election.
func (*Node) CompactRevision ¶
func (*Node) CurrentRevision ¶
func (*Node) DeleteIfRevision ¶
func (n *Node) DeleteIfRevision(ctx context.Context, key string, revision int64) (int64, *KeyValue, bool, error)
DeleteIfRevision deletes key only if its current revision matches (CAS).
func (*Node) HandleForward ¶
func (n *Node) HandleForward(ctx context.Context, req *peer.ForwardRequest) (*peer.ForwardResponse, error)
HandleForward implements peer.ForwardHandler. Called by the peer gRPC server when a follower forwards a write. Dispatches to the appropriate Node method. Since HandleForward runs on the leader, all write methods execute directly.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
strata
command
Command strata runs a Strata node and exposes it as an etcd v3 gRPC endpoint.
|
Command strata runs a Strata node and exposes it as an etcd v3 gRPC endpoint. |
|
Package etcd exposes a strata Node as an etcd v3 gRPC server.
|
Package etcd exposes a strata Node as an etcd v3 gRPC server. |
|
internal
|
|
|
checkpoint
Package checkpoint handles creating, writing, and restoring Pebble snapshots to/from object storage.
|
Package checkpoint handles creating, writing, and restoring Pebble snapshots to/from object storage. |
|
election
Package election implements S3-based leader election.
|
Package election implements S3-based leader election. |
|
metrics
Package metrics defines Prometheus metrics for a Strata node.
|
Package metrics defines Prometheus metrics for a Strata node. |
|
object
Package object provides a small interface for object storage operations used by Strata (WAL archive, checkpoints, manifest).
|
Package object provides a small interface for object storage operations used by Strata (WAL archive, checkpoints, manifest). |
|
peer
Package peer implements the leader→follower WAL streaming gRPC service, plus write forwarding (follower→leader).
|
Package peer implements the leader→follower WAL streaming gRPC service, plus write forwarding (follower→leader). |
|
store
Package store implements the Pebble-backed key-value state machine.
|
Package store implements the Pebble-backed key-value state machine. |
|
wal
Package wal implements the write-ahead log.
|
Package wal implements the write-ahead log. |
|
Package kine provides a kine server.Backend implementation backed by a strata Node.
|
Package kine provides a kine server.Backend implementation backed by a strata Node. |
Click to show internal directories.
Click to hide internal directories.