• Stars
    star
    304
  • Rank 132,077 (Top 3 %)
  • Language
    Erlang
  • License
    Apache License 2.0
  • Created about 3 years ago
  • Updated 21 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Khepri is a tree-like replicated on-disk database library for Erlang and Elixir.

The Khepri database library

Hex.pm Test Codecov

Khepri is a tree-like replicated on-disk database library for Erlang and Elixir.

The basics

Data are stored in a tree structure. Each node in the tree is referenced by its path from the root node. A path is a list of Erlang atoms and/or binaries. For ease of use, Unix-like path strings are accepted as well.

For consistency and replication and to manage data on disk, Khepri relies on Ra, an Erlang implementation of the Raft consensus algorithm. In Ra parlance, Khepri is a state machine in a Ra cluster.

Project maturity

Khepri is still under active development and should be considered Beta at this stage.

Known limitations

Khepri currently hosts the entire data set in memory as well as on disk, so there is a realistic limit to how large a data set can be stored in it.

For this reason and others, storing blobs of files in Khepri is not recommended. For that, use an external blob store.

Documentation

Getting started

Add as a dependency

Add Khepri as a dependency of your project:

Using Rebar:

%% In rebar.config
{deps, [{khepri, "0.13.0"}]}.

Using Erlang.mk:

# In your Makefile
DEPS += khepri
dep_khepri = hex 0.13.0

Using Mix:

# In mix.exs
defp deps do
  [
    {:khepri, "0.13.0"}
  ]
end

Start default Khepri store

To start the default store, use khepri:start/0:

khepri:start().

The default Khepri store uses the default Ra system. Data is stored in the configured default Ra system data directory, which is khepri#$NODENAME in the current working directory.

It is fine to get started and play with Khepri. However, it is recommended to configure your own Ra system and Ra cluster to select the directory where data is stored and to be able to have multiple Khepri database instances running on the same Erlang node.

Insert data

Here's how to insert a piece of data, say, an email address of Alice:

%% Using a native path:
ok = khepri:put([emails, <<"alice">>], "[email protected]").

%% Using a Unix-like path string:
ok = khepri:put("/:emails/alice", "[email protected]").

Read data back

To get Alice's email address back, query the same path:

{ok, "[email protected]"} = khepri:get("/:emails/alice").

Delete data

To delete Alice's email address:

ok = khepri:delete("/:emails/alice").

The emails parent node was automatically created when the alice node was inserted earlier. It has no data attached to it. However, after the alice node is deleted, the emails node will stay around. It is possible to tell Khepri to automatically remove emails as soon as its last child node is deleted. Khepri supports many more conditions by the way.

Transactional Operations

It is also possible to perform transactional queries and updates using anonymous functions, similar to Mnesia:

%% This transaction checks the quantity of wood left and returns `true` or
%% `false` if we need to process a new order.
khepri:transaction(
    fun() ->
        case khepri_tx:get([stock, wood]) of
            {ok, Quantity} when Quantity >= 100 ->
                %% There is enough wood left.
                false;
            _ ->
                %% There is less than 100 pieces of wood, or there is none
                %% at all (the node does not exist in Khepri). We need to
                %% request a new order.
                ok = khepri_tx:put([order, wood], 1000),
                true
        end
    end).

In this example, the transaction returns a boolean indicating if orders are ready to be processed. It does not send a message to a process or write something on disk for instance.

Because of the nature of the Raft consensus algorithm, transactions are not allowed to have side effects or take non-deterministic inputs such as the node name or the current date & time.

Triggers

Khepri supports stored procedures and triggers. They allow to store code in the database itself and automatically execute it after some event occurs.

  1. Store an anonymous function in the tree:

    StoredProcPath = [path, to, stored_procedure],
    
    Fun = fun(Props) ->
              #{path := Path,
                on_action := Action} = Props
          end,
    
    khepri:put(StoreId, StoredProcPath, Fun).
  2. Register a trigger using an event filter:

    %% A path is automatically considered a tree event filter.
    EventFilter = [stock, wood, <<"oak">>],
    
    ok = khepri:register_trigger(
           StoreId,
           TriggerId,
           EventFilter,
           StoredProcPath).

