Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ostinelli/ram

A distributed KV store for Erlang and Elixir.
https://github.com/ostinelli/ram

Last synced: about 2 months ago
JSON representation

A distributed KV store for Erlang and Elixir.

Awesome Lists containing this project

README

        

![CI](https://github.com/ostinelli/ram/actions/workflows/ci.yml/badge.svg) [![Hex pm](https://img.shields.io/hexpm/v/ram.svg)](https://hex.pm/packages/ram)

# Ram
**Ram** is a distributed KV store for Erlang and Elixir.
It chooses Consistency over Availability by using the [Raft Consensus Algorithm](https://raft.github.io/),
and is based on Rabbit MQ's implementation [Ra](https://github.com/rabbitmq/ra).

[[Documentation](https://hexdocs.pm/ram/)]

## Installation

### For Elixir
Add it to your deps:

```elixir
defp deps do
[{:ram, "~> 0.5"}]
end
```

### For Erlang
If you're using [rebar3](https://github.com/erlang/rebar3), add `ram` as a dependency in your project's `rebar.config` file:

```erlang
{deps, [
{ram, {git, "git://github.com/ostinelli/ram.git", {tag, "0.5.0"}}}
]}.
```
Or, if you're using [Hex.pm](https://hex.pm/) as package manager (with the [rebar3_hex](https://github.com/hexpm/rebar3_hex) plugin):

```erlang
{deps, [
{ram, "0.5.0"}
]}.
```

## Quick start

> Note: this example below assumes that you are familiar with [Distributed Erlang](https://www.erlang.org/doc/reference_manual/distributed.html).

### Elixir
Open 3 shells and start three Erlang nodes:

```bash
$ iex --name [email protected] -S mix
```

```bash
$ iex --name [email protected] -S mix
```

```bash
$ iex --name [email protected] -S mix
```

Choose the main node (for instance `[email protected]`), and on that node run the following.

First, create an Erlang cluster by connecting all nodes:
```erlang
iex([email protected])1> nodes = [:"[email protected]", :"[email protected]", :"[email protected]"]
[:"[email protected]", :"[email protected]", :"[email protected]"]
iex([email protected])2> for node <- nodes, do: Node.connect(node)
[true, true, true]
```

Now we can create a Ram cluster running on these nodes:

```erlang
iex([email protected])3> :ram.start_cluster(nodes)
13:03:12.902 [info] RAM[[email protected]] Cluster started on [:"[email protected]", :"[email protected]", :"[email protected]"]
:ok
```

You can now store and retrieve values from all the nodes:

```erlang
iex([email protected])4> :ram.put("key", "value")
:ok
iex([email protected])5> :ram.get("key")
"value"
```

```erlang
iex([email protected])1> :ram.get("key")
"value"
```

```erlang
iex([email protected])1> :ram.get("key")
"value"
```

### Erlang
Open 3 shells and start three Erlang nodes:

```bash
$ rebar3 shell --name [email protected]
```

```bash
$ rebar3 shell --name [email protected]
```

```bash
$ rebar3 shell --name [email protected]
```

Choose the main node (for instance `[email protected]`), and on that node run the following.

First, create an Erlang cluster by connecting all nodes:
```erlang
([email protected])1> Nodes = ['[email protected]', '[email protected]', '[email protected]'].
['[email protected]','[email protected]','[email protected]']
([email protected])2> [net_kernel:connect_node(Node) || Node <- Nodes].
[true,true,true]
```

Now we can create a Ram cluster running on these nodes:

```erlang
([email protected])3> ram:start_cluster(Nodes).
=INFO REPORT==== 4-Jan-2022::12:46:34.071524 ===
RAM[[email protected]] Cluster started on ['[email protected]','[email protected]',
'[email protected]']
ok
```

You can now store and retrieve values from all the nodes:

```erlang
([email protected])4> ram:put("key", "value").
ok
([email protected])5> ram:get("key").
"value"
```

```erlang
([email protected])1> ram:get("key").
"value"
```

```erlang
([email protected])1> ram:get("key").
"value"
```

## Configuration Options

### release_cursor_count
Specifies after how many logs `ram` should create a `ra` snapshot. Defaults to `1000`.

#### Elixir

```elixir
config :ram,
release_cursor_count: 1000
```

#### Erlang

```erlang
{ram, [
{release_cursor_count, 1000}
]}
```

### Other settings
Since Ram uses [Ra](https://github.com/rabbitmq/ra), please refer to Ra's
[documentation](https://github.com/rabbitmq/ra#configuration-reference) on available options.

## Contributing
So you want to contribute? That's great! Please follow the guidelines below. It will make it easier to get merged in.

Before implementing a new feature, please submit a ticket to discuss what you intend to do.
Your feature might already be in the works, or an alternative implementation might have already been discussed.

Do not commit to master in your fork. Provide a clean branch without merge commits.
Every pull request should have its own topic branch. In this way, every additional adjustments to the original pull request
might be done easily, and squashed with `git rebase -i`. The updated branch will be visible in the same pull request,
so there will be no need to open new pull requests when there are changes to be applied.

Ensure that proper testing is included. To run Ram tests you simply have to be in the project's root directory and run:

```bash
$ make test
```

## License

Copyright (c) 2021-2022 Roberto Ostinelli.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.