Coder Social home page Coder Social logo

h2okv's Introduction

H2o KV

A Toy KV Database.

Build & Run Server

Required: Rust 2018 (latest Rust Stable or later versions)

$ make
H2o KV started at 127.0.0.1:30160

Build & Run Client

$ make cli
Connected to h2okv server 127.0.0.1:30160, Ctrl-D to exit
h2okv> get foo
(None)
h2okv> set foo bar
OK
h2okv> get foo
"bar"
h2okv> put first 135
OK
h2okv> scan f
1) "first"
2) "foo"

DB Data Persistence

Each write query would make the whole DB saved into a file named h2okv.data under current working directory. For more details on disk persistence, please see comments in file src/persistence.rs.

H2oKV Protocols

Queries

The query is formed as follow:

+--------+-----+------+--------+----------+
| Header | CMD | Flag | Length | Content  |
+--------+-----+------+--------+----------+
| '\x0c' | 1   | 1    | 2      | Variable |
+--------+-----+------+--------+----------+

Where:

  • Header
    • protocol header: always be \x0c for now.
  • CMD
    • GET: \x01
    • PUT: \x02 see next protocol table
    • DEL: \x03
    • SCAN: \x04
  • Flag
    • Plain Text: \x00
    • GZIP Text: \x01
    • Ciphered Text: \x02 (details TBD)
  • Length
    • Two bytes indicating how many bytes the Content part are. LittleEndian.
  • Content
    • The KEY bytes for GET, PUT, and DEL
    • The key search pattern for SCAN

Protocol for PUT

+--------+--------+------+------+-----+-------+------+-------+
| Header | CMD    | Flag | KLen | KEY | VLLen | VLen | VALUE |
+--------+--------+------+------+-----+-------+------+-------+
| '\x0c' | '\x02' | 1    | 2    | Var | 1     | Var  | Var   |
+--------+--------+------+------+-----+-------+------+-------+
  • KLen
    • Two bytes indicating how many bytes the KEY part are
  • KEY
    • The KEY bytes
  • VLLen
    • 1 byte indicating how many bytes the VLen part are
  • VLen
    • bytes indicating how many bytes the VALUE part are, LittleEndian.
  • VALUE
    • The Value bytes

Responses

GET

+--------+------+------+------+-----+---------+
| Header | Stat | Flag | LLen | Len | Content |
+--------+------+------+------+-----+---------+
| '\x0c' | 1    | 1    | 1    | Var | Var     |
+--------+------+------+------+-----+---------+

SCAN

+--------+------+------+-------+-----+-----+-----+-----+-----+
| Header | Stat | Flag | Count | Len | Key | Len | Key | ... |
+--------+------+------+-------+-----+-----+-----+-----+-----+
| '\x0c' | 1    | 1    | 4     | 2   | Var | 2   | Var | ... |
+--------+------+------+-------+-----+-----+-----+-----+-----+

PUT, DEL, All

+--------+------+
| Header | Stat |
+--------+------+
| '\x0c' | 1    |
+--------+------+
  • Flag
    • Plain Text: \x00
    • GZIP Text: \x01
    • Ciphered Text: \x02 (details TBD)
  • Stat(us)
    • OK: \x00
    • Failed: \x01
    • No such Key: \x02 (for GET)
    • Unknown command: \xFF

h2okv's People

Stargazers

 avatar

Watchers

 avatar  avatar

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.