In the example above, as soon as the [stock, wood, <<"oak">>] node is created, updated or deleted, the anonymous function will be executed.

The function is executed at least once on the Ra leader's Erlang node. It may be executed multiple times if the leader changes and thus should be idempotent.

Unlike transaction functions, stored procedures may have whatever side effects they want.

Migrating from Mnesia

To help you migrate an existing Mnesia database, you can use the khepri_mnesia_migration application. It can take care of:

  • synchronizing the cluster membership and
  • copying Mnesia tables to a Khepri store.

How to build

Build

rebar3 compile

Build documentation

rebar3 edoc

Test

rebar3 xref
rebar3 eunit
rebar3 proper
rebar3 ct --sname ct
rebar3 as test dialyzer

Copyright and License

© 2021-2024 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.

This work is dual-licensed under the Apache License 2.0 and the Mozilla Public License 2.0. Users can choose any of these licenses according to their needs.

The logo (doc/khepri-logo.svg) and the favicon (doc/khepri-favicon.svg) are based on the following two resources:

SPDX-License-Identifier: Apache-2.0 OR MPL-2.0

More Repositories

1

rabbitmq-server

Open source RabbitMQ: core server and tier 1 (built-in) plugins
Starlark
11,564
star
2

rabbitmq-tutorials

Tutorials for using RabbitMQ in various ways
Java
6,393
star
3

rabbitmq-dotnet-client

RabbitMQ .NET client for .NET Standard 2.0+ and .NET 4.6.2+
C#
2,031
star
4

rabbitmq-delayed-message-exchange

Delayed Messaging for RabbitMQ
Erlang
1,898
star
5

internals

High level architecture overview
1,438
star
6

rabbitmq-java-client

RabbitMQ Java client
Java
1,215
star
7

amqp091-go

An AMQP 0-9-1 Go client maintained by the RabbitMQ team. Originally by @streadway: `streadway/amqp`
Go
1,198
star
8

cluster-operator

RabbitMQ Cluster Kubernetes Operator
Go
791
star
9

ra

A Raft implementation for Erlang and Elixir that strives to be efficient and make it easier to use multiple Raft clusters in a single system.
Erlang
778
star
10

rabbitmq-website

RabbitMQ website
JavaScript
665
star
11

erlang-rpm

Latest Erlang/OTP releases packaged as a zero dependency RPM, just enough for running RabbitMQ
Shell
541
star
12

rabbitmq-management

RabbitMQ Management UI and HTTP API
Erlang
368
star
13

rabbitmq-perf-test

A load testing tool
Java
338
star
14

tls-gen

Generates self-signed x509/TLS/SSL certificates useful for development
Python
336
star
15

erlando

Erlando
Erlang
306
star
16

rabbitmq-sharding

Sharded logical queues for RabbitMQ: a queue type which provides improved parallelism and thoughput at the cost of total ordering
Erlang
300
star
17

rabbitmq-peer-discovery-k8s

Kubernetes-based peer discovery mechanism for RabbitMQ
Erlang
296
star
18

rabbitmq-objc-client

RabbitMQ client for Objective-C and Swift
Objective-C
238
star
19

chef-cookbook

Development repository for Chef cookbook RabbitMQ
Ruby
211
star
20

rmq-0mq

ZeroMQ support in RabbitMQ
Erlang
210
star
21

rabbitmq-consistent-hash-exchange

RabbitMQ Consistent Hash Exchange Type
Erlang
207
star
22

rabbitmq-auth-backend-http

HTTP-based authorisation and authentication for RabbitMQ
Makefile
199
star
23

rabbitmq-erlang-client

Erlang client for RabbitMQ
Erlang
185
star
24

rabbitmq-mqtt

RabbitMQ MQTT plugin
Erlang
173
star
25

rabbitmq-stream-go-client

