Coder Social home page Coder Social logo

himadieievsv / redpulsar Goto Github PK

View Code? Open in Web Editor NEW
12.0 1.0 0.0 338 KB

Distributed locks and other utils, can be used with Jedis client and Lettuce client for Redis

License: Apache License 2.0

Kotlin 99.53% Lua 0.47%
algorythms cloud-computing countdownlatch distributed-algorithms distributed-systems jedis lock redis redlock semaphore lettuce

redpulsar's Introduction

RedPulsar

Release Unit Tests Integration Tests Apache 2.0 licensed codecov Maven Central

What is RedPulsar?

RedPulsar provides Distributed Locks with Redis and other utilities for cloud computing or different kinds of distributed systems. It is minimalistic, lightweight, and easy to use library written in Kotlin and currently can be used with both Jedis or Lettuce clients.

Features

  • Mutex: Distributed lock mechanism on a resource, that uses consensus of the majority of data storage nodes to determine if check obtained successfully.
  • Semaphore: Distributed semaphore implementation allowing multiple number of lock on a resource. It also uses consensus of the majority of data storage nodes to determine if check obtained successfully.
  • SimplifiedMutex: Simplified distributed lock mechanism on a resource. Unlike Mutex it uses single data storage node.
  • ListeningCountDownLatch: Implementation of distributed Count Down Latch, it uses that uses consensus of the majority of data storage instances ensuring count down consistency. ListeningCountDownLatch utilized Redis Pub/Sub mechanism to notify waiting workloads about count reaching zero.

Supporting data storages

Currently, RedPulsar supports Redis as a data storage. It can be used with both Jedis or Lettuce clients.

Java compatibility

Minimal required Java version is 11. RedPulsar project is written in Kotlin, but can be easily used in Java projects too.

Getting started

Gradle dependency:

implementation("com.himadieiev:redpulsar-jedis:1.2.0")
// OR
implementation("com.himadieiev:redpulsar-lettuce:1.2.0")

Development

To build RedPulsar locally, you need to have JDK 11+ installed. To build or test RedPulsar, run the following command:

git clone [email protected]:himadieievsv/redpulsar.git
cd redpulsar

# Code formatting
./gradlew ktlintFormat

# Run all tests
docker-compose up -d
./gradlew test 

# Run only unit tests
./gradlew test -DexcludeTags="integration"

# Build
./gradlew build -x test

# Publish to local maven repository
./gradlew publishToMavenLocal \
  -Psigning.secretKeyRingFile=... \
  -Psigning.password=... \
  -Psigning.keyId=...

Further development

Extending RedPulsar to use other data stores

Currently, all features are implemented with Redis. However, it is possible to extend RedPulsar to use other distributed data stores like AWS DynamoDB / Casandra / ScyllaDB etc. Even it could be implemented with RDBMS like MySQL or PostgreSQL. RedPulsar project have an abstraction level for data storage called Backend. See package com.himadieiev.redpulsar.core.locks.abstracts.backends for details what particular operation should be implemented. New data storage should use a new module and implement same abstractions as current Redis implementations.

Contributing

Contributions are welcome! Please make sure to create Issue first before working on improvements o new features, feel free to submit a Pull Request from a project fork.

Furthers plans

  • Add ListenerLock using Pub/Sub mechanism instead of polling.
  • Add FairLock implementation. It supposed to be a lock that grants lock to the longest waiting thread.
  • Leader election mechanisms.
  • Service discovery service.
  • etc.

redpulsar's People

Contributors

himadieievsv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

redpulsar's Issues

ListenerLock implementation

Summary
It nice to have ListenerLock in oppose to polling locks.
Basic requirements:

  1. Utilizing Pub/Sub mechanism
  2. Still should try to lock with by sending lock call to backend first and then listen for unlock event.

Motivation
Reduce calls to backend attempting to lock resource

It nice to have FairLock

Summary
It nice to have FairLock.
Basic requirements:

  1. Polling mechanism to obtain lock
  2. First client who tried to lock resource should be able to lock resource after its unlock

Motivation
FairLock is attempt to have fairness in lock obtaining racing, if client first requested lock it should be able obtain lock as soon as lock is available.

issue in multiInstanceExecute

multiInstanceExecute can get result properly with strategy waitForMajority.
There are multiple unit tests failures due to that

Load script prior to commands execution on Redis

Summary
Load LUA script prior to commands execution on Redis.
Initialization can be done when object created once per application.

Motivation
All Redis backends are sending LUA scripts as is. Those calls ending up with slitty bigger size.
Reduce that redundancy with using script hash to call it.

Caveats

  • Tracking what Redis instances already has scripts might be challenging if cluster topology changes or individual instance get restarted/replaced.

Provide Leader election algorithm

Summary
It nice to have Leader election algorithm too.
Basic requirements:
TBD

Motivation
Currently it is possible to have only one node in luster to perform workload using locks, but it have many drawbacks for using that approach in cluster with different types of nodes (computing power, network bandwidth, memory capacity, etc ). Ideally nodes should vote on the best candidate.

Workaround
Use locks

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.