Skip to content

tezc/resql

Repository files navigation

Status License: BSD

What is Resql?

Resql is a SQL database server that uses SQLite as its SQL engine and it provides replication and automatic failover capabilities.

Why ?

It's mostly about performance and consistency. Resql tries to be as fast as possible without giving up on consistency :

  • Performance : A quick benchmark in wiki : Benchmark
  • Consistency : Resql implements RAFT consensus algorithm and provides exactly-once execution of operations. If you're not familiar with distributed systems, basically, Resql executes client operations one by one. If configured with multiple nodes, it replicates your operations to each node. Once you get an answer from the server for an operation, you can be sure your operation is persisted. If the client retries an operation on a server crash/network issue etc, it's guaranteed that the operation will be executed exactly once.

Features

  • Can be used as a single node persistent database or in a cluster with replication and failover.
  • Light on resources: ~1 MB executable size, can start with a few MB of RAM. Currently, it uses 2 threads only, it'll occupy 2 cores on your machine at most.
  • C, Java and Go clients are available.
  • JSON, Full-Text Search, RTree and Geopoly SQLite extensions are included.

Limitations

  • Explicit transactions are not supported. e.g. No BEGIN, COMMIT or ROLLBACK. Instead of explicit transactions, you can batch your operations and send them in one go. A batch is executed atomically.
  • Not suitable for long-running analytical queries. e.g. Queries that last tens of seconds.

Build

Resql can be compiled on Linux, macOS and FreeBSD. CI runs on multiple architectures. Big-little endian systems and 32 bit CPUs are supported.

  • Requirements : CMake, GCC or Clang.

    These can be installed via the package manager of your OS.

    Ubuntu : apt install gcc cmake  
    MacOS  : brew install cmake
    
  • Compile

    git clone https://github.com/tezc/resql.git
    cd resql
    ./build.sh
    

    Build takes ~ 1 minute. It will create server, cli and benchmark executable under bin/ directory of the current directory.

  • After the build is completed, start the server :

    cd bin
    ./resql
    
  • Start command-line interface (CLI) to connect to the server

    ./resql-cli 
    Trying to connect to server at tcp://127.0.0.1:7600 
    Connected 
    
    Type .help for usage. 
    
    resql> SELECT client_name, remote, connect_time FROM resql_clients
    +-------------+-----------------+---------------------+
    | client_name | remote          | connect_time        |
    +-------------+-----------------+---------------------+
    | g6H06FPh_0  | 127.0.0.1:46924 | 2021-05-19 12:44:39 |
    +-------------+-----------------+---------------------+
    
    

Documentation

Get Started

Administration

Clients

Acknowledgements

This project contains code from other open source projects :

  • Sqlite               : Resql uses sqlite as database engine.
  • CRC32C           : A modified version of CRC32C implementation.
  • HdrHistogram : Used in resql_benchmark tool.
  • Linenoise         : Used in resql_cli.
  • Inih                   : A modified version of INI parser, used for the configuration file.
  • Redis               : Functions to get RAM capacity of the machine and RSS value.