GithubHelp home page GithubHelp logo

ornamental / kvp-store Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 50 KB

A simplistic key-value store with multi-version concurrency control

License: MIT License

Java 100.00%
database kvstore mvcc transaction embedded-database

kvp-store's Introduction

A simplistic embedded MVCC key-value storage

The storage organizes the data supplied to it in a log-like manner, writing the records one after another until a file reaches maximum allowed size, after which a new file is created and written to, and so on. The metadata is stored in an SQLite database.

The storage allows any number of concurrent reading transactions and a single writing transaction (not blocked by the reading transactions). Each reading transactions observes the storage snapshot which was relevant at the moment when the transaction was started. The writing transaction operates on the most recent storage state.

If a record is deleted and there are no readers which observe the corresponding storage state, it may be garbage-collected. The garbage collection does not affect a file unless the records ready to be collected occupy sufficiently much space in it. The garbage collection on a file moves all the remaining records to the end of the 'log' and removes the file that has become redundant.

The storage handles very big writing transactions (up to terabytes) without much impact on the RAM. It works best with shorter keys.

Usage

The principal interface is VersionedStorage serving to begin reading and modifying transactions on an MVCC storage. Read-only transactions are represented by the Reader interface, modifying transactions are represented by the Writer interface, both extending java.lang.AutoCloseable (in fact, Writer is a Reader). The supplied concrete implementation of the VersionedStorage interface is the class GroupingFileStorage.

Keys and values supplied to the storage transaction methods are represented by the Key interface, whose implementations must be able to return a byte array representing a key, and the Value interface, whose implementations must be aware of the size of data they hold and (in its most general form) be able to return a ReadableByteChannel as the data supplier.

Note that the Key implementations must override equals(Object) and hashCode() methods so that instances returning equal binary representations are equal. The default behaviour is implemented in the AbstractKey class.

There exist ready implementations of the Value interface wrapping byte[] and InputStream instances (ByteArrayValue and InputStreamValue, respectively).

Build prerequisites

The project depends on another GitHub project @ornamental/sqlite-statements. Build and install the corresponding artifact into local Maven repository before building this project.

kvp-store's People

Contributors

dependabot[bot] avatar ornamental avatar

Watchers

 avatar

kvp-store's Issues

Eliminate dependency on ORMLite

The ORM functionality is not employed at all as only raw SQL queries are sent to SQLite. Thus there is no need in using ORMLite, JDBC functionality combined with connection pooling should be sufficient.

  1. Implement JDBC connection pooling.
  2. Consider preparing certain statements on per-connection basis (as there will be only one RW connection, the INSERT, UPDATE, and DELETE statements only have to be prepared for this connection; RO queries will have to be prepared for each connection in the pool).
  3. Migrate to the new querying mechanism and exclude the dependencies which will become redundant.

Implement a log-like storage governed by an embedded database

Requirements

  1. The storage must support any number of concurrent readers and one writer not blocked by the readers.
  2. Each reader must observe the snapshot of the storage relevant at the moment of its creation; it must not see the changes added afterwards, either committed or not.
  3. The writer must observe the most relevant state with its own uncommitted changes.
  4. The writer must support commit and rollback operations.
  5. However much data a writing transaction might supply, the RAM footprint must not grow proportionally.
  6. The storage must be able to transfer data from byte arrays, input streams, and readable byte channels.

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.