Documentation
¶
Overview ¶
Package common provides core data structures and utilities shared across the distributed key-value store system. It defines fundamental types, configuration structures, and protocol elements used by other packages.
The package focuses on:
- Message protocol definition for inter-component communication
- Configuration structures for client and server components
- Custom logging implementation integrated with Dragonboat
- Utilities for Dragonboat (RAFT) integration
Key Components:
Message: Core data structure for all RPC communication between components, with a flexible structure that adapts to different operation types. Includes factory methods for creating various request and response messages.
MessageType: Enumeration defining all supported operation types in the system, categorized into key-value operations, lock operations, and control messages.
ServerConfig: Comprehensive configuration for server nodes, including RAFT parameters, storage settings, network configuration, and operation modes. Provides utilities for converting to Dragonboat-specific configurations.
ClientConfig: Configuration for client components, controlling connection parameters, timeouts, and retry behavior.
Logger: Custom logging implementation that integrates with Dragonboat's logging system while providing consistent formatting across the application.
Package util provides logging utilities for the application
Index ¶
- Constants
- func CreateLogger(pkgName string) logger.ILogger
- func InitLoggers(config ServerConfig)
- type ClientConfig
- type ClientTransportConfig
- type Message
- func NewAcquireRequest(key string, deleteIn uint64) *Message
- func NewAcquireResponse(ok bool, value []byte, err error) *Message
- func NewCustomRequest(meta []byte) *Message
- func NewCustomResponse(meta []byte, err error) *Message
- func NewDeleteRequest(key string) *Message
- func NewDeleteResponse(err error) *Message
- func NewErrorResponse(err string) *Message
- func NewExpireRequest(key string) *Message
- func NewExpireResponse(err error) *Message
- func NewGetRequest(key string) *Message
- func NewGetResponse(value []byte, ok bool, err error) *Message
- func NewHasRequest(key string) *Message
- func NewHasResponse(ok bool, err error) *Message
- func NewReleaseRequest(key string, ownerId []byte) *Message
- func NewReleaseResponse(ok bool, err error) *Message
- func NewSetEIfUnsetRequest(key string, value []byte, expireIn, deleteIn uint64) *Message
- func NewSetEIfUnsetResponse(err error) *Message
- func NewSetERequest(key string, value []byte, expireIn, deleteIn uint64) *Message
- func NewSetEResponse(err error) *Message
- func NewSetRequest(key string, value []byte) *Message
- func NewSetResponse(err error) *Message
- type MessageType
- type ServerConfig
- type ServerShard
- type ServerShardType
- type ServerTransportConfig
- type SocketConf
- type TCPConf
Constants ¶
const ( ShardTypeLocalIStore ServerShardType = "local store" ShardTypeRemoteIStore = "remote store" ShardTypeLocalILockManager = "local lock manager" ShardTypeRemoteILockManager = "remote lock manager" )
Variables ¶
This section is empty.
Functions ¶
func CreateLogger ¶
CreateLogger implements the Factory interface - note the error return value
func InitLoggers ¶
func InitLoggers(config ServerConfig)
InitLoggers initializes all loggers with the custom format
Types ¶
type ClientConfig ¶
type ClientConfig struct {
Transport ClientTransportConfig
TimeoutSecond int
}
func (*ClientConfig) String ¶
func (c *ClientConfig) String() string
String returns a formatted string representation of the client configuration
type ClientTransportConfig ¶
type ClientTransportConfig struct {
TCPConf
SocketConf
// Client specific settings
ConnectionsPerEndpoint int
Endpoints []string
RetryCount int
}
func (*ClientTransportConfig) String ¶
func (c *ClientTransportConfig) String() string
type Message ¶
type Message struct {
// Type of message
MsgType MessageType `json:"msg_type"`
// General fields
Key string `json:"key,omitempty"` // Used for: Set, Get, Has, Expire, Delete, Acquire, Release
ExpireIn uint64 `json:"expireIn,omitempty"` // Used for: Set operations
DeleteIn uint64 `json:"deleteIn,omitempty"` // Used for: Set, Acquire operations
Value []byte `json:"value,omitempty"` // Used for: Set (request), Get (response), Acquire (response)
// Response only fields
Ok bool `json:"ok,omitempty"` // Used for: Get, Has, Acquire, Release responses
Err string `json:"err,omitempty"` // Empty if no error, otherwise contains the error message
// Meta information
Meta []byte `json:"meta,omitempty"` // Unused, can be used for additional Adapters
}
Message represents a single message used for both requests and responses. Which fields are used depends on the type of message.
func NewAcquireRequest ¶
NewAcquireRequest creates a new Acquire request
func NewAcquireResponse ¶
NewAcquireResponse creates a new Acquire response
func NewCustomRequest ¶
NewCustomRequest creates a new Custom request
func NewCustomResponse ¶
NewCustomResponse creates a new Custom response
func NewDeleteRequest ¶
NewDeleteRequest creates a new Delete request
func NewDeleteResponse ¶
NewDeleteResponse creates a new Delete response
func NewErrorResponse ¶
NewErrorResponse creates a new Error response
func NewExpireRequest ¶
NewExpireRequest creates a new Expire request
func NewExpireResponse ¶
NewExpireResponse creates a new Expire response
func NewGetRequest ¶
NewGetRequest creates a new Get request
func NewGetResponse ¶
NewGetResponse creates a new Get response
func NewHasRequest ¶
NewHasRequest creates a new Has request
func NewHasResponse ¶
NewHasResponse creates a new Has response
func NewReleaseRequest ¶
NewReleaseRequest creates a new Release request
func NewReleaseResponse ¶
NewReleaseResponse creates a new Release response
func NewSetEIfUnsetRequest ¶
NewSetEIfUnsetRequest creates a new SetEIfUnset request
func NewSetEIfUnsetResponse ¶
NewSetEIfUnsetResponse creates a new SetEIfUnset response
func NewSetERequest ¶
NewSetERequest creates a new SetE request
func NewSetEResponse ¶
NewSetEResponse creates a new SetE response
func NewSetRequest ¶
NewSetRequest creates a new Set request
func NewSetResponse ¶
NewSetResponse creates a new Set response
type MessageType ¶
type MessageType uint8
MessageType defines the type of message used in RPC communication.
const ( MsgTUnknown MessageType = iota MsgTSuccess // Indicates a successful operation MsgTError // Indicates an error occurred MsgTKVSet // Set a key-value pair MsgTKVSetE // Set a key-value pair with expiration MsgTKVSetEIfUnset // Set a key-value pair if not already set MsgTKVExpire // Expire a key MsgTKVDelete // Delete a key-value pair MsgTKVGet // Get a value by key MsgTKVHas // Check if a key exists MsgTLCKAcquire // Acquire a lock MsgTLCKRelease // Release a lock MsgTCustom // Custom operation type )
func (MessageType) MarshalJSON ¶
func (t MessageType) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaller interface for MessageType. This allows MessageType to be serialized as a string in JSON.
func (MessageType) String ¶
func (t MessageType) String() string
String returns the string representation of a MessageType.
func (*MessageType) UnmarshalJSON ¶
func (t *MessageType) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for MessageType. This allows MessageType to be deserialized from a string in JSON.
type ServerConfig ¶
type ServerConfig struct {
// whether to start the server in single node mode or in a cluster
Shards []ServerShard
// Dragenboat parameters
RTTMillisecond uint64
ElectionRTTFactor uint64
HeartbeatRTTFactor uint64
SnapshotEntries uint64
CompactionOverhead uint64
DataDir string
ReplicaID uint64
ClusterMembers map[uint64]string
// remote kvStore parameters
TimeoutSecond int64
// Logging configuration
LogLevel string
// Transport configuration
Transport ServerTransportConfig
}
ServerConfig holds all configuration parameters for the RAFT cluster.
func (*ServerConfig) HasRemoteShard ¶
func (c *ServerConfig) HasRemoteShard() bool
HasRemoteShard checks if the configuration contains any remote shards
func (*ServerConfig) String ¶
func (c *ServerConfig) String() string
String returns a formatted string representation of the configuration
func (*ServerConfig) ToDragonboatConfig ¶
func (c *ServerConfig) ToDragonboatConfig(shardId uint64) config.Config
ToDragonboatConfig converts the ServerConfig to Dragonboat Config
func (*ServerConfig) ToNodeHostConfig ¶
func (c *ServerConfig) ToNodeHostConfig() config.NodeHostConfig
ToNodeHostConfig creates a NodeHostConfig for Dragonboat
type ServerShard ¶
type ServerShard struct {
// ShardID is the ID of the shard
ShardID uint64
// Store is the store for the shard
Type ServerShardType
}
type ServerShardType ¶
type ServerShardType string
type ServerTransportConfig ¶
type ServerTransportConfig struct {
TCPConf
SocketConf
// Server specific settings
WorkersPerConn int
Endpoint string
}
func (*ServerTransportConfig) String ¶
func (c *ServerTransportConfig) String() string
type SocketConf ¶ added in v1.0.1
func (*SocketConf) String ¶ added in v1.0.1
func (c *SocketConf) String() string