state

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateKey

func ValidateKey(key string) error

ValidateKey ensures the provided key is a valid absolute Unix path. It does not support '.' or '..' segments.

Types

type KVEntry

type KVEntry struct {
	// Key is the unique identifier for the entry.
	Key string
	// Value is the raw byte content of the entry.
	Value []byte
	// Type classifies the entry (e.g., "data", "membership").
	Type string
	// Version is the consensus sequence number for this specific update.
	Version uint64
	// Deleted indicates whether this entry is marked as deleted.
	Deleted bool
}

KVEntry represents a single entry in the Key-Value store.

type LogEntry

type LogEntry struct {
	// ID is the sequential identifier for the log entry.
	ID int64
	// Timestamp is the time the message was recorded.
	Timestamp string
	// Type classifies the message (e.g., Prepare, Accept).
	Type string
	// Sender is the agent ID that initiated the message.
	Sender string
	// Receiver is the agent ID that received the message.
	Receiver string
	// Message contains a text representation of the request.
	Message string
	// Reply contains a text representation of the response.
	Reply string
}

LogEntry represents a single recorded message exchange.

type PeerInfo

type PeerInfo struct {
	// ShortName is the human-readable name of the peer.
	ShortName string `json:"short_name"`
	// GRPCAddr is the gRPC host:port for the peer.
	GRPCAddr string `json:"grpc_addr"`
	// HTTPURL is the HTTP dashboard URL for the peer.
	HTTPURL string `json:"http_url"`
	// Certificate is the DER-encoded X.509 certificate of the peer.
	Certificate []byte `json:"certificate"`
}

PeerInfo contains metadata about a cluster member.

func (PeerInfo) Equal

func (p PeerInfo) Equal(other PeerInfo) bool

Equal checks if two PeerInfo structs are identical.

type Store

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

Store manages the persistence of agent state, including Paxos variables, Key-Value data, cluster membership, and a message log. It is backed by SQLite.

func NewStore

func NewStore(stateDir string) (*Store, error)

NewStore initializes a new Store, creating the necessary database files and schema.

func (*Store) AddMember

func (s *Store) AddMember(agentID string, info PeerInfo) error

AddMember adds or updates a peer in the local membership list.

func (*Store) Close

func (s *Store) Close() error

Close closes the underlying database connection.

func (*Store) CommitKV

func (s *Store) CommitKV(key string, value []byte, valType string, version uint64) error

CommitKV saves a value to the Key-Value store after consensus is reached. If the value is empty, the entry is marked as deleted.

func (*Store) GetAcceptorState

func (s *Store) GetAcceptorState(key string) (promisedID *paxosv1.ProposalID, acceptedID *paxosv1.ProposalID, acceptedValue []byte, err error)

GetAcceptorState retrieves the highest promised and accepted proposal IDs, and the accepted value for a given key.

func (*Store) GetAgentID

func (s *Store) GetAgentID() (string, error)

GetAgentID returns the established agent ID.

func (*Store) GetAllKVs

func (s *Store) GetAllKVs() ([]KVEntry, error)

GetAllKVs retrieves all non-deleted entries from the Key-Value store.

func (*Store) GetIdentity

func (s *Store) GetIdentity(passphrase string) (*identity.Identity, error)

GetIdentity retrieves the cryptographic identity for this agent.

func (*Store) GetKVEntry

func (s *Store) GetKVEntry(key string) (value []byte, valType string, version uint64, deleted bool, err error)

GetKVEntry retrieves the value, type, version, and deletion status of a specific key.

func (*Store) GetKVState

func (s *Store) GetKVState() (map[string]uint64, error)

GetKVState returns a map of all keys and their corresponding consensus version numbers.

func (*Store) GetKVsByPrefix

func (s *Store) GetKVsByPrefix(prefix string) ([]KVEntry, error)

GetKVsByPrefix retrieves all non-deleted entries from the Key-Value store that start with the specified prefix.

func (*Store) GetMembers

func (s *Store) GetMembers() (map[string]PeerInfo, error)

GetMembers retrieves the entire local membership list.

func (*Store) GetRecentMessages

func (s *Store) GetRecentMessages(limit int) ([]LogEntry, error)

GetRecentMessages retrieves the most recent message log entries up to the specified limit.

func (*Store) GetShortName

func (s *Store) GetShortName() (string, error)

GetShortName returns the established short name for this agent.

func (*Store) InitializeAgentID

func (s *Store) InitializeAgentID(passphrase string) (string, string, error)

InitializeAgentID retrieves the persistent agent ID and short name for this node. It also initializes the cryptographic identity for this agent if it doesn't exist.

func (*Store) LogMessage

func (s *Store) LogMessage(msgType, sender, receiver string, message, reply []byte) error

LogMessage records an incoming or outgoing message and its reply to the database.

func (*Store) RemoveMember

func (s *Store) RemoveMember(agentID string) error

RemoveMember removes a peer from the local membership list.

func (*Store) SaveIdentity

func (s *Store) SaveIdentity(ident *identity.Identity, passphrase string) error

SaveIdentity saves the cryptographic identity for this agent to the store.

func (*Store) SetAcceptedValue

func (s *Store) SetAcceptedValue(key string, id *paxosv1.ProposalID, value []byte) error

SetAcceptedValue records the acceptance of a proposal for a given key.

func (*Store) SetPromisedID

func (s *Store) SetPromisedID(key string, id *paxosv1.ProposalID) error

SetPromisedID records a promise not to accept proposals with a lower ID for a given key.

func (*Store) SetShortName

func (s *Store) SetShortName(shortName string) error

SetShortName updates the human-readable short name for this node.

Jump to

Keyboard shortcuts

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