Class LevelDBAtomicKVStore
- All Implemented Interfaces:
KVStore
,AtomicKVStore
AtomicKVStore
view of a LevelDB database.
A database directory is the only required configuration property. Instances may be stopped and (re)started multiple times.
-
Constructor Summary
ConstructorDescriptionConstructor.LevelDBAtomicKVStore
(org.iq80.leveldb.DBFactory factory) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Apply a set of mutations to this instance atomically.protected LevelDBKVStore
delegate()
Get the underlyingKVStore
.protected void
finalize()
Finalize this instance.org.iq80.leveldb.DB
getDB()
Get the underlyingDB
associated with this instance.Get the filesystem directory containing the database.org.iq80.leveldb.Options
Get theOptions
this instance will use when opening the database at startup.Create a read-only "snapshot" view of this instance equal to its current state.void
setBlockRestartInterval
(int blockRestartInterval) Configure the number of keys between restart points for delta encoding of keys.void
setBlockSize
(int blockSize) Configure the block size.void
setCacheSize
(long cacheSize) Configure the cache size.void
setCompressionType
(org.iq80.leveldb.CompressionType compressionType) Configure the compression type.void
setCreateIfMissing
(boolean createIfMissing) Configure whether to create the database if missing.void
setDirectory
(File directory) Configure the filesystem directory containing the database.void
setErrorIfExists
(boolean errorIfExists) Configure whether to throw an error if the database already exists.void
setMaxOpenFiles
(int maxOpenFiles) Configure the maximum number of open files.void
setOptions
(org.iq80.leveldb.Options options) Set theOptions
this instance will use when opening the database at startup.void
setParanoidChecks
(boolean paranoidChecks) Configure whether paranoid checks are enabled.void
setVerifyChecksums
(boolean verifyChecksums) Configure whether to verify checksums.void
setWriteBufferSize
(int writeBufferSize) Configure the write buffer size.void
start()
Start this instance.void
stop()
Stop this instance.toString()
Methods inherited from class io.permazen.kv.util.ForwardingKVStore
adjustCounter, apply, decodeCounter, encodeCounter, get, getAtLeast, getAtMost, getRange, put, remove, removeRange
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface io.permazen.kv.mvcc.AtomicKVStore
apply
Methods inherited from interface io.permazen.kv.KVStore
adjustCounter, decodeCounter, encodeCounter, get, getAtLeast, getAtMost, getRange, getRange, getRange, put, remove, removeRange, removeRange
-
Constructor Details
-
LevelDBAtomicKVStore
public LevelDBAtomicKVStore()Constructor.Uses the default
DBFactory
provided byLevelDBUtil.getDefaultDBFactory()
. -
LevelDBAtomicKVStore
public LevelDBAtomicKVStore(org.iq80.leveldb.DBFactory factory) Constructor.- Parameters:
factory
- factory for database- Throws:
IllegalArgumentException
- iffactory
is null
-
-
Method Details
-
getDirectory
Get the filesystem directory containing the database.- Returns:
- database directory
-
setDirectory
Configure the filesystem directory containing the database. Required property.- Parameters:
directory
- database directory- Throws:
IllegalStateException
- if this instance is alreadystart()
ed
-
getDB
public org.iq80.leveldb.DB getDB()Get the underlyingDB
associated with this instance.- Returns:
- the associated
DB
- Throws:
IllegalStateException
- if this instance is notstart()
ed
-
getOptions
public org.iq80.leveldb.Options getOptions()Get theOptions
this instance will use when opening the database at startup.- Returns:
- database options
-
setOptions
public void setOptions(org.iq80.leveldb.Options options) Set theOptions
this instance will use when opening the database at startup. Overwrites any previous options configuration(s).- Parameters:
options
- database options- Throws:
IllegalArgumentException
- ifoptions
is nullIllegalStateException
- if this instance is alreadystart()
ed
-
setBlockRestartInterval
public void setBlockRestartInterval(int blockRestartInterval) Configure the number of keys between restart points for delta encoding of keys. Default 16.- Parameters:
blockRestartInterval
- restart interval- Throws:
IllegalStateException
- if this instance is alreadystart()
ed
-
setBlockSize
public void setBlockSize(int blockSize) Configure the block size. Default 4K.- Parameters:
blockSize
- block size- Throws:
IllegalStateException
- if this instance is alreadystart()
ed
-
setCacheSize
public void setCacheSize(long cacheSize) Configure the cache size. Default 8MB.- Parameters:
cacheSize
- cache size- Throws:
IllegalStateException
- if this instance is alreadystart()
ed
-
setCompressionType
public void setCompressionType(org.iq80.leveldb.CompressionType compressionType) Configure the compression type. DefaultCompressionType.SNAPPY
.- Parameters:
compressionType
- compression type.- Throws:
IllegalArgumentException
- ifcompressionType
is nullIllegalStateException
- if this instance is alreadystart()
ed
-
setCreateIfMissing
public void setCreateIfMissing(boolean createIfMissing) Configure whether to create the database if missing. Default true.- Parameters:
createIfMissing
- true to create if missing- Throws:
IllegalStateException
- if this instance is alreadystart()
ed
-
setErrorIfExists
public void setErrorIfExists(boolean errorIfExists) Configure whether to throw an error if the database already exists. Default false.- Parameters:
errorIfExists
- true for error if database exists- Throws:
IllegalStateException
- if this instance is alreadystart()
ed
-
setMaxOpenFiles
public void setMaxOpenFiles(int maxOpenFiles) Configure the maximum number of open files. Default 1000.- Parameters:
maxOpenFiles
- maximum number of open files- Throws:
IllegalStateException
- if this instance is alreadystart()
ed
-
setParanoidChecks
public void setParanoidChecks(boolean paranoidChecks) Configure whether paranoid checks are enabled. Default false.- Parameters:
paranoidChecks
- true to enable- Throws:
IllegalStateException
- if this instance is alreadystart()
ed
-
setVerifyChecksums
public void setVerifyChecksums(boolean verifyChecksums) Configure whether to verify checksums. Default true.- Parameters:
verifyChecksums
- true to enable- Throws:
IllegalStateException
- if this instance is alreadystart()
ed
-
setWriteBufferSize
public void setWriteBufferSize(int writeBufferSize) Configure the write buffer size. Default 4MB.- Parameters:
writeBufferSize
- write buffer size- Throws:
IllegalStateException
- if this instance is alreadystart()
ed
-
start
@PostConstruct public void start()Description copied from interface:AtomicKVStore
Start this instance. This method must be called prior to creating any transactions.This method is idempotent: if this instance is already started, nothing happens.
Whether an instance that has been started and stopped can be restarted is implementation-dependent.
- Specified by:
start
in interfaceAtomicKVStore
-
stop
@PreDestroy public void stop()Description copied from interface:AtomicKVStore
Stop this instance.Any open
AtomicKVStore.readOnlySnapshot()
's should beclose()
'd before invoking this method; the behavior of those that are not is undefined.This method is idempotent: if this instance has not been started, or is already stopped, nothing happens.
- Specified by:
stop
in interfaceAtomicKVStore
-
delegate
Description copied from class:ForwardingKVStore
Get the underlyingKVStore
.- Specified by:
delegate
in classForwardingKVStore
- Returns:
- underlying
KVStore
-
readOnlySnapshot
Description copied from interface:AtomicKVStore
Create a read-only "snapshot" view of this instance equal to its current state.The returned
CloseableKVStore
should be treated as read-only. It may not actually be read-only, but if it's not, then any changes should have no effect on this instance. The returnedCloseableKVStore
must be completely independent from this instance (subsequent changes to either one do not affect the other).The returned
CloseableKVStore
should be promplyclose()
'd when no longer needed to release any underlying resources.- Specified by:
readOnlySnapshot
in interfaceAtomicKVStore
- Returns:
- read-only, snapshot view of this instance
-
apply
Description copied from interface:AtomicKVStore
Apply a set of mutations to this instance atomically.If this method returns normally, all of the given mutations will have been applied. If this method returns abnormally, then none of the given mutations will have been applied.
In any case, other threads observing this instance will never see a partial application of the given mutations.
This method is required to apply the mutations in this order: removes, puts, adjusts.
If
sync
is true, the implementation must durably persist the changes before returning.- Specified by:
apply
in interfaceAtomicKVStore
- Parameters:
mutations
- the mutations to applysync
- if true, caller requires that the changes be durably persisted
-
finalize
Finalize this instance. Invokesstop()
to close any unclosed iterators. -
toString
-