Java
1.7 and UP.
It uses NIO File channels for cache write backs to disk. Hence dependency on 1.7.
POM
<dependency> <groupId>org.wonderdb.journaling</groupId> <artifactId>journaling</artifactId> <version>0.1</version> </dependency>
Github location
https://github.com/dreamdbvilas/wonderdbjournaling.git
Design and How it works
Please refer to my blog page on journaling to understand design and how it works.
Configuration
Since there are not too mane configuration parameters for this module, You just need to pass these as a parameter to init method. Below section describes how to use it in the code.
Here are the parameters you can control.
logFolders[]
You can provide list of folders to store redo log files. If you have more than one disk then it is good idea to provide more than one log file folder from different disks. This will improve performance and throughput due to reduced disk contention.
maxRedoLogFileSize
Maximum redo log file size before log files are rotated. Based on your transaction volume or redo log file generation volume set it to some value. You can start with 100K to 2M.
applyType
This enum has following values
Every
Apply every redo log/transaction to backend data files.
SoOften
Similar to every, except it applies every so often depending on applyFrequency parameter.
OnLogSwitch
Apply changes on log switch. This is the best option if you have more than one disk and you have provided with more than one redo log folder.
None
Sometimes applications don’t want this module to apply changes to data files. In that case set this value to None.
WonderDB uses this setting since it applies data file changes from caches.
applyFrequency
This value is meaningful only if you have set applyType = SoOften.
Supporten APIs
API | Description |
---|---|
startTxn | It starts the transaction is returns TransactionId. |
log(txnId, fileName, posn, ChannelBuffer) | It puts given ChannelBuffer in transaction buffer. It means bytes in ChannelBuffer will are the changes to the data file provided in the give posn. |
commit(txnId) | Commits the transaction to redo log |
rollback(txnId) | Rollback transaction. |
Using it in the Code
Initialization
Call this first in the code during initialization of the app.
LogManager.getInistance.init(String[] logFolders, int maxFileSize, applyType, int applyFrequency);
Using it in the code
// start a transaction TransactionId txnId = LogManager.getInstance().startTxn(); // logging in transaction ChannelBuffer buffer = ChannelBuffers.wrappedBuffer("My First Txn Entry".getBytes()); LogManager.getInstance().log(txnId, "dataFile1", 10, buffer); buffer = ChannelBuffers.wrappedBuffer("My First Txn second entry".getBytes()); LogManager.getInstance().log(txnId, "dataFile2", 1000, buffer); // commit LogManager.getInstance().commit(txnId); // To rollback a txn call LogManager.getInstance().rollback(txnId);
Shutdown
Call following line during the shutdown at the end. It cleans up all resources like thread pools, caches, sockets etc. JVM will not exit properly if this line is not called during shutdown.
LogManager.getInstance().shutdown();
Questions?
Post you question on WonderDBCache google group.
Leave a Reply