A client library for RabbitMQ streams
Go
152
star
26

rabbitmq-prometheus

A minimalistic Prometheus exporter of core RabbitMQ metrics
Erlang
143
star
27

looking_glass

An Erlang/Elixir/BEAM profiler tool
Erlang
140
star
28

hop

RabbitMQ HTTP API client for Java, Groovy, and other JVM languages
Java
135
star
29

rabbitmq-stream-rust-client

A client library for RabbitMQ streams
Rust
122
star
30

messaging-topology-operator

RabbitMQ messaging topology operator
Go
111
star
31

rabbitmq-cli

Command line tools for RabbitMQ
Elixir
104
star
32

rabbitmq-stream-dotnet-client

RabbitMQ client for the stream protocol
C#
100
star
33

rabbitmq-amqp1.0

AMQP 1.0 support for RabbitMQ
Erlang
93
star
34

rabbitmq-web-stomp-examples

Makefile
92
star
35

rabbitmq-web-stomp

Provides support for STOMP over WebSockets
Erlang
89
star
36

rabbitmq-recent-history-exchange

RabbitMQ Recent History Exchange
Makefile
82
star
37

diy-kubernetes-examples

Examples that demonstrate how deploy a RabbitMQ cluster to Kubernetes, the DIY way
Makefile
82
star
38

rabbitmq-event-exchange

Expose broker events as messages
Erlang
78
star
39

rabbitmq-clusterer

This project is ABANDONWARE. Use https://www.rabbitmq.com/cluster-formation.html instead.
Erlang
72
star
40

rabbitmq-message-timestamp

A RabbitMQ plugin that adds a timestamp to all incoming messages
Makefile
72
star
41

rabbitmq-common

Common library used by rabbitmq-server and rabbitmq-erlang-client
Erlang
66
star
42

rabbitmq-c

The official rabbitmq-c sources have moved to:
C
65
star
43

tgir

Official repository for Thank Goodness It's RabbitMQ (TGIR)!
Makefile
62
star
44

rabbit-socks

