Documentation
¶
Index ¶
- Variables
- func RegisterReplicatorServer(s *grpc.Server, srv ReplicatorServer)
- type Option
- func WithByTickerReplication() Option
- func WithByTickerReplicationInterval(i time.Duration) Option
- func WithGCInterval(interval time.Duration) Option
- func WithLogger(logger *zap.Logger) Option
- func WithNodeMaxBufferSize(s int) Option
- func WithReadOnly() Option
- func WithReplicationChanCap(c int) Option
- type ReplicatorClient
- type ReplicatorServer
- type Rplx
- func (rplx *Rplx) AddNode(nodeID string, addr string, syncInterval time.Duration, opts grpc.DialOption) error
- func (rplx *Rplx) Delete(name string) error
- func (rplx *Rplx) Get(name string) (int64, error)
- func (rplx *Rplx) StartReplicationServer(ln net.Listener) error
- func (rplx *Rplx) Sync(ctx context.Context, mes *SyncRequest) (*SyncResponse, error)
- func (rplx *Rplx) UpdateTTL(name string, ttl time.Time) error
- func (rplx *Rplx) Upsert(name string, delta int64)
- type SyncNodeValue
- func (*SyncNodeValue) Descriptor() ([]byte, []int)
- func (m *SyncNodeValue) GetID() string
- func (m *SyncNodeValue) GetStamp() int64
- func (m *SyncNodeValue) GetValue() int64
- func (*SyncNodeValue) ProtoMessage()
- func (m *SyncNodeValue) Reset()
- func (m *SyncNodeValue) String() string
- func (m *SyncNodeValue) XXX_DiscardUnknown()
- func (m *SyncNodeValue) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (dst *SyncNodeValue) XXX_Merge(src proto.Message)
- func (m *SyncNodeValue) XXX_Size() int
- func (m *SyncNodeValue) XXX_Unmarshal(b []byte) error
- type SyncRequest
- func (*SyncRequest) Descriptor() ([]byte, []int)
- func (m *SyncRequest) GetNodeID() string
- func (m *SyncRequest) GetVariables() map[string]*SyncVariable
- func (*SyncRequest) ProtoMessage()
- func (m *SyncRequest) Reset()
- func (m *SyncRequest) String() string
- func (m *SyncRequest) XXX_DiscardUnknown()
- func (m *SyncRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (dst *SyncRequest) XXX_Merge(src proto.Message)
- func (m *SyncRequest) XXX_Size() int
- func (m *SyncRequest) XXX_Unmarshal(b []byte) error
- type SyncResponse
- func (*SyncResponse) Descriptor() ([]byte, []int)
- func (m *SyncResponse) GetCode() int64
- func (*SyncResponse) ProtoMessage()
- func (m *SyncResponse) Reset()
- func (m *SyncResponse) String() string
- func (m *SyncResponse) XXX_DiscardUnknown()
- func (m *SyncResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (dst *SyncResponse) XXX_Merge(src proto.Message)
- func (m *SyncResponse) XXX_Size() int
- func (m *SyncResponse) XXX_Unmarshal(b []byte) error
- type SyncVariable
- func (*SyncVariable) Descriptor() ([]byte, []int)
- func (m *SyncVariable) GetNodesValues() map[string]*SyncNodeValue
- func (m *SyncVariable) GetTTL() int64
- func (m *SyncVariable) GetTTLStamp() int64
- func (*SyncVariable) ProtoMessage()
- func (m *SyncVariable) Reset()
- func (m *SyncVariable) String() string
- func (m *SyncVariable) XXX_DiscardUnknown()
- func (m *SyncVariable) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (dst *SyncVariable) XXX_Merge(src proto.Message)
- func (m *SyncVariable) XXX_Size() int
- func (m *SyncVariable) XXX_Unmarshal(b []byte) error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrVariableNotExists describe error for non exists variable ErrVariableNotExists = errors.New("variable not exists") // ErrTTLLessThanNow describe error for func UpdateTTL ErrTTLLessThanNow = errors.New("TTL less than Now") )
var ( // ErrNodeAlreadyExists describe error for add already exists node ErrNodeAlreadyExists = errors.New("node already exists") )
Functions ¶
func RegisterReplicatorServer ¶
func RegisterReplicatorServer(s *grpc.Server, srv ReplicatorServer)
Types ¶
type Option ¶
type Option func(*Rplx)
Option describe Rplx option
func WithByTickerReplication ¶ added in v0.1.0
func WithByTickerReplication() Option
WithByTickerReplication option for run background by ticker replication
func WithByTickerReplicationInterval ¶ added in v0.1.0
WithByTickerReplicationInterval option for set by ticker replication interval
func WithGCInterval ¶
WithGCInterval option for set garbage collect interval
func WithNodeMaxBufferSize ¶
WithNodeMaxBufferSize option for set node max buffer size
func WithReadOnly ¶ added in v0.1.0
func WithReadOnly() Option
WithReadOnly option sets read only mode
func WithReplicationChanCap ¶
WithReplicationChanCap option for set replication channel capacity
type ReplicatorClient ¶
type ReplicatorClient interface {
Sync(ctx context.Context, in *SyncRequest, opts ...grpc.CallOption) (*SyncResponse, error)
}
ReplicatorClient is the client API for Replicator service.
For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
func NewReplicatorClient ¶
func NewReplicatorClient(cc *grpc.ClientConn) ReplicatorClient
type ReplicatorServer ¶
type ReplicatorServer interface {
Sync(context.Context, *SyncRequest) (*SyncResponse, error)
}
ReplicatorServer is the server API for Replicator service.
type Rplx ¶
type Rplx struct {
// contains filtered or unexported fields
}
Rplx describe main Rplx object
func (*Rplx) AddNode ¶
func (rplx *Rplx) AddNode(nodeID string, addr string, syncInterval time.Duration, opts grpc.DialOption) error
AddNode adds and serve new remote node
func (*Rplx) Delete ¶
Delete sets for variable ttl with -1 sec from Now, sends variable to replication (update TTL on clients) and remove variable from rplx.variables map
func (*Rplx) Get ¶
Get returns variable v or error if variable not exists or expired if variable expired, removes variable from rplx.variables map
func (*Rplx) StartReplicationServer ¶
StartReplicationServer starts grpc server for receive sync messages from remote nodes
func (*Rplx) Sync ¶
func (rplx *Rplx) Sync(ctx context.Context, mes *SyncRequest) (*SyncResponse, error)
Sync is GRPC function, fired on incoming sync message
type SyncNodeValue ¶
type SyncNodeValue struct {
ID string `protobuf:"bytes,1,opt,name=ID,proto3" json:"ID,omitempty"`
Value int64 `protobuf:"varint,2,opt,name=Value,proto3" json:"Value,omitempty"`
Stamp int64 `protobuf:"varint,3,opt,name=Stamp,proto3" json:"Stamp,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (*SyncNodeValue) Descriptor ¶
func (*SyncNodeValue) Descriptor() ([]byte, []int)
func (*SyncNodeValue) GetID ¶
func (m *SyncNodeValue) GetID() string
func (*SyncNodeValue) GetStamp ¶
func (m *SyncNodeValue) GetStamp() int64
func (*SyncNodeValue) GetValue ¶
func (m *SyncNodeValue) GetValue() int64
func (*SyncNodeValue) ProtoMessage ¶
func (*SyncNodeValue) ProtoMessage()
func (*SyncNodeValue) Reset ¶
func (m *SyncNodeValue) Reset()
func (*SyncNodeValue) String ¶
func (m *SyncNodeValue) String() string
func (*SyncNodeValue) XXX_DiscardUnknown ¶
func (m *SyncNodeValue) XXX_DiscardUnknown()
func (*SyncNodeValue) XXX_Marshal ¶
func (m *SyncNodeValue) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*SyncNodeValue) XXX_Merge ¶
func (dst *SyncNodeValue) XXX_Merge(src proto.Message)
func (*SyncNodeValue) XXX_Size ¶
func (m *SyncNodeValue) XXX_Size() int
func (*SyncNodeValue) XXX_Unmarshal ¶
func (m *SyncNodeValue) XXX_Unmarshal(b []byte) error
type SyncRequest ¶
type SyncRequest struct {
NodeID string `protobuf:"bytes,1,opt,name=NodeID,proto3" json:"NodeID,omitempty"`
// map key - variable name
Variables map[string]*SyncVariable `` /* 159-byte string literal not displayed */
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (*SyncRequest) Descriptor ¶
func (*SyncRequest) Descriptor() ([]byte, []int)
func (*SyncRequest) GetNodeID ¶
func (m *SyncRequest) GetNodeID() string
func (*SyncRequest) GetVariables ¶
func (m *SyncRequest) GetVariables() map[string]*SyncVariable
func (*SyncRequest) ProtoMessage ¶
func (*SyncRequest) ProtoMessage()
func (*SyncRequest) Reset ¶
func (m *SyncRequest) Reset()
func (*SyncRequest) String ¶
func (m *SyncRequest) String() string
func (*SyncRequest) XXX_DiscardUnknown ¶
func (m *SyncRequest) XXX_DiscardUnknown()
func (*SyncRequest) XXX_Marshal ¶
func (m *SyncRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*SyncRequest) XXX_Merge ¶
func (dst *SyncRequest) XXX_Merge(src proto.Message)
func (*SyncRequest) XXX_Size ¶
func (m *SyncRequest) XXX_Size() int
func (*SyncRequest) XXX_Unmarshal ¶
func (m *SyncRequest) XXX_Unmarshal(b []byte) error
type SyncResponse ¶
type SyncResponse struct {
Code int64 `protobuf:"varint,1,opt,name=Code,proto3" json:"Code,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (*SyncResponse) Descriptor ¶
func (*SyncResponse) Descriptor() ([]byte, []int)
func (*SyncResponse) GetCode ¶
func (m *SyncResponse) GetCode() int64
func (*SyncResponse) ProtoMessage ¶
func (*SyncResponse) ProtoMessage()
func (*SyncResponse) Reset ¶
func (m *SyncResponse) Reset()
func (*SyncResponse) String ¶
func (m *SyncResponse) String() string
func (*SyncResponse) XXX_DiscardUnknown ¶
func (m *SyncResponse) XXX_DiscardUnknown()
func (*SyncResponse) XXX_Marshal ¶
func (m *SyncResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*SyncResponse) XXX_Merge ¶
func (dst *SyncResponse) XXX_Merge(src proto.Message)
func (*SyncResponse) XXX_Size ¶
func (m *SyncResponse) XXX_Size() int
func (*SyncResponse) XXX_Unmarshal ¶
func (m *SyncResponse) XXX_Unmarshal(b []byte) error
type SyncVariable ¶
type SyncVariable struct {
// map key - nodeID
NodesValues map[string]*SyncNodeValue `` /* 163-byte string literal not displayed */
TTL int64 `protobuf:"varint,2,opt,name=TTL,proto3" json:"TTL,omitempty"`
TTLStamp int64 `protobuf:"varint,3,opt,name=TTLStamp,proto3" json:"TTLStamp,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (*SyncVariable) Descriptor ¶
func (*SyncVariable) Descriptor() ([]byte, []int)
func (*SyncVariable) GetNodesValues ¶
func (m *SyncVariable) GetNodesValues() map[string]*SyncNodeValue
func (*SyncVariable) GetTTL ¶
func (m *SyncVariable) GetTTL() int64
func (*SyncVariable) GetTTLStamp ¶
func (m *SyncVariable) GetTTLStamp() int64
func (*SyncVariable) ProtoMessage ¶
func (*SyncVariable) ProtoMessage()
func (*SyncVariable) Reset ¶
func (m *SyncVariable) Reset()
func (*SyncVariable) String ¶
func (m *SyncVariable) String() string
func (*SyncVariable) XXX_DiscardUnknown ¶
func (m *SyncVariable) XXX_DiscardUnknown()
func (*SyncVariable) XXX_Marshal ¶
func (m *SyncVariable) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*SyncVariable) XXX_Merge ¶
func (dst *SyncVariable) XXX_Merge(src proto.Message)
func (*SyncVariable) XXX_Size ¶
func (m *SyncVariable) XXX_Size() int
func (*SyncVariable) XXX_Unmarshal ¶
func (m *SyncVariable) XXX_Unmarshal(b []byte) error