All Projects → cojen → Tupl

cojen / Tupl

Licence: agpl-3.0
The Unnamed Persistence Library

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Tupl

Tidis
Distributed transactional NoSQL database, Redis protocol compatible using tikv as backend
Stars: ✭ 1,182 (+1324.1%)
Mutual labels:  transaction, database, nosql, raft
Iowow
The skiplist based persistent key/value storage engine
Stars: ✭ 206 (+148.19%)
Mutual labels:  database, nosql, key-value-store
Ardb
A redis protocol compatible nosql, it support multiple storage engines as backend like Google's LevelDB, Facebook's RocksDB, OpenLDAP's LMDB, PerconaFT, WiredTiger, ForestDB.
Stars: ✭ 1,707 (+1956.63%)
Mutual labels:  database, nosql, persistence
Permazen
Language-Natural Persistence Layer for Java
Stars: ✭ 265 (+219.28%)
Mutual labels:  database, persistence, raft
Summitdb
In-memory NoSQL database with ACID transactions, Raft consensus, and Redis API
Stars: ✭ 1,295 (+1460.24%)
Mutual labels:  database, nosql, raft
Gkvdb
[mirror] Go语言开发的基于DRH(Deep-Re-Hash)深度哈希分区算法的高性能高可用Key-Value嵌入式事务数据库。基于纯Go语言实现,具有优异的跨平台性,良好的高可用及文件IO复用设计,高效的底层数据库文件操作性能,支持原子操作、批量操作、事务操作、多表操作、多表事务、随机遍历等特性。
Stars: ✭ 109 (+31.33%)
Mutual labels:  transaction, database, nosql
simpledbm
SimpleDBM is an Open Source Multi-Threaded Embeddable Transactional Database Engine in Java.
Stars: ✭ 51 (-38.55%)
Mutual labels:  nosql, concurrency, transaction
Libmdbx
One of the fastest embeddable key-value ACID database without WAL. libmdbx surpasses the legendary LMDB in terms of reliability, features and performance.
Stars: ✭ 729 (+778.31%)
Mutual labels:  transaction, database, nosql
Nano Sql
Universal database layer for the client, server & mobile devices. It's like Lego for databases.
Stars: ✭ 717 (+763.86%)
Mutual labels:  database, nosql, persistence
Copycat
A novel implementation of the Raft consensus algorithm
Stars: ✭ 551 (+563.86%)
Mutual labels:  database, replication, raft
Dbreeze
C# .NET MONO NOSQL ( key value store embedded ) ACID multi-paradigm database management system.
Stars: ✭ 383 (+361.45%)
Mutual labels:  transaction, database, nosql
Redix
a persistent real-time key-value store, with the same redis protocol with powerful features
Stars: ✭ 907 (+992.77%)
Mutual labels:  database, nosql, key-value-store
Keyvast
KeyVast - A key value store
Stars: ✭ 33 (-60.24%)
Mutual labels:  database, nosql, key-value-store
Java Client Api
Java client for the MarkLogic enterprise NoSQL database
Stars: ✭ 52 (-37.35%)
Mutual labels:  database, nosql
Laravel Transactional Model Events
Add eloquent model events fired after a transaction is committed or rolled back
Stars: ✭ 52 (-37.35%)
Mutual labels:  transaction, database
Fluent
Vapor ORM (queries, models, and relations) for NoSQL and SQL databases
Stars: ✭ 1,071 (+1190.36%)
Mutual labels:  database, nosql
Nodbi
Document DBI connector for R
Stars: ✭ 56 (-32.53%)
Mutual labels:  database, nosql
Rqlite
The lightweight, distributed relational database built on SQLite
Stars: ✭ 9,147 (+10920.48%)
Mutual labels:  database, raft
Nodejs Driver
DataStax Node.js Driver for Apache Cassandra
Stars: ✭ 1,074 (+1193.98%)
Mutual labels:  database, nosql
Couchbase Lite C
C language bindings for the Couchbase Lite embedded NoSQL database engine
Stars: ✭ 58 (-30.12%)
Mutual labels:  database, nosql

