Giter Site home page Giter Site logo

negasus / rplx Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 3.54 MB

Golang library for multi-master replication integer variables with TTL

License: MIT License

Makefile 0.35% Go 99.15% Dockerfile 0.50%
go golang replication multimaster golang-library

rplx's Introduction

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

rplx's People

Contributors

negasus avatar

Stargazers

 avatar

Watchers

 avatar

rplx's Issues

Implement compacting values from not exists nodes

Save memory proposal.

If many nodes leaved cluster (and possible joined to cluster with new ID), its values with old IDs will be take memory forever.

Consider compacting proccess for orphans values to one virtual node value.

For example. Node2 and greater are orphans

Var1:
node1: 100
node2: 200
node3: 300
node4: 400

After compacting

Var1:
node1: 200
SpecialVirtualNode: 200+300+400

Add prometheus metrics

Add prometheus metrics

  • count of incoming/outcomping sync requests
  • size of sync requiests
  • count of remote nodes
    etc.

Possible write to closed channel

While closing channel in node.go#105 close(n.syncQueue), possible write to channel in node_sync.go#16 case n.syncQueue <- struct{}{}:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.