rplx

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2019 License: MIT Imports: 14 Imported by: 1

README

RPLX Go Report Card

Golang library for multi master replication integer variables with TTL support

todo

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrVariableNotExists returns if variable not exists
	ErrVariableNotExists = errors.New("variable not exists")
	ErrVariableExpired   = errors.New("variable expired")
)

Functions

func RegisterReplicatorServer

func RegisterReplicatorServer(s *grpc.Server, srv ReplicatorServer)

Types

type HelloRequest added in v0.2.0

type HelloRequest struct {
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*HelloRequest) Descriptor added in v0.2.0

func (*HelloRequest) Descriptor() ([]byte, []int)

func (*HelloRequest) ProtoMessage added in v0.2.0

func (*HelloRequest) ProtoMessage()

func (*HelloRequest) Reset added in v0.2.0

func (m *HelloRequest) Reset()

func (*HelloRequest) String added in v0.2.0

func (m *HelloRequest) String() string

func (*HelloRequest) XXX_DiscardUnknown added in v0.2.0

func (m *HelloRequest) XXX_DiscardUnknown()

func (*HelloRequest) XXX_Marshal added in v0.2.0

func (m *HelloRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*HelloRequest) XXX_Merge added in v0.2.0

func (dst *HelloRequest) XXX_Merge(src proto.Message)

func (*HelloRequest) XXX_Size added in v0.2.0

func (m *HelloRequest) XXX_Size() int

func (*HelloRequest) XXX_Unmarshal added in v0.2.0

func (m *HelloRequest) XXX_Unmarshal(b []byte) error

type HelloResponse added in v0.2.0

type HelloResponse struct {
	ID                   string   `protobuf:"bytes,1,opt,name=remoteNodeID,proto3" json:"remoteNodeID,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*HelloResponse) Descriptor added in v0.2.0

func (*HelloResponse) Descriptor() ([]byte, []int)

func (*HelloResponse) GetID added in v0.2.0

func (m *HelloResponse) GetID() string

func (*HelloResponse) ProtoMessage added in v0.2.0

func (*HelloResponse) ProtoMessage()

func (*HelloResponse) Reset added in v0.2.0

func (m *HelloResponse) Reset()

func (*HelloResponse) String added in v0.2.0

func (m *HelloResponse) String() string

func (*HelloResponse) XXX_DiscardUnknown added in v0.2.0

func (m *HelloResponse) XXX_DiscardUnknown()

func (*HelloResponse) XXX_Marshal added in v0.2.0

func (m *HelloResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*HelloResponse) XXX_Merge added in v0.2.0

func (dst *HelloResponse) XXX_Merge(src proto.Message)

func (*HelloResponse) XXX_Size added in v0.2.0

func (m *HelloResponse) XXX_Size() int

func (*HelloResponse) XXX_Unmarshal added in v0.2.0

func (m *HelloResponse) XXX_Unmarshal(b []byte) error

type Option

type Option func(*Rplx)

Option describe Rplx option

func WithGCInterval

func WithGCInterval(interval time.Duration) Option

WithGCInterval option for set garbage collect interval

func WithLogger

func WithLogger(logger *zap.Logger) Option

WithLogger option for specify logger

func WithNodeID added in v0.2.0

func WithNodeID(nodeID string) Option

WithNodeID option for specify rplx node name

func WithNodeMaxBufferSize

func WithNodeMaxBufferSize(s int) Option

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

func WithReplicationChanCap(c int) Option

WithReplicationChanCap option for set replication channel capacity

type ReplicatorClient

type ReplicatorClient interface {
	Hello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloResponse, error)
	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 {
	Hello(context.Context, *HelloRequest) (*HelloResponse, error)
	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 New

func New(opts ...Option) *Rplx

New creates new Rplx

func (*Rplx) AddRemoteNode added in v0.2.0

func (rplx *Rplx) AddRemoteNode(addr string, syncInterval time.Duration, opts grpc.DialOption) error

AddRemoteNode adds and listenReplicationChannel new remote node

func (*Rplx) Delete

func (rplx *Rplx) Delete(name string) error

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

func (rplx *Rplx) Get(name string) (int64, error)

Get returns variable v or error if variable not exists or expired if variable expired, removes variable from rplx.variables map

func (*Rplx) Hello added in v0.2.0

func (rplx *Rplx) Hello(ctx context.Context, req *HelloRequest) (*HelloResponse, error)

Hello is implementation grpc method for get Hello request

func (*Rplx) StartReplicationServer

func (rplx *Rplx) StartReplicationServer(ln net.Listener) error

StartReplicationServer starts grpc server for receive sync messages from remote nodes

func (*Rplx) Sync

func (rplx *Rplx) Sync(ctx context.Context, req *SyncRequest) (*SyncResponse, error)

Sync is GRPC function, fired on incoming sync message

func (*Rplx) UpdateTTL

func (rplx *Rplx) UpdateTTL(name string, ttl time.Time) error

UpdateTTL updates TTL for variable or return error if variable not exists

func (*Rplx) Upsert

func (rplx *Rplx) Upsert(name string, delta int64)

Upsert change variable on delta or create variable, if not exists

type SyncNodeValue

type SyncNodeValue struct {
	Value                int64    `protobuf:"varint,1,opt,name=Value,proto3" json:"Value,omitempty"`
	Version              int64    `protobuf:"varint,2,opt,name=Version,proto3" json:"Version,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*SyncNodeValue) Descriptor

func (*SyncNodeValue) Descriptor() ([]byte, []int)

func (*SyncNodeValue) GetValue

func (m *SyncNodeValue) GetValue() int64

func (*SyncNodeValue) GetVersion added in v0.2.0

func (m *SyncNodeValue) GetVersion() 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"`
	TTLVersion           int64                     `protobuf:"varint,3,opt,name=TTLVersion,proto3" json:"TTLVersion,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) GetTTLVersion added in v0.2.0

func (m *SyncVariable) GetTTLVersion() 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

Jump to

Keyboard shortcuts

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