Tupl

The Unnamed Persistence Library

Tupl is a high-performance, concurrent, transactional, scalable, low-level embedded database. Features include record-level locking, upgradable locks, deadlock detection, cursors, hot backups, striped files, encryption, pluggable replication, nested transaction scopes, and direct lock control.

Tupl can be used directly, or it can be used for implementing a high-level database. Tupl is powerful enough for supporting all the requirements of relational SQL databases as well as NoSQL databases. Because Tupl doesn't impose any structure or encoding for data, a high-level database is free to implement the most efficient format it requires.

To depend on Tupl, use the following POM snippet:

<dependency>
    <groupId>org.cojen</groupId>
    <artifactId>tupl</artifactId>
    <version>[1.3.11, 2.0.0)</version>
</dependency>

The main entry point is the Database class. Here is a simple example for opening a non-durable database:

DatabaseConfig config = new DatabaseConfig().maxCacheSize(100_000_000);
Database db = Database.open(config);

To open a durable database, a base file path must be provided. Database files are created using the base as a prefix.

DatabaseConfig config = new DatabaseConfig()
    .baseFilePath("/var/lib/tupl")
    .minCacheSize(100_000_000)
    .durabilityMode(DurabilityMode.NO_FLUSH);

Database db = Database.open(config);

Notice that a minimum cache size is set, and also notice the durability mode. A weak durability mode improves the performance of transactional changes, by not immediately flushing those changes to the underlying files.

Setting a minimum cache size is generally preferred over setting a maximum size, because it pre-allocates the cache when the Database is opened. This allows any heap size limits to be detected early, yielding an OutOfMemoryError. When not specified, the maximum cache size matches the minimum cache size. When neither is specified, the default cache size is 1000 pages, and the default page size is 4096 bytes.

Basic operations

A Tupl database manages a collection of indexes, which are ordered mappings of byte[] keys to byte[] values.

Database db = ...

// Open an index, creating it if necessary.
Index userIx = db.openIndex("user");

Indexes offer a low-level representation of data, and so applications which use them directly are responsible for performing their own encoding.

// Store a user in an auto-commit transaction.
User user = ...
byte[] userKey = encodeUserKey(user);
byte[] userValue = encodeUserValue(user);
userIx.store(null, userKey, userValue);

To bundle multiple operations together, specify an explicit transaction:

Index userByNameIx = ...

byte[] userNameKey = encodeUserName(user);

Transaction txn = db.newTransaction();
try {
    userIx.store(txn, userKey, userValue);
    userByNameIx.store(txn, userNameKey, userKey);
    txn.commit();
} finally {
    txn.reset();
}

Entries can retrieved by loading them directly, or via a cursor:

// Find all users whose last name starts with 'J'.
byte[] startKey = encodeUserName("J");
byte[] endKey = encodeUserName("K");

// Open a new cursor with an auto-commit transaction.
Cursor namesCursor = userByNameIx.newCursor(null);
try {
    // Find names greater than or equal to the start key.
    namesCursor.findGe(startKey);
    byte[] nameKey;
    while ((nameKey = namesCursor.key()) != null) {
        byte[] userKey = namesCursor.value();
        ...

        // Move to next name, while still being less than the end key.
        namesCursor.nextLt(endKey);
    }
} finally {
    namesCursor.reset();
}

The above example can also be implemented using a sub-view:

// View all users whose last name starts with 'J'.
View userByNameView = userByNameIx.viewPrefix(startKey, 0);

// Scan the entire view of names.
Cursor namesCursor = userByNameView.newCursor(null);
try {
    namesCursor.first();
    byte[] nameKey;
    while ((nameKey = namesCursor.key()) != null) {
        byte[] userKey = namesCursor.value();
        ...

        namesCursor.next();
    }
} finally {
    namesCursor.reset();
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].