Skip to content
This repository has been archived by the owner on Dec 10, 2020. It is now read-only.
/ rplx Public archive

Golang library for multi-master replication integer variables with TTL

License

Notifications You must be signed in to change notification settings

negasus/rplx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RPLX Go Report Card

Pronounced as Replix

Golang library for multi master replication integer variables with TTL support

todo

Usage examples

func main() {
	r = rplx.New(
		rplx.WithRemoteNodesProvider(remoteNodes()),
	)

	ln, err := net.Listen("tcp4", "127.0.0.1:3001")  

	if err != nil {
		panic(err)
	}

	if err := r.StartReplicationServer(ln); err != nil {
		panic(err)
	}
}

func remoteNodes() []*rplx.RemoteNodeOption {
    nodes := make([]*rplx.RemoteNodeOption, 0)

    nodes = append(nodes, &rplx.DefaultRemoteNodeOption("127.0.0.1:3002")) 

    return nodes
}

Also see example in test folder

Metrics

Creates Rplx instance with option WithMetrics() will registers prometheus metrics.

Name Type Description
rplx_variables_got Counter Vector Stores received variables count with fields: 'remote_node_id'
rplx_variables_sent Counter Vector Stores sent variables count with fields: 'remote_node_id'
rplx_variables_sent_response_codes Counter Vector Stores response code, received while variable sent with fields: 'remote_node_id', 'code'
rplx_variables_sent_duration Histogram Vector Stores duration for Sync Request, fields: 'remote_node_id', 'code'

Also included metrics from package github.com/grpc-ecosystem/go-grpc-prometheus

Public API

Get

Get(name string) (int64, error)

Returns variable value or error, if variable expired or not exists

Errors:

  • ErrVariableNotExists
  • ErrVariableExpired

Delete

Delete(name string) error

Delete variable

Errors:

  • ErrVariableNotExists

By fact this method sets TTL for variable to Now - second, send this info to replication and remove from local cache

UpdateTTL

UpdateTTL(name string, ttl time.Time) error

Update TTL for variable

Errors:

  • ErrVariableNotExists

Upsert

Upsert(name string, delta int64)

Update variable value on provided delta, or create new variable, if not exists

All

All() (notExpired map[string]int64, expired map[string]int64)

Returns two maps, where variable name as map item key and variable value as map item value

First return param contains not expires variables. Second param contains expired (while not garbage colleced) variables

Run integration tests

docker-compose up -d
docker build -t client -f ./test/client/Dockerfile .
docker run --rm --net host client
docker-compose down -v

Additional

  • README.RUS.md

About

Golang library for multi-master replication integer variables with TTL

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages