Documentation
¶
Index ¶
- Constants
- Variables
- func CalculateExponentialBackoff(attempt int, initialBackoff time.Duration, maxBackoff time.Duration, ...) time.Duration
- func IsRetryableError(err error) bool
- func RetryWithBackoff(ctx context.Context, fn RetryableFunc, maxRetries int, ...) error
- type BatchOperation
- type Client
- func (c *Client) BatchWrite(ctx context.Context, operations []BatchOperation, sync bool) (bool, error)
- func (c *Client) BeginTransaction(ctx context.Context, readOnly bool) (*Transaction, error)
- func (c *Client) Close() error
- func (c *Client) Compact(ctx context.Context, force bool) (bool, error)
- func (c *Client) Connect(ctx context.Context) error
- func (c *Client) Delete(ctx context.Context, key []byte, sync bool) (bool, error)
- func (c *Client) Get(ctx context.Context, key []byte) ([]byte, bool, error)
- func (c *Client) GetReplicationInfo() (*NodeInfo, error)
- func (c *Client) GetStats(ctx context.Context) (*Stats, error)
- func (c *Client) IsConnected() bool
- func (c *Client) IsPrimary() bool
- func (c *Client) IsReplica() bool
- func (c *Client) IsStandalone() bool
- func (c *Client) Put(ctx context.Context, key, value []byte, sync bool) (bool, error)
- func (c *Client) RefreshTopology(ctx context.Context) error
- func (c *Client) Scan(ctx context.Context, options ScanOptions) (Scanner, error)
- type ClientOptions
- type CompressionType
- type KeyValue
- type NodeInfo
- type ReplicaInfo
- type RetryableFunc
- type ScanOptions
- type Scanner
- type Stats
- type Transaction
- func (tx *Transaction) Commit(ctx context.Context) error
- func (tx *Transaction) Delete(ctx context.Context, key []byte) (bool, error)
- func (tx *Transaction) Get(ctx context.Context, key []byte) ([]byte, bool, error)
- func (tx *Transaction) Put(ctx context.Context, key, value []byte) (bool, error)
- func (tx *Transaction) Rollback(ctx context.Context) error
- func (tx *Transaction) Scan(ctx context.Context, options ScanOptions) (Scanner, error)
Constants ¶
const ( CompressionNone = transport.CompressionNone CompressionGzip = transport.CompressionGzip CompressionSnappy = transport.CompressionSnappy )
Compression options
Variables ¶
var ( // ErrNotConnected indicates the client is not connected to the server ErrNotConnected = errors.New("not connected to server") // ErrInvalidOptions indicates invalid client options ErrInvalidOptions = errors.New("invalid client options") // ErrTimeout indicates a request timed out ErrTimeout = errors.New("request timed out") // ErrKeyNotFound indicates a key was not found ErrKeyNotFound = errors.New("key not found") // ErrTransactionConflict indicates a transaction conflict occurred ErrTransactionConflict = errors.New("transaction conflict detected") )
Errors that can occur during client operations
var ErrTransactionClosed = errors.New("transaction is closed")
ErrTransactionClosed is returned when attempting to use a closed transaction
Functions ¶
func CalculateExponentialBackoff ¶
func CalculateExponentialBackoff( attempt int, initialBackoff time.Duration, maxBackoff time.Duration, backoffFactor float64, jitter float64, ) time.Duration
CalculateExponentialBackoff calculates the backoff time for a given attempt
func IsRetryableError ¶
IsRetryableError returns true if the error is considered retryable
Types ¶
type BatchOperation ¶
type BatchOperation struct {
Type string // "put" or "delete"
Key []byte
Value []byte // only used for "put" operations
}
BatchOperation represents a single operation in a batch
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a connection to a Kevo database server
func NewClient ¶
func NewClient(options ClientOptions) (*Client, error)
NewClient creates a new Kevo client with the given options
func (*Client) BatchWrite ¶
func (c *Client) BatchWrite(ctx context.Context, operations []BatchOperation, sync bool) (bool, error)
BatchWrite performs multiple operations in a single atomic batch If connected to a replica, it will automatically route the batch to the primary
func (*Client) BeginTransaction ¶
BeginTransaction starts a new transaction
func (*Client) Connect ¶
Connect establishes a connection to the server and discovers the replication topology if available
func (*Client) Delete ¶
Delete removes a key-value pair If connected to a replica, it will automatically route the delete to the primary
func (*Client) Get ¶
Get retrieves a value by key If connected to a primary with replicas, it will route reads to a replica
func (*Client) GetReplicationInfo ¶ added in v1.3.0
GetNodeInfo returns information about the current node and replication topology
func (*Client) IsConnected ¶
IsConnected returns whether the client is connected to the server
func (*Client) IsPrimary ¶ added in v1.3.0
IsPrimary returns true if the connected node is a primary
func (*Client) IsReplica ¶ added in v1.3.0
IsReplica returns true if the connected node is a replica
func (*Client) IsStandalone ¶ added in v1.3.0
IsStandalone returns true if the connected node is standalone (not part of replication)
func (*Client) Put ¶
Put stores a key-value pair If connected to a replica, it will automatically route the write to the primary
func (*Client) RefreshTopology ¶ added in v1.3.0
RefreshTopology updates the replication topology information
type ClientOptions ¶
type ClientOptions struct {
// Connection options
Endpoint string // Server address
ConnectTimeout time.Duration // Timeout for connection attempts
RequestTimeout time.Duration // Default timeout for requests
TransportType string // Transport type (e.g. "grpc")
PoolSize int // Connection pool size
// Security options
TLSEnabled bool // Enable TLS
CertFile string // Client certificate file
KeyFile string // Client key file
CAFile string // CA certificate file
// Retry options
MaxRetries int // Maximum number of retries
InitialBackoff time.Duration // Initial retry backoff
MaxBackoff time.Duration // Maximum retry backoff
BackoffFactor float64 // Backoff multiplier
RetryJitter float64 // Random jitter factor
// Performance options
Compression CompressionType // Compression algorithm
MaxMessageSize int // Maximum message size
// Keepalive options
KeepaliveTime time.Duration // Time between keepalive pings (0 for default)
KeepaliveTimeout time.Duration // Time to wait for ping ack (0 for default)
}
ClientOptions configures a Kevo client
func DefaultClientOptions ¶
func DefaultClientOptions() ClientOptions
DefaultClientOptions returns sensible default client options
type CompressionType ¶
type CompressionType = transport.CompressionType
CompressionType represents a compression algorithm
type NodeInfo ¶ added in v1.3.0
type NodeInfo struct {
Role string // "primary", "replica", or "standalone"
PrimaryAddr string // Address of the primary node
Replicas []ReplicaInfo // Available replica nodes
LastSequence uint64 // Last applied sequence number
ReadOnly bool // Whether the node is in read-only mode
}
NodeInfo contains information about the server node and topology
type ReplicaInfo ¶ added in v1.3.0
type ReplicaInfo struct {
Address string // Host:port of the replica
LastSequence uint64 // Last applied sequence number
Available bool // Whether the replica is available
Region string // Optional region information
Meta map[string]string // Additional metadata
}
ReplicaInfo represents information about a replica node
type RetryableFunc ¶
type RetryableFunc func() error
RetryableFunc is a function that can be retried
type ScanOptions ¶
type ScanOptions struct {
// Prefix limit the scan to keys with this prefix
Prefix []byte
// Suffix limit the scan to keys with this suffix
Suffix []byte
// StartKey sets the starting point for the scan (inclusive)
StartKey []byte
// EndKey sets the ending point for the scan (exclusive)
EndKey []byte
// Limit sets the maximum number of key-value pairs to return
Limit int32
}
ScanOptions configures a scan operation
type Scanner ¶
type Scanner interface {
// Next advances the scanner to the next key-value pair
Next() bool
// Key returns the current key
Key() []byte
// Value returns the current value
Value() []byte
// Error returns any error that occurred during iteration
Error() error
// Close releases resources associated with the scanner
Close() error
}
Scanner interface for iterating through keys and values
type Stats ¶
type Stats struct {
KeyCount int64
StorageSize int64
MemtableCount int32
SstableCount int32
WriteAmplification float64
ReadAmplification float64
}
Stats contains database statistics
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
Transaction represents a database transaction
func (*Transaction) Commit ¶
func (tx *Transaction) Commit(ctx context.Context) error
Commit commits the transaction
func (*Transaction) Rollback ¶
func (tx *Transaction) Rollback(ctx context.Context) error
Rollback aborts the transaction
func (*Transaction) Scan ¶
func (tx *Transaction) Scan(ctx context.Context, options ScanOptions) (Scanner, error)
Scan creates a scanner to iterate over keys in the transaction