Coder Social home page Coder Social logo

rog's Introduction

Rog

A simple distributed commit log inspired by Kafka.

TODOs

  • Distribute writes to multiple nodes

Building

To build both the cli and the server you can just run cargo build --release.

Integration tests

The integration tests are written in python with pytest. You can install the dependencies with pip: pip install -r tests/requirements.txt. The tests use protobuf for a few scenarios, so you need the protobuf compiler, you can generated the necessary files running this command:

protoc -I=tests/proto --python_out=tests tests/proto/addressbook.proto

And to execute all tests you can run:

pytest tests

If you don't want to install protoc you can run the tests with the local docker image, this image is used simply to run this tests in an isolated environment.

docker buildx build .

Rog CLI

To interact with the server you can use the rog cli.

Usage: rog-cli --address <ADDRESS> <COMMAND>

Commands:
  create-log
  publish
  fetch
  help        Print this message or the help of the given subcommand(s)

Options:
  -a, --address <ADDRESS>  Rog server address on the format ip:port, e.g.: 127.0.0.1:7878
  -h, --help               Print help

Protocol specification

The Rog protocol is implemented with TCP. In all commands the first byte is the command byte, this is used to identify which command is being sent. There are two client implementations in this repository: one in rust, for the cli and one in python used in the integration tests.

Commands

Create log

Field Type Description
Command byte u8 Fixed value for the create log command, 0
partitions u8 Number of partitions for the log
Log name size u8 Size of the log name in bytes
Log name String Log name
Successful response
Field Type Description
Success byte u8 Indicates if the response was successful or not, 0

Publish

Field Type Description
Command byte u8 Fixed value for the publish command, 1
partition u8 Partitions to publish the message
Log name size u8 Size of the log name in bytes
Log name String Log name
Data size u64 Size of the message in bytes
Data bytes The actual content of the message
Successful response
Field Type Description
Success byte u8 Indicates if the response was successful or not, 0

Fetch

Field Type Description
Command byte u8 Fixed value for the fetch command, 2
partition u8 Partition to fetch the message
Log name size u8 Size of the log name in bytes
Log name String Log name
Group size u64 Size of the group name
Group bytes The group name
Successful response
Field Type Description
Success byte u8 Indicates if the response was successful or not, 0
Message size u64 Size of the message content
Message String Actual message

Ack

Field Type Description
Command byte u8 Fixed value for the ack command, 3
partition u8 Partition to fetch the message
Log name size u8 Size of the log name in bytes
Log name String Log name
Group size u64 Size of the group name
Group bytes The group name
Successful response
Field Type Description
Success byte u8 Indicates if the response was successful or not, 0

Error response

All commands have the same possible error response.

Field Type Description
Success byte u8 Indicates if the response was successful or not, 1
Message size u64 Size of the error message
Message String Detailed error message

Storage

Rog keeps the messages stored in multiple log files, each file has an approximate max size of 1MiB. When a log is created, Rog creates a directory with name log name and one directory for each partition, the log files are kept inside the partition directory with the extension .log.

Log file format

The file follows a simple structure so that it is easily seekeable so that the fetching process doesn't need to load the whole file into memory. Each message is stored as an "entry" on the file.

Field Size Description
id 8 bytes The message id
entry size 8 bytes The size of the entry content in bytes
entry entry size bytes The entry content

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.