DB-Core
Minimal schema-less database management system with ACID guaranties.
Current status: WIP (See roadmap section for details)
Usage
Client application creates a so called instance of db-core. When instance is created it opens data store, initializes its internal components, and restores state from the last checkpoint. Using created instance client application can initiate transactions, create or open existing object, read and write data, delete objects, and then commit or rollback changes. Instance can be cloned and moved to other thread in a multithreaded application. In the end, application can shutdown all instances.
Database initialization (this is one-time action):
use Instance;
use FileState;
use FileType;
use FileDesc;
use Read;
use Write;
use ConfigMt;
use Path;
// Block size for the database.
let block_size = 8192;
// Create an empty directory for the database files.
let dspath = "/tmp/db-core-test-db";
if new.exists
create_dir.expect;
// Transaction log directory.
let log_dir = "/tmp/db-core-test-tranlog";
if new.exists
create_dir.expect;
// Define initial database files. There should be at least one file of each type (data store,
// versioning store, checkpont store).
let mut fdset = vec!;
let desc1 = FileDesc ;
let desc2 = FileDesc ;
let desc3 = FileDesc ;
fdset.push;
fdset.push;
fdset.push;
// Create a database.
initialize_datastore.expect;
Instance startup and termination, transaction management, read and write data:
// Some random data.
let data = b"Hello, world!";
// Prepare configuration.
let conf = new;
let mut c = conf.get_conf;
c.set_log_dir;
c.set_datastore_path;
drop;
// Start instance and open existing database.
let instance = new.expect;
// Begin transaction.
let mut trn = instance.begin_transaction.expect;
// Create a new object.
let file_id = 3;
let mut obj = instance.open_create.expect;
let obj_id = obj.get_id;
// Write some data.
obj.write_next.expect;
drop;
// Commit transaction.
instance.commit.expect;
// Begin transaction.
let mut trn = instance.begin_transaction.expect;
// Open object for reading and read some data.
let mut obj = instance.open_read.expect;
let mut read_buf = vec!;
let mut read = 0;
let len = read_buf.len;
while read < len
assert_eq!;
drop;
// Delete object (if object is in use wait for other transaction to finish for 1 second).
let wait_lock_ms = 1000;
instance.delete.expect;
// Rollback transaction.
instance.rollback.expect;
// Spawn another instance in a different thread.
let ss = instance.get_shared_state.expect;
let th = spawn;
// Add a database file.
let new_file_id = instance.add_datafile.expect;
// Terminate instance.
instance.terminate;
Roadmap
- Allow storing data directly on block device.
- Implement vacuuming.
- Add more tests.
See issues for details.
Contribution
Contributions are welcome! Please see CONTRIBUTING.md for details.