Skip to content

jeyaram-a/mentia

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mentia

A key/value database written in Java. Inspired by go-leveldb

Usage

    // First configure StoreConfig
    var config = new StoreConfig();
    // true -> faster writes but can lose data if server goes down
    // false -> slower writes but safe data         
    config.setAsyncWrite(true);
    // if async, for every watermark amount of data, in memory is persisted
    config.setIndexJournalFlushWatermark(UtilConstants.MB * 10);
    // how big each segment files are
    config.setSegmentIndexFoldMark(UtilConstants.MB * 200);
    // faster reads at the cost of more memory
    config.setCacheEnabled(true);
    // if cache enabled how big is the cache
    config.setCacheSize(UtilConstants.MB * 5);
    
    // Thread pool for disk access
    ExecutorService diskAccessPool = Executors.newFixedThreadPool(10, Thread.ofVirtual().factory());
    var path = "path_to_store";
    // sample is the store name
    // creates store if not present
    // if present restores state        
    var store = Store.open(path, "sample", config, pool);
    
    // persist
    store.put("key".getBytes(), "val".getBytes());
    
    // retrieve 
    System.out.println(new String(store.get("key".getBytes())));

Performance:

Running StoreTest.java locally on my Windows laptop

mvn test

Without cache enabled:

INFO: Writing took 11925 millis. Total 2513777890 bytes (~2.5 GB)
INFO: Read took 2 millis

Fresh read:

INFO: Read took 1 millis

TODO

  • Background compaction
  • Compression
  • Encryption
  • Server setup

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages