├── .gitmodules
├── src
├── androidMain
├── jvmMain
│ ├── kotlin
│ │ └── maryk
│ │ │ ├── Buffer.kt
│ │ │ ├── rocksdb
│ │ │ ├── Cache.kt
│ │ │ ├── Logger.kt
│ │ │ ├── Range.kt
│ │ │ ├── Slice.kt
│ │ │ ├── LRUCache.kt
│ │ │ ├── MemEnv.kt
│ │ │ ├── Options.kt
│ │ │ ├── Priority.kt
│ │ │ ├── ReadTier.kt
│ │ │ ├── Snapshot.kt
│ │ │ ├── TimedEnv.kt
│ │ │ ├── IndexType.kt
│ │ │ ├── BloomFilter.kt
│ │ │ ├── EnvOptions.kt
│ │ │ ├── PerfContext.kt
│ │ │ ├── RateLimiter.kt
│ │ │ ├── RocksObject.kt
│ │ │ ├── SanityLevel.kt
│ │ │ ├── TraceWriter.kt
│ │ │ ├── Transaction.kt
│ │ │ ├── WalFileType.kt
│ │ │ ├── ConfigOptions.kt
│ │ │ ├── EncodingType.kt
│ │ │ ├── FlushOptions.kt
│ │ │ ├── HistogramData.kt
│ │ │ ├── HistogramType.kt
│ │ │ ├── InfoLogLevel.kt
│ │ │ ├── LevelMetaData.kt
│ │ │ ├── MergeOperator.kt
│ │ │ ├── RocksIterator.kt
│ │ │ ├── SstFileReader.kt
│ │ │ ├── SstFileWriter.kt
│ │ │ ├── TraceOptions.kt
│ │ │ ├── TransactionDB.kt
│ │ │ ├── WriteOptions.kt
│ │ │ ├── MemTableConfig.kt
│ │ │ ├── RestoreOptions.kt
│ │ │ ├── SstFileManager.kt
│ │ │ ├── CompactionReason.kt
│ │ │ ├── CompactionStyle.kt
│ │ │ ├── LiveFileMetaData.kt
│ │ │ ├── MemoryUsageType.kt
│ │ │ ├── PersistentCache.kt
│ │ │ ├── PlainTableConfig.kt
│ │ │ ├── RocksDBException.kt
│ │ │ ├── SstFileMetaData.kt
│ │ │ ├── TxnDBWritePolicy.kt
│ │ │ ├── WriteEntry.kt
│ │ │ ├── WriteType.kt
│ │ │ ├── loadLibrary.kt
│ │ │ ├── AbstractWriteBatch.kt
│ │ │ ├── BuiltinComparator.kt
│ │ │ ├── ColumnFamilyHandle.kt
│ │ │ ├── CompactionPriority.kt
│ │ │ ├── ComparatorOptions.kt
│ │ │ ├── CompressionOptions.kt
│ │ │ ├── DataBlockIndexType.kt
│ │ │ ├── RocksMutableObject.kt
│ │ │ ├── TableFormatConfig.kt
│ │ │ ├── TransactionOptions.kt
│ │ │ ├── WBWIRocksIterator.kt
│ │ │ ├── AbstractTraceWriter.kt
│ │ │ ├── BackupEngineOptions.kt
│ │ │ ├── ColumnFamilyOptions.kt
│ │ │ ├── CompactRangeOptions.kt
│ │ │ ├── CompactionStopStyle.kt
│ │ │ ├── RocksCallbackObject.kt
│ │ │ ├── TickerType.kt
│ │ │ ├── WriteBatchInterface.kt
│ │ │ ├── WriteBatchWithIndex.kt
│ │ │ ├── BlockBasedTableConfig.kt
│ │ │ ├── ColumnFamilyMetaData.kt
│ │ │ ├── DBOptionsInterface.kt
│ │ │ ├── SizeApproximationFlag.kt
│ │ │ ├── StringAppendOperator.kt
│ │ │ ├── TransactionDBOptions.kt
│ │ │ ├── AbstractMutableOptions.kt
│ │ │ ├── AbstractNativeReference.kt
│ │ │ ├── AbstractRocksIterator.kt
│ │ │ ├── ColumnFamilyDescriptor.kt
│ │ │ ├── Env.kt
│ │ │ ├── RocksIteratorInterface.kt
│ │ │ ├── WaitingTransactions.kt
│ │ │ ├── ImportColumnFamilyOptions.kt
│ │ │ ├── IngestExternalFileOptions.kt
│ │ │ ├── AbstractTransactionNotifier.kt
│ │ │ ├── MutableDBOptionsInterface.kt
│ │ │ ├── OptimisticTransactionOptions.kt
│ │ │ ├── ComparatorType.kt
│ │ │ ├── DirectSlice.kt
│ │ │ ├── TransactionState.kt
│ │ │ ├── Holder.kt
│ │ │ ├── AbstractCompactionFilterFactory.kt
│ │ │ ├── AbstractImmutableNativeReference.kt
│ │ │ ├── BottommostLevelCompaction.kt
│ │ │ ├── RemoveEmptyValueCompactionFilter.kt
│ │ │ ├── ChecksumType.kt
│ │ │ ├── OptimisticTransactionDB.kt
│ │ │ ├── StatsLevel.kt
│ │ │ ├── WriteBatch.kt
│ │ │ ├── createCheckPoint.kt
│ │ │ ├── MutableColumnFamilyOptionsInterface.kt
│ │ │ ├── PerfLevel.kt
│ │ │ ├── BackupInfo.kt
│ │ │ ├── Status.kt
│ │ │ ├── TransactionLogIterator.kt
│ │ │ ├── WALRecoveryMode.kt
│ │ │ ├── AbstractCompactionFilter.kt
│ │ │ ├── CompactionOptions.kt
│ │ │ ├── ReadOptions.kt
│ │ │ ├── BackupEngine.kt
│ │ │ ├── CompressionType.kt
│ │ │ ├── FlushReason.kt
│ │ │ ├── FilterPolicy.kt
│ │ │ ├── AbstractTableFilter.kt
│ │ │ ├── GetStatus.kt
│ │ │ ├── WriteBufferManager.kt
│ │ │ ├── RocksDB.kt
│ │ │ ├── MutableDBOptions.kt
│ │ │ ├── Statistics.kt
│ │ │ ├── ExternalFileIngestionInfo.kt
│ │ │ ├── MutableColumnFamilyOptions.kt
│ │ │ ├── AbstractComparator.kt
│ │ │ ├── DBOptions.kt
│ │ │ ├── openOptimisticTransactionDB.kt
│ │ │ ├── AbstractSlice.kt
│ │ │ ├── openTransactionDB.kt
│ │ │ ├── TtlDB.kt
│ │ │ ├── FlushJobInfo.kt
│ │ │ ├── EventInfo.kt
│ │ │ └── OptionsUtil.kt
│ │ │ └── ByteBuffer.kt
│ └── AndroidManifest.xml
├── commonMain
│ └── kotlin
│ │ └── maryk
│ │ ├── rocksdb
│ │ ├── loadLibrary.kt
│ │ ├── AbstractMutableOptions.kt
│ │ ├── Range.kt
│ │ ├── MemEnv.kt
│ │ ├── RocksCallbackObject.kt
│ │ ├── Logger.kt
│ │ ├── AbstractTraceWriter.kt
│ │ ├── EnvOptions.kt
│ │ ├── Priority.kt
│ │ ├── Snapshot.kt
│ │ ├── ComparatorType.kt
│ │ ├── RemoveEmptyValueCompactionFilter.kt
│ │ ├── SanityLevel.kt
│ │ ├── MergeOperator.kt
│ │ ├── SstFileReader.kt
│ │ ├── InfoLogLevel.kt
│ │ ├── AbstractTableFilter.kt
│ │ ├── BloomFilter.kt
│ │ ├── PersistentCache.kt
│ │ ├── ChecksumType.kt
│ │ ├── WriteType.kt
│ │ ├── ReadTier.kt
│ │ ├── SizeApproximationFlag.kt
│ │ ├── TransactionState.kt
│ │ ├── TableFormatConfig.kt
│ │ ├── DataBlockIndexType.kt
│ │ ├── ComparatorOptions.kt
│ │ ├── WriteBufferManager.kt
│ │ ├── BuiltinComparator.kt
│ │ ├── ColumnFamilyHandle.kt
│ │ ├── FlushOptions.kt
│ │ ├── RateLimiter.kt
│ │ ├── FilterPolicy.kt
│ │ ├── CompactionStopStyle.kt
│ │ ├── AbstractImmutableNativeReference.kt
│ │ ├── WriteStallCondition.kt
│ │ ├── WALRecoveryMode.kt
│ │ ├── HistogramData.kt
│ │ ├── WaitingTransactions.kt
│ │ ├── WriteStallInfo.kt
│ │ ├── BackgroundErrorReason.kt
│ │ ├── PerfLevel.kt
│ │ ├── CompressionOptions.kt
│ │ ├── SstFileWriter.kt
│ │ ├── LiveFileMetaData.kt
│ │ ├── TraceOptions.kt
│ │ ├── ConfigOptions.kt
│ │ ├── Holder.kt
│ │ ├── MemTableConfig.kt
│ │ ├── Cache.kt
│ │ ├── LevelMetaData.kt
│ │ ├── RocksDBException.kt
│ │ ├── ImportColumnFamilyOptions.kt
│ │ ├── SstFileMetaData.kt
│ │ ├── RocksMutableObject.kt
│ │ ├── TimedEnv.kt
│ │ ├── GetStatus.kt
│ │ ├── TraceWriter.kt
│ │ ├── AbstractTransactionNotifier.kt
│ │ ├── RocksObject.kt
│ │ ├── ColumnFamilyDescriptor.kt
│ │ ├── BackupInfo.kt
│ │ ├── IndexType.kt
│ │ ├── DBOptionsInterface.kt
│ │ ├── StatisticsCollector.kt
│ │ ├── WalFileType.kt
│ │ ├── ColumnFamilyMetaData.kt
│ │ ├── MemTableInfo.kt
│ │ ├── BottommostLevelCompaction.kt
│ │ ├── TtlDB.kt
│ │ ├── FlushReason.kt
│ │ ├── StatsLevel.kt
│ │ ├── RestoreOptions.kt
│ │ ├── ExternalFileIngestionInfo.kt
│ │ ├── SstFileManager.kt
│ │ ├── MemoryUsageType.kt
│ │ ├── AbstractCompactionFilter.kt
│ │ ├── WriteBatchSavePoint.kt
│ │ ├── IngestExternalFileOptions.kt
│ │ ├── OptionsUtil.kt
│ │ ├── TransactionLogIterator.kt
│ │ ├── OptimisticTransactionOptions.kt
│ │ ├── AbstractNativeReference.kt
│ │ ├── CompactionPriority.kt
│ │ ├── TableProperties.kt
│ │ ├── AbstractCompactionFilterFactory.kt
│ │ ├── WriteEntry.kt
│ │ ├── PlainTableConfig.kt
│ │ ├── util
│ │ │ └── memCompare.kt
│ │ ├── openOptimisticTransactionDB.kt
│ │ ├── Slice.kt
│ │ ├── openTransactionDB.kt
│ │ ├── CompactionStyle.kt
│ │ ├── CheckPoint.kt
│ │ ├── WBWIRocksIterator.kt
│ │ ├── Status.kt
│ │ ├── FlushJobInfo.kt
│ │ ├── useAutoClosable.kt
│ │ ├── DirectSlice.kt
│ │ ├── EventListener.kt
│ │ ├── RocksIterator.kt
│ │ ├── TxnDBWritePolicy.kt
│ │ ├── AbstractWriteBatch.kt
│ │ ├── CompactionOptions.kt
│ │ └── EncodingType.kt
│ │ ├── Buffer.kt
│ │ └── ByteBuffer.kt
├── commonTest
│ └── kotlin
│ │ └── maryk
│ │ ├── createFolder.kt
│ │ ├── deleteFolder.kt
│ │ ├── doesFolderExist.kt
│ │ ├── rocksdb
│ │ ├── util
│ │ │ ├── Sleep.kt
│ │ │ ├── ThreadSafeCounter.kt
│ │ │ ├── dummyString.kt
│ │ │ └── createTestDBFolder.kt
│ │ ├── CompressionTypesTest.kt
│ │ ├── ImportColumnFamilyOptionsTest.kt
│ │ ├── OptimisticTransactionOptionsTest.kt
│ │ ├── Types.kt
│ │ ├── LRUCacheTest.kt
│ │ ├── BackupableDBOptionsTest.kt
│ │ ├── WriteBufferManagerTest.kt
│ │ ├── CompactionOptionsFIFOTest.kt
│ │ ├── IngestExternalFileOptionsTest.kt
│ │ ├── CompressionOptionsTest.kt
│ │ ├── CompactionOptionsTest.kt
│ │ └── PlainTableConfigTest.kt
│ │ ├── assertContentEquals.kt
│ │ ├── assertBufferEquals.kt
│ │ └── assertContains.kt
├── main
│ └── AndroidManifest.xml
├── nativeMain
│ └── kotlin
│ │ └── maryk
│ │ ├── BooleanToUByte.kt
│ │ ├── rocksdb
│ │ ├── TableFormatConfig.kt
│ │ ├── loadRocksDBLibrary.kt
│ │ ├── FilterPolicy.kt
│ │ ├── MemTableConfig.kt
│ │ ├── Range.kt
│ │ ├── RocksObject.kt
│ │ ├── AbstractNativeReference.kt
│ │ ├── ComparatorOptions.kt
│ │ ├── RocksCallbackObject.kt
│ │ ├── SanityLevel.kt
│ │ ├── AbstractTraceWriter.kt
│ │ ├── ComparatorType.kt
│ │ ├── BuiltinComparator.kt
│ │ ├── RemoveEmptyValueCompactionFilter.kt
│ │ ├── WalFileType.kt
│ │ ├── DBOptionsInterface.kt
│ │ ├── ChecksumType.kt
│ │ ├── DataBlockIndexType.kt
│ │ ├── AbstractTransactionNotifier.kt
│ │ ├── IndexType.kt
│ │ ├── TraceWriter.kt
│ │ ├── Priority.kt
│ │ ├── SizeApproximationFlag.kt
│ │ ├── MemEnv.kt
│ │ ├── TimedEnv.kt
│ │ ├── AbstractMutableOptions.kt
│ │ ├── RocksMutableObject.kt
│ │ ├── ReadTier.kt
│ │ ├── WBWIRocksIterator.kt
│ │ ├── TraceOptions.kt
│ │ ├── GetStatus.kt
│ │ ├── LevelMetaData.kt
│ │ ├── MemoryUsageType.kt
│ │ ├── AbstractCompactionFilterFactory.kt
│ │ ├── WaitingTransactions.kt
│ │ ├── WriteStallCondition.kt
│ │ ├── RocksDBException.kt
│ │ ├── RocksIteratorInterface.kt
│ │ ├── BackgroundErrorReason.kt
│ │ ├── Snapshot.kt
│ │ ├── ColumnFamilyDescriptor.kt
│ │ ├── WriteType.kt
│ │ ├── EncodingType.kt
│ │ ├── ColumnFamilyMetaData.kt
│ │ ├── CompactionPriority.kt
│ │ ├── LiveFileMetaData.kt
│ │ ├── CompactionStyle.kt
│ │ ├── AbstractImmutableNativeReference.kt
│ │ ├── BackupInfo.kt
│ │ ├── EnvOptions.kt
│ │ ├── TransactionState.kt
│ │ ├── WriteBatchSavePoint.kt
│ │ ├── SstFileReader.kt
│ │ ├── CompactionStopStyle.kt
│ │ ├── PerfLevel.kt
│ │ ├── StatsLevel.kt
│ │ ├── AbstractCompactionFilterContext.kt
│ │ ├── RestoreOptions.kt
│ │ ├── Holder.kt
│ │ ├── WALRecoveryMode.kt
│ │ ├── TxnDBWritePolicy.kt
│ │ ├── CompactionReason.kt
│ │ ├── FlushReason.kt
│ │ ├── RocksIterator.kt
│ │ ├── WriteEntry.kt
│ │ ├── BottommostLevelCompaction.kt
│ │ ├── InfoLogLevel.kt
│ │ ├── OptimisticTransactionOptions.kt
│ │ ├── HistogramData.kt
│ │ ├── MutableColumnFamilyOptionsInterface.kt
│ │ ├── Checkpoint.kt
│ │ ├── Cache.kt
│ │ ├── SstFileMetaData.kt
│ │ ├── Slice.kt
│ │ ├── RocksEnv.kt
│ │ ├── BloomFilter.kt
│ │ ├── PersistentCache.kt
│ │ ├── WriteBatchInterface.kt
│ │ ├── WriteBufferManager.kt
│ │ ├── ColumnFamilyHandle.kt
│ │ └── CompressionType.kt
│ │ ├── UByteToBoolean.kt
│ │ ├── toByteArray.kt
│ │ ├── asSizeT.kt
│ │ ├── byteArrayToCPointer.kt
│ │ ├── convertToStatus.kt
│ │ ├── Buffer.kt
│ │ └── wrapWithMultiErrorThrower.kt
├── jvmTest
│ └── kotlin
│ │ └── maryk
│ │ ├── createFolder.kt
│ │ ├── doesFolderExist.kt
│ │ ├── deleteFolder.kt
│ │ └── rocksdb
│ │ └── util
│ │ ├── Sleep.kt
│ │ └── ThreadSafeCounter.kt
├── linuxTest
│ └── kotlin
│ │ └── maryk
│ │ ├── deleteFolder.kt
│ │ ├── doesFolderExist.kt
│ │ └── createFolder.kt
├── mingwTest
│ └── kotlin
│ │ └── maryk
│ │ ├── createFolder.kt
│ │ ├── deleteFolder.kt
│ │ └── doesFolderExist.kt
├── appleTest
│ └── kotlin
│ │ └── maryk
│ │ ├── doesFolderExist.kt
│ │ ├── deleteFolder.kt
│ │ └── createFolder.kt
├── nativeTest
│ └── kotlin
│ │ └── maryk
│ │ └── rocksdb
│ │ └── util
│ │ ├── Sleep.kt
│ │ └── ThreadSafeCounter.kt
└── androidNativeTest
│ └── kotlin
│ └── maryk
│ └── folderUtils.kt
├── .gitignore
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── settings.gradle.kts
└── .github
└── workflows
└── build.yml
/.gitmodules:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/androidMain:
--------------------------------------------------------------------------------
1 | /Users/jurmous/space/rocksdb-multiplatform/src/jvmMain
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | build
3 |
4 | xcodeBuild
5 | local.properties
6 | /.kotlin/
7 | /lib/
8 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/Buffer.kt:
--------------------------------------------------------------------------------
1 | package maryk
2 |
3 | actual typealias Buffer = java.nio.Buffer
4 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/loadLibrary.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | expect fun loadRocksDBLibrary()
4 |
--------------------------------------------------------------------------------
/src/commonTest/kotlin/maryk/createFolder.kt:
--------------------------------------------------------------------------------
1 | package maryk
2 |
3 | expect fun createFolder(path: String) : Boolean
4 |
--------------------------------------------------------------------------------
/src/commonTest/kotlin/maryk/deleteFolder.kt:
--------------------------------------------------------------------------------
1 | package maryk
2 |
3 | expect fun deleteFolder(path: String) : Boolean
4 |
--------------------------------------------------------------------------------
/src/jvmMain/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/src/commonTest/kotlin/maryk/doesFolderExist.kt:
--------------------------------------------------------------------------------
1 | package maryk
2 |
3 | expect fun doesFolderExist(path: String): Boolean
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/Cache.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias Cache = org.rocksdb.Cache
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/Logger.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias Logger = org.rocksdb.Logger
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/Range.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias Range = org.rocksdb.Range
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/Slice.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias Slice = org.rocksdb.Slice
4 |
--------------------------------------------------------------------------------
/src/commonTest/kotlin/maryk/rocksdb/util/Sleep.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb.util
2 |
3 | expect fun sleepMillis(millis: Long)
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/LRUCache.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias LRUCache = org.rocksdb.LRUCache
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/MemEnv.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias MemEnv = org.rocksdb.RocksMemEnv
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/Options.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias Options = org.rocksdb.Options
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/Priority.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias Priority = org.rocksdb.Priority
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/ReadTier.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias ReadTier = org.rocksdb.ReadTier
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/Snapshot.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias Snapshot = org.rocksdb.Snapshot
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/TimedEnv.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias TimedEnv = org.rocksdb.TimedEnv
4 |
--------------------------------------------------------------------------------
/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marykdb/rocksdb-multiplatform/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/IndexType.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias IndexType = org.rocksdb.IndexType
4 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/BooleanToUByte.kt:
--------------------------------------------------------------------------------
1 | package maryk
2 |
3 | internal fun Boolean.toUByte(): UByte = if (this) 1u else 0u
4 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/TableFormatConfig.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual abstract class TableFormatConfig
4 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/loadRocksDBLibrary.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual fun loadRocksDBLibrary() {
4 | }
5 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/AbstractMutableOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | expect open class AbstractMutableOptions
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/BloomFilter.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias BloomFilter = org.rocksdb.BloomFilter
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/EnvOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias EnvOptions = org.rocksdb.EnvOptions
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/PerfContext.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias PerfContext = org.rocksdb.PerfContext
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/RateLimiter.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias RateLimiter = org.rocksdb.RateLimiter
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/RocksObject.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias RocksObject = org.rocksdb.RocksObject
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/SanityLevel.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias SanityLevel = org.rocksdb.SanityLevel
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/TraceWriter.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias TraceWriter = org.rocksdb.TraceWriter
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/Transaction.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias Transaction = org.rocksdb.Transaction
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/WalFileType.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias WalFileType = org.rocksdb.WalFileType
4 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/FilterPolicy.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual abstract class FilterPolicy : RocksObject()
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/ConfigOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias ConfigOptions = org.rocksdb.ConfigOptions
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/EncodingType.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias EncodingType = org.rocksdb.EncodingType
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/FlushOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias FlushOptions = org.rocksdb.FlushOptions
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/HistogramData.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias HistogramData = org.rocksdb.HistogramData
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/HistogramType.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias HistogramType = org.rocksdb.HistogramType
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/InfoLogLevel.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias InfoLogLevel = org.rocksdb.InfoLogLevel
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/LevelMetaData.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias LevelMetaData = org.rocksdb.LevelMetaData
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/MergeOperator.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias MergeOperator = org.rocksdb.MergeOperator
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/RocksIterator.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias RocksIterator = org.rocksdb.RocksIterator
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/SstFileReader.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias SstFileReader = org.rocksdb.SstFileReader
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/SstFileWriter.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias SstFileWriter = org.rocksdb.SstFileWriter
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/TraceOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias TraceOptions = org.rocksdb.TraceOptions
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/TransactionDB.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias TransactionDB = org.rocksdb.TransactionDB
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/WriteOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias WriteOptions = org.rocksdb.WriteOptions
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/MemTableConfig.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias MemTableConfig = org.rocksdb.MemTableConfig
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/RestoreOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias RestoreOptions = org.rocksdb.RestoreOptions
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/SstFileManager.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias SstFileManager = org.rocksdb.SstFileManager
4 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/MemTableConfig.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual abstract class MemTableConfig actual constructor()
4 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/Range.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual class Range actual constructor(start: Slice, limit: Slice)
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/CompactionReason.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias CompactionReason = org.rocksdb.CompactionReason
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/CompactionStyle.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias CompactionStyle = org.rocksdb.CompactionStyle
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/LiveFileMetaData.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias LiveFileMetaData = org.rocksdb.LiveFileMetaData
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/MemoryUsageType.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias MemoryUsageType = org.rocksdb.MemoryUsageType
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/PersistentCache.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias PersistentCache = org.rocksdb.PersistentCache
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/PlainTableConfig.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias PlainTableConfig = org.rocksdb.PlainTableConfig
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/RocksDBException.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias RocksDBException = org.rocksdb.RocksDBException
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/SstFileMetaData.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias SstFileMetaData = org.rocksdb.SstFileMetaData
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/TxnDBWritePolicy.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias TxnDBWritePolicy = org.rocksdb.TxnDBWritePolicy
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/WriteEntry.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias WriteEntry = org.rocksdb.WBWIRocksIterator.WriteEntry
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/WriteType.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias WriteType = org.rocksdb.WBWIRocksIterator.WriteType
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/loadLibrary.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual fun loadRocksDBLibrary() {
4 | RocksDB.loadLibrary()
5 | }
6 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/AbstractWriteBatch.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias AbstractWriteBatch = org.rocksdb.AbstractWriteBatch
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/BuiltinComparator.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias BuiltinComparator = org.rocksdb.BuiltinComparator
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/ColumnFamilyHandle.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias ColumnFamilyHandle = org.rocksdb.ColumnFamilyHandle
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/CompactionPriority.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias CompactionPriority = org.rocksdb.CompactionPriority
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/ComparatorOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias ComparatorOptions = org.rocksdb.ComparatorOptions
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/CompressionOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias CompressionOptions = org.rocksdb.CompressionOptions
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/DataBlockIndexType.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias DataBlockIndexType = org.rocksdb.DataBlockIndexType
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/RocksMutableObject.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias RocksMutableObject = org.rocksdb.RocksMutableObject
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/TableFormatConfig.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias TableFormatConfig = org.rocksdb.TableFormatConfig
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/TransactionOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias TransactionOptions = org.rocksdb.TransactionOptions
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/WBWIRocksIterator.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias WBWIRocksIterator = org.rocksdb.WBWIRocksIterator
4 |
--------------------------------------------------------------------------------
/src/jvmTest/kotlin/maryk/createFolder.kt:
--------------------------------------------------------------------------------
1 | package maryk
2 |
3 | import java.io.File
4 |
5 | actual fun createFolder(path: String) = File(path).mkdirs()
6 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/RocksObject.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual abstract class RocksObject: AbstractImmutableNativeReference()
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/AbstractTraceWriter.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias AbstractTraceWriter = org.rocksdb.AbstractTraceWriter
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/BackupEngineOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias BackupEngineOptions = org.rocksdb.BackupEngineOptions
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/ColumnFamilyOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias ColumnFamilyOptions = org.rocksdb.ColumnFamilyOptions
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/CompactRangeOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias CompactRangeOptions = org.rocksdb.CompactRangeOptions
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/CompactionStopStyle.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias CompactionStopStyle = org.rocksdb.CompactionStopStyle
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/RocksCallbackObject.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias RocksCallbackObject = org.rocksdb.RocksCallbackObject
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/TickerType.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import org.rocksdb.TickerType
4 |
5 | actual typealias TickerType = TickerType
6 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/WriteBatchInterface.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias WriteBatchInterface = org.rocksdb.WriteBatchInterface
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/WriteBatchWithIndex.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias WriteBatchWithIndex = org.rocksdb.WriteBatchWithIndex
4 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/AbstractNativeReference.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual abstract class AbstractNativeReference : AutoCloseable
4 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/Range.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /** Range from start to limit. */
4 | expect class Range(start: Slice, limit: Slice)
5 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/BlockBasedTableConfig.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias BlockBasedTableConfig = org.rocksdb.BlockBasedTableConfig
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/ColumnFamilyMetaData.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias ColumnFamilyMetaData = org.rocksdb.ColumnFamilyMetaData
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/DBOptionsInterface.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias DBOptionsInterface = org.rocksdb.DBOptionsInterface
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/SizeApproximationFlag.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias SizeApproximationFlag = org.rocksdb.SizeApproximationFlag
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/StringAppendOperator.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias StringAppendOperator = org.rocksdb.StringAppendOperator
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/TransactionDBOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias TransactionDBOptions = org.rocksdb.TransactionDBOptions
4 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/MemEnv.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /** In-memory environment implementation. */
4 | expect class MemEnv(baseEnv: Env) : Env
5 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/RocksCallbackObject.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | expect abstract class RocksCallbackObject : AbstractImmutableNativeReference
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/AbstractMutableOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias AbstractMutableOptions = org.rocksdb.AbstractMutableOptions
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/AbstractNativeReference.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias AbstractNativeReference = org.rocksdb.AbstractNativeReference
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/AbstractRocksIterator.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias AbstractRocksIterator = org.rocksdb.AbstractRocksIterator
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/ColumnFamilyDescriptor.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias ColumnFamilyDescriptor = org.rocksdb.ColumnFamilyDescriptor
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/Env.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias Env = org.rocksdb.Env
4 |
5 | actual fun getDefaultEnv(): Env = Env.getDefault()
6 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/RocksIteratorInterface.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias RocksIteratorInterface = org.rocksdb.RocksIteratorInterface
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/WaitingTransactions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias WaitingTransactions = org.rocksdb.Transaction.WaitingTransactions
4 |
--------------------------------------------------------------------------------
/src/jvmTest/kotlin/maryk/doesFolderExist.kt:
--------------------------------------------------------------------------------
1 | package maryk
2 |
3 | import java.io.File
4 |
5 | actual fun doesFolderExist(path: String) =
6 | File(path).exists()
7 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/ComparatorOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual class ComparatorOptions
4 | actual constructor()
5 | : RocksObject()
6 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/RocksCallbackObject.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual abstract class RocksCallbackObject : AbstractImmutableNativeReference()
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/ImportColumnFamilyOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias ImportColumnFamilyOptions = org.rocksdb.ImportColumnFamilyOptions
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/IngestExternalFileOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias IngestExternalFileOptions = org.rocksdb.IngestExternalFileOptions
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/AbstractTransactionNotifier.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias AbstractTransactionNotifier = org.rocksdb.AbstractTransactionNotifier
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/MutableDBOptionsInterface.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias MutableDBOptionsInterface = org.rocksdb.MutableDBOptionsInterface
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/OptimisticTransactionOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias OptimisticTransactionOptions = org.rocksdb.OptimisticTransactionOptions
4 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/SanityLevel.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual enum class SanityLevel {
4 | NONE,
5 | LOOSELY_COMPATIBLE,
6 | EXACT_MATCH;
7 | }
8 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/Buffer.kt:
--------------------------------------------------------------------------------
1 | package maryk
2 |
3 | expect abstract class Buffer {
4 | abstract fun array(): Any
5 | fun remaining(): Int
6 | fun position(): Int
7 | }
8 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/Logger.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /** Logger used by RocksDB for info and debug output. */
4 | expect abstract class Logger : RocksCallbackObject
5 |
--------------------------------------------------------------------------------
/src/commonTest/kotlin/maryk/rocksdb/util/ThreadSafeCounter.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb.util
2 |
3 | expect class ThreadSafeCounter() {
4 | fun increment()
5 | fun value(): Int
6 | }
7 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/ComparatorType.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual enum class ComparatorType {
4 | JAVA_COMPARATOR,
5 | JAVA_NATIVE_COMPARATOR_WRAPPER,
6 | }
7 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/DirectSlice.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias DirectSlice = org.rocksdb.DirectSlice
4 |
5 | actual val DirectSliceNone = DirectSlice.NONE
6 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/TransactionState.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import org.rocksdb.Transaction
4 |
5 | actual typealias TransactionState = Transaction.TransactionState
6 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/AbstractTraceWriter.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual abstract class AbstractTraceWriter actual constructor() : RocksCallbackObject(), TraceWriter
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/Holder.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import org.rocksdb.Holder
4 |
5 | /** Simple instance reference wrapper. */
6 | actual typealias Holder = Holder
7 |
--------------------------------------------------------------------------------
/src/jvmTest/kotlin/maryk/deleteFolder.kt:
--------------------------------------------------------------------------------
1 | package maryk
2 |
3 | import java.io.File
4 |
5 | actual fun deleteFolder(path: String): Boolean {
6 | return File(path).deleteRecursively()
7 | }
8 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/ComparatorType.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual enum class ComparatorType {
4 | JAVA_COMPARATOR,
5 | JAVA_NATIVE_COMPARATOR_WRAPPER,
6 | }
7 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/AbstractCompactionFilterFactory.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias AbstractCompactionFilterFactory = org.rocksdb.AbstractCompactionFilterFactory
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/AbstractImmutableNativeReference.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias AbstractImmutableNativeReference = org.rocksdb.AbstractImmutableNativeReference
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/BottommostLevelCompaction.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias BottommostLevelCompaction = org.rocksdb.CompactRangeOptions.BottommostLevelCompaction
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/RemoveEmptyValueCompactionFilter.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias RemoveEmptyValueCompactionFilter = org.rocksdb.RemoveEmptyValueCompactionFilter
4 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/BuiltinComparator.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual enum class BuiltinComparator {
4 | BYTEWISE_COMPARATOR,
5 | REVERSE_BYTEWISE_COMPARATOR
6 | }
7 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/ChecksumType.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /** Checksum types used in conjunction with BlockBasedTable. */
4 | actual typealias ChecksumType = org.rocksdb.ChecksumType
5 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/UByteToBoolean.kt:
--------------------------------------------------------------------------------
1 | package maryk
2 |
3 | private val TRUE = 1u.toUByte()
4 | internal fun UByte.toBoolean() = when (this) {
5 | TRUE -> true
6 | else -> false
7 | }
8 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/OptimisticTransactionDB.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import org.rocksdb.OptimisticTransactionDB
4 |
5 | actual typealias OptimisticTransactionDB = OptimisticTransactionDB
6 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/RemoveEmptyValueCompactionFilter.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual class RemoveEmptyValueCompactionFilter actual constructor() : AbstractCompactionFilter()
4 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/StatsLevel.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias StatsLevel = org.rocksdb.StatsLevel
4 |
5 | fun getStatsLevel(value: Byte) =
6 | StatsLevel.getStatsLevel(value)
7 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/WriteBatch.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias WriteBatch = org.rocksdb.WriteBatch
4 |
5 | actual typealias WriteBatchSavePoint = org.rocksdb.WriteBatch.SavePoint
6 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/createCheckPoint.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias Checkpoint = org.rocksdb.Checkpoint
4 |
5 | actual fun createCheckpoint(db: RocksDB) = Checkpoint.create(db)
6 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/MutableColumnFamilyOptionsInterface.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias MutableColumnFamilyOptionsInterface =
4 | org.rocksdb.MutableColumnFamilyOptionsInterface
5 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/WalFileType.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual enum class WalFileType(
4 | private val value: Byte
5 | ) {
6 | kArchivedLogFile(0x0),
7 | kAliveLogFile(0x1)
8 | }
9 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/AbstractTraceWriter.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Base class for TraceWriters.
5 | */
6 | expect abstract class AbstractTraceWriter() : RocksCallbackObject, TraceWriter
7 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/EnvOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Wrapper for RocksDB EnvOptions controlling I/O behaviour for auxiliary tools.
5 | */
6 | expect class EnvOptions() : RocksObject
7 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/PerfLevel.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias PerfLevel = org.rocksdb.PerfLevel
4 |
5 | actual fun perfLevelFromValue(value: Byte): PerfLevel = PerfLevel.getPerfLevel(value)
6 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/BackupInfo.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Instances of this class describe a Backup made by
5 | * [BackupEngine].
6 | */
7 | actual typealias BackupInfo = org.rocksdb.BackupInfo
8 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/Priority.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * The Thread Pool priority.
5 | */
6 | expect enum class Priority {
7 | BOTTOM,
8 | LOW,
9 | HIGH,
10 | TOTAL;
11 | }
12 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/DBOptionsInterface.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual interface DBOptionsInterface> {
4 | actual fun setEnv(env: Env): T
5 | actual fun getEnv(): Env
6 | }
7 |
--------------------------------------------------------------------------------
/src/linuxTest/kotlin/maryk/deleteFolder.kt:
--------------------------------------------------------------------------------
1 | package maryk
2 |
3 | import platform.posix.rmdir
4 |
5 | actual fun deleteFolder(path: String) =
6 | when (rmdir(path)) {
7 | 0 -> true
8 | else -> false
9 | }
10 |
--------------------------------------------------------------------------------
/src/linuxTest/kotlin/maryk/doesFolderExist.kt:
--------------------------------------------------------------------------------
1 | package maryk
2 |
3 | import platform.posix.opendir
4 |
5 | actual fun doesFolderExist(path: String): Boolean {
6 | val directory = opendir(path)
7 | return directory != null
8 | }
9 |
--------------------------------------------------------------------------------
/src/mingwTest/kotlin/maryk/createFolder.kt:
--------------------------------------------------------------------------------
1 | package maryk
2 |
3 | import platform.posix.mkdir
4 |
5 | actual fun createFolder(path: String) =
6 | when (mkdir(path)) {
7 | 0 -> true
8 | else -> false
9 | }
10 |
--------------------------------------------------------------------------------
/src/mingwTest/kotlin/maryk/deleteFolder.kt:
--------------------------------------------------------------------------------
1 | package maryk
2 |
3 | import platform.posix.rmdir
4 |
5 | actual fun deleteFolder(path: String) =
6 | when (rmdir(path)) {
7 | 0 -> true
8 | else -> false
9 | }
10 |
--------------------------------------------------------------------------------
/src/mingwTest/kotlin/maryk/doesFolderExist.kt:
--------------------------------------------------------------------------------
1 | package maryk
2 |
3 | import platform.posix.opendir
4 |
5 | actual fun doesFolderExist(path: String): Boolean {
6 | val directory = opendir(path)
7 | return directory != null
8 | }
9 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/ChecksumType.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual enum class ChecksumType(
4 | internal val value: Byte
5 | ) {
6 | kNoChecksum(0),
7 | kCRC32c(1),
8 | kxxHash(2);
9 | }
10 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/DataBlockIndexType.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual enum class DataBlockIndexType(
4 | private val value: Byte
5 | ) {
6 | kDataBlockBinarySearch(0),
7 | kDataBlockBinaryAndHash(1);
8 | }
9 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/Snapshot.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /** Snapshot of database */
4 | expect class Snapshot : RocksObject {
5 | /** Return the associated sequence number */
6 | fun getSequenceNumber(): Long
7 | }
8 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/AbstractTransactionNotifier.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual abstract class AbstractTransactionNotifier: RocksCallbackObject() {
4 | actual abstract fun snapshotCreated(newSnapshot: Snapshot)
5 | }
6 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/IndexType.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual enum class IndexType(
4 | internal val value: Byte
5 | ) {
6 | kBinarySearch(0),
7 | kHashSearch(1),
8 | kTwoLevelIndexSearch(2);
9 | }
10 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/TraceWriter.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual interface TraceWriter {
4 | actual fun write(data: Slice)
5 |
6 | actual fun closeWriter()
7 |
8 | actual fun getFileSize(): Long
9 | }
10 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/Status.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias Status = org.rocksdb.Status
4 |
5 | actual typealias StatusCode = org.rocksdb.Status.Code
6 |
7 | actual typealias StatusSubCode = org.rocksdb.Status.SubCode
8 |
--------------------------------------------------------------------------------
/src/jvmTest/kotlin/maryk/rocksdb/util/Sleep.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb.util
2 |
3 | actual fun sleepMillis(millis: Long) {
4 | if (millis <= 0L) {
5 | Thread.yield()
6 | } else {
7 | Thread.sleep(millis)
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/ComparatorType.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /** Types of comparators supported by the RocksDB JNI layer. */
4 | expect enum class ComparatorType {
5 | JAVA_COMPARATOR,
6 | JAVA_NATIVE_COMPARATOR_WRAPPER,
7 | }
8 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/RemoveEmptyValueCompactionFilter.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /** A wrapper around EmptyValueCompactionFilter implemented in C++ */
4 | expect class RemoveEmptyValueCompactionFilter() : AbstractCompactionFilter
5 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/Priority.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual enum class Priority(
4 | internal val value: UByte
5 | ) {
6 | BOTTOM(0u),
7 | LOW(1u),
8 | HIGH(2u),
9 | USER(3u),
10 | TOTAL(4u);
11 | }
12 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/TransactionLogIterator.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias TransactionLogIterator = org.rocksdb.TransactionLogIterator
4 | actual typealias TransactionLogBatchResult = org.rocksdb.TransactionLogIterator.BatchResult
5 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/SanityLevel.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Sanity checks applied when loading options files.
5 | */
6 | expect enum class SanityLevel {
7 | NONE,
8 | LOOSELY_COMPATIBLE,
9 | EXACT_MATCH,
10 | }
11 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/SizeApproximationFlag.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual enum class SizeApproximationFlag(
4 | internal val value: Byte
5 | ) {
6 | NONE(0x0),
7 | INCLUDE_MEMTABLES(0x1),
8 | INCLUDE_FILES(0x2)
9 | }
10 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/WALRecoveryMode.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias WALRecoveryMode = org.rocksdb.WALRecoveryMode
4 |
5 | actual fun walRecoveryModeFromValue(value: Byte): WALRecoveryMode =
6 | WALRecoveryMode.getWALRecoveryMode(value)
7 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/AbstractCompactionFilter.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias AbstractCompactionFilter = org.rocksdb.AbstractCompactionFilter
4 |
5 | actual typealias AbstractCompactionFilterContext = org.rocksdb.AbstractCompactionFilter.Context
6 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/MemEnv.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import rocksdb.rocksdb_mem_env_create
4 |
5 | actual class MemEnv actual constructor(baseEnv: Env) : Env(
6 | rocksdb_mem_env_create(baseEnv.native) ?: error("Unable to create in-memory env"),
7 | )
8 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/TimedEnv.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import rocksdb.rocksdb_timed_env_create
4 |
5 | actual class TimedEnv actual constructor(baseEnv: Env) : Env(
6 | rocksdb_timed_env_create(baseEnv.native) ?: error("Unable to create timed env"),
7 | )
8 |
--------------------------------------------------------------------------------
/src/linuxTest/kotlin/maryk/createFolder.kt:
--------------------------------------------------------------------------------
1 | package maryk
2 |
3 | import platform.posix.S_IRWXU
4 | import platform.posix.mkdir
5 |
6 | actual fun createFolder(path: String) =
7 | when (mkdir(path, S_IRWXU.toUInt())) {
8 | 0 -> true
9 | else -> false
10 | }
11 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/AbstractMutableOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual open class AbstractMutableOptions : RocksMutableObject() {
4 | protected open fun dispose() {}
5 |
6 | final override fun disposeInternal() {
7 | dispose()
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/RocksMutableObject.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual abstract class RocksMutableObject : AbstractNativeReference() {
4 | protected abstract fun disposeInternal()
5 | actual override final fun close() {
6 | disposeInternal()
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/MergeOperator.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * MergeOperator holds an operator to be applied when compacting
5 | * two merge operands held under the same key in order to obtain a single
6 | * value.
7 | */
8 | expect abstract class MergeOperator : RocksObject
9 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/SstFileReader.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Helper to inspect external SST files prior to ingestion.
5 | */
6 | expect class SstFileReader(options: Options) : RocksObject {
7 | fun open(filePath: String)
8 |
9 | fun verifyChecksum()
10 | }
11 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-all.zip
4 | networkTimeout=10000
5 | validateDistributionUrl=true
6 | zipStoreBase=GRADLE_USER_HOME
7 | zipStorePath=wrapper/dists
8 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/InfoLogLevel.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /** RocksDB log levels. */
4 | expect enum class InfoLogLevel {
5 | DEBUG_LEVEL,
6 | INFO_LEVEL,
7 | WARN_LEVEL,
8 | ERROR_LEVEL,
9 | FATAL_LEVEL,
10 | HEADER_LEVEL,
11 | NUM_INFO_LOG_LEVELS;
12 | }
13 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/CompactionOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias CompactionOptions = org.rocksdb.CompactionOptions
4 | actual typealias CompactionOptionsFIFO = org.rocksdb.CompactionOptionsFIFO
5 | actual typealias CompactionOptionsUniversal = org.rocksdb.CompactionOptionsUniversal
6 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/ReadOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias ReadOptions = org.rocksdb.ReadOptions
4 |
5 | actual fun ReadOptions.setTableFilter(tableFilter: AbstractTableFilter): ReadOptions =
6 | this.apply { setTableFilter(tableFilter as org.rocksdb.AbstractTableFilter) }
7 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/ReadTier.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual enum class ReadTier(
4 | private val value: Byte
5 | ) {
6 | READ_ALL_TIER(0),
7 | BLOCK_CACHE_TIER(1),
8 | PERSISTED_TIER(2),
9 | MEMTABLE_TIER(3);
10 |
11 | actual fun getValue() = value
12 | }
13 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/AbstractTableFilter.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /** Base class for table filters implemented in Kotlin. */
4 | expect abstract class AbstractTableFilter protected constructor() : RocksCallbackObject {
5 | protected abstract fun filter(tableProperties: TableProperties): Boolean
6 | }
7 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/BloomFilter.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /** Bloom filter wrapper used by [BlockBasedTableConfig]. */
4 | expect class BloomFilter : FilterPolicy {
5 | constructor()
6 | constructor(bitsPerKey: Double)
7 | constructor(bitsPerKey: Double, useBlockBasedBuilder: Boolean)
8 | }
9 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/PersistentCache.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /** Persistent cache for caching IO pages on persistent media. */
4 | expect class PersistentCache(
5 | env: Env,
6 | path: String,
7 | size: Long,
8 | logger: Logger,
9 | optimizedForNvm: Boolean
10 | ) : RocksObject
11 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/WBWIRocksIterator.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import cnames.structs.rocksdb_iterator_t
4 | import kotlinx.cinterop.CPointer
5 |
6 | actual class WBWIRocksIterator internal constructor(
7 | native: CPointer
8 | ) : AbstractRocksIterator(native)
9 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/TraceOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual class TraceOptions actual constructor(
4 | private val maxTraceFileSize: Long
5 | ) {
6 | // 64 GB
7 | actual constructor() : this(64 * 1024L * 1024L * 1024L)
8 |
9 | actual fun getMaxTraceFileSize() = maxTraceFileSize
10 | }
11 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/GetStatus.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual class GetStatus internal constructor(
4 | internal val status: Status,
5 | internal val requiredSize: Int
6 | )
7 |
8 | actual fun GetStatus.getStatus(): Status = this.status
9 |
10 | actual fun GetStatus.getRequiredSize(): Int = this.requiredSize
11 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/ChecksumType.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Checksum types used in conjunction with BlockBasedTable.
5 | */
6 | expect enum class ChecksumType {
7 | /** Not implemented yet. */
8 | kNoChecksum,
9 | /** CRC32 Checksum */
10 | kCRC32c,
11 | /** XX Hash */
12 | kxxHash;
13 | }
14 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/WriteType.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb;
2 |
3 | /**
4 | * Enumeration of the Write operation
5 | * that created the record in the Write Batch
6 | */
7 | expect enum class WriteType {
8 | PUT,
9 | MERGE,
10 | DELETE,
11 | SINGLE_DELETE,
12 | DELETE_RANGE,
13 | LOG,
14 | XID;
15 | }
16 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/BackupEngine.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import org.rocksdb.BackupEngineOptions
4 |
5 | actual typealias BackupEngine = org.rocksdb.BackupEngine
6 |
7 | actual fun openBackupEngine(
8 | env: Env,
9 | options: BackupEngineOptions
10 | ): BackupEngine = BackupEngine.open(
11 | env, options
12 | )
13 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/LevelMetaData.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual class LevelMetaData(
4 | val level: Int,
5 | val size: ULong,
6 | val files: List,
7 | ) {
8 | actual fun level() = level.toInt()
9 |
10 | actual fun size() = size.toLong()
11 |
12 | actual fun files() = files
13 | }
14 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/MemoryUsageType.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual enum class MemoryUsageType(
4 | private val value: Byte
5 | ) {
6 | kMemTableTotal(0),
7 | kMemTableUnFlushed(1),
8 | kTableReadersTotal(2),
9 | kCacheTotal(3),
10 | kNumUsageTypes(4);
11 |
12 | actual fun getValue() = value
13 | }
14 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/ReadTier.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | expect enum class ReadTier {
4 | READ_ALL_TIER,
5 | BLOCK_CACHE_TIER,
6 | PERSISTED_TIER,
7 | MEMTABLE_TIER;
8 |
9 | /**
10 | * Returns the byte value of the enumerations value
11 | * @return byte representation
12 | */
13 | fun getValue(): Byte
14 | }
15 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/SizeApproximationFlag.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Flags for [RocksDB.getApproximateSizes]
5 | * that specify whether memtable stats should be included,
6 | * or file stats approximation or both.
7 | */
8 | expect enum class SizeApproximationFlag {
9 | NONE,
10 | INCLUDE_MEMTABLES,
11 | INCLUDE_FILES
12 | }
13 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/TransactionState.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Represents the execution state of a transaction.
5 | */
6 | expect enum class TransactionState {
7 | STARTED,
8 | AWAITING_PREPARE,
9 | PREPARED,
10 | AWAITING_COMMIT,
11 | COMMITTED,
12 | AWAITING_ROLLBACK,
13 | ROLLEDBACK,
14 | LOCKS_STOLEN;
15 | }
16 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/AbstractCompactionFilterFactory.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual abstract class AbstractCompactionFilterFactory> actual constructor() :
4 | RocksCallbackObject() {
5 | actual abstract fun name(): String
6 |
7 | actual abstract fun createCompactionFilter(context: AbstractCompactionFilterContext): T
8 | }
9 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/TableFormatConfig.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * TableFormatConfig configures the table factory backing SST files produced by RocksDB.
5 | * Instances are typically passed into [Options.setTableFormatConfig] or
6 | * [ColumnFamilyOptions.setTableFormatConfig] to bind the desired table format.
7 | */
8 | expect abstract class TableFormatConfig
9 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/CompressionType.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias CompressionType = org.rocksdb.CompressionType
4 |
5 | actual fun getCompressionType(libraryName: String?) =
6 | CompressionType.getCompressionType(libraryName)
7 |
8 | actual fun getCompressionType(byteIdentifier: Byte) =
9 | CompressionType.getCompressionType(byteIdentifier)
10 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/toByteArray.kt:
--------------------------------------------------------------------------------
1 | @file:OptIn(UnsafeNumber::class)
2 |
3 | package maryk
4 |
5 | import kotlinx.cinterop.ByteVar
6 | import kotlinx.cinterop.CPointer
7 | import kotlinx.cinterop.UnsafeNumber
8 | import kotlinx.cinterop.readBytes
9 | import platform.posix.size_t
10 |
11 | fun CPointer.toByteArray(value: size_t) =
12 | this.readBytes(value.toInt())
13 |
--------------------------------------------------------------------------------
/src/commonTest/kotlin/maryk/rocksdb/util/dummyString.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb.util
2 |
3 | import kotlin.random.Random
4 |
5 | /**
6 | * Generate a random string of bytes.
7 | * @param len the length of the string to generate.
8 | * @return the random string of bytes
9 | */
10 | fun dummyString(len: Int) =
11 | ByteArray(len).apply {
12 | Random.nextBytes(this)
13 | }
14 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/FlushReason.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias FlushReason = org.rocksdb.FlushReason
4 |
5 | actual fun FlushReason.value(): Byte = ordinal.toByte()
6 |
7 | actual fun flushReasonFromValue(value: Byte): FlushReason =
8 | FlushReason.values().firstOrNull { it.ordinal.toByte() == value }
9 | ?: error("Unknown FlushReason value: $value")
10 |
--------------------------------------------------------------------------------
/src/jvmTest/kotlin/maryk/rocksdb/util/ThreadSafeCounter.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb.util
2 |
3 | import java.util.concurrent.atomic.AtomicInteger
4 |
5 | actual class ThreadSafeCounter actual constructor() {
6 | private val counter = AtomicInteger(0)
7 |
8 | actual fun increment() {
9 | counter.incrementAndGet()
10 | }
11 |
12 | actual fun value(): Int = counter.get()
13 | }
14 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/DataBlockIndexType.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * DataBlockIndexType used in conjunction with BlockBasedTable.
5 | */
6 | expect enum class DataBlockIndexType {
7 | /**
8 | * traditional block type
9 | */
10 | kDataBlockBinarySearch,
11 |
12 | /**
13 | * additional hash index
14 | */
15 | kDataBlockBinaryAndHash;
16 | }
17 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/ComparatorOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 |
4 | /**
5 | * This class controls the behaviour
6 | * of Java implementations of
7 | * AbstractComparator
8 | *
9 | * Note that dispose() must be called before a ComparatorOptions
10 | * instance becomes out-of-scope to release the allocated memory in C++.
11 | */
12 | expect class ComparatorOptions() : RocksObject
13 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/WriteBufferManager.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Coordinates write buffer memory usage across column families and instances.
5 | */
6 | expect class WriteBufferManager : RocksObject {
7 | constructor(bufferSize: Long, cache: Cache, allowStall: Boolean)
8 |
9 | constructor(bufferSize: Long, cache: Cache)
10 |
11 | fun allowStall(): Boolean
12 | }
13 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/WaitingTransactions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual class WaitingTransactions(
4 | val columnFamilyId: Long,
5 | val key: String,
6 | val transactionIds: LongArray,
7 | ){
8 |
9 | actual fun getColumnFamilyId(): Long = columnFamilyId
10 | actual fun getKey(): String = key
11 | actual fun getTransactionIds(): LongArray = transactionIds
12 | }
13 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/WriteStallCondition.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual enum class WriteStallCondition(internal val value: UByte) {
4 | DELAYED(0u),
5 | STOPPED(1u),
6 | NORMAL(2u);
7 | }
8 |
9 | internal fun writeStallConditionFromValue(value: UByte): WriteStallCondition =
10 | WriteStallCondition.entries.firstOrNull { it.value == value } ?: WriteStallCondition.NORMAL
11 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/BuiltinComparator.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Builtin RocksDB comparators
5 | *
6 | * 1. BYTEWISE_COMPARATOR - Sorts all keys in ascending bytewise order.
7 | * 2. REVERSE_BYTEWISE_COMPARATOR - Sorts all keys in descending bytewise order
8 | */
9 | expect enum class BuiltinComparator {
10 | BYTEWISE_COMPARATOR,
11 | REVERSE_BYTEWISE_COMPARATOR
12 | }
13 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/ColumnFamilyHandle.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | expect class ColumnFamilyHandle : RocksObject {
4 | /**
5 | * Gets the name of the Column Family.
6 | *
7 | * @throws RocksDBException if an error occurs whilst retrieving the name.
8 | */
9 | fun getName(): ByteArray
10 |
11 | /** Gets the ID of the Column Family. */
12 | fun getID(): Int
13 | }
14 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/FlushOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Options that configure manual flush behaviour when calling [RocksDB.flush].
5 | */
6 | expect class FlushOptions() : RocksObject {
7 | fun setWaitForFlush(wait: Boolean): FlushOptions
8 | fun waitForFlush(): Boolean
9 | fun setAllowWriteStall(allow: Boolean): FlushOptions
10 | fun allowWriteStall(): Boolean
11 | }
12 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/RateLimiter.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | expect class RateLimiter : RocksObject {
4 | constructor(rateBytesPerSecond: Long)
5 | constructor(rateBytesPerSecond: Long, refillPeriodMicros: Long)
6 | constructor(rateBytesPerSecond: Long, refillPeriodMicros: Long, fairness: Int)
7 |
8 | fun setBytesPerSecond(rateBytesPerSecond: Long)
9 | fun getBytesPerSecond(): Long
10 | }
11 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/FilterPolicy.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Filters are stored in rocksdb and are consulted automatically
5 | * by rocksdb to decide whether or not to read some
6 | * information from disk. In many cases, a filter can cut down the
7 | * number of disk seeks form a handful to a single disk seek per
8 | * DB::Get() call.
9 | */
10 | expect abstract class FilterPolicy : RocksObject
11 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/FilterPolicy.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Filters are stored in rocksdb and are consulted automatically
5 | * by rocksdb to decide whether or not to read some
6 | * information from disk. In many cases, a filter can cut down the
7 | * number of disk seeks form a handful to a single disk seek per
8 | * DB::Get() call.
9 | */
10 | actual typealias FilterPolicy = org.rocksdb.Filter
11 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/CompactionStopStyle.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Algorithm used to make a compaction request stop picking new files
5 | * into a single compaction run
6 | */
7 | expect enum class CompactionStopStyle {
8 | /** Pick files of similar size */
9 | CompactionStopStyleSimilarSize,
10 |
11 | /** Total size of picked files > next file */
12 | CompactionStopStyleTotalSize;
13 | }
14 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/AbstractTableFilter.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual abstract class AbstractTableFilter protected actual constructor() :
4 | org.rocksdb.AbstractTableFilter() {
5 | final override fun filter(tableProperties: org.rocksdb.TableProperties): Boolean =
6 | filter(TableProperties(tableProperties))
7 |
8 | protected actual abstract fun filter(tableProperties: TableProperties): Boolean
9 | }
10 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/AbstractImmutableNativeReference.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Offers functionality for implementations of
5 | * {@link AbstractNativeReference} which have an immutable reference to the
6 | * underlying native C++ object
7 | */
8 | expect abstract class AbstractImmutableNativeReference : AbstractNativeReference {
9 | open fun isOwningHandle(): Boolean
10 |
11 | override fun close()
12 | }
13 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/asSizeT.kt:
--------------------------------------------------------------------------------
1 | package maryk
2 |
3 | import kotlinx.cinterop.ExperimentalForeignApi
4 | import kotlinx.cinterop.UnsafeNumber
5 | import kotlinx.cinterop.convert
6 | import platform.posix.size_t
7 |
8 | @OptIn(ExperimentalForeignApi::class, UnsafeNumber::class)
9 | fun Int.asSizeT(): size_t = this.convert()
10 |
11 | @OptIn(ExperimentalForeignApi::class, UnsafeNumber::class)
12 | fun Long.asSizeT(): size_t = this.convert()
13 |
--------------------------------------------------------------------------------
/src/appleTest/kotlin/maryk/doesFolderExist.kt:
--------------------------------------------------------------------------------
1 | package maryk
2 |
3 | import kotlinx.cinterop.*
4 | import platform.Foundation.*
5 |
6 | actual fun doesFolderExist(path: String): Boolean {
7 | return memScoped {
8 | val isDir = alloc()
9 | val fileManager = NSFileManager.defaultManager()
10 | val exists = fileManager.fileExistsAtPath(path, isDirectory = isDir.ptr)
11 | exists && isDir.value
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/WriteStallCondition.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /** Possible stall states reported by the RocksDB write controller. */
4 | expect enum class WriteStallCondition {
5 | /** Writes are slowed down but still admitted. */
6 | DELAYED,
7 |
8 | /** Writes are rejected until backpressure clears. */
9 | STOPPED,
10 |
11 | /** Writes are flowing normally without throttling. */
12 | NORMAL,
13 | }
14 |
--------------------------------------------------------------------------------
/src/commonTest/kotlin/maryk/rocksdb/util/createTestDBFolder.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb.util
2 |
3 | import maryk.createFolder
4 | import kotlin.random.Random
5 | import kotlin.random.nextUInt
6 |
7 | private const val TEST_DB_ROOT = "build/test-database"
8 |
9 | @Suppress("EXPERIMENTAL_API_USAGE")
10 | fun createTestDBFolder(name: String?): String {
11 | createFolder(TEST_DB_ROOT)
12 | return "$TEST_DB_ROOT/${name!!}_" + Random.nextUInt()
13 | }
14 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/WALRecoveryMode.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Recovery modes used when replaying the write-ahead log during open.
5 | */
6 | expect enum class WALRecoveryMode {
7 | TolerateCorruptedTailRecords,
8 | AbsoluteConsistency,
9 | PointInTimeRecovery,
10 | SkipAnyCorruptedRecords;
11 |
12 | fun getValue(): Byte
13 | }
14 |
15 | expect fun walRecoveryModeFromValue(value: Byte): WALRecoveryMode
16 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/GetStatus.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias GetStatus = org.rocksdb.GetStatus
4 |
5 | /**
6 | * The status of the fetch operation.
7 | */
8 | actual fun GetStatus.getStatus(): Status {
9 | return this.status
10 | }
11 |
12 | /**
13 | * The size of the data fetched, which may be bigger than the buffer.
14 | */
15 | actual fun GetStatus.getRequiredSize(): Int {
16 | return this.requiredSize
17 | }
18 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/RocksDBException.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual class RocksDBException
4 | actual constructor(msg: String, private val status: Status?)
5 | : Exception(msg) {
6 | actual constructor(msg: String) : this(msg, null)
7 |
8 | actual constructor(status: Status) : this(
9 | status.getState() ?: status.getCodeString(),
10 | status
11 | )
12 |
13 | actual fun getStatus() = status
14 | }
15 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/RocksIteratorInterface.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual interface RocksIteratorInterface {
4 | actual fun isValid(): Boolean
5 |
6 | actual fun seekToFirst()
7 |
8 | actual fun seekToLast()
9 |
10 | actual fun seek(target: ByteArray)
11 |
12 | actual fun seekForPrev(target: ByteArray)
13 |
14 | actual fun next()
15 |
16 | actual fun prev()
17 |
18 | actual fun status()
19 | }
20 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/HistogramData.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | expect class HistogramData {
4 | fun getMedian(): Double
5 |
6 | fun getPercentile95(): Double
7 |
8 | fun getPercentile99(): Double
9 |
10 | fun getAverage(): Double
11 |
12 | fun getStandardDeviation(): Double
13 |
14 | fun getMax(): Double
15 |
16 | fun getCount(): Long
17 |
18 | fun getSum(): Long
19 |
20 | fun getMin(): Double
21 | }
22 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/WaitingTransactions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 | /**
3 | * Represents a collection of waiting transactions.
4 | */
5 | expect class WaitingTransactions {
6 | /** The column family ID */
7 | fun getColumnFamilyId(): Long
8 |
9 | /** The key on which the transactions are waiting. */
10 | fun getKey(): String
11 |
12 | /** The IDs of the waiting transactions. */
13 | fun getTransactionIds(): LongArray
14 | }
15 |
--------------------------------------------------------------------------------
/src/commonTest/kotlin/maryk/rocksdb/CompressionTypesTest.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import kotlin.test.Test
4 |
5 | class CompressionTypesTest {
6 | @Test
7 | fun getCompressionType() {
8 | for (compressionType in CompressionType.entries) {
9 | val libraryName = compressionType.getLibraryName()
10 | compressionType == getCompressionType(
11 | libraryName
12 | )
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/WriteBufferManager.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual class WriteBufferManager : org.rocksdb.WriteBufferManager {
4 | actual constructor(bufferSize: Long, cache: Cache, allowStall: Boolean) :
5 | super(bufferSize, cache, allowStall)
6 |
7 | actual constructor(bufferSize: Long, cache: Cache) :
8 | super(bufferSize, cache)
9 |
10 | actual override fun allowStall(): Boolean = super.allowStall()
11 | }
12 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/BackgroundErrorReason.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual enum class BackgroundErrorReason(internal val value: UInt) {
4 | FLUSH(0u),
5 | COMPACTION(1u),
6 | WRITE_CALLBACK(2u),
7 | MEMTABLE(3u);
8 | }
9 |
10 | internal fun backgroundErrorReasonFromValue(value: UInt): BackgroundErrorReason =
11 | BackgroundErrorReason.entries.firstOrNull { it.value == value }
12 | ?: BackgroundErrorReason.MEMTABLE
13 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/Snapshot.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import cnames.structs.rocksdb_snapshot_t
4 | import kotlinx.cinterop.CPointer
5 |
6 | actual class Snapshot internal constructor(
7 | internal val native: CPointer
8 | ) : RocksObject() {
9 | actual fun getSequenceNumber() = rocksdb.rocksdb_snapshot_get_sequence_number(native).toLong()
10 |
11 | override fun close() {
12 | super.close()
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/WriteStallInfo.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /** Snapshot of the write controller's stall state. */
4 | expect class WriteStallInfo {
5 | /** Column family associated with the stall transition. */
6 | fun columnFamilyName(): String
7 |
8 | /** New stall condition. */
9 | fun currentCondition(): WriteStallCondition
10 |
11 | /** Previous stall condition. */
12 | fun previousCondition(): WriteStallCondition
13 | }
14 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/BackgroundErrorReason.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /** Reason reported when RocksDB encounters a background error. */
4 | expect enum class BackgroundErrorReason {
5 | /** A flush job failed. */
6 | FLUSH,
7 |
8 | /** A compaction job failed. */
9 | COMPACTION,
10 |
11 | /** A write callback failed. */
12 | WRITE_CALLBACK,
13 |
14 | /** An error occurred while writing to the memtable. */
15 | MEMTABLE,
16 | }
17 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/PerfLevel.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Controls which performance counters RocksDB collects.
5 | */
6 | expect enum class PerfLevel {
7 | UNINITIALIZED,
8 | DISABLE,
9 | ENABLE_COUNT,
10 | ENABLE_TIME_EXCEPT_FOR_MUTEX,
11 | ENABLE_TIME_AND_CPU_TIME_EXCEPT_FOR_MUTEX,
12 | ENABLE_TIME,
13 | OUT_OF_BOUNDS;
14 |
15 | fun getValue(): Byte
16 | }
17 |
18 | expect fun perfLevelFromValue(value: Byte): PerfLevel
19 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/ColumnFamilyDescriptor.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual class ColumnFamilyDescriptor actual constructor(
4 | private val columnFamilyName: ByteArray,
5 | private val columnFamilyOptions: ColumnFamilyOptions
6 | ) {
7 | actual constructor(columnFamilyName: ByteArray) : this(columnFamilyName, ColumnFamilyOptions())
8 |
9 | actual fun getName() = columnFamilyName
10 |
11 | actual fun getOptions() = columnFamilyOptions
12 | }
13 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/CompressionOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | expect class CompressionOptions() : RocksObject {
4 | fun setWindowBits(windowBits: Int): CompressionOptions
5 | fun windowBits(): Int
6 | fun setLevel(level: Int): CompressionOptions
7 | fun level(): Int
8 | fun setStrategy(strategy: Int): CompressionOptions
9 | fun strategy(): Int
10 | fun setMaxDictBytes(bytes: Int): CompressionOptions
11 | fun maxDictBytes(): Int
12 | }
13 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/SstFileWriter.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Helper to build external SST files for ingestion.
5 | */
6 | expect class SstFileWriter(envOptions: EnvOptions, options: Options) : RocksObject {
7 | fun open(filePath: String)
8 |
9 | fun put(key: ByteArray, value: ByteArray)
10 |
11 | fun merge(key: ByteArray, value: ByteArray)
12 |
13 | fun delete(key: ByteArray)
14 |
15 | fun finish()
16 |
17 | fun fileSize(): Long
18 | }
19 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/RocksDB.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias RocksDB = org.rocksdb.RocksDB
4 |
5 | actual val defaultColumnFamily = RocksDB.DEFAULT_COLUMN_FAMILY
6 | actual val rocksDBNotFound = RocksDB.NOT_FOUND
7 |
8 | actual fun destroyRocksDB(path: String, options: Options) {
9 | RocksDB.destroyDB(path, options)
10 | }
11 |
12 | actual fun listColumnFamilies(
13 | options: Options,
14 | path: String
15 | ) = RocksDB.listColumnFamilies(options, path)
16 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/LiveFileMetaData.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Metadata describing an SST file that is currently live in the database.
5 | */
6 | expect class LiveFileMetaData : SstFileMetaData {
7 | /**
8 | * Returns the name of the column family this file belongs to.
9 | */
10 | fun columnFamilyName(): ByteArray
11 |
12 | /**
13 | * Returns the level at which the file resides in the LSM tree.
14 | */
15 | fun level(): Int
16 | }
17 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/WriteType.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual enum class WriteType(
4 | internal val value: UInt
5 | ) {
6 | PUT(0u),
7 | MERGE(1u),
8 | DELETE(2u),
9 | SINGLE_DELETE(3u),
10 | DELETE_RANGE(4u),
11 | LOG(5u),
12 | XID(6u);
13 | }
14 |
15 | internal fun getWriteTypeByValue(value: UInt): WriteType =
16 | WriteType.entries.firstOrNull { it.value == value }
17 | ?: throw IllegalStateException("Unknown WriteType value: $value")
18 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/TraceOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * TraceOptions is used for
5 | * [RocksDB.startTrace].
6 | */
7 | expect class TraceOptions() {
8 | constructor(maxTraceFileSize: Long)
9 |
10 | /**
11 | * To avoid the trace file size grows large than the storage space,
12 | * user can set the max trace file size in Bytes. Default is 64GB
13 | *
14 | * @return the max trace size
15 | */
16 | fun getMaxTraceFileSize(): Long
17 | }
18 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/EncodingType.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import maryk.rocksdb.EncodingType.kPlain
4 | import maryk.rocksdb.EncodingType.kPrefix
5 |
6 | actual enum class EncodingType(
7 | internal val value: Byte
8 | ) {
9 | kPlain(0),
10 | kPrefix(1);
11 | }
12 |
13 | internal fun toEncodingType(value: Byte) = when (value) {
14 | 0.toByte() -> kPlain
15 | 1.toByte() -> kPrefix
16 | else -> throw RocksDBException("Unrecognized $value for EncodingType")
17 | }
18 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/ConfigOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Options for configuring how RocksDB parses options files and strings.
5 | */
6 | expect class ConfigOptions() : RocksObject {
7 | fun setDelimiter(delimiter: String): ConfigOptions
8 | fun setIgnoreUnknownOptions(ignore: Boolean): ConfigOptions
9 | fun setEnv(env: Env): ConfigOptions
10 | fun setInputStringsEscaped(escaped: Boolean): ConfigOptions
11 | fun setSanityLevel(level: SanityLevel): ConfigOptions
12 | }
13 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/ColumnFamilyMetaData.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual class ColumnFamilyMetaData internal constructor(
4 | val size: ULong,
5 | val fileCount: ULong,
6 | val name: String,
7 | val levels: List,
8 | ) {
9 | actual fun size(): Long = size.toLong()
10 |
11 | actual fun fileCount(): Long = fileCount.toLong()
12 |
13 | actual fun name(): ByteArray = name.encodeToByteArray()
14 |
15 | actual fun levels(): List = levels
16 | }
17 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/CompactionPriority.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual enum class CompactionPriority(
4 | internal val value: Byte
5 | ) {
6 | ByCompensatedSize(0x0),
7 | OldestLargestSeqFirst(0x1),
8 | OldestSmallestSeqFirst(0x2),
9 | MinOverlappingRatio(0x3);
10 | }
11 |
12 | fun getCompactionPriority(value: Byte) =
13 | CompactionPriority.entries.firstOrNull { it.value == value }
14 | ?: throw IllegalArgumentException("Illegal value provided for CompactionPriority.")
15 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/Holder.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /** Simple instance reference wrapper. */
4 | expect class Holder {
5 | /** Constructs a new Holder with null instance. */
6 | constructor()
7 |
8 | /**
9 | * Constructs a new Holder.
10 | * [value] the instance or null
11 | */
12 | constructor(value: T?)
13 |
14 | /** Get the instance reference. */
15 | fun getValue(): T?
16 |
17 | /** Set the instance reference. */
18 | fun setValue(value: T?)
19 | }
20 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/MemTableConfig.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * MemTableConfig is used to config the internal mem-table of a RocksDB.
5 | * It is required for each memtable to have one such sub-class.
6 | *
7 | * To make a RocksDB to use a specific MemTable format, its associated
8 | * MemTableConfig should be properly set and passed into Options
9 | * via Options.setMemTableFactory() and open the db using that Options.
10 | *
11 | * @see Options
12 | */
13 | expect abstract class MemTableConfig()
14 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/Cache.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | expect abstract class Cache : RocksObject {
4 | /**
5 | * Returns the memory size for the entries
6 | * residing in cache.
7 | *
8 | * @return cache usage size.
9 | *
10 | */
11 | fun getUsage(): Long
12 |
13 | /**
14 | * Returns the memory size for the entries
15 | * being pinned in cache.
16 | *
17 | * @return cache pinned usage size.
18 | *
19 | */
20 | fun getPinnedUsage(): Long
21 | }
22 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/LevelMetaData.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * The metadata that describes a level.
5 | */
6 | expect class LevelMetaData {
7 | /** The level which this meta data describes. */
8 | fun level(): Int
9 |
10 | /**
11 | * The size of this level in bytes, which is equal to the sum of
12 | * the file size of its [.files].
13 | */
14 | fun size(): Long
15 |
16 | /** The metadata of all sst files in this level. */
17 | fun files(): List
18 | }
19 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/RocksDBException.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | expect class RocksDBException : Exception {
4 | /**
5 | * The private construct used by a set of public static factory method.
6 | * @param msg the specified error message.
7 | */
8 | constructor(msg: String)
9 |
10 | constructor(msg: String, status: Status?)
11 |
12 | constructor(status: Status)
13 |
14 | /** Get the status returned from RocksDB, or null if no status is available */
15 | fun getStatus(): Status?
16 | }
17 |
--------------------------------------------------------------------------------
/src/nativeTest/kotlin/maryk/rocksdb/util/Sleep.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb.util
2 |
3 | import kotlin.time.Duration
4 | import kotlin.time.Duration.Companion.milliseconds
5 | import kotlin.time.TimeSource
6 |
7 | actual fun sleepMillis(millis: Long) {
8 | if (millis <= 0L) {
9 | return
10 | }
11 | val timeout: Duration = millis.milliseconds
12 | val timer = TimeSource.Monotonic.markNow()
13 | while (timer.elapsedNow() < timeout) {
14 | // Busy wait placeholder for native sleep implementation.
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/byteArrayToCPointer.kt:
--------------------------------------------------------------------------------
1 | package maryk
2 |
3 | import kotlinx.cinterop.ByteVar
4 | import kotlinx.cinterop.CArrayPointer
5 | import kotlinx.cinterop.MemScope
6 | import kotlinx.cinterop.allocArray
7 | import kotlinx.cinterop.set
8 |
9 | fun MemScope.byteArrayToCPointer(
10 | key: ByteArray,
11 | offset: Int,
12 | len: Int
13 | ): CArrayPointer {
14 | val cKey = allocArray(len)
15 | for (i in (0 until len)) {
16 | cKey[i] = key[i + offset]
17 | }
18 | return cKey
19 | }
20 |
--------------------------------------------------------------------------------
/src/nativeTest/kotlin/maryk/rocksdb/util/ThreadSafeCounter.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb.util
2 |
3 | import kotlin.concurrent.atomics.AtomicInt
4 | import kotlin.concurrent.atomics.ExperimentalAtomicApi
5 | import kotlin.concurrent.atomics.incrementAndFetch
6 |
7 | @OptIn(ExperimentalAtomicApi::class)
8 | actual class ThreadSafeCounter actual constructor() {
9 | private val counter = AtomicInt(0)
10 |
11 | actual fun increment() {
12 | counter.incrementAndFetch()
13 | }
14 |
15 | actual fun value(): Int = counter.load()
16 | }
17 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/ImportColumnFamilyOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Options controlling how external SST files are imported when creating column families.
5 | */
6 | expect class ImportColumnFamilyOptions() : RocksObject {
7 | /**
8 | * Whether the importer should move files instead of copying them.
9 | */
10 | fun setMoveFiles(moveFiles: Boolean): ImportColumnFamilyOptions
11 |
12 | /** Returns whether files will be moved rather than copied during import. */
13 | fun moveFiles(): Boolean
14 | }
15 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/LiveFileMetaData.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual class LiveFileMetaData internal constructor(
4 | private val columnFamilyNameValue: ByteArray,
5 | private val levelValue: Int,
6 | fileName: String,
7 | path: String,
8 | size: ULong,
9 | smallestKey: ByteArray,
10 | largestKey: ByteArray,
11 | ) : SstFileMetaData(fileName, path, size, smallestKey, largestKey) {
12 | actual fun columnFamilyName(): ByteArray = columnFamilyNameValue
13 |
14 | actual fun level(): Int = levelValue
15 | }
16 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/SstFileMetaData.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | expect open class SstFileMetaData {
4 | /** Get the name of the file. */
5 | fun fileName(): String
6 |
7 | /** Get the full path where the file locates. */
8 | fun path(): String
9 |
10 | /** Get the file size in bytes. */
11 | fun size(): Long
12 |
13 | /** Get the smallest user defined key in the file. */
14 | fun smallestKey(): ByteArray
15 |
16 | /** Get the largest user defined key in the file. */
17 | fun largestKey(): ByteArray
18 | }
19 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/MutableDBOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias MutableDBOptions = org.rocksdb.MutableDBOptions
4 |
5 | actual typealias MutableDBOptionsBuilder =
6 | org.rocksdb.MutableDBOptions.MutableDBOptionsBuilder
7 |
8 | actual fun mutableDBOptionsBuilder(): MutableDBOptionsBuilder =
9 | org.rocksdb.MutableDBOptions.builder()
10 |
11 | actual fun parseMutableDBOptions(
12 | str: String,
13 | ignoreUnknown: Boolean
14 | ): MutableDBOptionsBuilder =
15 | org.rocksdb.MutableDBOptions.parse(str, ignoreUnknown)
16 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/CompactionStyle.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual enum class CompactionStyle(
4 | internal val value: Byte
5 | ) {
6 | LEVEL(0),
7 | UNIVERSAL(1),
8 | FIFO(2),
9 | NONE(3);
10 | }
11 |
12 | fun getCompactionStyle(value: Byte): CompactionStyle {
13 | for (compactionStyle in CompactionStyle.entries) {
14 | if (compactionStyle.value == value) {
15 | return compactionStyle
16 | }
17 | }
18 | throw IllegalArgumentException("Illegal value provided for CompactionStyle.")
19 | }
20 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/RocksMutableObject.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * RocksMutableObject is an implementation of [AbstractNativeReference]
5 | * whose reference to the underlying native C++ object can change.
6 | *
7 | * The use of `RocksMutableObject` should be kept to a minimum, as it
8 | * has synchronization overheads and introduces complexity. Instead it is
9 | * recommended to use [RocksObject] where possible.
10 | */
11 | expect abstract class RocksMutableObject : AbstractNativeReference {
12 | override final fun close()
13 | }
14 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/TimedEnv.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /** Timed environment. */
4 | expect class TimedEnv : Env {
5 |
6 | /**
7 | * Creates a new environment that measures function call times for
8 | * filesystem operations, reporting results to variables in PerfContext.
9 | *
10 | * The caller must delete the result when it is
11 | * no longer needed.
12 | *
13 | * @param baseEnv the base environment,
14 | * must remain live while the result is in use.
15 | */
16 | constructor(baseEnv: Env)
17 | }
18 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/AbstractImmutableNativeReference.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import kotlin.concurrent.AtomicInt
4 |
5 | actual abstract class AbstractImmutableNativeReference(): AbstractNativeReference() {
6 | private val isClosed = AtomicInt(0)
7 |
8 | actual open fun isOwningHandle(): Boolean {
9 | return isClosed.value == 0
10 | }
11 |
12 | internal fun disownHandle() {
13 | isClosed.getAndSet(1)
14 | }
15 |
16 | actual override fun close() {
17 | isClosed.compareAndSet(0, 1)
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/commonTest/kotlin/maryk/rocksdb/ImportColumnFamilyOptionsTest.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import kotlin.test.Test
4 | import kotlin.test.assertFalse
5 | import kotlin.test.assertTrue
6 |
7 | class ImportColumnFamilyOptionsTest {
8 | init {
9 | loadRocksDBLibrary()
10 | }
11 |
12 | @Test
13 | fun moveFilesFlag() {
14 | ImportColumnFamilyOptions().use { options ->
15 | assertFalse(options.moveFiles())
16 |
17 | options.setMoveFiles(true)
18 | assertTrue(options.moveFiles())
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/GetStatus.kt:
--------------------------------------------------------------------------------
1 | // Add the following to GetStatus.kt
2 |
3 | package maryk.rocksdb
4 | /**
5 | * The result of a fetch and the total size of the object fetched.
6 | * If the target of the fetch is not big enough, this may be bigger than the contents of the target.
7 | */
8 | expect class GetStatus
9 |
10 | /**
11 | * The status of the fetch operation.
12 | */
13 | expect fun GetStatus.getStatus(): Status
14 |
15 | /**
16 | * The size of the data fetched, which may be bigger than the buffer.
17 | */
18 | expect fun GetStatus.getRequiredSize(): Int
19 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/TraceWriter.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | expect interface TraceWriter {
4 | /**
5 | * Write the [data].
6 | * @param data the data
7 | *
8 | * @throws RocksDBException if an error occurs whilst writing.
9 | */
10 | fun write(data: Slice)
11 |
12 | /**
13 | * Close the writer.
14 | * @throws RocksDBException if an error occurs whilst closing the writer.
15 | */
16 | fun closeWriter()
17 |
18 | /** Get the size of the file that this writer is writing to. */
19 | fun getFileSize(): Long
20 | }
21 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/convertToStatus.kt:
--------------------------------------------------------------------------------
1 | package maryk
2 |
3 | import maryk.rocksdb.Status
4 | import maryk.rocksdb.getStatusCode
5 | import maryk.rocksdb.getStatusSubCode
6 |
7 | fun convertToStatus(error: String): Status? {
8 | val regex = Regex("""^\[(\d+)\|(\d+)]\s*(.+)$""")
9 | val matchResult = regex.find(error)
10 |
11 | return if (matchResult != null) {
12 | val (code, subcode, message) = matchResult.destructured
13 | Status(getStatusCode(code.toByte()), getStatusSubCode(subcode.toByte()), message)
14 | } else {
15 | null
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/AbstractTransactionNotifier.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | expect abstract class AbstractTransactionNotifier: RocksCallbackObject {
4 | /**
5 | * Protected constructor to initialize the notifier.
6 | */
7 | protected constructor()
8 |
9 | /**
10 | * Called when a snapshot is created.
11 | *
12 | * @param newSnapshot The snapshot that has been created.
13 | *
14 | * @throws RocksDBException When an error occurs during snapshot creation.
15 | */
16 | abstract fun snapshotCreated(newSnapshot: Snapshot)
17 | }
18 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/RocksObject.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * RocksObject is an implementation of [AbstractNativeReference] which
5 | * has an immutable and therefore thread-safe reference to the underlying
6 | * native C++ RocksDB object.
7 | *
8 | * RocksObject is the base-class of almost all RocksDB classes that have a
9 | * pointer to some underlying native C++ `rocksdb` object.
10 | *
11 | * The use of `RocksObject` should always be preferred over
12 | * [RocksMutableObject].
13 | */
14 | expect abstract class RocksObject : AbstractImmutableNativeReference
15 |
--------------------------------------------------------------------------------
/src/commonTest/kotlin/maryk/rocksdb/OptimisticTransactionOptionsTest.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import kotlin.random.Random
4 | import kotlin.test.Test
5 | import kotlin.test.assertEquals
6 |
7 | class OptimisticTransactionOptionsTest {
8 | init {
9 | loadRocksDBLibrary()
10 | }
11 |
12 | @Test
13 | fun setSnapshot() {
14 | OptimisticTransactionOptions().use { opt ->
15 | val boolValue = Random.nextBoolean()
16 | opt.setSetSnapshot(boolValue)
17 | assertEquals(boolValue, opt.isSetSnapshot())
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/commonTest/kotlin/maryk/rocksdb/Types.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /** Convert first 4 bytes of a [data] to an int */
4 | fun byteToInt(data: ByteArray) =
5 | data[0].toInt() and 0xff or
6 | (data[1].toInt() and 0xff shl 8) or
7 | (data[2].toInt() and 0xff shl 16) or
8 | (data[3].toInt() and 0xff shl 24)
9 |
10 | /** Convert an int in [v] to byte array with 4 bytes */
11 | fun intToByte(v: Int) = byteArrayOf(
12 | (v.ushr(0) and 0xff).toByte(),
13 | (v.ushr(8) and 0xff).toByte(),
14 | (v.ushr(16) and 0xff).toByte(),
15 | (v.ushr(24) and 0xff).toByte()
16 | )
17 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/BackupInfo.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual class BackupInfo
4 | internal constructor(
5 | private val backupId: Int,
6 | private val timestamp: Long,
7 | private val size: Long,
8 | private val numberFiles: Int,
9 | private val appMetadata: String?
10 | )
11 | {
12 | actual fun backupId() = backupId
13 |
14 | actual fun timestamp() = timestamp
15 |
16 | actual fun size() = size
17 |
18 | actual fun numberFiles(): Int = numberFiles
19 |
20 | actual fun appMetadata() = appMetadata
21 | }
22 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/EnvOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import cnames.structs.rocksdb_envoptions_t
4 | import kotlinx.cinterop.CPointer
5 | import rocksdb.rocksdb_envoptions_create
6 | import rocksdb.rocksdb_envoptions_destroy
7 |
8 | actual class EnvOptions actual constructor() : RocksObject() {
9 | internal val native: CPointer = rocksdb_envoptions_create()!!
10 |
11 | override fun close() {
12 | if (isOwningHandle()) {
13 | rocksdb_envoptions_destroy(native)
14 | super.close()
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/TransactionState.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual enum class TransactionState(
4 | val value: Byte
5 | ) {
6 | STARTED(0),
7 | AWAITING_PREPARE(1),
8 | PREPARED(2),
9 | AWAITING_COMMIT(3),
10 | COMMITTED(4),
11 | AWAITING_ROLLBACK(5),
12 | ROLLEDBACK(6),
13 | LOCKS_STOLEN(7);
14 | }
15 |
16 | fun getTransactionState(value: Byte): TransactionState {
17 | return TransactionState.entries.firstOrNull { it.value == value }
18 | ?: throw IllegalArgumentException("Illegal value provided for TransactionState.")
19 | }
20 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/WriteBatchSavePoint.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual class WriteBatchSavePoint actual constructor(
4 | private var size: Long,
5 | private var count: Long,
6 | private var contentFlags: Long
7 | ) {
8 | actual fun getSize() = size
9 |
10 | actual fun getCount() = count
11 |
12 | actual fun getContentFlags() = contentFlags
13 |
14 | actual fun isCleared() = size or count or contentFlags == 0L
15 |
16 | actual fun clear() {
17 | this.size = 0
18 | this.count = 0
19 | this.contentFlags = 0
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/SstFileReader.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual class SstFileReader actual constructor(
4 | @Suppress("UNUSED_PARAMETER") options: Options
5 | ) : RocksObject() {
6 | actual fun open(@Suppress("UNUSED_PARAMETER") filePath: String) {
7 | throw RocksDBException("SstFileReader is not yet supported on Kotlin/Native; update the RocksDB C API to enable it.")
8 | }
9 |
10 | actual fun verifyChecksum() {
11 | throw RocksDBException("SstFileReader is not yet supported on Kotlin/Native; update the RocksDB C API to enable it.")
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/CompactionStopStyle.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual enum class CompactionStopStyle(
4 | internal val value: Byte
5 | ) {
6 | CompactionStopStyleSimilarSize(0),
7 | CompactionStopStyleTotalSize(1);
8 | }
9 |
10 | fun getCompactionStopStyle(value: Byte): CompactionStopStyle {
11 | for (compactionStopStyle in CompactionStopStyle.entries) {
12 | if (compactionStopStyle.value == value) {
13 | return compactionStopStyle
14 | }
15 | }
16 | throw IllegalArgumentException("Illegal value provided for CompactionStopStyle.")
17 | }
18 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/PerfLevel.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual enum class PerfLevel(internal val value: Byte) {
4 | UNINITIALIZED(0),
5 | DISABLE(1),
6 | ENABLE_COUNT(2),
7 | ENABLE_TIME_EXCEPT_FOR_MUTEX(3),
8 | ENABLE_TIME_AND_CPU_TIME_EXCEPT_FOR_MUTEX(4),
9 | ENABLE_TIME(5),
10 | OUT_OF_BOUNDS(6);
11 |
12 | actual fun getValue(): Byte = value
13 | }
14 |
15 | actual fun perfLevelFromValue(value: Byte): PerfLevel =
16 | PerfLevel.values().firstOrNull { it.value == value }
17 | ?: throw IllegalArgumentException("Unknown PerfLevel constant $value")
18 |
--------------------------------------------------------------------------------
/src/commonTest/kotlin/maryk/rocksdb/LRUCacheTest.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import kotlin.test.Test
4 |
5 | class LRUCacheTest {
6 | init {
7 | loadRocksDBLibrary()
8 | }
9 |
10 | @Test
11 | fun newLRUCache() {
12 | val capacity: Long = 1000
13 | val numShardBits = 16
14 | val strictCapacityLimit = true
15 | val highPriPoolRatio = 5.0
16 | LRUCache(
17 | capacity,
18 | numShardBits,
19 | strictCapacityLimit,
20 | highPriPoolRatio
21 | ).use {
22 | //no op
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | google()
4 | mavenCentral()
5 | gradlePluginPortal()
6 | }
7 | resolutionStrategy {
8 | eachPlugin {
9 | if(requested.id.namespace == "com.android") {
10 | useModule("com.android.tools.build:gradle:${requested.version}")
11 | }
12 | if (requested.id.id == "kotlin-multiplatform") {
13 | useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}")
14 | }
15 | }
16 | }
17 | }
18 | rootProject.name = "rocksdb-multiplatform"
19 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/ColumnFamilyDescriptor.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | expect class ColumnFamilyDescriptor(
4 | columnFamilyName: ByteArray,
5 | columnFamilyOptions: ColumnFamilyOptions
6 | ) {
7 | /**
8 | * Creates a new Column Family using a name and default
9 | * options,
10 | * @param columnFamilyName name of column family.
11 | */
12 | constructor(columnFamilyName: ByteArray)
13 |
14 | /** Retrieve name of column family. */
15 | fun getName(): ByteArray
16 |
17 | /** Retrieve assigned options instance. */
18 | fun getOptions(): ColumnFamilyOptions
19 | }
20 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/Statistics.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import java.util.EnumSet
4 |
5 | actual typealias Statistics = org.rocksdb.Statistics
6 |
7 | actual fun createStatistics(enabledHistograms: Set): Statistics {
8 | val javaSet = when {
9 | enabledHistograms.isEmpty() -> EnumSet.noneOf(HistogramType::class.java)
10 | enabledHistograms is EnumSet<*> ->
11 | @Suppress("UNCHECKED_CAST")
12 | enabledHistograms as EnumSet
13 | else -> EnumSet.copyOf(enabledHistograms)
14 | }
15 | return org.rocksdb.Statistics(javaSet)
16 | }
17 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/BackupInfo.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Instances of this class describe a Backup made by
5 | * [BackupEngine].
6 | */
7 | expect class BackupInfo {
8 | /** @return the backup id.*/
9 | fun backupId(): Int
10 |
11 | /** @return the timestamp of the backup. */
12 | fun timestamp(): Long
13 |
14 | /** @return the size of the backup */
15 | fun size(): Long
16 |
17 | /** @return the number of files of this backup. */
18 | fun numberFiles(): Int
19 |
20 | /** @return the associated application metadata, or null */
21 | fun appMetadata(): String?
22 | }
23 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/IndexType.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * IndexType used in conjunction with BlockBasedTable.
5 | */
6 | expect enum class IndexType {
7 | /**
8 | * A space efficient index block that is optimized for
9 | * binary-search-based index.
10 | */
11 | kBinarySearch,
12 | /**
13 | * The hash index, if enabled, will do the hash lookup when
14 | * `Options.prefix_extractor` is provided.
15 | */
16 | kHashSearch,
17 | /**
18 | * A two-level index implementation. Both levels are binary search indexes.
19 | */
20 | kTwoLevelIndexSearch;
21 | }
22 |
--------------------------------------------------------------------------------
/src/commonTest/kotlin/maryk/assertContentEquals.kt:
--------------------------------------------------------------------------------
1 | package maryk
2 |
3 | import kotlin.test.assertTrue
4 | import kotlin.test.fail
5 |
6 | fun assertContentEquals(expected: ByteArray?, actual: ByteArray?) {
7 | if (actual == null) {
8 | if (expected != null) {
9 | fail("Actual byte array cannot be null")
10 | }
11 |
12 | return
13 | } else if (expected == null) {
14 | fail("Actual byte array should be null")
15 | }
16 | assertTrue(expected.contentEquals(actual), "Actual byte array [${actual.joinToString(", ")}] does not match expected byte array [${expected.joinToString(", ")}]")
17 | }
18 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/StatsLevel.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual enum class StatsLevel(
4 | internal val value: UByte
5 | ) {
6 | DISABLE_ALL(0u),
7 | EXCEPT_TICKERS(1u),
8 | EXCEPT_HISTOGRAM_OR_TIMERS(2u),
9 | EXCEPT_TIMERS(3u),
10 | EXCEPT_DETAILED_TIMERS(4u),
11 | EXCEPT_TIME_FOR_MUTEX(5u),
12 | ALL(6u);
13 | }
14 |
15 | fun getStatsLevel(value: UByte): StatsLevel {
16 | for (level in StatsLevel.entries) {
17 | if (level.value == value) {
18 | return level
19 | }
20 | }
21 | throw IllegalArgumentException("Illegal value provided for StatsLevel.")
22 | }
23 |
--------------------------------------------------------------------------------
/src/commonTest/kotlin/maryk/rocksdb/BackupableDBOptionsTest.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import maryk.createFolder
4 | import kotlin.test.Test
5 | import kotlin.test.assertEquals
6 |
7 | class BackupableDBOptionsTest {
8 | private val arbitraryPath =
9 | "build/test-database/BackupableDBOptionsTest"
10 |
11 | init {
12 | createFolder(arbitraryPath)
13 | loadRocksDBLibrary()
14 | }
15 |
16 | @Test
17 | fun backupDir() {
18 | BackupEngineOptions(arbitraryPath).use { backupableDBOptions ->
19 | assertEquals(arbitraryPath, backupableDBOptions.backupDir())
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/DBOptionsInterface.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Common interface for database options implementations.
5 | */
6 | expect interface DBOptionsInterface> {
7 | /**
8 | * Use the specified [Env] instance to interact with the environment.
9 | *
10 | * Default: [getDefaultEnv]
11 | *
12 | * @param env environment instance to use.
13 | * @return the current options instance.
14 | */
15 | fun setEnv(env: Env): T
16 |
17 | /**
18 | * Returns the environment configured on this options instance.
19 | */
20 | fun getEnv(): Env
21 | }
22 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/StatisticsCollector.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | data class StatsCollectorInput(
4 | val statistics: Statistics,
5 | val callback: StatisticsCollectorCallback
6 | )
7 |
8 | interface StatisticsCollectorCallback {
9 | fun tickerCallback(tickerType: TickerType, tickerCount: Long)
10 | fun histogramCallback(histogramType: HistogramType, histogramData: HistogramData)
11 | }
12 |
13 | expect class StatisticsCollector(
14 | statsCollectorInputList: List,
15 | statsCollectionIntervalInMilliSeconds: Int
16 | ) {
17 | fun start()
18 | fun shutDown(shutdownTimeout: Int)
19 | }
20 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/WalFileType.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | expect enum class WalFileType {
4 | /**
5 | * Indicates that WAL file is in archive directory. WAL files are moved from
6 | * the main db directory to archive directory once they are not live and stay
7 | * there until cleaned up. Files are cleaned depending on archive size
8 | * (Options::WAL_size_limit_MB) and time since last cleaning
9 | * (Options::WAL_ttl_seconds).
10 | */
11 | kArchivedLogFile,
12 |
13 | /**
14 | * Indicates that WAL file is live and resides in the main db directory
15 | */
16 | kAliveLogFile
17 | }
18 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/ColumnFamilyMetaData.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * The metadata that describes a column family.
5 | */
6 | expect class ColumnFamilyMetaData {
7 | /**
8 | * The size of this column family in bytes, which is equal to the sum of
9 | * the file size of its [.levels].
10 | */
11 | fun size(): Long
12 |
13 | /** The number of files in this column family. */
14 | fun fileCount(): Long
15 |
16 | /** The name of the column family. */
17 | fun name(): ByteArray
18 |
19 | /** The metadata of all levels in this column family. */
20 | fun levels(): List
21 | }
22 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/ExternalFileIngestionInfo.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual class ExternalFileIngestionInfo internal constructor(
4 | internal val delegate: org.rocksdb.ExternalFileIngestionInfo
5 | ) {
6 | actual fun columnFamilyName(): String = delegate.columnFamilyName
7 |
8 | actual fun externalFilePath(): String = delegate.externalFilePath
9 |
10 | actual fun internalFilePath(): String = delegate.internalFilePath
11 |
12 | actual fun globalSequenceNumber(): Long = delegate.globalSeqno
13 |
14 | actual fun tableProperties(): TableProperties? =
15 | delegate.tableProperties?.let(::TableProperties)
16 | }
17 |
--------------------------------------------------------------------------------
/src/appleTest/kotlin/maryk/deleteFolder.kt:
--------------------------------------------------------------------------------
1 | package maryk
2 |
3 | import platform.Foundation.NSError
4 | import platform.Foundation.NSFileManager
5 | import kotlinx.cinterop.*
6 |
7 | actual fun deleteFolder(path: String): Boolean {
8 | memScoped {
9 | val errorRef = alloc>()
10 | val result = NSFileManager.defaultManager().removeItemAtPath(
11 | path = path,
12 | error = errorRef.ptr
13 | )
14 | val error = errorRef.value
15 |
16 | if (error != null) {
17 | throw Exception(error.localizedDescription)
18 | }
19 |
20 | return result
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/MutableColumnFamilyOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias MutableColumnFamilyOptions = org.rocksdb.MutableColumnFamilyOptions
4 |
5 | actual typealias MutableColumnFamilyOptionsBuilder =
6 | org.rocksdb.MutableColumnFamilyOptions.MutableColumnFamilyOptionsBuilder
7 |
8 | actual fun mutableColumnFamilyOptionsBuilder(): MutableColumnFamilyOptionsBuilder =
9 | org.rocksdb.MutableColumnFamilyOptions.builder()
10 |
11 | actual fun parseMutableColumnFamilyOptions(
12 | str: String,
13 | ignoreUnknown: Boolean
14 | ): MutableColumnFamilyOptionsBuilder =
15 | org.rocksdb.MutableColumnFamilyOptions.parse(str, ignoreUnknown)
16 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/AbstractComparator.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias AbstractComparator = org.rocksdb.AbstractComparator
4 |
5 | actual fun AbstractComparator.getComparatorType(): ComparatorType {
6 | val method = org.rocksdb.AbstractComparator::class.java.getDeclaredMethod("getComparatorType")
7 | method.isAccessible = true
8 | val value = method.invoke(this) as Enum<*>
9 | return when (value.name) {
10 | "JAVA_COMPARATOR" -> ComparatorType.JAVA_COMPARATOR
11 | "JAVA_NATIVE_COMPARATOR_WRAPPER" -> ComparatorType.JAVA_NATIVE_COMPARATOR_WRAPPER
12 | else -> error("Unknown comparator type ${value.name}")
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/MemTableInfo.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /** Metadata describing a sealed memtable. */
4 | expect class MemTableInfo {
5 | /** Column family that owns the memtable. */
6 | fun columnFamilyName(): String
7 |
8 | /** Sequence number of the first entry that was inserted. */
9 | fun firstSeqno(): Long
10 |
11 | /** Earliest sequence number that may appear in this memtable. */
12 | fun earliestSeqno(): Long
13 |
14 | /** Total number of key/value pairs contained in the memtable. */
15 | fun numEntries(): Long
16 |
17 | /** Total number of delete markers contained in the memtable. */
18 | fun numDeletes(): Long
19 | }
20 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/AbstractCompactionFilterContext.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Note that disposeInternal should be called only after all
5 | * RocksDB instances referencing the compaction filter are closed.
6 | * Otherwise an undefined behavior will occur.
7 | */
8 | actual abstract class AbstractCompactionFilter> protected constructor() : RocksObject()
9 |
10 | actual open class AbstractCompactionFilterContext(
11 | private val fullCompaction: Boolean,
12 | private val manualCompaction: Boolean
13 | ) {
14 | actual fun isFullCompaction() = fullCompaction
15 |
16 | actual fun isManualCompaction() = manualCompaction
17 | }
18 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/DBOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias DBOptions = org.rocksdb.DBOptions
4 |
5 | actual fun DBOptions.addEventListener(listener: EventListener): DBOptions {
6 | val existing: MutableList =
7 | listeners()?.toMutableList() ?: mutableListOf()
8 | existing += listener
9 | return setListeners(existing)
10 | }
11 |
12 | actual fun Options.addEventListener(listener: EventListener): Options {
13 | val existing: MutableList =
14 | listeners()?.toMutableList() ?: mutableListOf()
15 | existing += listener
16 | setListeners(existing)
17 | return this
18 | }
19 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/BottommostLevelCompaction.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * For level based compaction, we can configure if we want to skip/force bottommost level compaction.
5 | */
6 | expect enum class BottommostLevelCompaction {
7 | /** Skip bottommost level compaction */
8 | kSkip,
9 | /** Only compact bottommost level if there is a compaction filter. This is the default option */
10 | kIfHaveCompactionFilter,
11 | /** Always compact bottommost level */
12 | kForce,
13 | /**
14 | * Always compact bottommost level but in bottommost level avoid
15 | * double-compacting files created in the same compaction.
16 | */
17 | kForceOptimized,
18 | }
19 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/openOptimisticTransactionDB.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | @Throws(RocksDBException::class)
4 | actual fun openOptimisticTransactionDB(
5 | dbOptions: DBOptions,
6 | path: String,
7 | columnFamilyDescriptors: List,
8 | columnFamilyHandles: MutableList
9 | ): OptimisticTransactionDB =
10 | org.rocksdb.OptimisticTransactionDB.open(dbOptions, path, columnFamilyDescriptors, columnFamilyHandles)
11 |
12 | @Throws(RocksDBException::class)
13 | actual fun openOptimisticTransactionDB(
14 | options: Options,
15 | path: String
16 | ): OptimisticTransactionDB =
17 | org.rocksdb.OptimisticTransactionDB.open(options, path)
18 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/RestoreOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import rocksdb.rocksdb_restore_options_create
4 | import rocksdb.rocksdb_restore_options_destroy
5 | import rocksdb.rocksdb_restore_options_set_keep_log_files
6 |
7 | actual class RestoreOptions actual constructor(
8 | val keepLogFiles: Boolean
9 | ) : RocksObject() {
10 | val native = rocksdb_restore_options_create()
11 |
12 | init {
13 | rocksdb_restore_options_set_keep_log_files(native, if (keepLogFiles) 1 else 0)
14 | }
15 |
16 | override fun close() {
17 | if (isOwningHandle()) {
18 | rocksdb_restore_options_destroy(native)
19 | super.close()
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/Holder.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /** Simple instance reference wrapper. */
4 | actual class Holder {
5 | private var value: T?
6 |
7 | /** Constructs a new Holder with null instance. */
8 | actual constructor() {
9 | this.value = null
10 | }
11 |
12 | /**
13 | * Constructs a new Holder.
14 | * [value] the instance or null
15 | */
16 | actual constructor(value: T?) {
17 | this.value = value
18 | }
19 |
20 | /** Get the instance reference. */
21 | actual fun getValue() = this.value
22 |
23 | /** Set the instance reference. */
24 | actual fun setValue(value: T?) {
25 | this.value = value
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/AbstractSlice.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Regards the lifecycle of Java Slices in RocksDB:
5 | * At present when you configure a Comparator from Java, it creates an
6 | * instance of a C++ BaseComparatorJniCallback subclass and
7 | * passes that to RocksDB as the comparator. That subclass of
8 | * BaseComparatorJniCallback creates the Java
9 | *
10 | * @see AbstractSlice subclass Objects. When you dispose
11 | * the Java @see AbstractComparator subclass, it disposes the
12 | * C++ BaseComparatorJniCallback subclass, which in turn destroys the
13 | * Java @see maryk.rocksdb.AbstractSlice subclass Objects.
14 | */
15 | actual typealias AbstractSlice = org.rocksdb.AbstractSlice
16 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/WALRecoveryMode.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual enum class WALRecoveryMode(private val value: Byte) {
4 | TolerateCorruptedTailRecords(0),
5 | AbsoluteConsistency(1),
6 | PointInTimeRecovery(2),
7 | SkipAnyCorruptedRecords(3);
8 |
9 | actual fun getValue(): Byte = value
10 | }
11 |
12 | actual fun walRecoveryModeFromValue(value: Byte): WALRecoveryMode = when (value.toInt()) {
13 | 0 -> WALRecoveryMode.TolerateCorruptedTailRecords
14 | 1 -> WALRecoveryMode.AbsoluteConsistency
15 | 2 -> WALRecoveryMode.PointInTimeRecovery
16 | 3 -> WALRecoveryMode.SkipAnyCorruptedRecords
17 | else -> throw IllegalArgumentException("Unknown WALRecoveryMode value $value")
18 | }
19 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/Buffer.kt:
--------------------------------------------------------------------------------
1 | package maryk
2 |
3 | actual abstract class Buffer(
4 | internal var capacity: Int,
5 | internal var limit: Int,
6 | internal var position: Int = 0
7 | ) {
8 |
9 | actual abstract fun array(): Any
10 |
11 | open fun flip(): Buffer {
12 | limit = position
13 | position = 0
14 | return this
15 | }
16 |
17 | actual fun position(): Int = position
18 |
19 | actual fun remaining() = limit - position
20 |
21 | fun limit(newLimit: Int): Buffer {
22 | if (newLimit > capacity || newLimit < 0) throw IllegalArgumentException()
23 | limit = newLimit
24 | if (position > limit) position = limit
25 | return this
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/commonTest/kotlin/maryk/rocksdb/WriteBufferManagerTest.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import kotlin.test.Test
4 | import kotlin.test.assertFalse
5 | import kotlin.test.assertTrue
6 |
7 | class WriteBufferManagerTest {
8 | init {
9 | loadRocksDBLibrary()
10 | }
11 |
12 | @Test
13 | fun allowStallFlagReflectsConstruction() {
14 | LRUCache(4L * 1024 * 1024).use { cache ->
15 | WriteBufferManager(2L * 1024 * 1024, cache).use { manager ->
16 | assertFalse(manager.allowStall())
17 | }
18 |
19 | WriteBufferManager(2L * 1024 * 1024, cache, allowStall = true).use { manager ->
20 | assertTrue(manager.allowStall())
21 | }
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/TtlDB.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /** RocksDB variant with time-to-live support. */
4 | expect class TtlDB : RocksDB {
5 | fun createColumnFamilyWithTtl(
6 | columnFamilyDescriptor: ColumnFamilyDescriptor,
7 | ttl: Int
8 | ): ColumnFamilyHandle
9 | }
10 |
11 | expect fun openTtlDB(options: Options, dbPath: String): TtlDB
12 |
13 | expect fun openTtlDB(options: Options, dbPath: String, ttl: Int, readOnly: Boolean): TtlDB
14 |
15 | expect fun openTtlDB(
16 | options: DBOptions,
17 | dbPath: String,
18 | columnFamilyDescriptors: List,
19 | columnFamilyHandles: MutableList,
20 | ttlValues: List,
21 | readOnly: Boolean
22 | ): TtlDB
23 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/TxnDBWritePolicy.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual enum class TxnDBWritePolicy(val value: Byte) {
4 | WRITE_COMMITTED(0x00),
5 |
6 | /**
7 | * Write data after the prepare phase of 2pc.
8 | */
9 | WRITE_PREPARED(0x1),
10 |
11 | /**
12 | * Write data before the prepare phase of 2pc.
13 | */
14 | WRITE_UNPREPARED(0x2);
15 |
16 | actual fun getValue(): Byte = value
17 | }
18 |
19 |
20 | fun getTxnDBWritePolicy(value: Byte): TxnDBWritePolicy {
21 | for (level in TxnDBWritePolicy.entries) {
22 | if (level.value == value) {
23 | return level
24 | }
25 | }
26 | throw IllegalArgumentException("Illegal value provided for TxnDBWritePolicy.")
27 | }
28 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/FlushReason.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /** Reasons that can trigger a memtable flush. */
4 | expect enum class FlushReason {
5 | OTHERS,
6 | GET_LIVE_FILES,
7 | SHUTDOWN,
8 | EXTERNAL_FILE_INGESTION,
9 | MANUAL_COMPACTION,
10 | WRITE_BUFFER_MANAGER,
11 | WRITE_BUFFER_FULL,
12 | TEST,
13 | DELETE_FILES,
14 | AUTO_COMPACTION,
15 | MANUAL_FLUSH,
16 | ERROR_RECOVERY,
17 | ERROR_RECOVERY_RETRY_FLUSH,
18 | WAL_FULL,
19 | CATCH_UP_AFTER_ERROR_RECOVERY,
20 | }
21 |
22 | /** Encoded value used by RocksDB internals. */
23 | expect fun FlushReason.value(): Byte
24 |
25 | /** Resolve a [FlushReason] from its encoded value. */
26 | expect fun flushReasonFromValue(value: Byte): FlushReason
27 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/StatsLevel.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * The level of Statistics to report.
5 | */
6 | expect enum class StatsLevel {
7 | /**
8 | * Collect all stats except time inside mutex lock AND time spent on
9 | * compression.
10 | */
11 | EXCEPT_DETAILED_TIMERS,
12 |
13 | /**
14 | * Collect all stats except the counters requiring to get time inside the
15 | * mutex lock.
16 | */
17 | EXCEPT_TIME_FOR_MUTEX,
18 |
19 | /**
20 | * Collect all stats, including measuring duration of mutex operations.
21 | *
22 | * If getting time is expensive on the platform to run, it can
23 | * reduce scalability to more threads, especially for writes.
24 | */
25 | ALL;
26 | }
27 |
--------------------------------------------------------------------------------
/src/androidNativeTest/kotlin/maryk/folderUtils.kt:
--------------------------------------------------------------------------------
1 | package maryk
2 |
3 | import kotlinx.cinterop.UnsafeNumber
4 | import kotlinx.cinterop.convert
5 | import platform.posix.S_IRWXU
6 | import platform.posix.closedir
7 | import platform.posix.mkdir
8 | import platform.posix.opendir
9 | import platform.posix.rmdir
10 |
11 | @OptIn(UnsafeNumber::class)
12 | actual fun createFolder(path: String): Boolean {
13 | return mkdir(path, S_IRWXU.convert()) == 0
14 | }
15 |
16 | actual fun deleteFolder(path: String): Boolean {
17 | return rmdir(path) == 0
18 | }
19 |
20 | actual fun doesFolderExist(path: String): Boolean {
21 | val directory = opendir(path)
22 | if (directory != null) {
23 | closedir(directory)
24 | return true
25 | }
26 | return false
27 | }
28 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/RestoreOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * RestoreOptions to control the behavior of restore.
5 | *
6 | * Note that dispose() must be called before this instance become out-of-scope
7 | * to release the allocated memory in c++.
8 | */
9 | expect class RestoreOptions
10 | /**
11 | * Constructor
12 | *
13 | * @param keepLogFiles If true, restore won't overwrite the existing log files
14 | * in wal_dir. It will also move all log files from archive directory to
15 | * wal_dir. Use this option in combination with
16 | * BackupableDBOptions::backup_log_files = false for persisting in-memory
17 | * databases.
18 | * Default: false
19 | */
20 | constructor(keepLogFiles: Boolean) : RocksObject
21 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/ExternalFileIngestionInfo.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /** Metadata describing an external SST file that was ingested into a RocksDB instance. */
4 | expect class ExternalFileIngestionInfo {
5 | /** Column family the file was ingested into. */
6 | fun columnFamilyName(): String
7 |
8 | /** Absolute path of the file before ingestion. */
9 | fun externalFilePath(): String
10 |
11 | /** Relative path of the file within the RocksDB data directory. */
12 | fun internalFilePath(): String
13 |
14 | /** Global sequence number assigned to keys contained in the file. */
15 | fun globalSequenceNumber(): Long
16 |
17 | /** Table properties associated with the ingested file. */
18 | fun tableProperties(): TableProperties?
19 | }
20 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/SstFileManager.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Tracks SST files associated with a database and throttles deletion to avoid IO spikes.
5 | */
6 | expect class SstFileManager(env: Env): AutoCloseable {
7 | fun setMaxAllowedSpaceUsage(maxAllowedSpace: Long)
8 |
9 | fun setCompactionBufferSize(compactionBufferSize: Long)
10 |
11 | fun isMaxAllowedSpaceReached(): Boolean
12 |
13 | fun isMaxAllowedSpaceReachedIncludingCompactions(): Boolean
14 |
15 | fun getTotalSize(): Long
16 |
17 | fun getDeleteRateBytesPerSecond(): Long
18 |
19 | fun setDeleteRateBytesPerSecond(deleteRate: Long)
20 |
21 | fun getMaxTrashDBRatio(): Double
22 |
23 | fun setMaxTrashDBRatio(ratio: Double)
24 |
25 | override fun close()
26 | }
27 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/openTransactionDB.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | @Throws(RocksDBException::class)
4 | actual fun openTransactionDB(
5 | dbOptions: DBOptions,
6 | transactionDbOptions: TransactionDBOptions,
7 | path: String,
8 | columnFamilyDescriptors: List,
9 | columnFamilyHandles: MutableList
10 | ): TransactionDB =
11 | org.rocksdb.TransactionDB.open(dbOptions, transactionDbOptions, path, columnFamilyDescriptors, columnFamilyHandles)
12 |
13 | @Throws(RocksDBException::class)
14 | actual fun openTransactionDB(
15 | options: Options,
16 | transactionDbOptions: TransactionDBOptions,
17 | path: String
18 | ): TransactionDB =
19 | org.rocksdb.TransactionDB.open(options, transactionDbOptions, path)
20 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/MemoryUsageType.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * MemoryUsageType
5 | *
6 | * The value will be used as a key to indicate the type of memory usage
7 | * described
8 | */
9 | expect enum class MemoryUsageType {
10 | /** Memory usage of all the mem-tables. */
11 | kMemTableTotal,
12 | /** Memory usage of those un-flushed mem-tables. */
13 | kMemTableUnFlushed,
14 | /** Memory usage of all the table readers. */
15 | kTableReadersTotal,
16 | /** Memory usage by Cache. */
17 | kCacheTotal,
18 | /** Max usage types - copied to keep 1:1 with native. */
19 | kNumUsageTypes;
20 |
21 | /**
22 | * Returns the byte value of the enumerations value
23 | * @return byte representation
24 | */
25 | fun getValue(): Byte
26 | }
27 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/AbstractCompactionFilter.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * A CompactionFilter allows an application to modify/delete a key-value at
5 | * the time of compaction.
6 | */
7 | expect abstract class AbstractCompactionFilter>: RocksObject
8 |
9 | expect open class AbstractCompactionFilterContext {
10 | /**
11 | * Does this compaction run include all data files
12 | *
13 | * @return true if this is a full compaction run
14 | */
15 | fun isFullCompaction(): Boolean
16 |
17 | /**
18 | * Is this compaction requested by the client,
19 | * or is it occurring as an automatic compaction process
20 | *
21 | * @return true if the compaction was initiated by the client
22 | */
23 | fun isManualCompaction(): Boolean
24 | }
25 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/TtlDB.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias TtlDB = org.rocksdb.TtlDB
4 |
5 | actual fun openTtlDB(options: Options, dbPath: String): TtlDB =
6 | org.rocksdb.TtlDB.open(options, dbPath)
7 |
8 | actual fun openTtlDB(options: Options, dbPath: String, ttl: Int, readOnly: Boolean): TtlDB =
9 | org.rocksdb.TtlDB.open(options, dbPath, ttl, readOnly)
10 |
11 | actual fun openTtlDB(
12 | options: DBOptions,
13 | dbPath: String,
14 | columnFamilyDescriptors: List,
15 | columnFamilyHandles: MutableList,
16 | ttlValues: List,
17 | readOnly: Boolean
18 | ): TtlDB = org.rocksdb.TtlDB.open(
19 | options,
20 | dbPath,
21 | columnFamilyDescriptors,
22 | columnFamilyHandles,
23 | ttlValues,
24 | readOnly
25 | )
26 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/WriteBatchSavePoint.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * A structure for describing the save point in the Write Batch.
5 | */
6 | expect class WriteBatchSavePoint(
7 | size: Long,
8 | count: Long,
9 | contentFlags: Long
10 | ) {
11 | /**
12 | * Get the size of the serialized representation.
13 | *
14 | * @return the size of the serialized representation.
15 | */
16 | fun getSize(): Long
17 |
18 | /**
19 | * Get the number of elements.
20 | *
21 | * @return the number of elements.
22 | */
23 | fun getCount(): Long
24 |
25 | /**
26 | * Get the content flags.
27 | *
28 | * @return the content flags.
29 | */
30 | fun getContentFlags(): Long
31 |
32 | fun isCleared(): Boolean
33 |
34 | fun clear()
35 | }
36 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/CompactionReason.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual enum class CompactionReason(
4 | internal val value: Byte
5 | ) {
6 | kUnknown(0x0),
7 | kLevelL0FilesNum(0x1),
8 | kLevelMaxLevelSize(0x2),
9 | kUniversalSizeAmplification(0x3),
10 | kUniversalSizeRatio(0x4),
11 | kUniversalSortedRunNum(0x5),
12 | kFIFOMaxSize(0x6),
13 | kFIFOReduceNumFiles(0x7),
14 | kFIFOTtl(0x8),
15 | kManualCompaction(0x9),
16 | kFilesMarkedForCompaction(0x10),
17 | kBottommostFiles(0x0A),
18 | kTtl(0x0B),
19 | kFlush(0x0C),
20 | kExternalSstIngestion(0x0D);
21 | }
22 |
23 | internal fun compactionReasonFromValue(value: UInt): CompactionReason =
24 | CompactionReason.entries.firstOrNull { it.value.toUByte().toUInt() == value }
25 | ?: CompactionReason.kUnknown
26 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/FlushReason.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual enum class FlushReason(internal val id: Byte) {
4 | OTHERS(0x00),
5 | GET_LIVE_FILES(0x01),
6 | SHUTDOWN(0x02),
7 | EXTERNAL_FILE_INGESTION(0x03),
8 | MANUAL_COMPACTION(0x04),
9 | WRITE_BUFFER_MANAGER(0x05),
10 | WRITE_BUFFER_FULL(0x06),
11 | TEST(0x07),
12 | DELETE_FILES(0x08),
13 | AUTO_COMPACTION(0x09),
14 | MANUAL_FLUSH(0x0a),
15 | ERROR_RECOVERY(0x0b),
16 | ERROR_RECOVERY_RETRY_FLUSH(0x0c),
17 | WAL_FULL(0x0d),
18 | CATCH_UP_AFTER_ERROR_RECOVERY(0x0e);
19 | }
20 |
21 | actual fun FlushReason.value(): Byte = id
22 |
23 | actual fun flushReasonFromValue(value: Byte): FlushReason =
24 | FlushReason.entries.firstOrNull { it.id == value }
25 | ?: error("Unknown FlushReason value: $value")
26 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/IngestExternalFileOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Options controlling ingestion of external SST files.
5 | */
6 | expect class IngestExternalFileOptions() : RocksObject {
7 | fun setMoveFiles(moveFiles: Boolean): IngestExternalFileOptions
8 | fun moveFiles(): Boolean
9 |
10 | fun setSnapshotConsistency(snapshotConsistency: Boolean): IngestExternalFileOptions
11 | fun snapshotConsistency(): Boolean
12 |
13 | fun setAllowGlobalSeqNo(allowGlobalSeqNo: Boolean): IngestExternalFileOptions
14 | fun allowGlobalSeqNo(): Boolean
15 |
16 | fun setAllowBlockingFlush(allowBlockingFlush: Boolean): IngestExternalFileOptions
17 | fun allowBlockingFlush(): Boolean
18 |
19 | fun setIngestBehind(ingestBehind: Boolean): IngestExternalFileOptions
20 | fun ingestBehind(): Boolean
21 | }
22 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/OptionsUtil.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Helpers for reading RocksDB options files into live option instances.
5 | */
6 | expect object OptionsUtil {
7 | @Throws(RocksDBException::class)
8 | fun loadLatestOptions(
9 | configOptions: ConfigOptions,
10 | dbPath: String,
11 | dbOptions: DBOptions,
12 | columnFamilyDescriptors: MutableList
13 | )
14 |
15 | @Throws(RocksDBException::class)
16 | fun loadOptionsFromFile(
17 | configOptions: ConfigOptions,
18 | optionsFilePath: String,
19 | dbOptions: DBOptions,
20 | columnFamilyDescriptors: MutableList
21 | )
22 |
23 | @Throws(RocksDBException::class)
24 | fun getLatestOptionsFileName(dbPath: String, env: Env): String
25 | }
26 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/RocksIterator.kt:
--------------------------------------------------------------------------------
1 | @file:OptIn(UnsafeNumber::class)
2 |
3 | package maryk.rocksdb
4 |
5 | import cnames.structs.rocksdb_iterator_t
6 | import kotlinx.cinterop.*
7 | import maryk.toByteArray
8 | import platform.posix.size_tVar
9 | import rocksdb.rocksdb_iter_key
10 | import rocksdb.rocksdb_iter_value
11 |
12 | actual class RocksIterator internal constructor(
13 | native: CPointer
14 | ) : AbstractRocksIterator(native) {
15 | actual fun key(): ByteArray = memScoped {
16 | val length = alloc()
17 | rocksdb_iter_key(native, length.ptr)!!.toByteArray(length.value)
18 | }
19 |
20 | actual fun value(): ByteArray = memScoped {
21 | val length = alloc()
22 | rocksdb_iter_value(native, length.ptr)!!.toByteArray(length.value)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/WriteEntry.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual class WriteEntry actual constructor(
4 | val type: WriteType,
5 | val key: DirectSlice,
6 | val value: DirectSlice?
7 | ) : AutoCloseable {
8 | actual fun getType() = type
9 |
10 | actual fun getKey() = key
11 |
12 | actual fun getValue() = value
13 |
14 | actual override fun close() {}
15 |
16 | override fun equals(other: Any?) = when {
17 | this === other -> true
18 | other !is WriteEntry -> false
19 | else -> type == other.type && key == other.key && value == other.value
20 | }
21 |
22 | override fun hashCode(): Int {
23 | var result = type.hashCode()
24 | result = 31 * result + key.hashCode()
25 | result = 31 * result + (value?.hashCode() ?: 0)
26 | return result
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/BottommostLevelCompaction.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import maryk.rocksdb.BottommostLevelCompaction.kForce
4 | import maryk.rocksdb.BottommostLevelCompaction.kForceOptimized
5 | import maryk.rocksdb.BottommostLevelCompaction.kIfHaveCompactionFilter
6 | import maryk.rocksdb.BottommostLevelCompaction.kSkip
7 |
8 | actual enum class BottommostLevelCompaction(
9 | internal val value: UByte
10 | ) {
11 | kSkip(0u),
12 | kIfHaveCompactionFilter(1u),
13 | kForce(2u),
14 | kForceOptimized(3u)
15 | }
16 |
17 | fun bottommostLevelCompactionFromByte(bottommostLevelCompaction: UByte): BottommostLevelCompaction? {
18 | return when (bottommostLevelCompaction.toUInt()) {
19 | 0u -> kSkip
20 | 1u -> kIfHaveCompactionFilter
21 | 2u -> kForce
22 | 3u -> kForceOptimized
23 | else -> null
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/InfoLogLevel.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual enum class InfoLogLevel(
4 | internal val value: UByte
5 | ) {
6 | DEBUG_LEVEL(0u),
7 | INFO_LEVEL(1u),
8 | WARN_LEVEL(2u),
9 | ERROR_LEVEL(3u),
10 | FATAL_LEVEL(4u),
11 | HEADER_LEVEL(5u),
12 | NUM_INFO_LOG_LEVELS(6u);
13 | }
14 |
15 | /**
16 | * Get InfoLogLevel by byte value.
17 | *
18 | * @param value byte representation of InfoLogLevel.
19 | *
20 | * @return [InfoLogLevel] instance.
21 | * @throws IllegalArgumentException if an invalid
22 | * value is provided.
23 | */
24 | fun getInfoLogLevel(value: UByte): InfoLogLevel {
25 | for (infoLogLevel in InfoLogLevel.entries) {
26 | if (infoLogLevel.value == value) {
27 | return infoLogLevel
28 | }
29 | }
30 | throw IllegalArgumentException("Illegal value provided for InfoLogLevel.")
31 | }
32 |
--------------------------------------------------------------------------------
/src/appleTest/kotlin/maryk/createFolder.kt:
--------------------------------------------------------------------------------
1 | package maryk
2 |
3 | import kotlinx.cinterop.alloc
4 | import kotlinx.cinterop.ObjCObjectVar
5 | import kotlinx.cinterop.memScoped
6 | import kotlinx.cinterop.ptr
7 | import kotlinx.cinterop.value
8 | import platform.Foundation.NSFileManager
9 | import platform.Foundation.NSError
10 |
11 | actual fun createFolder(path: String): Boolean {
12 | memScoped {
13 | val errorRef = alloc>()
14 | val result = NSFileManager.defaultManager().createDirectoryAtPath(
15 | path = path,
16 | withIntermediateDirectories = true,
17 | attributes = null,
18 | error = errorRef.ptr
19 | )
20 | val error = errorRef.value
21 |
22 | if (error != null) {
23 | throw Exception(error.localizedDescription)
24 | }
25 |
26 | return result
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/OptimisticTransactionOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import maryk.toBoolean
4 | import maryk.toUByte
5 |
6 | actual class OptimisticTransactionOptions actual constructor(): RocksObject() {
7 | val native = rocksdb.rocksdb_optimistictransaction_options_create()
8 |
9 | actual fun isSetSnapshot(): Boolean {
10 | return rocksdb.rocksdb_optimistictransaction_options_get_set_snapshot(native).toBoolean()
11 | }
12 |
13 | actual fun setSetSnapshot(setSnapshot: Boolean): OptimisticTransactionOptions {
14 | rocksdb.rocksdb_optimistictransaction_options_set_set_snapshot(native, setSnapshot.toUByte())
15 | return this
16 | }
17 |
18 | override fun close() {
19 | if (isOwningHandle()) {
20 | rocksdb.rocksdb_optimistictransaction_options_destroy(native)
21 | super.close()
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/commonTest/kotlin/maryk/rocksdb/CompactionOptionsFIFOTest.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import kotlin.test.Test
4 | import kotlin.test.assertEquals
5 | import kotlin.test.assertFalse
6 | import kotlin.test.assertTrue
7 |
8 | class CompactionOptionsFIFOTest {
9 | init {
10 | loadRocksDBLibrary()
11 | }
12 |
13 | @Test
14 | fun maxTableFilesSize() {
15 | val size = 500L * 1024 * 1026
16 | CompactionOptionsFIFO().use { options ->
17 | options.setMaxTableFilesSize(size)
18 | assertEquals(size, options.maxTableFilesSize())
19 | }
20 | }
21 |
22 | @Test
23 | fun allowCompactionFlag() {
24 | CompactionOptionsFIFO().use { options ->
25 | assertFalse(options.allowCompaction())
26 |
27 | options.setAllowCompaction(true)
28 | assertTrue(options.allowCompaction())
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/HistogramData.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import cnames.structs.rocksdb_statistics_histogram_data_t
4 | import kotlinx.cinterop.CPointer
5 |
6 | actual class HistogramData(
7 | val median: Double,
8 | val p95: Double,
9 | val p99: Double,
10 | val average: Double,
11 | val stdDev: Double,
12 | val max: Double,
13 | val count: ULong,
14 | val sum: ULong,
15 | val min: Double,
16 | ) {
17 | actual fun getMedian(): Double = median
18 |
19 | actual fun getPercentile95(): Double = p95
20 |
21 | actual fun getPercentile99(): Double = p99
22 |
23 | actual fun getAverage(): Double = average
24 |
25 | actual fun getStandardDeviation(): Double = stdDev
26 |
27 | actual fun getMax(): Double = max
28 |
29 | actual fun getCount(): Long = count.toLong()
30 |
31 | actual fun getSum(): Long = sum.toLong()
32 |
33 | actual fun getMin(): Double = min
34 | }
35 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/MutableColumnFamilyOptionsInterface.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual interface MutableColumnFamilyOptionsInterface> {
4 | actual fun setWriteBufferSize(writeBufferSize: Long): T
5 | actual fun writeBufferSize(): Long
6 | actual fun setDisableAutoCompactions(disableAutoCompactions: Boolean): T
7 | actual fun disableAutoCompactions(): Boolean
8 | actual fun setLevel0FileNumCompactionTrigger(level0FileNumCompactionTrigger: Int): T
9 | actual fun level0FileNumCompactionTrigger(): Int
10 | actual fun setMaxCompactionBytes(maxCompactionBytes: Long): T
11 | actual fun maxCompactionBytes(): Long
12 | actual fun setMaxBytesForLevelBase(maxBytesForLevelBase: Long): T
13 | actual fun maxBytesForLevelBase(): Long
14 | actual fun setCompressionType(compressionType: CompressionType): T
15 | actual fun compressionType(): CompressionType
16 | }
17 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/Checkpoint.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import cnames.structs.rocksdb_checkpoint_t
4 | import kotlinx.cinterop.CPointer
5 | import maryk.wrapWithErrorThrower
6 | import rocksdb.rocksdb_checkpoint_create
7 | import rocksdb.rocksdb_checkpoint_object_create
8 |
9 | actual class Checkpoint
10 | internal constructor(private val native: CPointer?)
11 | : RocksObject() {
12 | actual fun createCheckpoint(checkpointPath: String) {
13 | wrapWithErrorThrower { error ->
14 | rocksdb_checkpoint_create(native, checkpointPath, 1024u, error)
15 | }
16 | }
17 | }
18 |
19 | actual fun createCheckpoint(db: RocksDB): Checkpoint {
20 | check(db.isOwningHandle()) { "RocksDB instance must be initialized." }
21 | return Unit.wrapWithErrorThrower { error ->
22 | Checkpoint(
23 | rocksdb_checkpoint_object_create(db.native, error)
24 | )
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/TransactionLogIterator.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Streams batches from RocksDB's write-ahead log.
5 | */
6 | expect class TransactionLogIterator : RocksObject {
7 | /**
8 | * @return true when the iterator currently points at a valid batch.
9 | */
10 | fun isValid(): Boolean
11 |
12 | /**
13 | * Advances the iterator to the next WAL batch.
14 | */
15 | fun next()
16 |
17 | /**
18 | * Throws a [RocksDBException] if the iterator encountered an error.
19 | */
20 | @Throws(RocksDBException::class)
21 | fun status()
22 |
23 | /**
24 | * Returns the current batch.
25 | */
26 | fun getBatch(): TransactionLogBatchResult
27 | }
28 |
29 | /**
30 | * Result containing the sequence number and write batch for a WAL entry.
31 | */
32 | expect class TransactionLogBatchResult {
33 | fun sequenceNumber(): Long
34 |
35 | fun writeBatch(): WriteBatch
36 | }
37 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/Cache.kt:
--------------------------------------------------------------------------------
1 | @file:OptIn(ExperimentalNativeApi::class)
2 |
3 | package maryk.rocksdb
4 |
5 | import cnames.structs.rocksdb_cache_t
6 | import kotlinx.cinterop.CPointer
7 | import kotlinx.cinterop.UnsafeNumber
8 | import kotlin.experimental.ExperimentalNativeApi
9 |
10 | actual abstract class Cache() : RocksObject() {
11 | internal lateinit var native: CPointer
12 |
13 | @OptIn(UnsafeNumber::class)
14 | actual fun getUsage(): Long {
15 | assert(isOwningHandle())
16 | return rocksdb.rocksdb_cache_get_usage(native).toLong()
17 | }
18 |
19 | @OptIn(UnsafeNumber::class)
20 | actual fun getPinnedUsage(): Long {
21 | assert(isOwningHandle())
22 | return rocksdb.rocksdb_cache_get_pinned_usage(native).toLong()
23 | }
24 |
25 | override fun close() {
26 | if (isOwningHandle()) {
27 | rocksdb.rocksdb_free(native)
28 | }
29 | super.close()
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/OptimisticTransactionOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | expect class OptimisticTransactionOptions() : RocksObject {
4 |
5 | /**
6 | * Checks whether a snapshot is set for this transaction.
7 | *
8 | * A snapshot ensures that the transaction operates on a consistent view of the database
9 | * at a specific point in time.
10 | *
11 | * @return `true` if a snapshot is set, otherwise `false`.
12 | */
13 | fun isSetSnapshot(): Boolean
14 |
15 | /**
16 | * Sets whether a snapshot should be used for this transaction.
17 | *
18 | * Setting this to `true` is equivalent to invoking {@link Transaction#setSnapshot()}.
19 | *
20 | * **Default:** `false`
21 | *
22 | * @param setSnapshot `true` to set a snapshot, `false` otherwise.
23 | * @return The current instance of [TransactionalOptions].
24 | */
25 | fun setSetSnapshot(setSnapshot: Boolean): OptimisticTransactionOptions
26 | }
27 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/AbstractNativeReference.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * AbstractNativeReference is the base-class of all RocksDB classes that have
5 | * a pointer to a native C++ {@code rocksdb} object.
6 | *
7 | * AbstractNativeReference has the {@link AbstractNativeReference#dispose()}
8 | * method, which frees its associated C++ object.
9 | *
10 | * This function should be called manually, however, if required it will be
11 | * called automatically during the regular Java GC process via
12 | * {@link AbstractNativeReference#finalize()}.
13 | *
14 | * Note - Java can only see the long member variable (which is the C++ pointer
15 | * value to the native object), as such it does not know the real size of the
16 | * object and therefore may assign a low GC priority for it; So it is strongly
17 | * suggested that you manually dispose of objects when you are finished with
18 | * them.
19 | */
20 | expect abstract class AbstractNativeReference : AutoCloseable
21 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/CompactionPriority.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /** Compaction Priorities */
4 | expect enum class CompactionPriority {
5 | /** Slightly Prioritize larger files by size compensated by #deletes */
6 | ByCompensatedSize,
7 |
8 | /**
9 | * First compact files whose data's latest update time is oldest.
10 | * Try this if you only update some hot keys in small ranges.
11 | */
12 | OldestLargestSeqFirst,
13 |
14 | /**
15 | * First compact files whose range hasn't been compacted to the next level
16 | * for the longest. If your updates are random across the key space,
17 | * write amplification is slightly better with this option.
18 | */
19 | OldestSmallestSeqFirst,
20 |
21 | /**
22 | * First compact files whose ratio between overlapping size in next level
23 | * and its size is the smallest. It in many cases can optimize write
24 | * amplification.
25 | */
26 | MinOverlappingRatio;
27 | }
28 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/FlushJobInfo.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual class FlushJobInfo internal constructor(
4 | internal val delegate: org.rocksdb.FlushJobInfo
5 | ) {
6 | actual fun columnFamilyId(): Long = delegate.columnFamilyId
7 |
8 | actual fun columnFamilyName(): String = delegate.columnFamilyName
9 |
10 | actual fun filePath(): String = delegate.filePath
11 |
12 | actual fun threadId(): Long = delegate.threadId
13 |
14 | actual fun jobId(): Int = delegate.jobId
15 |
16 | actual fun triggeredWritesSlowdown(): Boolean = delegate.isTriggeredWritesSlowdown
17 |
18 | actual fun triggeredWritesStop(): Boolean = delegate.isTriggeredWritesStop
19 |
20 | actual fun smallestSeqno(): Long = delegate.smallestSeqno
21 |
22 | actual fun largestSeqno(): Long = delegate.largestSeqno
23 |
24 | actual fun tableProperties(): TableProperties = TableProperties(delegate.tableProperties)
25 |
26 | actual fun flushReason(): FlushReason = delegate.flushReason
27 | }
28 |
--------------------------------------------------------------------------------
/src/commonTest/kotlin/maryk/assertBufferEquals.kt:
--------------------------------------------------------------------------------
1 | import maryk.ByteBuffer
2 | import kotlin.test.assertTrue
3 | import kotlin.test.fail
4 |
5 | fun assertBufferEquals(expected: ByteBuffer?, actual: ByteBuffer?) {
6 | if (expected == null && actual == null) return
7 | if (expected == null) fail("Expected ByteBuffer is null but actual is not null")
8 | if (actual == null) fail("Actual ByteBuffer is null but expected is not null")
9 |
10 | val expectedSize = expected.position()
11 | val actualSize = actual.position()
12 |
13 | // Check if the sizes match.
14 | assertTrue(expectedSize == actualSize,
15 | "ByteBuffer sizes differ: expected size $expectedSize, actual size $actualSize")
16 |
17 | // Compare each byte one by one.
18 | for (i in 0 until expectedSize) {
19 | val expectedByte = expected[i]
20 | val actualByte = actual[i]
21 | assertTrue(expectedByte == actualByte,
22 | "ByteBuffers differ at index $i: expected $expectedByte, but got $actualByte")
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/ByteBuffer.kt:
--------------------------------------------------------------------------------
1 | package maryk
2 |
3 | actual typealias ByteBuffer = java.nio.ByteBuffer
4 |
5 | actual fun allocateByteBuffer(capacity: Int, memSafeByteBuffer: (buffer: ByteBuffer) -> Unit) = memSafeByteBuffer(ByteBuffer.allocate(capacity))
6 | actual fun allocateDirectByteBuffer(capacity: Int, memSafeByteBuffer: (buffer: ByteBuffer) -> Unit) = memSafeByteBuffer(ByteBuffer.allocateDirect(capacity))
7 | actual fun wrapByteBuffer(bytes: ByteArray, memSafeByteBuffer: (buffer: ByteBuffer) -> Unit) = memSafeByteBuffer(ByteBuffer.wrap(bytes))
8 |
9 | // Separate function because Java 9 changes bytebuffer signature since it was added to Buffer
10 | // If Android supports proper duplicate it could be added back to ByteBuffer
11 | actual fun duplicateByteBuffer(byteBuffer: ByteBuffer, memSafeByteBuffer: (buffer: ByteBuffer) -> Unit) = memSafeByteBuffer(byteBuffer.duplicate())
12 |
13 | actual fun ByteBuffer.flip() {
14 | this.flip()
15 | }
16 |
17 | actual fun ByteBuffer.limit(newLimit: Int) {
18 | this.limit(newLimit)
19 | }
20 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/TableProperties.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Read-only metadata exported for a flushed or ingested SST table.
5 | */
6 | expect class TableProperties {
7 | fun dataSize(): Long
8 | fun indexSize(): Long
9 | fun filterSize(): Long
10 | fun rawKeySize(): Long
11 | fun rawValueSize(): Long
12 | fun numDataBlocks(): Long
13 | fun numEntries(): Long
14 | fun numDeletions(): Long
15 | fun numMergeOperands(): Long
16 | fun numRangeDeletions(): Long
17 | fun formatVersion(): Long
18 | fun columnFamilyId(): Long
19 | fun columnFamilyName(): String?
20 | fun creationTime(): Long
21 | fun oldestKeyTime(): Long
22 | fun slowCompressionEstimatedDataSize(): Long
23 | fun fastCompressionEstimatedDataSize(): Long
24 | fun filterPolicyName(): String?
25 | fun comparatorName(): String?
26 | fun mergeOperatorName(): String?
27 | fun prefixExtractorName(): String?
28 | fun propertyCollectorsNames(): String?
29 | fun compressionName(): String?
30 | }
31 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/AbstractCompactionFilterFactory.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Each compaction will create a new [AbstractCompactionFilter]
5 | * allowing the application to know about different compactions
6 | *
7 | * @param The concrete type of the compaction filter
8 | */
9 | expect abstract class AbstractCompactionFilterFactory>() : RocksCallbackObject {
10 | /**
11 | * A name which identifies this compaction filter
12 | *
13 | * The name will be printed to the LOG file on start up for diagnosis
14 | *
15 | * @return name which identifies this compaction filter.
16 | */
17 | abstract fun name(): String
18 |
19 | /**
20 | * Create a new compaction filter
21 | *
22 | * @param context The context describing the need for a new compaction filter
23 | *
24 | * @return A new instance of [AbstractCompactionFilter]
25 | */
26 | abstract fun createCompactionFilter(
27 | context: AbstractCompactionFilterContext
28 | ): T
29 | }
30 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/WriteEntry.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Represents an entry returned by
5 | * [WBWIRocksIterator.entry]
6 | *
7 | * It is worth noting that a WriteEntry with
8 | * the type [WriteType.DELETE]
9 | * or [WriteType.LOG]
10 | * will not have a value.
11 | */
12 | expect class WriteEntry(type: WriteType, key: DirectSlice, value: DirectSlice?) : AutoCloseable {
13 | /**
14 | * Returns the type of the Write Entry
15 | *
16 | * @return the WriteType of the WriteEntry
17 | */
18 | fun getType(): WriteType
19 |
20 | /**
21 | * Returns the key of the Write Entry
22 | *
23 | * @return The slice containing the key
24 | * of the WriteEntry
25 | */
26 | fun getKey(): DirectSlice
27 |
28 | /**
29 | * Returns the value of the Write Entry
30 | *
31 | * @return The slice containing the value of
32 | * the WriteEntry or null if the WriteEntry has
33 | * no value
34 | */
35 | fun getValue(): DirectSlice?
36 |
37 | override fun close()
38 | }
39 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/EventInfo.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual typealias BackgroundErrorReason = org.rocksdb.BackgroundErrorReason
4 |
5 | actual typealias WriteStallCondition = org.rocksdb.WriteStallCondition
6 |
7 | actual class WriteStallInfo internal constructor(
8 | internal val delegate: org.rocksdb.WriteStallInfo
9 | ) {
10 | actual fun columnFamilyName(): String = delegate.columnFamilyName
11 |
12 | actual fun currentCondition(): WriteStallCondition = delegate.currentCondition
13 |
14 | actual fun previousCondition(): WriteStallCondition = delegate.previousCondition
15 | }
16 |
17 | actual class MemTableInfo internal constructor(
18 | internal val delegate: org.rocksdb.MemTableInfo
19 | ) {
20 | actual fun columnFamilyName(): String = delegate.columnFamilyName
21 |
22 | actual fun firstSeqno(): Long = delegate.firstSeqno
23 |
24 | actual fun earliestSeqno(): Long = delegate.earliestSeqno
25 |
26 | actual fun numEntries(): Long = delegate.numEntries
27 |
28 | actual fun numDeletes(): Long = delegate.numDeletes
29 | }
30 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/PlainTableConfig.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Configuration wrapper for plain table factories.
5 | */
6 | expect class PlainTableConfig() : TableFormatConfig {
7 | fun keySize(): Int
8 | fun setKeySize(keySize: Int): PlainTableConfig
9 |
10 | fun bloomBitsPerKey(): Int
11 | fun setBloomBitsPerKey(bloomBitsPerKey: Int): PlainTableConfig
12 |
13 | fun hashTableRatio(): Double
14 | fun setHashTableRatio(hashTableRatio: Double): PlainTableConfig
15 |
16 | fun indexSparseness(): Long
17 | fun setIndexSparseness(indexSparseness: Int): PlainTableConfig
18 |
19 | fun hugePageTlbSize(): Int
20 | fun setHugePageTlbSize(hugePageTlbSize: Int): PlainTableConfig
21 |
22 | fun encodingType(): EncodingType
23 | fun setEncodingType(encodingType: EncodingType): PlainTableConfig
24 |
25 | fun fullScanMode(): Boolean
26 | fun setFullScanMode(fullScanMode: Boolean): PlainTableConfig
27 |
28 | fun storeIndexInFile(): Boolean
29 | fun setStoreIndexInFile(storeIndexInFile: Boolean): PlainTableConfig
30 | }
31 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/SstFileMetaData.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual open class SstFileMetaData protected constructor() {
4 | private lateinit var fileNameValue: String
5 | private lateinit var pathValue: String
6 | private var sizeValue: ULong = 0u
7 | private lateinit var smallestKeyValue: ByteArray
8 | private lateinit var largestKeyValue: ByteArray
9 |
10 | internal constructor(
11 | fileName: String,
12 | path: String,
13 | size: ULong,
14 | smallestKey: ByteArray,
15 | largestKey: ByteArray,
16 | ) : this() {
17 | fileNameValue = fileName
18 | pathValue = path
19 | sizeValue = size
20 | smallestKeyValue = smallestKey
21 | largestKeyValue = largestKey
22 | }
23 |
24 | actual fun fileName(): String = fileNameValue
25 |
26 | actual fun path(): String = pathValue
27 |
28 | actual fun size(): Long = sizeValue.toLong()
29 |
30 | actual fun smallestKey(): ByteArray = smallestKeyValue
31 |
32 | actual fun largestKey(): ByteArray = largestKeyValue
33 | }
34 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/wrapWithMultiErrorThrower.kt:
--------------------------------------------------------------------------------
1 | package maryk
2 |
3 | import kotlinx.cinterop.ByteVar
4 | import kotlinx.cinterop.CArrayPointer
5 | import kotlinx.cinterop.CPointerVar
6 | import kotlinx.cinterop.allocArray
7 | import kotlinx.cinterop.get
8 | import kotlinx.cinterop.memScoped
9 | import kotlinx.cinterop.toKString
10 | import maryk.rocksdb.RocksDBException
11 |
12 | fun T.wrapWithMultiErrorThrower(
13 | numKeys: Int,
14 | runnable: T.(CArrayPointer>) -> R?
15 | ): R? = memScoped {
16 | // Allocate an array of pointers for `errs`
17 | val errsArray = allocArray>(numKeys)
18 |
19 | val result = runnable(errsArray)
20 |
21 | for (i in 0 until numKeys) {
22 | val singleErrorPtr = errsArray[i]
23 | if (singleErrorPtr != null) {
24 | val errMsg = singleErrorPtr.toKString()
25 |
26 | throw RocksDBException(
27 | errMsg,
28 | convertToStatus(errMsg)
29 | )
30 | }
31 | }
32 |
33 | return@memScoped result
34 | }
35 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/util/memCompare.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb.util
2 |
3 | import maryk.ByteBuffer
4 |
5 | /**
6 | * Compares the first `count` bytes of two areas of memory. Returns
7 | * zero if they are the same, a value less than zero if `x` is
8 | * lexically less than `y`, or a value greater than zero if `x`
9 | * is lexically greater than `y`. Note that lexical order is determined
10 | * as if comparing unsigned char arrays.
11 | *
12 | * Similar to [memcmp.c](https://github.com/gcc-mirror/gcc/blob/master/libiberty/memcmp.c).
13 | *
14 | * @param x the first value to compare with
15 | * @param y the second value to compare against
16 | * @param count the number of bytes to compare
17 | *
18 | * @return the result of the comparison
19 | */
20 | fun memCompare(
21 | x: ByteBuffer, y: ByteBuffer,
22 | count: Int
23 | ): Int {
24 | for (idx in 0 until count) {
25 | val aa: Int = x.get(idx).toInt() and 0xff
26 | val bb: Int = y.get(idx).toInt() and 0xff
27 | if (aa != bb) {
28 | return aa - bb
29 | }
30 | }
31 | return 0
32 | }
33 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/ByteBuffer.kt:
--------------------------------------------------------------------------------
1 | package maryk
2 |
3 | expect abstract class ByteBuffer : Buffer {
4 | final override fun array(): ByteArray
5 | fun put(src: ByteArray): ByteBuffer
6 | abstract operator fun get(index: Int): Byte
7 | operator fun get(dst: ByteArray, offset: Int, length: Int): ByteBuffer
8 | operator fun get(dst: ByteArray): ByteBuffer
9 | abstract fun put(index: Int, byte: Byte): ByteBuffer
10 | abstract fun getInt(): Int
11 | }
12 |
13 | internal expect fun duplicateByteBuffer(byteBuffer: ByteBuffer, memSafeByteBuffer: (buffer: ByteBuffer) -> Unit)
14 |
15 | internal expect fun allocateByteBuffer(capacity: Int, memSafeByteBuffer: (buffer: ByteBuffer) -> Unit)
16 |
17 | internal expect fun allocateDirectByteBuffer(capacity: Int, memSafeByteBuffer: (buffer: ByteBuffer) -> Unit)
18 |
19 | internal expect fun wrapByteBuffer(bytes: ByteArray, memSafeByteBuffer: (buffer: ByteBuffer) -> Unit)
20 |
21 | // because of java 1.8 and java 9 incompatibilities and Android using 1.8 interface, these two methods are needed
22 | internal expect fun ByteBuffer.flip()
23 | internal expect fun ByteBuffer.limit(newLimit: Int)
24 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/openOptimisticTransactionDB.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | @Throws(RocksDBException::class)
4 | expect fun openOptimisticTransactionDB(options: Options, path: String): OptimisticTransactionDB
5 |
6 | /**
7 | * Open an OptimisticTransactionDB similar to
8 | * {@link RocksDB#open(DBOptions, String, List, List)}.
9 | *
10 | * @param dbOptions {@link org.rocksdb.DBOptions} instance.
11 | * @param path the path to the rocksdb.
12 | * @param columnFamilyDescriptors list of column family descriptors
13 | * @param columnFamilyHandles will be filled with ColumnFamilyHandle instances
14 | *
15 | * @return a {@link OptimisticTransactionDB} instance on success, null if the
16 | * specified {@link OptimisticTransactionDB} can not be opened.
17 | *
18 | * @throws RocksDBException if an error occurs whilst opening the database.
19 | */
20 | @Throws(RocksDBException::class)
21 | expect fun openOptimisticTransactionDB(
22 | dbOptions: DBOptions,
23 | path: String,
24 | columnFamilyDescriptors: List,
25 | columnFamilyHandles: MutableList
26 | ): OptimisticTransactionDB
27 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/Slice.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual class Slice actual constructor(
4 | override var data: ByteArray
5 | ) : AbstractSlice() {
6 | actual constructor(str: String) : this(str.encodeToByteArray())
7 |
8 | actual constructor(data: ByteArray, offset: Int) : this(data.copyOfRange(offset, data.size))
9 |
10 | override fun getData(): ByteArray {
11 | return data
12 | }
13 |
14 | actual override fun clear() {
15 | data = ByteArray(0)
16 | }
17 |
18 | actual override fun removePrefix(n: Int) {
19 | data = data.copyOfRange(n, data.size)
20 | }
21 |
22 | override fun size(): Int {
23 | return data.size.toInt()
24 | }
25 |
26 | override fun empty(): Boolean {
27 | return data.isEmpty()
28 | }
29 |
30 | @OptIn(ExperimentalStdlibApi::class)
31 | override fun toString(hex: Boolean): String {
32 | return if (hex) {
33 | data.toHexString()
34 | } else data.decodeToString()
35 | }
36 |
37 | override operator fun get(offset: Int): Byte {
38 | return data[offset]
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/commonTest/kotlin/maryk/assertContains.kt:
--------------------------------------------------------------------------------
1 | package maryk
2 |
3 | import kotlin.test.fail
4 |
5 | fun assertContains(results: Collection, toMatch: ByteArray?) {
6 | for (result in results) {
7 | if (result == null) {
8 | if (toMatch == null) return else break
9 | } else {
10 | if (toMatch != null && result.contentEquals(toMatch)) return
11 | }
12 | }
13 | fail("Results do not contain ${toMatch?.decodeToString()}.")
14 | }
15 |
16 | fun assertContains(results: Collection, vararg toMatch: ByteArray?) {
17 | results@for (match in toMatch) {
18 | assertContains(results, match)
19 | }
20 | }
21 |
22 | fun assertContainsExactly(results: Collection, vararg toMatch: ByteArray?) {
23 | if (results.size != toMatch.size) fail("Results do not match exactly $toMatch")
24 | assertContains(results, *toMatch)
25 | }
26 |
27 | fun assertContainsExactly(results: Collection, toMatch: List) {
28 | if (results.size != toMatch.size) fail("Results do not match exactly $toMatch")
29 | assertContains(results, *toMatch.toTypedArray())
30 | }
31 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/Slice.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Base class for slices which will receive
5 | * byte[] based access to the underlying data.
6 | *
7 | * byte[] backed slices typically perform better with
8 | * small keys and values. When using larger keys and
9 | * values consider using [org.rocksdb.DirectSlice]
10 | */
11 | expect class Slice : AbstractSlice {
12 | /**
13 | * Constructs a slice where the data is taken from
14 | * a String.
15 | *
16 | * @param str String value.
17 | */
18 | constructor(str: String)
19 |
20 | /**
21 | * Constructs a slice where the data is a copy of
22 | * the byte array from a specific offset.
23 | *
24 | * @param data byte array.
25 | * @param offset offset within the byte array.
26 | */
27 | constructor(data: ByteArray, offset: Int)
28 |
29 | /**
30 | * Constructs a slice where the data is a copy of
31 | * the byte array.
32 | *
33 | * @param data byte array.
34 | */
35 | constructor(data: ByteArray)
36 |
37 | override fun removePrefix(n: Int)
38 | override fun clear()
39 | }
40 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/RocksEnv.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import cnames.structs.rocksdb_env_t
4 | import kotlinx.cinterop.CPointer
5 |
6 | /**
7 | * A RocksEnv is an interface used by the rocksdb implementation to access
8 | * operating system functionality like the filesystem etc.
9 | *
10 | * All Env implementations are safe for concurrent access from
11 | * multiple threads without any external synchronization.
12 | */
13 | class RocksEnv
14 | /**
15 | * Internal constructor that uses the specified native handle
16 | * to construct a RocksEnv.
17 | *
18 | * Note that the ownership of the input handle
19 | * belongs to the caller, and the newly created RocksEnv will not take
20 | * the ownership of the input handle. As a result, calling
21 | * `dispose()` of the created RocksEnv will be no-op.
22 | */
23 | internal constructor(native: CPointer?) : Env(native) {
24 |
25 | override fun equals(other: Any?): Boolean {
26 | if (other !is RocksEnv) return false
27 | if (this.native === other.native) return true
28 | return true
29 | }
30 |
31 | override fun hashCode(): Int {
32 | return this.native.hashCode()
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/openTransactionDB.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Opens a `TransactionDB` instance with the specified options and database path.
5 | *
6 | * This method is analogous to [openRocksDB], but includes transaction-specific options.
7 | *
8 | * @param options An instance of [Options] to configure the database.
9 | * @param transactionDbOptions An instance of [TransactionDBOptions] to configure transaction behavior.
10 | * @param path The filesystem path where the database should be opened or created.
11 | *
12 | * @return A `TransactionDB` instance if the database is successfully opened; otherwise, `null`.
13 | *
14 | * @throws RocksDBException If an error occurs while opening the database.
15 | */
16 | @Throws(RocksDBException::class)
17 | expect fun openTransactionDB(options: Options, transactionDbOptions: TransactionDBOptions, path: String): TransactionDB
18 |
19 | @Throws(RocksDBException::class)
20 | expect fun openTransactionDB(
21 | dbOptions: DBOptions,
22 | transactionDbOptions: TransactionDBOptions,
23 | path: String,
24 | columnFamilyDescriptors: List,
25 | columnFamilyHandles: MutableList
26 | ): TransactionDB
27 |
--------------------------------------------------------------------------------
/src/commonTest/kotlin/maryk/rocksdb/IngestExternalFileOptionsTest.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import kotlin.test.Test
4 | import kotlin.test.assertFalse
5 | import kotlin.test.assertTrue
6 |
7 | class IngestExternalFileOptionsTest {
8 | init {
9 | loadRocksDBLibrary()
10 | }
11 |
12 | @Test
13 | fun togglesRoundTrip() {
14 | IngestExternalFileOptions().use { options ->
15 | assertFalse(options.moveFiles())
16 | assertTrue(options.snapshotConsistency())
17 | assertTrue(options.allowGlobalSeqNo())
18 | assertTrue(options.allowBlockingFlush())
19 | assertFalse(options.ingestBehind())
20 |
21 | options.setMoveFiles(true)
22 | options.setSnapshotConsistency(false)
23 | options.setAllowGlobalSeqNo(false)
24 | options.setAllowBlockingFlush(false)
25 | options.setIngestBehind(true)
26 |
27 | assertTrue(options.moveFiles())
28 | assertFalse(options.snapshotConsistency())
29 | assertFalse(options.allowGlobalSeqNo())
30 | assertFalse(options.allowBlockingFlush())
31 | assertTrue(options.ingestBehind())
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/BloomFilter.kt:
--------------------------------------------------------------------------------
1 | @file:OptIn(ExperimentalForeignApi::class)
2 |
3 | package maryk.rocksdb
4 |
5 | import cnames.structs.rocksdb_filterpolicy_t
6 | import kotlinx.cinterop.CPointer
7 | import kotlinx.cinterop.ExperimentalForeignApi
8 | import rocksdb.rocksdb_filterpolicy_create_bloom
9 | import rocksdb.rocksdb_filterpolicy_create_bloom_full
10 | import rocksdb.rocksdb_filterpolicy_destroy
11 |
12 | actual class BloomFilter internal constructor(
13 | internal val native: CPointer
14 | ) : FilterPolicy() {
15 | actual constructor() : this(rocksdb_filterpolicy_create_bloom(10.toDouble())!!)
16 |
17 | actual constructor(bitsPerKey: Double) : this(
18 | rocksdb_filterpolicy_create_bloom(bitsPerKey)!!
19 | )
20 |
21 | actual constructor(bitsPerKey: Double, useBlockBasedBuilder: Boolean) : this(
22 | // The value useBlockBasedBuilder is ignored in java implementation so ignore it here too.
23 | rocksdb_filterpolicy_create_bloom_full(bitsPerKey)!!
24 | )
25 |
26 | override fun close() {
27 | if (isOwningHandle()) {
28 | rocksdb_filterpolicy_destroy(native)
29 | super.close()
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/PersistentCache.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import cnames.structs.rocksdb_persistent_cache_t
4 | import kotlinx.cinterop.CPointer
5 | import maryk.toUByte
6 | import maryk.wrapWithNullErrorThrower
7 | import rocksdb.rocksdb_persistent_cache_create
8 | import rocksdb.rocksdb_persistent_cache_destroy
9 |
10 | actual class PersistentCache actual constructor(
11 | env: Env,
12 | path: String,
13 | size: Long,
14 | logger: Logger,
15 | optimizedForNvm: Boolean,
16 | ) : RocksObject() {
17 | private val loggerRef = logger
18 |
19 | internal val native: CPointer =
20 | Unit.wrapWithNullErrorThrower { error ->
21 | rocksdb_persistent_cache_create(
22 | env.native,
23 | path,
24 | size.toULong(),
25 | logger.native,
26 | optimizedForNvm.toUByte(),
27 | error,
28 | )
29 | } ?: error("Unable to create persistent cache at $path")
30 |
31 | override fun close() {
32 | if (isOwningHandle()) {
33 | rocksdb_persistent_cache_destroy(native)
34 | super.close()
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/CompactionStyle.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Enum CompactionStyle
5 | *
6 | * RocksDB supports different styles of compaction. Available
7 | * compaction styles can be chosen using this enumeration.
8 | *
9 | * 1. **LEVEL** - Level based Compaction style
10 | * 2. **UNIVERSAL** - Universal Compaction Style is a
11 | * compaction style, targeting the use cases requiring lower write
12 | * amplification, trading off read amplification and space
13 | * amplification.
14 | * 3. **FIFO** - FIFO compaction style is the simplest
15 | * compaction strategy. It is suited for keeping event log data with
16 | * very low overhead (query log for example). It periodically deletes
17 | * the old data, so it's basically a TTL compaction style.
18 | * 4. **NONE** - Disable background compaction.
19 | * Compaction jobs are submitted [RocksDB.compactFiles] ().
20 | *
21 | * @see [Universal Compaction](https://github.com/facebook/rocksdb/wiki/Universal-Compaction)
22 | * @see [FIFO Compaction](https://github.com/facebook/rocksdb/wiki/FIFO-compaction-style)
23 | */
24 | expect enum class CompactionStyle {
25 | LEVEL,
26 | UNIVERSAL,
27 | FIFO,
28 | NONE;
29 | }
30 |
31 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/CheckPoint.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Provides Checkpoint functionality. Checkpoints
5 | * provide persistent snapshots of RocksDB databases.
6 | */
7 | expect class Checkpoint : RocksObject {
8 | /**
9 | * Builds an open-able snapshot of RocksDB on the same disk, which
10 | * accepts an output directory on the same disk, and under the directory
11 | * (1) hard-linked SST files pointing to existing live SST files
12 | * (2) a copied manifest files and other files
13 | *
14 | * @param checkpointPath path to the folder where the snapshot is going
15 | * to be stored.
16 | * @throws RocksDBException thrown if an error occurs within the native
17 | * part of the library.
18 | */
19 | fun createCheckpoint(checkpointPath: String)
20 | }
21 |
22 | /**
23 | * Creates a Checkpoint object to be used for creating open-able
24 | * snapshots.
25 | *
26 | * @param db [RocksDB] instance.
27 | * @return a Checkpoint instance.
28 | *
29 | * @throws IllegalArgumentException if [RocksDB]
30 | * instance is null.
31 | * @throws IllegalStateException if [RocksDB]
32 | * instance is not initialized.
33 | */
34 | expect fun createCheckpoint(db: RocksDB): Checkpoint
35 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/WBWIRocksIterator.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 |
4 | /**
5 | * An iterator over a [WriteBatchWithIndex] that allows traversing the entries
6 | * in the write batch.
7 | *
8 | * The iterator provides access to each [WriteEntry] in the write batch,
9 | * which includes the operation type, key, and value.
10 | *
11 | * **Note:** The [WriteEntry] returned by [entry] is only valid until the iterator
12 | * is repositioned. To retain the data across iterator movements, make a copy of the
13 | * [WriteEntry]'s data.
14 | *
15 | * **Thread Safety:** This iterator is not thread-safe with respect to the [WriteEntry]
16 | * as it performs a non-atomic update across the fields of the [WriteEntry].
17 | */
18 | expect class WBWIRocksIterator : AbstractRocksIterator {
19 | // /**
20 | // * Retrieves the current [WriteEntry] that the iterator is pointing to.
21 | // *
22 | // * The [WriteEntry] includes the type of write operation, the key, and the value.
23 | // *
24 | // * @return The current [WriteEntry].
25 | // */
26 | // fun entry(): WriteEntry
27 |
28 | /**
29 | * Closes the iterator and releases any associated resources.
30 | */
31 | override fun close()
32 | }
33 |
--------------------------------------------------------------------------------
/src/commonTest/kotlin/maryk/rocksdb/CompressionOptionsTest.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import kotlin.test.Test
4 | import kotlin.test.assertEquals
5 |
6 | class CompressionOptionsTest {
7 | init {
8 | loadRocksDBLibrary()
9 | }
10 |
11 | @Test
12 | fun windowBits() {
13 | val windowBits = 7
14 | CompressionOptions().use { options ->
15 | options.setWindowBits(windowBits)
16 | assertEquals(windowBits, options.windowBits())
17 | }
18 | }
19 |
20 | @Test
21 | fun level() {
22 | val level = 6
23 | CompressionOptions().use { options ->
24 | options.setLevel(level)
25 | assertEquals(level, options.level())
26 | }
27 | }
28 |
29 | @Test
30 | fun strategy() {
31 | val strategy = 2
32 | CompressionOptions().use { options ->
33 | options.setStrategy(strategy)
34 | assertEquals(strategy, options.strategy())
35 | }
36 | }
37 |
38 | @Test
39 | fun maxDictBytes() {
40 | val maxDictBytes = 999
41 | CompressionOptions().use { options ->
42 | options.setMaxDictBytes(maxDictBytes)
43 | assertEquals(maxDictBytes, options.maxDictBytes())
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/jvmMain/kotlin/maryk/rocksdb/OptionsUtil.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual object OptionsUtil {
4 | @Throws(RocksDBException::class)
5 | actual fun loadLatestOptions(
6 | configOptions: ConfigOptions,
7 | dbPath: String,
8 | dbOptions: DBOptions,
9 | columnFamilyDescriptors: MutableList
10 | ) {
11 | org.rocksdb.OptionsUtil.loadLatestOptions(
12 | configOptions,
13 | dbPath,
14 | dbOptions,
15 | columnFamilyDescriptors
16 | )
17 | }
18 |
19 | @Throws(RocksDBException::class)
20 | actual fun loadOptionsFromFile(
21 | configOptions: ConfigOptions,
22 | optionsFilePath: String,
23 | dbOptions: DBOptions,
24 | columnFamilyDescriptors: MutableList
25 | ) {
26 | org.rocksdb.OptionsUtil.loadOptionsFromFile(
27 | configOptions,
28 | optionsFilePath,
29 | dbOptions,
30 | columnFamilyDescriptors
31 | )
32 | }
33 |
34 | @Throws(RocksDBException::class)
35 | actual fun getLatestOptionsFileName(dbPath: String, env: Env): String {
36 | return org.rocksdb.OptionsUtil.getLatestOptionsFileName(dbPath, env)
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/Status.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Represents the status returned by a function call in RocksDB.
5 | *
6 | * Currently only used with {@link RocksDBException} when the
7 | * status is not {@link Code#Ok}
8 | */
9 | expect class Status(code: StatusCode, subCode: StatusSubCode?, state: String?) {
10 | fun getCode(): StatusCode
11 |
12 | fun getSubCode(): StatusSubCode?
13 |
14 | fun getState(): String?
15 |
16 | fun getCodeString(): String
17 | }
18 |
19 | // should stay in sync with /include/rocksdb/status.h:Code and /java/rocksjni/portal.h:toJavaStatusCode
20 | expect enum class StatusCode {
21 | Ok,
22 | NotFound,
23 | Corruption,
24 | NotSupported,
25 | InvalidArgument,
26 | IOError,
27 | MergeInProgress,
28 | Incomplete,
29 | ShutdownInProgress,
30 | TimedOut,
31 | Aborted,
32 | Busy,
33 | Expired,
34 | TryAgain,
35 | Undefined
36 | }
37 |
38 | // should stay in sync with /include/rocksdb/status.h:SubCode and /java/rocksjni/portal.h:toJavaStatusSubCode
39 | expect enum class StatusSubCode {
40 | None,
41 | MutexTimeout,
42 | LockTimeout,
43 | LockLimit,
44 | NoSpace,
45 | Deadlock,
46 | StaleFile,
47 | MemoryLimit,
48 | Undefined
49 | }
50 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/FlushJobInfo.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /** Metadata describing a flush job. */
4 | expect class FlushJobInfo {
5 | /** Identifier of the column family that produced the SST file. */
6 | fun columnFamilyId(): Long
7 |
8 | /** Name of the column family that produced the SST file. */
9 | fun columnFamilyName(): String
10 |
11 | /** Absolute path of the flushed SST file. */
12 | fun filePath(): String
13 |
14 | /** Thread identifier that executed the flush. */
15 | fun threadId(): Long
16 |
17 | /** Job identifier that is unique within the thread. */
18 | fun jobId(): Int
19 |
20 | /** Whether the flush was triggered because writes were slowed down. */
21 | fun triggeredWritesSlowdown(): Boolean
22 |
23 | /** Whether writes were stopped while waiting for this flush. */
24 | fun triggeredWritesStop(): Boolean
25 |
26 | /** Smallest sequence number contained in the flushed file. */
27 | fun smallestSeqno(): Long
28 |
29 | /** Largest sequence number contained in the flushed file. */
30 | fun largestSeqno(): Long
31 |
32 | /** Table properties associated with the flushed SST file. */
33 | fun tableProperties(): TableProperties
34 |
35 | /** Reason why the flush was initiated. */
36 | fun flushReason(): FlushReason
37 | }
38 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/useAutoClosable.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Executes the given [block] function on this resource and then closes it down correctly whether an exception
5 | * is thrown or not.
6 | *
7 | * @param block a function to process this [Closeable] resource.
8 | * @return the result of [block] function invoked on this resource.
9 | */
10 | inline fun T.use(block: (T) -> R): R {
11 | var exception: Throwable? = null
12 | try {
13 | return block(this)
14 | } catch (e: Throwable) {
15 | exception = e
16 | throw e
17 | } finally {
18 | this.closeFinally(exception)
19 | }
20 | }
21 |
22 | /**
23 | * Closes this [Closeable], suppressing possible exception or error thrown by [Closeable.close] function when
24 | * it's being closed due to some other [cause] exception occurred.
25 | *
26 | * The suppressed exception is added to the list of suppressed exceptions of [cause] exception, when it's supported.
27 | */
28 | fun AutoCloseable?.closeFinally(cause: Throwable?) = when {
29 | this == null -> {}
30 | cause == null -> close()
31 | else ->
32 | try {
33 | close()
34 | } catch (closeException: Throwable) {
35 | // Ignored
36 | // cause.addSuppressed(closeException)
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/commonTest/kotlin/maryk/rocksdb/CompactionOptionsTest.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import kotlin.test.Test
4 | import kotlin.test.assertEquals
5 |
6 | class CompactionOptionsTest {
7 | init {
8 | loadRocksDBLibrary()
9 | }
10 |
11 | @Test
12 | fun compressionRoundTrip() {
13 | CompactionOptions().use { options ->
14 | val original = options.compression()
15 | options.setCompression(CompressionType.NO_COMPRESSION)
16 | assertEquals(CompressionType.NO_COMPRESSION, options.compression())
17 |
18 | options.setCompression(original)
19 | assertEquals(original, options.compression())
20 | }
21 | }
22 |
23 | @Test
24 | fun outputFileSizeLimit() {
25 | val limit = 250L * 1024 * 1024
26 | CompactionOptions().use { options ->
27 | assertEquals(-1, options.outputFileSizeLimit())
28 |
29 | options.setOutputFileSizeLimit(limit)
30 | assertEquals(limit, options.outputFileSizeLimit())
31 | }
32 | }
33 |
34 | @Test
35 | fun maxSubcompactions() {
36 | CompactionOptions().use { options ->
37 | assertEquals(0, options.maxSubcompactions())
38 |
39 | options.setMaxSubcompactions(9)
40 | assertEquals(9, options.maxSubcompactions())
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/DirectSlice.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import maryk.ByteBuffer
4 |
5 | expect class DirectSlice: AbstractSlice {
6 | /**
7 | * Constructs a slice
8 | * where the data is taken from
9 | * a String.
10 | *
11 | * @param str The string
12 | */
13 | constructor(str: String)
14 |
15 | /**
16 | * Constructs a slice where the data is
17 | * read from the provided
18 | * ByteBuffer up to a certain length
19 | *
20 | * @param data The buffer containing the data
21 | * @param length The length of the data to use for the slice
22 | */
23 | constructor(data: ByteBuffer, length: Int)
24 |
25 | /**
26 | * Constructs a slice where the data is
27 | * read from the provided
28 | * ByteBuffer
29 | *
30 | * @param data The bugger containing the data
31 | */
32 | constructor(data: ByteBuffer)
33 |
34 | /**
35 | * Retrieves the byte at a specific offset
36 | * from the underlying data
37 | *
38 | * @param offset The (zero-based) offset of the byte to retrieve
39 | *
40 | * @return the requested byte
41 | */
42 | operator fun get(offset: Int): Byte
43 |
44 | override fun clear()
45 |
46 | override fun removePrefix(n: Int)
47 | }
48 |
49 | expect val DirectSliceNone: DirectSlice
50 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/WriteBatchInterface.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | actual interface WriteBatchInterface {
4 | actual fun count(): Int
5 |
6 | actual fun put(key: ByteArray, value: ByteArray)
7 |
8 | actual fun put(columnFamilyHandle: ColumnFamilyHandle, key: ByteArray, value: ByteArray)
9 |
10 | actual fun merge(key: ByteArray, value: ByteArray)
11 |
12 | actual fun merge(
13 | columnFamilyHandle: ColumnFamilyHandle,
14 | key: ByteArray,
15 | value: ByteArray
16 | )
17 |
18 | actual fun delete(key: ByteArray)
19 |
20 | actual fun delete(columnFamilyHandle: ColumnFamilyHandle, key: ByteArray)
21 |
22 | actual fun singleDelete(key: ByteArray)
23 |
24 | actual fun singleDelete(columnFamilyHandle: ColumnFamilyHandle, key: ByteArray)
25 |
26 | actual fun deleteRange(beginKey: ByteArray, endKey: ByteArray)
27 |
28 | actual fun deleteRange(
29 | columnFamilyHandle: ColumnFamilyHandle,
30 | beginKey: ByteArray,
31 | endKey: ByteArray
32 | )
33 |
34 | actual fun putLogData(blob: ByteArray)
35 |
36 | actual fun clear()
37 |
38 | actual fun setSavePoint()
39 |
40 | actual fun rollbackToSavePoint()
41 |
42 | actual fun popSavePoint()
43 |
44 | actual fun setMaxBytes(maxBytes: Long)
45 |
46 | actual fun getWriteBatch(): WriteBatch
47 | }
48 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/EventListener.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /** Receives callbacks for background RocksDB operations. */
4 | expect abstract class EventListener : RocksCallbackObject {
5 | /** Invoked before a flush job starts. */
6 | open fun onFlushBeginEvent(db: RocksDB, flushJobInfo: FlushJobInfo)
7 |
8 | /** Invoked after a flush completes. */
9 | open fun onFlushCompletedEvent(db: RocksDB, flushJobInfo: FlushJobInfo)
10 |
11 | /** Invoked before a compaction job begins. */
12 | open fun onCompactionBeginEvent(db: RocksDB, compactionJobInfo: CompactionJobInfo)
13 |
14 | /** Invoked when a compaction job finishes. */
15 | open fun onCompactionCompletedEvent(db: RocksDB, compactionJobInfo: CompactionJobInfo)
16 |
17 | /** Invoked after an external SST file has been ingested into the database. */
18 | open fun onExternalFileIngested(db: RocksDB, ingestionInfo: ExternalFileIngestionInfo)
19 |
20 | /** Invoked when RocksDB reports a background error condition. */
21 | open fun onBackgroundErrorEvent(reason: BackgroundErrorReason, status: Status?)
22 |
23 | /** Invoked when the write controller transitions between stall conditions. */
24 | open fun onStallConditionsChanged(info: WriteStallInfo)
25 |
26 | /** Invoked when a memtable has been sealed. */
27 | open fun onMemTableSealed(info: MemTableInfo)
28 | }
29 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/RocksIterator.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * An iterator that yields a sequence of key/value pairs from a source.
5 | * Multiple implementations are provided by this library.
6 | * In particular, iterators are provided
7 | * to access the contents of a Table or a DB.
8 | *
9 | *
10 | * Multiple threads can invoke const methods on an RocksIterator without
11 | * external synchronization, but if any of the threads may call a
12 | * non-const method, all threads accessing the same RocksIterator must use
13 | * external synchronization.
14 | *
15 | * @see maryk.rocksdb.RocksObject
16 | */
17 | expect class RocksIterator : AbstractRocksIterator {
18 | /**
19 | * Return the key for the current entry. The underlying storage for
20 | * the returned slice is valid only until the next modification of
21 | * the iterator.
22 | *
23 | * REQUIRES: [.isValid]
24 | *
25 | * @return key for the current entry.
26 | */
27 | fun key(): ByteArray
28 |
29 | /**
30 | * Return the value for the current entry. The underlying storage for
31 | * the returned slice is valid only until the next modification of
32 | * the iterator.
33 | *
34 | * REQUIRES: !AtEnd() && !AtStart()
35 | * @return value for the current entry.
36 | */
37 | fun value(): ByteArray
38 | }
39 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/WriteBufferManager.kt:
--------------------------------------------------------------------------------
1 | @file:OptIn(UnsafeNumber::class)
2 |
3 | package maryk.rocksdb
4 |
5 | import cnames.structs.rocksdb_write_buffer_manager_t
6 | import kotlinx.cinterop.CPointer
7 | import kotlinx.cinterop.UnsafeNumber
8 | import maryk.asSizeT
9 | import rocksdb.rocksdb_write_buffer_manager_create_with_cache
10 | import rocksdb.rocksdb_write_buffer_manager_destroy
11 |
12 | actual class WriteBufferManager internal constructor(
13 | internal val native: CPointer,
14 | private val allowStallFlag: Boolean,
15 | ) : RocksObject() {
16 | actual constructor(
17 | bufferSize: Long,
18 | cache: Cache,
19 | allowStall: Boolean,
20 | ) : this(
21 | requireNotNull(
22 | rocksdb_write_buffer_manager_create_with_cache(
23 | bufferSize.asSizeT(),
24 | cache.native,
25 | allowStall,
26 | ),
27 | ),
28 | allowStall,
29 | )
30 |
31 | actual constructor(
32 | bufferSize: Long,
33 | cache: Cache,
34 | ) : this(bufferSize, cache, false)
35 |
36 | actual fun allowStall(): Boolean = allowStallFlag
37 |
38 | override fun close() {
39 | if (isOwningHandle()) {
40 | rocksdb_write_buffer_manager_destroy(native)
41 | super.close()
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/ColumnFamilyHandle.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import cnames.structs.rocksdb_column_family_handle_t
4 | import kotlinx.cinterop.CPointer
5 | import kotlinx.cinterop.UnsafeNumber
6 | import kotlinx.cinterop.alloc
7 | import kotlinx.cinterop.memScoped
8 | import kotlinx.cinterop.ptr
9 | import kotlinx.cinterop.value
10 | import maryk.toByteArray
11 | import platform.posix.size_tVar
12 | import rocksdb.rocksdb_column_family_handle_destroy
13 | import rocksdb.rocksdb_column_family_handle_get_id
14 | import rocksdb.rocksdb_column_family_handle_get_name
15 |
16 | actual class ColumnFamilyHandle
17 | internal constructor(
18 | val native: CPointer
19 | )
20 | : RocksObject() {
21 | override fun close() {
22 | if (isOwningHandle()) {
23 | rocksdb_column_family_handle_destroy(native)
24 | super.close()
25 | }
26 | }
27 |
28 | @OptIn(UnsafeNumber::class)
29 | actual fun getName(): ByteArray = memScoped {
30 | val length = alloc()
31 | rocksdb_column_family_handle_get_name(native, length.ptr)?.let { name ->
32 | name.toByteArray(length.value).also {
33 | rocksdb.rocksdb_free(name)
34 | }
35 | } ?: throw RocksDBException("Missing Column Family Name")
36 | }
37 |
38 | actual fun getID(): Int =
39 | rocksdb_column_family_handle_get_id(native).toInt()
40 | }
41 |
--------------------------------------------------------------------------------
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | name: Build
2 |
3 | on:
4 | push:
5 | branches: [ main ]
6 | pull_request:
7 | branches: [ main ]
8 |
9 | permissions:
10 | contents: read
11 |
12 | jobs:
13 | native-tests:
14 | strategy:
15 | fail-fast: false
16 | matrix:
17 | include:
18 | - os: macos-latest
19 | display-name: macOS Arm & Simulators
20 | gradle-tasks: macosArm64Test iosSimulatorArm64Test tvosSimulatorArm64Test watchosSimulatorArm64Test
21 | - os: macos-15-intel
22 | display-name: macOS Intel
23 | gradle-tasks: macosX64Test
24 | - os: ubuntu-latest
25 | display-name: Linux targets
26 | gradle-tasks: linuxX64Test jvmTest
27 | - os: windows-latest
28 | display-name: Windows targets
29 | gradle-tasks: mingwX64Test
30 | name: ${{ matrix.display-name }}
31 | runs-on: ${{ matrix.os }}
32 | defaults:
33 | run:
34 | shell: bash
35 | steps:
36 | - name: Checkout
37 | uses: actions/checkout@v4
38 |
39 | - name: Setup Java
40 | uses: actions/setup-java@v4
41 | with:
42 | distribution: temurin
43 | java-version: 21
44 |
45 | - name: Setup Gradle
46 | uses: gradle/actions/setup-gradle@v4
47 |
48 | - name: Run ${{ matrix.display-name }} tests
49 | run: ./gradlew --stacktrace --info ${{ matrix.gradle-tasks }}
50 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/TxnDBWritePolicy.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * Represents the transaction database write policies for RocksDB.
5 | *
6 | * This enum defines the different policies that determine when data is written
7 | * to the database in the context of transactions. Each policy corresponds to
8 | * a specific phase in the two-phase commit (2PC) protocol.
9 | */
10 | expect enum class TxnDBWritePolicy {
11 | /**
12 | * Write only the committed data.
13 | *
14 | * This policy ensures that only data from transactions that have been
15 | * successfully committed are written to the database.
16 | */
17 | WRITE_COMMITTED,
18 |
19 | /**
20 | * Write data after the prepare phase of 2PC.
21 | *
22 | * In this policy, data is written to the database after the transaction
23 | * has passed the prepare phase but before the commit phase of the two-phase
24 | * commit protocol.
25 | */
26 | WRITE_PREPARED,
27 |
28 | /**
29 | * Write data before the prepare phase of 2PC.
30 | *
31 | * This policy allows data to be written to the database before the transaction
32 | * enters the prepare phase of the two-phase commit protocol.
33 | */
34 | WRITE_UNPREPARED;
35 |
36 | /**
37 | * Retrieves the byte value associated with the write policy.
38 | *
39 | * @return The byte representation of the write policy.
40 | */
41 | fun getValue(): Byte
42 | }
43 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/AbstractWriteBatch.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | expect abstract class AbstractWriteBatch : RocksObject, WriteBatchInterface {
4 | override fun count(): Int
5 |
6 | override fun put(key: ByteArray, value: ByteArray)
7 |
8 | override fun put(
9 | columnFamilyHandle: ColumnFamilyHandle,
10 | key: ByteArray, value: ByteArray
11 | )
12 |
13 | override fun merge(key: ByteArray, value: ByteArray)
14 |
15 | override fun merge(
16 | columnFamilyHandle: ColumnFamilyHandle,
17 | key: ByteArray, value: ByteArray
18 | )
19 |
20 | override fun delete(key: ByteArray)
21 |
22 | override fun delete(columnFamilyHandle: ColumnFamilyHandle, key: ByteArray)
23 |
24 | override fun singleDelete(key: ByteArray)
25 |
26 | override fun singleDelete(
27 | columnFamilyHandle: ColumnFamilyHandle,
28 | key: ByteArray
29 | )
30 |
31 | override fun deleteRange(beginKey: ByteArray, endKey: ByteArray)
32 |
33 | override fun deleteRange(
34 | columnFamilyHandle: ColumnFamilyHandle, beginKey: ByteArray,
35 | endKey: ByteArray
36 | )
37 |
38 | override fun putLogData(blob: ByteArray)
39 |
40 | override fun clear()
41 |
42 | override fun setSavePoint()
43 |
44 | override fun rollbackToSavePoint()
45 |
46 | override fun popSavePoint()
47 |
48 | override fun setMaxBytes(maxBytes: Long)
49 |
50 | override fun getWriteBatch(): WriteBatch
51 | }
52 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/CompactionOptions.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | expect class CompactionOptions() : RocksObject {
4 | fun compression(): CompressionType
5 | fun setCompression(compression: CompressionType): CompactionOptions
6 | fun outputFileSizeLimit(): Long
7 | fun setOutputFileSizeLimit(limit: Long): CompactionOptions
8 | fun maxSubcompactions(): Int
9 | fun setMaxSubcompactions(count: Int): CompactionOptions
10 | }
11 |
12 | expect class CompactionOptionsFIFO() : RocksObject {
13 | fun setMaxTableFilesSize(size: Long): CompactionOptionsFIFO
14 | fun maxTableFilesSize(): Long
15 | fun setAllowCompaction(allow: Boolean): CompactionOptionsFIFO
16 | fun allowCompaction(): Boolean
17 | }
18 |
19 | expect class CompactionOptionsUniversal() : RocksObject {
20 | fun setSizeRatio(sizeRatio: Int): CompactionOptionsUniversal
21 | fun sizeRatio(): Int
22 | fun setMinMergeWidth(width: Int): CompactionOptionsUniversal
23 | fun minMergeWidth(): Int
24 | fun setMaxMergeWidth(width: Int): CompactionOptionsUniversal
25 | fun maxMergeWidth(): Int
26 | fun setMaxSizeAmplificationPercent(percent: Int): CompactionOptionsUniversal
27 | fun maxSizeAmplificationPercent(): Int
28 | fun setCompressionSizePercent(percent: Int): CompactionOptionsUniversal
29 | fun compressionSizePercent(): Int
30 | fun setStopStyle(stopStyle: CompactionStopStyle): CompactionOptionsUniversal
31 | fun stopStyle(): CompactionStopStyle
32 | }
33 |
--------------------------------------------------------------------------------
/src/commonTest/kotlin/maryk/rocksdb/PlainTableConfigTest.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import kotlin.test.Test
4 | import kotlin.test.assertEquals
5 | import kotlin.test.assertFalse
6 | import kotlin.test.assertTrue
7 |
8 | class PlainTableConfigTest {
9 | init {
10 | loadRocksDBLibrary()
11 | }
12 |
13 | @Test
14 | fun plainTableConfigRoundTrip() {
15 | val config = PlainTableConfig()
16 | .setKeySize(16)
17 | .setBloomBitsPerKey(8)
18 | .setHashTableRatio(0.75)
19 | .setIndexSparseness(32)
20 | .setHugePageTlbSize(2)
21 | .setEncodingType(EncodingType.kPlain)
22 | .setFullScanMode(true)
23 | .setStoreIndexInFile(true)
24 |
25 | assertEquals(16, config.keySize())
26 | assertEquals(8, config.bloomBitsPerKey())
27 | assertEquals(0.75, config.hashTableRatio())
28 | assertEquals(32L, config.indexSparseness())
29 | assertEquals(2, config.hugePageTlbSize())
30 | assertEquals(EncodingType.kPlain, config.encodingType())
31 | assertTrue(config.fullScanMode())
32 | assertTrue(config.storeIndexInFile())
33 |
34 | config.setFullScanMode(false)
35 | config.setStoreIndexInFile(false)
36 | assertFalse(config.fullScanMode())
37 | assertFalse(config.storeIndexInFile())
38 |
39 | Options().use { options ->
40 | options.setTableFormatConfig(config)
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/nativeMain/kotlin/maryk/rocksdb/CompressionType.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | import maryk.rocksdb.CompressionType.NO_COMPRESSION
4 |
5 | actual enum class CompressionType(
6 | internal val value: Byte,
7 | private val libraryName: String?
8 | ) {
9 | NO_COMPRESSION(0x0, null),
10 | SNAPPY_COMPRESSION(0x1, "snappy"),
11 | ZLIB_COMPRESSION(0x2, "z"),
12 | BZLIB2_COMPRESSION(0x3, "bzip2"),
13 | LZ4_COMPRESSION(0x4, "lz4"),
14 | LZ4HC_COMPRESSION(0x5, "lz4hc"),
15 | XPRESS_COMPRESSION(0x6, "xpress"),
16 | ZSTD_COMPRESSION(0x7, "zstd"),
17 | DISABLE_COMPRESSION_OPTION(0xff.toByte(), null); // rocksdb::CompressionType::kDisableCompressionOption
18 |
19 | actual fun getLibraryName() = libraryName
20 | }
21 |
22 | actual fun getCompressionType(libraryName: String?): CompressionType {
23 | if (libraryName != null) {
24 | for (compressionType in CompressionType.entries) {
25 | if (compressionType.getLibraryName() != null && compressionType.getLibraryName() == libraryName) {
26 | return compressionType
27 | }
28 | }
29 | }
30 | return NO_COMPRESSION
31 | }
32 |
33 | actual fun getCompressionType(byteIdentifier: Byte): CompressionType {
34 | for (compressionType in CompressionType.entries) {
35 | if (compressionType.value == byteIdentifier) {
36 | return compressionType
37 | }
38 | }
39 |
40 | throw IllegalArgumentException("Illegal value provided for CompressionType.")
41 | }
42 |
--------------------------------------------------------------------------------
/src/commonMain/kotlin/maryk/rocksdb/EncodingType.kt:
--------------------------------------------------------------------------------
1 | package maryk.rocksdb
2 |
3 | /**
4 | * EncodingType
5 | *
6 | * The value will determine how to encode keys
7 | * when writing to a new SST file.
8 | *
9 | *
10 | * This value will be stored
11 | * inside the SST file which will be used when reading from
12 | * the file, which makes it possible for users to choose
13 | * different encoding type when reopening a DB. Files with
14 | * different encoding types can co-exist in the same DB and
15 | * can be read.
16 | */
17 | expect enum class EncodingType {
18 | /**
19 | * Always write full keys without any special encoding.
20 | */
21 | kPlain,
22 | /**
23 | *
24 | * Find opportunity to write the same prefix once for multiple rows.
25 | * In some cases, when a key follows a previous key with the same prefix,
26 | * instead of writing out the full key, it just writes out the size of the
27 | * shared prefix, as well as other bytes, to save some bytes.
28 | *
29 | *
30 | * When using this option, the user is required to use the same prefix
31 | * extractor to make sure the same prefix will be extracted from the same key.
32 | * The Name() value of the prefix extractor will be stored in the file. When
33 | * reopening the file, the name of the options.prefix_extractor given will be
34 | * bitwise compared to the prefix extractors stored in the file. An error
35 | * will be returned if the two don't match.
36 | */
37 | kPrefix;
38 | }
39 |
--------------------------------------------------------------------------------