Websocket and Socket.IO support for RabbitMQ (deprecated -- see https://github.com/sockjs/sockjs-erlang instead)
Erlang
58
star
45

rabbitmq-jms-client

RabbitMQ JMS client
Java
57
star
46

rabbitmq-web-mqtt

Provides support for MQTT over WebSockets
Erlang
55
star
47

rabbitmq-shovel

RabbitMQ Shovel plugin
Erlang
53
star
48

rabbitmq-top

Adds top-like information on the Erlang VM to the management plugin.
Makefile
53
star
49

rabbitmq-stream-java-client

RabbitMQ Stream Java Client
Java
52
star
50

rabbitmq-auth-mechanism-ssl

RabbitMQ TLS (x509 certificate) authentication mechanism
Makefile
52
star
51

aten

An adaptive accrual node failure detection library for Elixir and Erlang
Erlang
50
star
52

rabbitmq-stomp

RabbitMQ STOMP plugin
Erlang
49
star
53

rabbitmq-tracing

RabbitMQ Tracing
Erlang
48
star
54

mnevis

Raft-based, consensus oriented implementation of Mnesia transactions
Erlang
48
star
55

rabbitmq-priority-queue

Priority Queues
46
star
56

gen-batch-server

A generic batching server for Erlang and Elixir
Erlang
45
star
57

osiris

Log based streaming subsystem for RabbitMQ
Erlang
44
star
58

rabbitmq-peer-discovery-consul

Consul-based peer discovery backend for RabbitMQ 3.7.0+
Erlang
40
star
59

rabbitmq-management-visualiser

RabbitMQ Topology Visualiser
JavaScript
40
star
60

rabbitmq-federation

RabbitMQ Federation plugin
Erlang
39
star
61

rabbitmq-oauth2-tutorial

Explore integration of RabbitMQ with Oauth 2.0 auth backend plugin
Shell
39
star
62

rabbitmq-auth-backend-oauth2

RabbitMQ authorization backend that uses OAuth 2.0 (JWT) tokens
Erlang
38
star
63

rabbitmq-codegen

RabbitMQ protocol code-generation and machine-readable spec
Python
36
star
64

support-tools

A staging area for various support and troubleshooting tools that are not (or not yet) included into RabbitMQ distribution
Shell
35
star
65

rabbitmq-perf-html

Web page to view performance results
JavaScript
33
star
66

rules_erlang

Bazel rules for building Erlang applications and libraries
Starlark
32
star
67

rabbitmq-public-umbrella

Work with ease on multiple RabbitMQ sub-projects, e.g. core broker, plugins and some client libraries
Makefile
32
star
68

rabbitmq-web-mqtt-examples

Examples for the Web MQTT plugin
JavaScript
31
star
69

rabbitmq-smtp

RabbitMQ SMTP gateway
Erlang
31
star
70

ra-kv-store

Raft-based key-value store
Clojure
31
star
71

rabbitmq-metronome

RabbitMQ example plugin
Makefile
27
star
72

rabbitmq-rtopic-exchange

RabbitMQ Reverse Topic Exchange
Erlang
26
star
73

workloads

Continuous validation of RabbitMQ workloads
JavaScript
24
star
74

horus

Erlang library to create standalone modules from anonymous functions
Erlang
24
star
75

rabbitmq-tracer

AMQP 0-9-1 protocol analyzer
Java
23
star
76

rabbitmq-shovel-management

RabbitMQ Shovel Management
Makefile
23
star
77

rabbitmq-peer-discovery-aws

AWS-based peer discovery backend for RabbitMQ 3.7.0+
Erlang
23
star
78

rabbitmq-auth-backend-ldap

RabbitMQ LDAP authentication
Erlang
22
star
79

rabbitmq-auth-backend-amqp

Authentication over AMQP RPC
Erlang
21
star
80

rabbitmq-amqp1.0-client

Erlang AMQP 1.0 client
Erlang
20
star
81

erlang-data-structures

Erlang Data Structures
Erlang
20
star
82

rabbitmq-management-themes

Makefile
19
star
83

rabbitmq-service-nodejs-sample

A simple node.js sample app for the RabbitMQ service/add-on
JavaScript
18
star
84

rabbitmq-auth-backend-oauth2-spike

See rabbitmq/rabbitmq-auth-backend-oauth2 instead.
Erlang
17
star
85

rabbitmq-msg-store-index-eleveldb

LevelDB-based message store index for RabbitMQ
Erlang
17
star
86

chocolatey-package

RabbitMQ chocolatey package
PowerShell
17
star
87

lz4-erlang

LZ4 compression library for Erlang.
C
17
star
88

rabbitmq-auth-backend-cache

Authorisation result caching plugin (backend) for RabbitMQ
Erlang
17
star
89

rabbitmq-management-agent

RabbitMQ Management Agent
Erlang
16
star
90

rabbitmq-jsonrpc-channel

RabbitMQ JSON-RPC Channels
JavaScript
15
star
91

rabbitmq-ha

Highly available queues for RabbitMQ
Erlang
15
star
92

rabbitmq-jsonrpc

RabbitMQ JSON-RPC Integration
Makefile
15
star
93

stdout_formatter

Erlang library to format paragraphs, lists and tables as plain text
Erlang
15
star
94

rabbitmq-peer-discovery-etcd

etcd-based peer discovery backend for RabbitMQ 3.7.0+
Erlang
15
star
95

rabbitmq-federation-management

RabbitMQ Federation Management
Makefile
14
star
96

rabbitmq-server-release

RabbitMQ packaging and release engineering bits that do not belong to the Concourse pipelines.
Shell
13
star
97

seshat

Erlang
13
star
98

credentials-obfuscation

Tiny library/OTP app for credential obfuscation
Erlang
13
star
99

rabbitmq-jms-topic-exchange

Custom exchange that implements JMS topic selection for RabbitMQ
Erlang
13
star
100

rabbitmq-store-exporter

RabbitMQ Store Exporter
Erlang
12
star