├── .github └── workflows │ └── update_to_master.yml ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── LICENSE ├── README.md ├── build.gradle.kts ├── buildDependencies.sh ├── buildRocksdbApple.sh ├── buildRocksdbLinux.sh ├── buildRocksdbMinGW.sh ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle.kts └── src ├── androidMain ├── appleTest └── kotlin │ └── maryk │ ├── createFolder.kt │ ├── deleteFolder.kt │ └── doesFolderExist.kt ├── commonMain └── kotlin │ └── maryk │ ├── Buffer.kt │ ├── ByteBuffer.kt │ └── rocksdb │ ├── AbstractCompactionFilter.kt │ ├── AbstractCompactionFilterFactory.kt │ ├── AbstractComparator.kt │ ├── AbstractImmutableNativeReference.kt │ ├── AbstractMutableOptions.kt │ ├── AbstractNativeReference.kt │ ├── AbstractRocksIterator.kt │ ├── AbstractSlice.kt │ ├── AbstractTraceWriter.kt │ ├── AbstractTransactionNotifier.kt │ ├── AbstractWriteBatch.kt │ ├── BackupEngine.kt │ ├── BackupEngineOptions.kt │ ├── BackupInfo.kt │ ├── BottommostLevelCompaction.kt │ ├── BuiltinComparator.kt │ ├── Cache.kt │ ├── CheckPoint.kt │ ├── ChecksumType.kt │ ├── ColumnFamilyDescriptor.kt │ ├── ColumnFamilyHandle.kt │ ├── ColumnFamilyMetaData.kt │ ├── ColumnFamilyOptions.kt │ ├── CompactRangeOptions.kt │ ├── CompactionPriority.kt │ ├── CompactionReason.kt │ ├── CompactionStopStyle.kt │ ├── CompactionStyle.kt │ ├── ComparatorOptions.kt │ ├── CompressionType.kt │ ├── DBOptions.kt │ ├── DataBlockIndexType.kt │ ├── DirectSlice.kt │ ├── EncodingType.kt │ ├── Env.kt │ ├── FilterPolicy.kt │ ├── GetStatus.kt │ ├── HistogramData.kt │ ├── HistogramType.kt │ ├── Holder.kt │ ├── IndexType.kt │ ├── InfoLogLevel.kt │ ├── LRUCache.kt │ ├── LevelMetaData.kt │ ├── MemTableConfig.kt │ ├── MemoryUsageType.kt │ ├── MergeOperator.kt │ ├── OptimisticTransactionDB.kt │ ├── OptimisticTransactionOptions.kt │ ├── Options.kt │ ├── Priority.kt │ ├── Range.kt │ ├── ReadOptions.kt │ ├── ReadTier.kt │ ├── RemoveEmptyValueCompactionFilter.kt │ ├── RestoreOptions.kt │ ├── RocksCallbackObject.kt │ ├── RocksDB.kt │ ├── RocksDBException.kt │ ├── RocksIterator.kt │ ├── RocksIteratorInterface.kt │ ├── RocksMutableObject.kt │ ├── RocksObject.kt │ ├── SizeApproximationFlag.kt │ ├── Slice.kt │ ├── Snapshot.kt │ ├── SstFileMetaData.kt │ ├── Statistics.kt │ ├── StatsLevel.kt │ ├── Status.kt │ ├── StringAppendOperator.kt │ ├── TableFormatConfig.kt │ ├── TickerType.kt │ ├── TimedEnv.kt │ ├── TraceOptions.kt │ ├── TraceWriter.kt │ ├── Transaction.kt │ ├── TransactionDB.kt │ ├── TransactionDBOptions.kt │ ├── TransactionOptions.kt │ ├── TransactionState.kt │ ├── TxnDBWritePolicy.kt │ ├── WBWIRocksIterator.kt │ ├── WaitingTransactions.kt │ ├── WalFileType.kt │ ├── WriteBatch.kt │ ├── WriteBatchInterface.kt │ ├── WriteBatchSavePoint.kt │ ├── WriteBatchWithIndex.kt │ ├── WriteEntry.kt │ ├── WriteOptions.kt │ ├── WriteType.kt │ ├── loadLibrary.kt │ ├── openOptimisticTransactionDB.kt │ ├── openRocksDB.kt │ ├── openTransactionDB.kt │ ├── useAutoClosable.kt │ └── util │ ├── BytewiseComparator.kt │ ├── IntComparator.kt │ ├── ReverseBytewiseComparator.kt │ └── memCompare.kt ├── commonTest └── kotlin │ └── maryk │ ├── assertBufferEquals.kt │ ├── assertContains.kt │ ├── assertContentEquals.kt │ ├── createFolder.kt │ ├── deleteFolder.kt │ ├── doesFolderExist.kt │ └── rocksdb │ ├── AbstractComparatorTest.kt │ ├── AbstractTransactionTest.kt │ ├── BackupEngineTest.kt │ ├── BackupableDBOptionsTest.kt │ ├── CheckpointTest.kt │ ├── ColumnFamilyOptionsTest.kt │ ├── ColumnFamilyTest.kt │ ├── CompactRangeOptionsTest.kt │ ├── ComparatorTest.kt │ ├── CompressionTypesTest.kt │ ├── DBOptionsTest.kt │ ├── DefaultEnvTest.kt │ ├── DirectSliceTest.kt │ ├── KeyMayExistTest.kt │ ├── LRUCacheTest.kt │ ├── OptimisticTransactionDBTest.kt │ ├── OptimisticTransactionOptionsTest.kt │ ├── OptimisticTransactionTest.kt │ ├── OptionsTest.kt │ ├── ReadOnlyTest.kt │ ├── ReadOptionsTest.kt │ ├── RocksDBExceptionTest.kt │ ├── RocksDBTest.kt │ ├── RocksIteratorTest.kt │ ├── SliceTest.kt │ ├── TransactionDBOptionsTest.kt │ ├── TransactionDBTest.kt │ ├── TransactionOptionsTest.kt │ ├── TransactionTest.kt │ ├── Types.kt │ ├── WriteBatchTest.kt │ ├── WriteOptionsTest.kt │ └── util │ ├── createTestDBFolder.kt │ └── dummyString.kt ├── jvmMain ├── AndroidManifest.xml └── kotlin │ └── maryk │ ├── Buffer.kt │ ├── ByteBuffer.kt │ └── rocksdb │ ├── AbstractCompactionFilter.kt │ ├── AbstractCompactionFilterFactory.kt │ ├── AbstractComparator.kt │ ├── AbstractImmutableNativeReference.kt │ ├── AbstractMutableOptions.kt │ ├── AbstractNativeReference.kt │ ├── AbstractRocksIterator.kt │ ├── AbstractSlice.kt │ ├── AbstractTraceWriter.kt │ ├── AbstractTransactionNotifier.kt │ ├── AbstractWriteBatch.kt │ ├── BackupEngine.kt │ ├── BackupEngineOptions.kt │ ├── BackupInfo.kt │ ├── BottommostLevelCompaction.kt │ ├── BuiltinComparator.kt │ ├── Cache.kt │ ├── ChecksumType.kt │ ├── ColumnFamilyDescriptor.kt │ ├── ColumnFamilyHandle.kt │ ├── ColumnFamilyMetaData.kt │ ├── ColumnFamilyOptions.kt │ ├── CompactRangeOptions.kt │ ├── CompactionPriority.kt │ ├── CompactionReason.kt │ ├── CompactionStopStyle.kt │ ├── CompactionStyle.kt │ ├── ComparatorOptions.kt │ ├── CompressionType.kt │ ├── DBOptions.kt │ ├── DataBlockIndexType.kt │ ├── DirectSlice.kt │ ├── EncodingType.kt │ ├── Env.kt │ ├── FilterPolicy.kt │ ├── GetStatus.kt │ ├── HistogramData.kt │ ├── HistogramType.kt │ ├── Holder.kt │ ├── IndexType.kt │ ├── InfoLogLevel.kt │ ├── LRUCache.kt │ ├── LevelMetaData.kt │ ├── MemTableConfig.kt │ ├── MemoryUsageType.kt │ ├── MergeOperator.kt │ ├── OptimisticTransactionDB.kt │ ├── OptimisticTransactionOptions.kt │ ├── Options.kt │ ├── Priority.kt │ ├── Range.kt │ ├── ReadOptions.kt │ ├── ReadTier.kt │ ├── RemoveEmptyValueCompactionFilter.kt │ ├── RestoreOptions.kt │ ├── RocksCallbackObject.kt │ ├── RocksDB.kt │ ├── RocksDBException.kt │ ├── RocksIterator.kt │ ├── RocksIteratorInterface.kt │ ├── RocksMutableObject.kt │ ├── RocksObject.kt │ ├── SizeApproximationFlag.kt │ ├── Slice.kt │ ├── Snapshot.kt │ ├── SstFileMetaData.kt │ ├── Statistics.kt │ ├── StatsLevel.kt │ ├── Status.kt │ ├── StringAppendOperator.kt │ ├── TableFormatConfig.kt │ ├── TickerType.kt │ ├── TimedEnv.kt │ ├── TraceOptions.kt │ ├── TraceWriter.kt │ ├── Transaction.kt │ ├── TransactionDB.kt │ ├── TransactionDBOptions.kt │ ├── TransactionOptions.kt │ ├── TransactionState.kt │ ├── TxnDBWritePolicy.kt │ ├── WBWIRocksIterator.kt │ ├── WaitingTransactions.kt │ ├── WalFileType.kt │ ├── WriteBatch.kt │ ├── WriteBatchInterface.kt │ ├── WriteBatchWithIndex.kt │ ├── WriteEntry.kt │ ├── WriteOptions.kt │ ├── WriteType.kt │ ├── createCheckPoint.kt │ ├── loadLibrary.kt │ ├── openOptimisticTransactionDB.kt │ ├── openRocksDB.kt │ └── openTransactionDB.kt ├── jvmTest └── kotlin │ └── maryk │ ├── createFolder.kt │ ├── deleteFolder.kt │ ├── doesFolderExist.kt │ └── rocksdb │ └── WriteBatchThreadedTest.kt ├── linuxTest └── kotlin │ └── maryk │ ├── createFolder.kt │ ├── deleteFolder.kt │ └── doesFolderExist.kt ├── main └── AndroidManifest.xml ├── mingwTest └── kotlin │ └── maryk │ ├── createFolder.kt │ ├── deleteFolder.kt │ └── doesFolderExist.kt ├── nativeInterop └── cinterop │ └── rocksdb.def └── nativeMain └── kotlin └── maryk ├── BooleanToUByte.kt ├── Buffer.kt ├── ByteBuffer.kt ├── UByteToBoolean.kt ├── byteArrayToCPointer.kt ├── convertToStatus.kt ├── rocksdb ├── AbstractCompactionFilterContext.kt ├── AbstractCompactionFilterFactory.kt ├── AbstractComparator.kt ├── AbstractImmutableNativeReference.kt ├── AbstractMutableOptions.kt ├── AbstractNativeReference.kt ├── AbstractRocksIterator.kt ├── AbstractSlice.kt ├── AbstractTraceWriter.kt ├── AbstractTransactionNotifier.kt ├── AbstractWriteBatch.kt ├── BackupEngine.kt ├── BackupEngineOptions.kt ├── BackupInfo.kt ├── BottommostLevelCompaction.kt ├── BuiltinComparator.kt ├── Cache.kt ├── Checkpoint.kt ├── ChecksumType.kt ├── ColumnFamilyDescriptor.kt ├── ColumnFamilyHandle.kt ├── ColumnFamilyMetaData.kt ├── ColumnFamilyOptions.kt ├── CompactRangeOptions.kt ├── CompactionPriority.kt ├── CompactionReason.kt ├── CompactionStopStyle.kt ├── CompactionStyle.kt ├── ComparatorOptions.kt ├── CompressionType.kt ├── DBOptions.kt ├── DataBlockIndexType.kt ├── DirectSlice.kt ├── EncodingType.kt ├── Env.kt ├── FilterPolicy.kt ├── GetStatus.kt ├── HistogramData.kt ├── HistogramType.kt ├── Holder.kt ├── IndexType.kt ├── InfoLogLevel.kt ├── LRUCache.kt ├── LevelMetaData.kt ├── MemTableConfig.kt ├── MemoryUsageType.kt ├── MergeOperator.kt ├── OptimisticTransactionDB.kt ├── OptimisticTransactionOptions.kt ├── Options.kt ├── Priority.kt ├── Range.kt ├── ReadOptions.kt ├── ReadTier.kt ├── RemoveEmptyValueCompactionFilter.kt ├── RestoreOptions.kt ├── RocksCallbackObject.kt ├── RocksDB.kt ├── RocksDBException.kt ├── RocksEnv.kt ├── RocksIterator.kt ├── RocksIteratorInterface.kt ├── RocksMutableObject.kt ├── RocksObject.kt ├── SizeApproximationFlag.kt ├── Slice.kt ├── Snapshot.kt ├── SstFileMetaData.kt ├── Statistics.kt ├── StatsLevel.kt ├── Status.kt ├── StringAppendOperator.kt ├── TableFormatConfig.kt ├── TickerType.kt ├── TimedEnv.kt ├── TraceOptions.kt ├── TraceWriter.kt ├── Transaction.kt ├── TransactionDB.kt ├── TransactionDBOptions.kt ├── TransactionOptions.kt ├── TransactionState.kt ├── TxnDBWritePolicy.kt ├── WBWIRocksIterator.kt ├── WaitingTransactions.kt ├── WalFileType.kt ├── WriteBatch.kt ├── WriteBatchInterface.kt ├── WriteBatchSavePoint.kt ├── WriteBatchWithIndex.kt ├── WriteEntry.kt ├── WriteOptions.kt ├── WriteType.kt ├── loadRocksDBLibrary.kt ├── openOptimisticTransactionDB.kt ├── openRocksDB.kt └── openTransactionDB.kt ├── toByteArray.kt ├── wrapWithErrorThrower.kt └── wrapWithMultiErrorThrower.kt /.github/workflows/update_to_master.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Gradle 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle 3 | 4 | name: Run tests on commit and PR to master 5 | 6 | on: 7 | push: 8 | branches: [ master ] 9 | pull_request: 10 | branches: [ master ] 11 | 12 | jobs: 13 | test-jvm: 14 | runs-on: ubuntu-latest 15 | 16 | steps: 17 | - name: Checkout 18 | uses: actions/checkout@v3 19 | - name: Set up JDK 17 20 | uses: actions/setup-java@v3 21 | with: 22 | distribution: 'zulu' 23 | java-version: 17 24 | - name: Setup Gradle 25 | uses: gradle/gradle-build-action@v2 26 | - name: Run kotlin JVM tests 27 | run: ./gradlew jvmTest 28 | 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | build 3 | 4 | xcodeBuild 5 | local.properties 6 | /.kotlin/ 7 | /lib/ 8 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "rocksdb"] 2 | path = rocksdb 3 | url = git@github.com:marykdb/rocksdb.git 4 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | project(RocksDBWithDependencies) 3 | 4 | set(lz4_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/lib/lz4-1.9.4/lib") 5 | set(lz4_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/lib/lz4-1.9.4") 6 | set(lz4_LIBRARIES "${CMAKE_CURRENT_BINARY_DIR}/liblz4.so") 7 | 8 | set(Snappy_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/lib/snappy-1.2.1") 9 | set(Snappy_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/lib/snappy-1.2.1") 10 | set(Snappy_DIR "${Snappy_ROOT_DIR}") 11 | set(Snappy_LIBRARIES "${CMAKE_CURRENT_BINARY_DIR}/libsnappy.so") 12 | 13 | set(BZIP2_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/lib/bzip2-1.0.8") 14 | set(BZIP2_LIBRARIES "${CMAKE_CURRENT_BINARY_DIR}/libbz2.so") 15 | 16 | set(ZSTD_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/lib/zstd-1.5.6/lib") 17 | set(ZSTD_LIBRARIES "${CMAKE_CURRENT_BINARY_DIR}/libzstd.so") 18 | 19 | set(ZLIB_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/lib/zlib-1.3.1") 20 | set(ZLIB_LIBRARIES "${CMAKE_CURRENT_BINARY_DIR}/libzlib.so") 21 | 22 | include_directories(${lz4_INCLUDE_DIRS}) 23 | include_directories(${Snappy_ROOT_DIR}) 24 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib/snappy/include) 25 | include_directories(${ZLIB_INCLUDE_DIRS}) 26 | 27 | if(NOT TARGET Snappy::snappy) 28 | add_library(Snappy::snappy STATIC IMPORTED) 29 | set_target_properties(Snappy::snappy PROPERTIES 30 | IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/libsnappy.so" # Adjust if needed for your platform 31 | INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/lib/snappy-1.2.1" 32 | ) 33 | endif() 34 | 35 | # Include the RocksDB project 36 | add_subdirectory(rocksdb rocksdb-build) 37 | 38 | 39 | -------------------------------------------------------------------------------- /buildRocksdbLinux.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ARCH="" # e.g. arm64, x86_64, etc. 4 | 5 | for arg in "$@"; do 6 | case $arg in 7 | --arch=*) 8 | ARCH="${arg#*=}" 9 | ;; 10 | *) 11 | echo "Unknown option: $arg" 12 | exit 1 13 | ;; 14 | esac 15 | done 16 | 17 | # Validate 18 | if [ -z "$ARCH" ]; then 19 | echo "Usage: $0 --arch=" 20 | exit 1 21 | fi 22 | 23 | echo "Building RocksDB for $ARCH..." 24 | 25 | # Optional: navigate to the rocksdb directory 26 | cd "rocksdb" || { echo "Failed to navigate to rocksdb"; exit 1; } 27 | 28 | # Simple function to check build output 29 | check_build() { 30 | local output="$1" 31 | local folder="$2" 32 | 33 | if echo "$output" | grep -q "AR build/$folder/librocksdb.a"; then 34 | echo "** BUILD SUCCEEDED for $ARCH **" 35 | elif echo "$output" | grep -q "make: Nothing to be done for 'static_lib'."; then 36 | echo "** BUILD NOT NEEDED for $ARCH (Already up to date) **" 37 | else 38 | echo "** BUILD FAILED for $ARCH **" 39 | echo "$output" 40 | exit 1 41 | fi 42 | } 43 | 44 | EXTRA_FLAGS="-I../lib/include -DZLIB -DBZIP2 -DSNAPPY -DLZ4 -DZSTD " 45 | 46 | if [[ "$ARCH" == "arm64" ]]; then 47 | folder="linux_arm64" 48 | cc="$HOME/.konan/dependencies/aarch64-unknown-linux-gnu-gcc-8.3.0-glibc-2.25-kernel-4.9-2/bin/aarch64-unknown-linux-gnu-gcc" 49 | cxx="$HOME/.konan/dependencies/aarch64-unknown-linux-gnu-gcc-8.3.0-glibc-2.25-kernel-4.9-2/bin/aarch64-unknown-linux-gnu-g++" 50 | EXTRA_FLAGS+="-march=armv8-a" 51 | else 52 | folder="linux_x86_64" 53 | cc="$HOME/.konan/dependencies/x86_64-unknown-linux-gnu-gcc-8.3.0-glibc-2.19-kernel-4.9-2/bin/x86_64-unknown-linux-gnu-gcc" 54 | cxx="$HOME/.konan/dependencies/x86_64-unknown-linux-gnu-gcc-8.3.0-glibc-2.19-kernel-4.9-2/bin/x86_64-unknown-linux-gnu-g++" 55 | EXTRA_FLAGS+="-march=x86-64" 56 | fi 57 | 58 | # Check if the build output already exists 59 | if [ -f "build/$folder/librocksdb.a" ]; then 60 | echo "** BUILD SKIPPED: build/$folder/librocksdb.a already exists **" 61 | exit 0 62 | fi 63 | 64 | if [[ "$(uname -s)" == "Linux" ]]; then 65 | output=$( 66 | make -j"$(nproc)" \ 67 | LIB_MODE=static \ 68 | LIBNAME="build/$folder/librocksdb" \ 69 | DEBUG_LEVEL=0 \ 70 | CC=$cc \ 71 | CXX=$cxx \ 72 | OBJ_DIR="build/$folder" \ 73 | EXTRA_CXXFLAGS="$EXTRA_FLAGS" \ 74 | EXTRA_CFLAGS="$EXTRA_FLAGS" \ 75 | PORTABLE=1 \ 76 | LD_FLAGS="-lbz2 -lz -lz4 -lsnappy" \ 77 | static_lib 78 | ) 79 | 80 | check_build "$output" "$folder" 81 | else 82 | echo "Should only build on linux" 83 | exit 1 84 | fi 85 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.code.style=official 2 | 3 | org.gradle.jvmargs=-Xms128m -Xmx1024m 4 | kotlin.native.cacheKind=none 5 | kotlin.mpp.enableCInteropCommonization=true 6 | kotlin.mpp.stability.nowarn=true 7 | kotlin.mpp.androidSourceSetLayoutVersion=2 8 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marykdb/rocksdb-multiplatform/724d7bf6a64d902702225c613c8d3b30be3660ad/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-all.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /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/androidMain: -------------------------------------------------------------------------------- 1 | /Users/jurmous/space/rocksdb-multiplatform/src/jvmMain -------------------------------------------------------------------------------- /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/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/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/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/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/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/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/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/commonMain/kotlin/maryk/rocksdb/AbstractMutableOptions.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | expect open class AbstractMutableOptions 4 | -------------------------------------------------------------------------------- /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/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/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/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/BackupEngineOptions.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | /** 4 | * BackupableDBOptions to control the behavior of a backupable database. 5 | * It will be used during the creation of a [org.rocksdb.BackupEngine]. 6 | * 7 | * Note that dispose() must be called before an Options instance 8 | * become out-of-scope to release the allocated memory in c++. 9 | * 10 | * @see org.rocksdb.BackupEngine 11 | */ 12 | expect class BackupEngineOptions 13 | /** 14 | * BackupableDBOptions constructor. 15 | * 16 | * @param path Where to keep the backup files. Has to be different than db 17 | * name. Best to set this to `db name_ + "/backups"` 18 | * @throws IllegalArgumentException if illegal path is used. 19 | */ 20 | (path: String) 21 | : RocksObject { 22 | /** Returns the path to the BackupableDB directory. */ 23 | fun backupDir(): String 24 | } 25 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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/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/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/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/commonMain/kotlin/maryk/rocksdb/CompactionReason.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | expect enum class CompactionReason { 4 | kUnknown, 5 | 6 | /** [Level] number of L0 files > level0_file_num_compaction_trigger */ 7 | kLevelL0FilesNum, 8 | 9 | /** [Level] total size of level > MaxBytesForLevel() */ 10 | kLevelMaxLevelSize, 11 | 12 | /** [Universal] Compacting for size amplification */ 13 | kUniversalSizeAmplification, 14 | 15 | /** [Universal] Compacting for size ratio */ 16 | kUniversalSizeRatio, 17 | 18 | /** [Universal] number of sorted runs > level0_file_num_compaction_trigger */ 19 | kUniversalSortedRunNum, 20 | 21 | /** [FIFO] total size > max_table_files_size */ 22 | kFIFOMaxSize, 23 | 24 | /** [FIFO] reduce number of files. */ 25 | kFIFOReduceNumFiles, 26 | 27 | /** [FIFO] files with creation time < (current_time - interval) */ 28 | kFIFOTtl, 29 | 30 | /** Manual compaction */ 31 | kManualCompaction, 32 | 33 | /** DB::SuggestCompactRange() marked files for compaction */ 34 | kFilesMarkedForCompaction, 35 | 36 | /** 37 | * [Level] Automatic compaction within bottommost level to cleanup duplicate 38 | * versions of same user key, usually due to a released snapshot. 39 | */ 40 | kBottommostFiles, 41 | 42 | /** Compaction based on TTL */ 43 | kTtl, 44 | 45 | /** 46 | * According to the comments in flush_job.cc, RocksDB treats flush as 47 | * a level 0 compaction in internal stats. 48 | */ 49 | kFlush, 50 | 51 | /** Compaction caused by external sst file ingestion */ 52 | kExternalSstIngestion; 53 | } 54 | -------------------------------------------------------------------------------- /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/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/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/CompressionType.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | /** 4 | * Enum CompressionType 5 | * 6 | * DB contents are stored in a set of blocks, each of which holds a 7 | * sequence of key,value pairs. Each block may be compressed before 8 | * being stored in a file. The following enum describes which 9 | * compression method (if any) is used to compress a block. 10 | */ 11 | expect enum class CompressionType { 12 | NO_COMPRESSION, 13 | SNAPPY_COMPRESSION, 14 | ZLIB_COMPRESSION, 15 | BZLIB2_COMPRESSION, 16 | LZ4_COMPRESSION, 17 | LZ4HC_COMPRESSION, 18 | XPRESS_COMPRESSION, 19 | ZSTD_COMPRESSION, 20 | DISABLE_COMPRESSION_OPTION; 21 | 22 | /** 23 | * Returns the library name of the compression type 24 | * identified by the enumeration value. 25 | */ 26 | fun getLibraryName(): String? 27 | } 28 | 29 | /** 30 | * Get the CompressionType enumeration value by 31 | * passing the library name to this method. 32 | * 33 | * If library cannot be found the enumeration 34 | * value `NO_COMPRESSION` will be returned. 35 | * 36 | * @param libraryName compression library name. 37 | * 38 | * @return CompressionType instance. 39 | */ 40 | expect fun getCompressionType(libraryName: String?): CompressionType 41 | 42 | /** 43 | * Get the CompressionType enumeration value by 44 | * passing the byte identifier to this method. 45 | * 46 | * @param byteIdentifier of CompressionType. 47 | * 48 | * @return CompressionType instance. 49 | * 50 | * @throws IllegalArgumentException If CompressionType cannot be found for the 51 | * provided byteIdentifier 52 | */ 53 | expect fun getCompressionType(byteIdentifier: Byte): CompressionType 54 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /src/commonMain/kotlin/maryk/rocksdb/Env.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | /** 4 | * Base class for all Env implementations in RocksDB. 5 | */ 6 | expect abstract class Env : RocksObject { 7 | /** 8 | * Gets the number of background worker threads of the pool 9 | * for this environment. 10 | * 11 | * @return the number of threads. 12 | */ 13 | fun getBackgroundThreads(priority: Priority): Int 14 | 15 | /** 16 | * Sets the number of background worker threads of the specified thread 17 | * pool for this environment. 18 | * 19 | * @param number the number of threads 20 | * @param priority the priority id of a specified thread pool. 21 | * 22 | * Default number: 1 23 | * @return current [RocksEnv] instance. 24 | */ 25 | fun setBackgroundThreads(number: Int, priority: Priority): Env 26 | 27 | /** 28 | * Returns the length of the queue associated with the specified 29 | * thread pool. 30 | * 31 | * @param priority the priority id of a specified thread pool. 32 | * @return the thread pool queue length. 33 | */ 34 | fun getThreadPoolQueueLen(priority: Priority): Int 35 | 36 | /** 37 | * Enlarge number of background worker threads of a specific thread pool 38 | * for this environment if it is smaller than specified. 'LOW' is the default 39 | * pool. 40 | * 41 | * @param number the number of threads. 42 | * @return current [RocksEnv] instance. 43 | */ 44 | fun incBackgroundThreadsIfNeeded( 45 | number: Int, 46 | priority: Priority 47 | ): Env 48 | 49 | /** 50 | * Lower IO priority for threads from the specified pool. 51 | * 52 | * @param priority the priority id of a specified thread pool. 53 | */ 54 | fun lowerThreadPoolIOPriority(priority: Priority): Env 55 | 56 | /** 57 | * Lower CPU priority for threads from the specified pool. 58 | * 59 | * @param priority the priority id of a specified thread pool. 60 | */ 61 | fun lowerThreadPoolCPUPriority(priority: Priority): Env 62 | } 63 | 64 | /** 65 | * Returns the default environment suitable for the current operating 66 | * system. 67 | * 68 | * The result of `getDefault()` is a singleton whose ownership 69 | * belongs to rocksdb c++. As a result, the returned RocksEnv will not 70 | * have the ownership of its c++ resource, and calling its dispose()/close() 71 | * will be no-op. 72 | * 73 | * @return the default [maryk.rocksdb.RocksEnv] instance. 74 | */ 75 | expect fun getDefaultEnv(): Env 76 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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/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/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/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/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/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/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/commonMain/kotlin/maryk/rocksdb/ReadOptions.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | expect class ReadOptions() : RocksObject { 4 | /** 5 | * If true, all data read from underlying storage will be 6 | * verified against corresponding checksums. 7 | * Default: true 8 | * 9 | * @return true if checksum verification is on. 10 | */ 11 | fun verifyChecksums(): Boolean 12 | 13 | /** 14 | * If true, all data read from underlying storage will be 15 | * verified against corresponding checksums. 16 | * Default: true 17 | * 18 | * @param verifyChecksums if true, then checksum verification 19 | * will be performed on every read. 20 | * @return the reference to the current ReadOptions. 21 | */ 22 | fun setVerifyChecksums( 23 | verifyChecksums: Boolean 24 | ): ReadOptions 25 | 26 | /** 27 | * Fill the cache when loading the block-based sst formated db. 28 | * Callers may wish to set this field to false for bulk scans. 29 | * Default: true 30 | * 31 | * @return true if the fill-cache behavior is on. 32 | */ 33 | fun fillCache(): Boolean 34 | 35 | /** 36 | * Fill the cache when loading the block-based sst formatted db. 37 | * Callers may wish to set this field to false for bulk scans. 38 | * Default: true 39 | * 40 | * @param fillCache if true, then fill-cache behavior will be 41 | * performed. 42 | * @return the reference to the current ReadOptions. 43 | */ 44 | fun setFillCache(fillCache: Boolean): ReadOptions 45 | 46 | /** 47 | * Returns whether the iterator only iterates over the same prefix as the seek 48 | * 49 | * @return the setting of whether the iterator only iterates over the same 50 | * prefix as the seek, default is false 51 | */ 52 | fun prefixSameAsStart(): Boolean 53 | 54 | /** 55 | * Enforce that the iterator only iterates over the same prefix as the seek. 56 | * This option is effective only for prefix seeks, i.e. prefix_extractor is 57 | * non-null for the column family and [.totalOrderSeek] is false. 58 | * Unlike iterate_upper_bound, [.setPrefixSameAsStart] only 59 | * works within a prefix but in both directions. 60 | * 61 | * @param prefixSameAsStart if true, then the iterator only iterates over the 62 | * same prefix as the seek 63 | * @return the reference to the current ReadOptions. 64 | */ 65 | fun setPrefixSameAsStart(prefixSameAsStart: Boolean): ReadOptions 66 | } 67 | -------------------------------------------------------------------------------- /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/RemoveEmptyValueCompactionFilter.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | /** A wrapper around EmptyValueCompactionFilter implemented in C++ */ 4 | expect class RemoveEmptyValueCompactionFilter() : AbstractCompactionFilter 5 | -------------------------------------------------------------------------------- /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/RocksCallbackObject.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | expect abstract class RocksCallbackObject : AbstractImmutableNativeReference 4 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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/commonMain/kotlin/maryk/rocksdb/SstFileMetaData.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | expect 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/commonMain/kotlin/maryk/rocksdb/Statistics.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | expect class Statistics : RocksObject { 4 | constructor() 5 | 6 | /** 7 | * Gets the current stats level. 8 | * 9 | * @return The stats level. 10 | */ 11 | fun statsLevel(): StatsLevel? 12 | 13 | /** 14 | * Sets the stats level. 15 | * 16 | * @param statsLevel The stats level to set. 17 | */ 18 | fun setStatsLevel(statsLevel: StatsLevel) 19 | 20 | /** 21 | * Get the count for a ticker. 22 | * 23 | * @param tickerType The ticker to get the count for 24 | * 25 | * @return The count for the ticker 26 | */ 27 | fun getTickerCount(tickerType: TickerType): Long 28 | 29 | /** 30 | * Gets the histogram data for a particular histogram. 31 | * 32 | * @param histogramType The histogram to retrieve the data for 33 | * 34 | * @return The histogram data 35 | */ 36 | fun getHistogramData(histogramType: HistogramType): HistogramData 37 | 38 | /** 39 | * Resets all ticker and histogram stats. 40 | * 41 | * @throws RocksDBException if an error occurs when resetting the statistics. 42 | */ 43 | fun reset() 44 | } 45 | -------------------------------------------------------------------------------- /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/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/StringAppendOperator.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | /** 4 | * `StringAppendOperator` is a merge operator that concatenates 5 | * two strings. 6 | * 7 | * This operator is useful for scenarios where merging values involves 8 | * simple string concatenation, potentially with a delimiter. 9 | * 10 | * **Example Usage:** 11 | * 12 | * ```kotlin 13 | * val mergeOperator = StringAppendOperator(",") 14 | * dbOptions.setMergeOperator(mergeOperator) 15 | * ``` 16 | */ 17 | expect class StringAppendOperator : MergeOperator { 18 | 19 | /** 20 | * Constructs a `StringAppendOperator` with a default delimiter `,`. 21 | * 22 | * This constructor is useful when a simple comma-separated concatenation is desired. 23 | */ 24 | constructor() 25 | 26 | /** 27 | * Constructs a `StringAppendOperator` with the specified character delimiter. 28 | * 29 | * @param delim The character delimiter to use between concatenated strings. 30 | * 31 | * **Example:** 32 | * 33 | * ```kotlin 34 | * val mergeOperator = StringAppendOperator(';') 35 | * ``` 36 | */ 37 | constructor(delim: Char) 38 | 39 | /** 40 | * Constructs a `StringAppendOperator` with the specified string delimiter. 41 | * 42 | * @param delim The string delimiter to use between concatenated strings. 43 | * 44 | * **Example:** 45 | * 46 | * ```kotlin 47 | * val mergeOperator = StringAppendOperator("||") 48 | * ``` 49 | */ 50 | constructor(delim: String) 51 | } 52 | -------------------------------------------------------------------------------- /src/commonMain/kotlin/maryk/rocksdb/TableFormatConfig.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | /** 4 | * TableFormatConfig is used to config the internal Table format of a RocksDB. 5 | * To make a RocksDB to use a specific Table format, its associated 6 | * TableFormatConfig should be properly set and passed into Options via 7 | * Options.setTableFormatConfig() and open the db using that Options. 8 | */ 9 | expect abstract class TableFormatConfig 10 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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/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/WriteBatch.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | /** 4 | * WriteBatch holds a collection of updates to apply atomically to a DB. 5 | * 6 | * The updates are applied in the order in which they are added 7 | * to the WriteBatch. For example, the value of "key" will be "v3" 8 | * after the following batch is written: 9 | * 10 | * batch.put("key", "v1"); 11 | * batch.remove("key"); 12 | * batch.put("key", "v2"); 13 | * batch.put("key", "v3"); 14 | * 15 | * Multiple threads can invoke const methods on a WriteBatch without 16 | * external synchronization, but if any of the threads may call a 17 | * non-const method, all threads accessing the same WriteBatch must use 18 | * external synchronization. 19 | */ 20 | expect class WriteBatch() : AbstractWriteBatch { 21 | /** 22 | * Retrieve data size of the batch. 23 | * @return the serialized data size of the batch. 24 | */ 25 | fun getDataSize(): Long 26 | 27 | /** 28 | * Gets the WAL termination point. 29 | * See [.markWalTerminationPoint] 30 | * @return the WAL termination point 31 | */ 32 | fun getWalTerminationPoint(): WriteBatchSavePoint 33 | 34 | /** 35 | * Retrieve the serialized version of this batch. 36 | * 37 | * @return the serialized representation of this write batch. 38 | * 39 | * @throws RocksDBException if an error occurs whilst retrieving 40 | * the serialized batch data. 41 | */ 42 | fun data(): ByteArray 43 | 44 | /** Returns true if Put will be called during Iterate. */ 45 | fun hasPut(): Boolean 46 | 47 | /** Returns true if Delete will be called during Iterate. */ 48 | fun hasDelete(): Boolean 49 | 50 | /** Returns true if SingleDelete will be called during Iterate. */ 51 | fun hasSingleDelete(): Boolean 52 | 53 | /** Returns true if DeleteRange will be called during Iterate. */ 54 | fun hasDeleteRange(): Boolean 55 | 56 | /** Returns true if Merge will be called during Iterate. */ 57 | fun hasMerge(): Boolean 58 | 59 | /** Returns true if MarkBeginPrepare will be called during Iterate. */ 60 | fun hasBeginPrepare(): Boolean 61 | 62 | /** Returns true if MarkEndPrepare will be called during Iterate. */ 63 | fun hasEndPrepare(): Boolean 64 | 65 | /** Returns true if MarkCommit will be called during Iterate. */ 66 | fun hasCommit(): Boolean 67 | 68 | /** @return true if MarkRollback will be called during Iterate. */ 69 | fun hasRollback(): Boolean 70 | 71 | /** 72 | * Marks this point in the WriteBatch as the last record to 73 | * be inserted into the WAL, provided the WAL is enabled. 74 | */ 75 | fun markWalTerminationPoint() 76 | } 77 | 78 | -------------------------------------------------------------------------------- /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/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/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/commonMain/kotlin/maryk/rocksdb/loadLibrary.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | expect fun loadRocksDBLibrary() 4 | -------------------------------------------------------------------------------- /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/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/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/commonMain/kotlin/maryk/rocksdb/util/IntComparator.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb.util 2 | 3 | import maryk.ByteBuffer 4 | import maryk.rocksdb.AbstractComparator 5 | import maryk.rocksdb.ComparatorOptions 6 | 7 | /** 8 | * This is a Java implementation of a Comparator for Java int 9 | * keys. 10 | * 11 | * This comparator assumes keys are (at least) four bytes, so 12 | * the caller must guarantee that in accessing other APIs in 13 | * combination with this comparator. 14 | * 15 | * The performance of Comparators implemented in Java is always 16 | * less than their C++ counterparts due to the bridging overhead, 17 | * as such you likely don't want to use this apart from benchmarking 18 | * or testing. 19 | */ 20 | class IntComparator(copt: ComparatorOptions?) : AbstractComparator(copt) { 21 | override fun name(): String { 22 | return "rocksdb.java.IntComparator" 23 | } 24 | 25 | override fun compare(a: ByteBuffer, b: ByteBuffer): Int { 26 | return compareIntKeys(a, b) 27 | } 28 | 29 | /** 30 | * Compares integer keys 31 | * so that they are in ascending order 32 | * 33 | * @param a 4-bytes representing an integer key 34 | * @param b 4-bytes representing an integer key 35 | * 36 | * @return negative if a < b, 0 if a == b, positive otherwise 37 | */ 38 | private fun compareIntKeys(a: ByteBuffer, b: ByteBuffer): Int { 39 | val iA: Int = a.getInt() 40 | val iB: Int = b.getInt() 41 | 42 | // protect against int key calculation overflow 43 | val diff = iA.toLong() - iB 44 | val result: Int 45 | result = if (diff < Int.MIN_VALUE) { 46 | Int.MIN_VALUE 47 | } else if (diff > Int.MAX_VALUE) { 48 | Int.MAX_VALUE 49 | } else { 50 | diff.toInt() 51 | } 52 | return result 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/commonMain/kotlin/maryk/rocksdb/util/ReverseBytewiseComparator.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb.util 2 | 3 | import maryk.ByteBuffer 4 | import maryk.rocksdb.AbstractComparator 5 | import maryk.rocksdb.ComparatorOptions 6 | import kotlin.math.min 7 | import maryk.limit 8 | 9 | /** 10 | * This is a common implementation of the C++ 11 | * equivalent ReverseBytewiseComparatorImpl using [ByteBuffer] 12 | * 13 | * The performance of Comparators implemented in Java is always 14 | * less than their C++ counterparts due to the bridging overhead, 15 | * as such you likely don't want to use this apart from benchmarking 16 | * and you most likely instead wanted 17 | * [maryk.rocksdb.BuiltinComparator.REVERSE_BYTEWISE_COMPARATOR] 18 | */ 19 | class ReverseBytewiseComparator(copt: ComparatorOptions?) : AbstractComparator(copt) { 20 | override fun name() = "rocksdb.java.ReverseBytewiseComparator" 21 | 22 | override fun compare(a: ByteBuffer, b: ByteBuffer): Int { 23 | return -BytewiseComparator.compare(a, b) 24 | } 25 | 26 | override fun findShortestSeparator( 27 | start: ByteBuffer, 28 | limit: ByteBuffer 29 | ) { 30 | // Find length of common prefix 31 | val minLength: Int = min(start.remaining(), limit.remaining()) 32 | var diffIndex = 0 33 | while (diffIndex < minLength && 34 | start.get(diffIndex) == limit.get(diffIndex) 35 | ) { 36 | diffIndex++ 37 | } 38 | require(diffIndex <= minLength) 39 | if (diffIndex == minLength) { 40 | // Do not shorten if one string is a prefix of the other 41 | // 42 | // We could handle cases like: 43 | // V 44 | // A A 2 X Y 45 | // A A 2 46 | // in a similar way as BytewiseComparator::FindShortestSeparator(). 47 | // We keep it simple by not implementing it. We can come back to it 48 | // later when needed. 49 | } else { 50 | val startByte: Int = start.get(diffIndex).toInt() and 0xff 51 | val limitByte: Int = limit.get(diffIndex).toInt() and 0xff 52 | if (startByte > limitByte && diffIndex < start.remaining() - 1) { 53 | // Case like 54 | // V 55 | // A A 3 A A 56 | // A A 1 B B 57 | // 58 | // or 59 | // v 60 | // A A 2 A A 61 | // A A 1 B B 62 | // In this case "AA2" will be good. 63 | start.limit(diffIndex + 1) 64 | require(BytewiseComparator.compare(start, limit) > 0) 65 | } 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /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/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/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/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/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/commonTest/kotlin/maryk/doesFolderExist.kt: -------------------------------------------------------------------------------- 1 | package maryk 2 | 3 | expect fun doesFolderExist(path: String): Boolean 4 | -------------------------------------------------------------------------------- /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/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/commonTest/kotlin/maryk/rocksdb/DefaultEnvTest.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | import kotlin.test.Test 4 | import kotlin.test.assertEquals 5 | import kotlin.test.assertTrue 6 | 7 | class DefaultEnvTest { 8 | init { 9 | loadRocksDBLibrary() 10 | } 11 | 12 | @Test 13 | fun backgroundThreads() { 14 | getDefaultEnv().use { defaultEnv -> 15 | defaultEnv.setBackgroundThreads(5, Priority.BOTTOM) 16 | assertEquals(5, defaultEnv.getBackgroundThreads(Priority.BOTTOM)) 17 | 18 | defaultEnv.setBackgroundThreads(5, Priority.LOW) 19 | assertEquals(5, defaultEnv.getBackgroundThreads(Priority.LOW)) 20 | 21 | defaultEnv.setBackgroundThreads(5, Priority.HIGH) 22 | assertEquals(5, defaultEnv.getBackgroundThreads(Priority.HIGH)) 23 | } 24 | } 25 | 26 | @Test 27 | fun threadPoolQueueLen() { 28 | getDefaultEnv().use { defaultEnv -> 29 | assertEquals(0, defaultEnv.getThreadPoolQueueLen(Priority.BOTTOM)) 30 | assertEquals(0, defaultEnv.getThreadPoolQueueLen(Priority.LOW)) 31 | assertEquals(0, defaultEnv.getThreadPoolQueueLen(Priority.HIGH)) 32 | } 33 | } 34 | 35 | @Test 36 | fun incBackgroundThreadsIfNeeded() { 37 | getDefaultEnv().use { defaultEnv -> 38 | defaultEnv.incBackgroundThreadsIfNeeded(20, Priority.BOTTOM) 39 | assertTrue(20 <= defaultEnv.getBackgroundThreads(Priority.BOTTOM)) 40 | 41 | defaultEnv.incBackgroundThreadsIfNeeded(20, Priority.LOW) 42 | assertTrue(20 <= defaultEnv.getBackgroundThreads(Priority.LOW)) 43 | 44 | defaultEnv.incBackgroundThreadsIfNeeded(20, Priority.HIGH) 45 | assertTrue(20 <= defaultEnv.getBackgroundThreads(Priority.HIGH)) 46 | } 47 | } 48 | 49 | @Test 50 | fun lowerThreadPoolIOPriority() { 51 | getDefaultEnv().use { defaultEnv -> 52 | defaultEnv.lowerThreadPoolIOPriority(Priority.BOTTOM) 53 | 54 | defaultEnv.lowerThreadPoolIOPriority(Priority.LOW) 55 | 56 | defaultEnv.lowerThreadPoolIOPriority(Priority.HIGH) 57 | } 58 | } 59 | 60 | @Test 61 | fun lowerThreadPoolCPUPriority() { 62 | getDefaultEnv().use { defaultEnv -> 63 | defaultEnv.lowerThreadPoolCPUPriority(Priority.BOTTOM) 64 | 65 | defaultEnv.lowerThreadPoolCPUPriority(Priority.LOW) 66 | 67 | defaultEnv.lowerThreadPoolCPUPriority(Priority.HIGH) 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/ReadOptionsTest.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | import kotlin.random.Random 4 | import kotlin.test.Test 5 | import kotlin.test.assertEquals 6 | import kotlin.test.assertFailsWith 7 | import kotlin.test.assertTrue 8 | 9 | class ReadOptionsTest { 10 | init { 11 | loadRocksDBLibrary() 12 | } 13 | 14 | @Test 15 | fun verifyChecksum() { 16 | ReadOptions().use { opt -> 17 | val boolValue = Random.nextBoolean() 18 | opt.setVerifyChecksums(boolValue) 19 | assertEquals(boolValue, opt.verifyChecksums()) 20 | } 21 | } 22 | 23 | @Test 24 | fun fillCache() { 25 | ReadOptions().use { opt -> 26 | val boolValue = Random.nextBoolean() 27 | opt.setFillCache(boolValue) 28 | assertEquals(boolValue, opt.fillCache()) 29 | } 30 | } 31 | 32 | @Test 33 | fun prefixSameAsStart() { 34 | ReadOptions().use { opt -> 35 | opt.setPrefixSameAsStart(true) 36 | assertTrue(opt.prefixSameAsStart()) 37 | } 38 | } 39 | 40 | @Test 41 | fun failSetVerifyChecksumUninitialized() { 42 | setupUninitializedReadOptions().use { readOptions -> 43 | assertFailsWith { 44 | readOptions.setVerifyChecksums(true) 45 | } 46 | } 47 | } 48 | 49 | @Test 50 | fun failVerifyChecksumUninitialized() { 51 | setupUninitializedReadOptions().use { readOptions -> 52 | assertFailsWith { 53 | readOptions.verifyChecksums() 54 | } 55 | } 56 | } 57 | 58 | @Test 59 | fun failSetFillCacheUninitialized() { 60 | setupUninitializedReadOptions().use { readOptions -> 61 | assertFailsWith { 62 | readOptions.setFillCache(true) 63 | } 64 | } 65 | } 66 | 67 | @Test 68 | fun failFillCacheUninitialized() { 69 | setupUninitializedReadOptions().use { readOptions -> 70 | assertFailsWith { 71 | readOptions.fillCache() 72 | } 73 | } 74 | } 75 | 76 | private fun setupUninitializedReadOptions() = 77 | ReadOptions().apply { 78 | close() 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/commonTest/kotlin/maryk/rocksdb/SliceTest.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | import maryk.assertContentEquals 4 | import kotlin.test.Test 5 | import kotlin.test.assertEquals 6 | import kotlin.test.assertFalse 7 | import kotlin.test.assertNotEquals 8 | import kotlin.test.assertTrue 9 | 10 | class SliceTest { 11 | init { 12 | loadRocksDBLibrary() 13 | } 14 | 15 | @Test 16 | fun slice() { 17 | Slice("testSlice").use { slice -> 18 | assertFalse(slice.empty()) 19 | assertEquals(9, slice.size()) 20 | assertContentEquals("testSlice".encodeToByteArray(), slice.data()) 21 | } 22 | 23 | Slice("otherSlice".encodeToByteArray()).use { otherSlice -> 24 | assertContentEquals("otherSlice".encodeToByteArray(), otherSlice.data()) 25 | } 26 | 27 | Slice( 28 | "otherSlice".encodeToByteArray(), 29 | 5 30 | ).use { thirdSlice -> 31 | assertContentEquals("Slice".encodeToByteArray(), thirdSlice.data()) 32 | } 33 | } 34 | 35 | @Test 36 | fun sliceClear() { 37 | Slice("abc").use { slice -> 38 | assertEquals("abc", slice.toString()) 39 | slice.clear() 40 | assertTrue(slice.toString().isEmpty()) 41 | slice.clear() // make sure we don't double-free 42 | } 43 | } 44 | 45 | @Test 46 | fun sliceRemovePrefix() { 47 | Slice("abc").use { slice -> 48 | assertEquals("abc", slice.toString()) 49 | slice.removePrefix(1) 50 | assertEquals("bc", slice.toString()) 51 | } 52 | } 53 | 54 | @Test 55 | fun sliceEquals() { 56 | Slice("abc").use { slice -> 57 | Slice("abc").use { slice2 -> 58 | assertEquals(slice, slice2) 59 | assertEquals(slice.hashCode(), slice2.hashCode()) 60 | } 61 | } 62 | } 63 | 64 | @Test 65 | fun sliceStartWith() { 66 | Slice("matchpoint").use { slice -> 67 | Slice("mat").use { match -> 68 | Slice("nomatch").use { noMatch -> 69 | assertTrue(slice.startsWith(match)) 70 | assertFalse(slice.startsWith(noMatch)) 71 | } 72 | } 73 | } 74 | } 75 | 76 | @Test 77 | fun sliceToString() { 78 | Slice("stringTest").use { slice -> 79 | assertEquals("stringTest", slice.toString()) 80 | assertNotEquals("", slice.toString(true)) 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/commonTest/kotlin/maryk/rocksdb/TransactionDBOptionsTest.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | import kotlin.random.Random 4 | import kotlin.test.AfterTest 5 | import kotlin.test.BeforeTest 6 | import kotlin.test.Test 7 | import kotlin.test.assertEquals 8 | 9 | class TransactionDBOptionsTest { 10 | init { 11 | loadRocksDBLibrary() 12 | } 13 | 14 | @BeforeTest 15 | fun setup() { 16 | // Setup code if needed before each test 17 | } 18 | 19 | @AfterTest 20 | fun teardown() { 21 | // Teardown code if needed after each test 22 | } 23 | 24 | @Test 25 | fun maxNumLocks() { 26 | TransactionDBOptions().use { opt -> 27 | val longValue = Random.Default.nextLong() 28 | opt.setMaxNumLocks(longValue) 29 | assertEquals(longValue, opt.getMaxNumLocks(), "MaxNumLocks should be equal to the set value") 30 | } 31 | } 32 | 33 | @Test 34 | fun maxNumStripes() { 35 | TransactionDBOptions().use { opt -> 36 | val longValue = Random.Default.nextLong() 37 | opt.setNumStripes(longValue) 38 | assertEquals(longValue, opt.getNumStripes(), "NumStripes should be equal to the set value") 39 | } 40 | } 41 | 42 | @Test 43 | fun transactionLockTimeout() { 44 | TransactionDBOptions().use { opt -> 45 | val longValue = Random.Default.nextLong() 46 | opt.setTransactionLockTimeout(longValue) 47 | assertEquals(longValue, opt.getTransactionLockTimeout(), "TransactionLockTimeout should be equal to the set value") 48 | } 49 | } 50 | 51 | @Test 52 | fun defaultLockTimeout() { 53 | TransactionDBOptions().use { opt -> 54 | val longValue = Random.Default.nextLong() 55 | opt.setDefaultLockTimeout(longValue) 56 | assertEquals(longValue, opt.getDefaultLockTimeout(), "DefaultLockTimeout should be equal to the set value") 57 | } 58 | } 59 | 60 | @Test 61 | fun writePolicy() { 62 | TransactionDBOptions().use { opt -> 63 | val writePolicy = TxnDBWritePolicy.WRITE_UNPREPARED // non-default 64 | opt.setWritePolicy(writePolicy) 65 | assertEquals(writePolicy, opt.getWritePolicy(), "WritePolicy should be equal to the set value") 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/commonTest/kotlin/maryk/rocksdb/TransactionOptionsTest.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | import kotlin.random.Random 4 | import kotlin.test.AfterTest 5 | import kotlin.test.BeforeTest 6 | import kotlin.test.Test 7 | import kotlin.test.assertEquals 8 | 9 | class TransactionOptionsTest { 10 | companion object { 11 | init { 12 | loadRocksDBLibrary() 13 | } 14 | } 15 | 16 | @BeforeTest 17 | fun setup() { 18 | // Setup code if needed before each test 19 | } 20 | 21 | @AfterTest 22 | fun teardown() { 23 | // Teardown code if needed after each test 24 | } 25 | 26 | @Test 27 | fun snapshot() { 28 | TransactionOptions().use { opt -> 29 | val boolValue = Random.Default.nextBoolean() 30 | opt.setSetSnapshot(boolValue) 31 | assertEquals(boolValue, opt.isSetSnapshot(), "Snapshot should be equal to the set value") 32 | } 33 | } 34 | 35 | @Test 36 | fun deadlockDetect() { 37 | TransactionOptions().use { opt -> 38 | val boolValue = Random.Default.nextBoolean() 39 | opt.setDeadlockDetect(boolValue) 40 | assertEquals(boolValue, opt.isDeadlockDetect(), "DeadlockDetect should be equal to the set value") 41 | } 42 | } 43 | 44 | @Test 45 | fun lockTimeout() { 46 | TransactionOptions().use { opt -> 47 | val longValue = Random.Default.nextLong() 48 | opt.setLockTimeout(longValue) 49 | assertEquals(longValue, opt.getLockTimeout(), "LockTimeout should be equal to the set value") 50 | } 51 | } 52 | 53 | @Test 54 | fun expiration() { 55 | TransactionOptions().use { opt -> 56 | val longValue = Random.Default.nextLong() 57 | opt.setExpiration(longValue) 58 | assertEquals(longValue, opt.getExpiration(), "Expiration should be equal to the set value") 59 | } 60 | } 61 | 62 | @Test 63 | fun deadlockDetectDepth() { 64 | TransactionOptions().use { opt -> 65 | val longValue = Random.Default.nextLong() 66 | opt.setDeadlockDetectDepth(longValue) 67 | assertEquals(longValue, opt.getDeadlockDetectDepth(), "DeadlockDetectDepth should be equal to the set value") 68 | } 69 | } 70 | 71 | @Test 72 | fun maxWriteBatchSize() { 73 | TransactionOptions().use { opt -> 74 | val longValue = Random.Default.nextLong() 75 | opt.setMaxWriteBatchSize(longValue) 76 | assertEquals(longValue, opt.getMaxWriteBatchSize(), "MaxWriteBatchSize should be equal to the set value") 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /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/commonTest/kotlin/maryk/rocksdb/WriteOptionsTest.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | import kotlin.test.BeforeTest 4 | import kotlin.test.Test 5 | import kotlin.test.assertFalse 6 | import kotlin.test.assertTrue 7 | 8 | class WriteOptionsTest { 9 | @BeforeTest 10 | fun beforeTest() { 11 | loadRocksDBLibrary() 12 | } 13 | 14 | @Test 15 | fun writeOptions() { 16 | WriteOptions().use { writeOptions -> 17 | writeOptions.setSync(true) 18 | assertTrue(writeOptions.sync()) 19 | writeOptions.setSync(false) 20 | assertFalse(writeOptions.sync()) 21 | 22 | writeOptions.setDisableWAL(true) 23 | assertTrue(writeOptions.disableWAL()) 24 | writeOptions.setDisableWAL(false) 25 | assertFalse(writeOptions.disableWAL()) 26 | 27 | writeOptions.setIgnoreMissingColumnFamilies(true) 28 | assertTrue(writeOptions.ignoreMissingColumnFamilies()) 29 | writeOptions.setIgnoreMissingColumnFamilies(false) 30 | assertFalse(writeOptions.ignoreMissingColumnFamilies()) 31 | 32 | writeOptions.setNoSlowdown(true) 33 | assertTrue(writeOptions.noSlowdown()) 34 | writeOptions.setNoSlowdown(false) 35 | assertFalse(writeOptions.noSlowdown()) 36 | 37 | writeOptions.setLowPri(true) 38 | assertTrue(writeOptions.lowPri()) 39 | writeOptions.setLowPri(false) 40 | assertFalse(writeOptions.lowPri()) 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/commonTest/kotlin/maryk/rocksdb/util/createTestDBFolder.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb.util 2 | 3 | import kotlin.random.Random 4 | import kotlin.random.nextUInt 5 | 6 | @Suppress("EXPERIMENTAL_API_USAGE") 7 | fun createTestDBFolder(name: String?) = 8 | ("build/test-database/${name!!}_" + Random.nextUInt()) 9 | -------------------------------------------------------------------------------- /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/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /src/jvmMain/kotlin/maryk/Buffer.kt: -------------------------------------------------------------------------------- 1 | package maryk 2 | 3 | actual typealias Buffer = java.nio.Buffer 4 | -------------------------------------------------------------------------------- /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/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/jvmMain/kotlin/maryk/rocksdb/AbstractCompactionFilterFactory.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias AbstractCompactionFilterFactory = org.rocksdb.AbstractCompactionFilterFactory 4 | -------------------------------------------------------------------------------- /src/jvmMain/kotlin/maryk/rocksdb/AbstractComparator.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias AbstractComparator = org.rocksdb.AbstractComparator 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/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/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/jvmMain/kotlin/maryk/rocksdb/AbstractTraceWriter.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias AbstractTraceWriter = org.rocksdb.AbstractTraceWriter 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/AbstractWriteBatch.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias AbstractWriteBatch = org.rocksdb.AbstractWriteBatch 4 | -------------------------------------------------------------------------------- /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/jvmMain/kotlin/maryk/rocksdb/BackupEngineOptions.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias BackupEngineOptions = org.rocksdb.BackupEngineOptions 4 | -------------------------------------------------------------------------------- /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/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/BuiltinComparator.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias BuiltinComparator = org.rocksdb.BuiltinComparator 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/ChecksumType.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | /** Checksum types used in conjunction with BlockBasedTable. */ 4 | actual typealias ChecksumType = org.rocksdb.ChecksumType 5 | -------------------------------------------------------------------------------- /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/ColumnFamilyHandle.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias ColumnFamilyHandle = org.rocksdb.ColumnFamilyHandle 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/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/CompactionPriority.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias CompactionPriority = org.rocksdb.CompactionPriority 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/CompactionStopStyle.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias CompactionStopStyle = org.rocksdb.CompactionStopStyle 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/ComparatorOptions.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias ComparatorOptions = org.rocksdb.ComparatorOptions 4 | -------------------------------------------------------------------------------- /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/jvmMain/kotlin/maryk/rocksdb/DBOptions.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias DBOptions = org.rocksdb.DBOptions 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/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/EncodingType.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias EncodingType = org.rocksdb.EncodingType 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/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/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/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/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/jvmMain/kotlin/maryk/rocksdb/IndexType.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias IndexType = org.rocksdb.IndexType 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/LRUCache.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias LRUCache = org.rocksdb.LRUCache 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/MemTableConfig.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias MemTableConfig = org.rocksdb.MemTableConfig 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/MergeOperator.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias MergeOperator = org.rocksdb.MergeOperator 4 | -------------------------------------------------------------------------------- /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/jvmMain/kotlin/maryk/rocksdb/OptimisticTransactionOptions.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | import org.rocksdb.OptimisticTransactionOptions 4 | 5 | actual typealias OptimisticTransactionOptions = OptimisticTransactionOptions 6 | -------------------------------------------------------------------------------- /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/Range.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias Range = org.rocksdb.Range 4 | -------------------------------------------------------------------------------- /src/jvmMain/kotlin/maryk/rocksdb/ReadOptions.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias ReadOptions = org.rocksdb.ReadOptions 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/RemoveEmptyValueCompactionFilter.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias RemoveEmptyValueCompactionFilter = org.rocksdb.RemoveEmptyValueCompactionFilter 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/RocksCallbackObject.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias RocksCallbackObject = org.rocksdb.RocksCallbackObject 4 | -------------------------------------------------------------------------------- /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/jvmMain/kotlin/maryk/rocksdb/RocksDBException.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias RocksDBException = org.rocksdb.RocksDBException 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/RocksIteratorInterface.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias RocksIteratorInterface = org.rocksdb.RocksIteratorInterface 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/RocksObject.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias RocksObject = org.rocksdb.RocksObject 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/Slice.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias Slice = org.rocksdb.Slice 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/SstFileMetaData.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias SstFileMetaData = org.rocksdb.SstFileMetaData 4 | -------------------------------------------------------------------------------- /src/jvmMain/kotlin/maryk/rocksdb/Statistics.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias Statistics = org.rocksdb.Statistics 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/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/jvmMain/kotlin/maryk/rocksdb/StringAppendOperator.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias StringAppendOperator = org.rocksdb.StringAppendOperator 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/TickerType.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | import org.rocksdb.TickerType 4 | 5 | actual typealias TickerType = TickerType 6 | -------------------------------------------------------------------------------- /src/jvmMain/kotlin/maryk/rocksdb/TimedEnv.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias TimedEnv = org.rocksdb.TimedEnv 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/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/TransactionDB.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias TransactionDB = org.rocksdb.TransactionDB 4 | -------------------------------------------------------------------------------- /src/jvmMain/kotlin/maryk/rocksdb/TransactionDBOptions.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias TransactionDBOptions = org.rocksdb.TransactionDBOptions 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/TransactionState.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | import org.rocksdb.Transaction 4 | 5 | actual typealias TransactionState = Transaction.TransactionState 6 | -------------------------------------------------------------------------------- /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/WBWIRocksIterator.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias WBWIRocksIterator = org.rocksdb.WBWIRocksIterator 4 | -------------------------------------------------------------------------------- /src/jvmMain/kotlin/maryk/rocksdb/WaitingTransactions.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias WaitingTransactions = org.rocksdb.Transaction.WaitingTransactions 4 | -------------------------------------------------------------------------------- /src/jvmMain/kotlin/maryk/rocksdb/WalFileType.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias WalFileType = org.rocksdb.WalFileType 4 | -------------------------------------------------------------------------------- /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/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/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/WriteOptions.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual typealias WriteOptions = org.rocksdb.WriteOptions 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/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/loadLibrary.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual fun loadRocksDBLibrary() { 4 | RocksDB.loadLibrary() 5 | } 6 | -------------------------------------------------------------------------------- /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/jvmMain/kotlin/maryk/rocksdb/openRocksDB.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual fun openRocksDB(path: String) = RocksDB.open(path) 4 | 5 | actual fun openRocksDB(options: Options, path: String) = RocksDB.open(options, path) 6 | 7 | actual fun openRocksDB( 8 | path: String, 9 | columnFamilyDescriptors: List, 10 | columnFamilyHandles: MutableList 11 | ) = RocksDB.open(path, columnFamilyDescriptors, columnFamilyHandles) 12 | 13 | actual fun openRocksDB( 14 | options: DBOptions, 15 | path: String, 16 | columnFamilyDescriptors: List, 17 | columnFamilyHandles: MutableList 18 | ) = RocksDB.open(options, path, columnFamilyDescriptors, columnFamilyHandles) 19 | 20 | actual fun openReadOnlyRocksDB(path: String) = 21 | RocksDB.openReadOnly(path) 22 | 23 | actual fun openReadOnlyRocksDB( 24 | path: String, 25 | columnFamilyDescriptors: List, 26 | columnFamilyHandles: MutableList 27 | ) = RocksDB.openReadOnly(path, columnFamilyDescriptors, columnFamilyHandles) 28 | 29 | actual fun openReadOnlyRocksDB(options: Options, path: String) = 30 | RocksDB.openReadOnly(options, path) 31 | 32 | actual fun openReadOnlyRocksDB( 33 | options: DBOptions, 34 | path: String, 35 | columnFamilyDescriptors: List, 36 | columnFamilyHandles: MutableList 37 | ) = RocksDB.openReadOnly(options, path, columnFamilyDescriptors, columnFamilyHandles) 38 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /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/nativeInterop/cinterop/rocksdb.def: -------------------------------------------------------------------------------- 1 | headers = c.h 2 | package = rocksdb 3 | staticLibraries = libbz2.a liblz4.a libz.a libzstd.a libsnappy.a librocksdb.a 4 | libraryPaths = rocksdb/include/rocksdb lib/include 5 | libraryPaths.ios_arm64 = rocksdb/build/ios_arm64 6 | libraryPaths.ios_simulator_arm64 = rocksdb/build/ios_simulator_arm64 7 | libraryPaths.macos_arm64 = rocksdb/build/macos_arm64 8 | libraryPaths.macos_x64 = rocksdb/build/macos_x86_64 9 | libraryPaths.linux_arm64 = rocksdb/build/linux_arm64 10 | libraryPaths.linux_x64 = rocksdb/build/linux_x86_64 11 | libraryPaths.mingw_x64 = rocksdb/build/mingw_x86_64 rocksdb/build/mingw_x86_64/rocksdb-build 12 | 13 | noStringConversion = rocksdb_key_may_exist rocksdb_key_may_exist_cf rocksdb_get rocksdb_get_cf rocksdb_put rocksdb_put_cf rocksdb_delete rocksdb_delete_cf rocksdb_merge rocksdb_merge_cf rocksdb_create_column_family rocksdb_delete_range_cf rocksdb_iter_seek rocksdb_iter_seek_for_prev rocksdb_compact_range_cf_opt rocksdb_compact_range_cf rocksdb_compact_range_opt rocksdb_compact_range rocksdb_transaction_get rocksdb_transaction_get_cf rocksdb_transaction_get_for_update rocksdb_transaction_get_for_update_cf rocksdb_transaction_put rocksdb_transaction_put_cf rocksdb_transaction_put_untracked rocksdb_transaction_put_untracked_cf rocksdb_transaction_delete rocksdb_transaction_delete_cf rocksdb_transaction_merge rocksdb_transaction_merge_cf rocksdb_transaction_merge_untracked rocksdb_transaction_merge_untracked_cf rocksdb_transaction_delete_untracked rocksdb_transaction_delete_untracked_cf rocksdb_transaction_undo_get_for_update rocksdb_transaction_undo_get_for_update_cf rocksdb_writebatch_put rocksdb_writebatch_put_cf rocksdb_writebatch_merge rocksdb_writebatch_merge_cf rocksdb_writebatch_delete rocksdb_writebatch_delete_cf rocksdb_writebatch_singledelete rocksdb_writebatch_singledelete_cf rocksdb_writebatch_delete_range rocksdb_writebatch_delete_range_cf rocksdb_writebatch_put_log_data rocksdb_writebatch_wi_get_from_batch rocksdb_writebatch_wi_get_from_batch_cf rocksdb_writebatch_wi_merge rocksdb_writebatch_wi_merge_cf rocksdb_writebatch_wi_put rocksdb_writebatch_wi_put_cf rocksdb_writebatch_wi_delete rocksdb_writebatch_wi_delete_cf rocksdb_writebatch_wi_singledelete rocksdb_writebatch_wi_singledelete_cf rocksdb_writebatch_wi_delete_range rocksdb_writebatch_wi_delete_range_cf rocksdb_writebatch_wi_put_log_data rocksdb_transaction_put_log_data 14 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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/nativeMain/kotlin/maryk/rocksdb/AbstractImmutableNativeReference.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | import kotlin.concurrent.AtomicReference 4 | import kotlin.experimental.ExperimentalNativeApi 5 | import kotlin.native.identityHashCode 6 | 7 | actual abstract class AbstractImmutableNativeReference(): AbstractNativeReference() { 8 | private val isClosed = AtomicReference(false) 9 | 10 | actual open fun isOwningHandle(): Boolean { 11 | return !isClosed.value 12 | } 13 | 14 | internal fun disownHandle() { 15 | isClosed.getAndSet(true) 16 | } 17 | 18 | actual override fun close() { 19 | isClosed.compareAndSet(false, true) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/nativeMain/kotlin/maryk/rocksdb/AbstractMutableOptions.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual open class AbstractMutableOptions 4 | -------------------------------------------------------------------------------- /src/nativeMain/kotlin/maryk/rocksdb/AbstractNativeReference.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual abstract class AbstractNativeReference : AutoCloseable 4 | -------------------------------------------------------------------------------- /src/nativeMain/kotlin/maryk/rocksdb/AbstractSlice.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual abstract class AbstractSlice protected constructor() : RocksMutableObject() { 4 | abstract var data: T 5 | 6 | actual fun data(): T { 7 | return this.getData() 8 | } 9 | 10 | protected abstract fun getData(): T 11 | 12 | actual abstract fun removePrefix(n: Int) 13 | 14 | actual abstract fun clear() 15 | 16 | abstract operator fun get(offset: Int): Byte 17 | 18 | actual open fun size(): Int { 19 | throw NotImplementedError() 20 | } 21 | 22 | actual open fun empty(): Boolean { 23 | throw NotImplementedError() 24 | } 25 | 26 | actual open fun toString(hex: Boolean): String { 27 | throw NotImplementedError() 28 | } 29 | 30 | actual override fun toString(): String { 31 | return toString(false) 32 | } 33 | 34 | actual open fun compare(other: AbstractSlice<*>): Int { 35 | val minLength = minOf(this.size(), other.size()) 36 | 37 | for (i in 0 until minLength) { 38 | val a = this[i].toInt() and 0xFF 39 | val b = other[i].toInt() and 0xFF 40 | if (a != b) { 41 | return a - b 42 | } 43 | } 44 | 45 | return this.size() - other.size() 46 | } 47 | 48 | actual override fun hashCode(): Int { 49 | return toString().hashCode() 50 | } 51 | 52 | actual override fun equals(other: Any?) = when (other) { 53 | null, !is AbstractSlice<*> -> false 54 | else -> { 55 | this.compare(other) == 0 56 | } 57 | } 58 | 59 | actual fun startsWith(prefix: AbstractSlice<*>): Boolean { 60 | if (prefix.size() == 0) return true 61 | 62 | if (prefix.size() > this.size()) return false 63 | 64 | for (i in 0 until prefix.size()) { 65 | if (this[i] != prefix[i]) { 66 | return false 67 | } 68 | } 69 | return true 70 | } 71 | 72 | override fun disposeInternal() { 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/nativeMain/kotlin/maryk/rocksdb/AbstractTraceWriter.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual abstract class AbstractTraceWriter actual constructor() : RocksCallbackObject(), TraceWriter 4 | -------------------------------------------------------------------------------- /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/AbstractWriteBatch.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual abstract class AbstractWriteBatch : RocksObject(), WriteBatchInterface { 4 | 5 | actual override fun singleDelete(key: ByteArray) { 6 | throw NotImplementedError() 7 | } 8 | 9 | actual override fun singleDelete(columnFamilyHandle: ColumnFamilyHandle, key: ByteArray) { 10 | throw NotImplementedError() 11 | } 12 | 13 | actual override fun count(): Int = 14 | throw NotImplementedError() 15 | 16 | actual override fun put(key: ByteArray, value: ByteArray) { 17 | throw NotImplementedError() 18 | } 19 | 20 | actual override fun put(columnFamilyHandle: ColumnFamilyHandle, key: ByteArray, value: ByteArray) { 21 | throw NotImplementedError() 22 | } 23 | 24 | actual override fun merge(key: ByteArray, value: ByteArray) { 25 | throw NotImplementedError() 26 | } 27 | 28 | actual override fun merge(columnFamilyHandle: ColumnFamilyHandle, key: ByteArray, value: ByteArray) { 29 | throw NotImplementedError() 30 | } 31 | 32 | actual override fun delete(key: ByteArray) { 33 | throw NotImplementedError() 34 | } 35 | 36 | actual override fun delete(columnFamilyHandle: ColumnFamilyHandle, key: ByteArray) { 37 | throw NotImplementedError() 38 | } 39 | 40 | actual override fun deleteRange(beginKey: ByteArray, endKey: ByteArray) { 41 | throw NotImplementedError() 42 | } 43 | 44 | actual override fun deleteRange(columnFamilyHandle: ColumnFamilyHandle, beginKey: ByteArray, endKey: ByteArray) { 45 | throw NotImplementedError() 46 | } 47 | 48 | actual override fun putLogData(blob: ByteArray) { 49 | throw NotImplementedError() 50 | } 51 | 52 | actual override fun clear() { 53 | throw NotImplementedError() 54 | } 55 | 56 | actual override fun setSavePoint() { 57 | throw NotImplementedError() 58 | } 59 | 60 | actual override fun rollbackToSavePoint() { 61 | throw NotImplementedError() 62 | } 63 | 64 | actual override fun popSavePoint() { 65 | throw NotImplementedError() 66 | } 67 | 68 | actual override fun setMaxBytes(maxBytes: Long) { 69 | throw NotImplementedError() 70 | } 71 | 72 | actual override fun getWriteBatch(): WriteBatch { 73 | throw NotImplementedError() 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/nativeMain/kotlin/maryk/rocksdb/BackupEngineOptions.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | import platform.posix.access 4 | import platform.posix.W_OK 5 | import rocksdb.rocksdb_backup_engine_options_create 6 | import rocksdb.rocksdb_backup_engine_options_destroy 7 | 8 | actual class BackupEngineOptions 9 | actual constructor(private val path: String) 10 | : RocksObject() { 11 | 12 | init { 13 | val pathToCheck = if (!path.endsWith('/')) "$path/" else path 14 | // Use POSIX access function to check write permission 15 | require(access(pathToCheck, W_OK) == 0) { "Path $path is not writable" } 16 | } 17 | 18 | val native = rocksdb_backup_engine_options_create(path) 19 | 20 | actual fun backupDir(): String { 21 | return path 22 | } 23 | 24 | override fun close() { 25 | if (isOwningHandle()) { 26 | rocksdb_backup_engine_options_destroy(native) 27 | super.close() 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /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/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/BuiltinComparator.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual enum class BuiltinComparator { 4 | BYTEWISE_COMPARATOR, 5 | REVERSE_BYTEWISE_COMPARATOR 6 | } 7 | -------------------------------------------------------------------------------- /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 kotlin.experimental.ExperimentalNativeApi 8 | 9 | actual abstract class Cache() : RocksObject() { 10 | protected lateinit var native: CPointer 11 | 12 | actual fun getUsage(): Long { 13 | assert(isOwningHandle()); 14 | return rocksdb.rocksdb_cache_get_usage(native).toLong() 15 | } 16 | 17 | actual fun getPinnedUsage(): Long { 18 | assert(isOwningHandle()); 19 | return rocksdb.rocksdb_cache_get_pinned_usage(native).toLong() 20 | } 21 | 22 | override fun close() { 23 | if (isOwningHandle()) { 24 | rocksdb.rocksdb_free(native) 25 | } 26 | super.close() 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /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/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/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/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.alloc 6 | import kotlinx.cinterop.memScoped 7 | import kotlinx.cinterop.ptr 8 | import kotlinx.cinterop.value 9 | import maryk.toByteArray 10 | import platform.posix.uint64_tVar 11 | import rocksdb.rocksdb_column_family_handle_destroy 12 | import rocksdb.rocksdb_column_family_handle_get_id 13 | import rocksdb.rocksdb_column_family_handle_get_name 14 | 15 | actual class ColumnFamilyHandle 16 | internal constructor( 17 | val native: CPointer 18 | ) 19 | : RocksObject() { 20 | override fun close() { 21 | if (isOwningHandle()) { 22 | rocksdb_column_family_handle_destroy(native) 23 | super.close() 24 | } 25 | } 26 | 27 | actual fun getName(): ByteArray = memScoped { 28 | val length = alloc() 29 | rocksdb_column_family_handle_get_name(native, length.ptr)?.let { name -> 30 | name.toByteArray(length.value).also { 31 | rocksdb.rocksdb_free(name) 32 | } 33 | } ?: throw RocksDBException("Missing Column Family Name") 34 | } 35 | 36 | actual fun getID(): Int = 37 | rocksdb_column_family_handle_get_id(native).toInt() 38 | } 39 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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/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/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/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(0x7f, null); 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/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/nativeMain/kotlin/maryk/rocksdb/DirectSlice.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | import kotlinx.cinterop.Arena 4 | import kotlinx.cinterop.ByteVar 5 | import kotlinx.cinterop.alloc 6 | import kotlinx.cinterop.nativeHeap 7 | import kotlinx.cinterop.plus 8 | import kotlinx.cinterop.ptr 9 | import kotlinx.cinterop.toCValues 10 | import maryk.ByteBuffer 11 | import maryk.DirectByteBuffer 12 | import maryk.toByteArray 13 | 14 | actual class DirectSlice() : AbstractSlice() { 15 | private val scope = Arena() 16 | override lateinit var data: ByteBuffer 17 | 18 | override fun disposeInternal() { 19 | scope.clear() 20 | super.disposeInternal() 21 | } 22 | actual constructor(str: String) : this() { 23 | data = DirectByteBuffer(str.encodeToByteArray().toCValues().getPointer(scope), str.length) 24 | } 25 | 26 | actual constructor(data: ByteBuffer) : this() { 27 | this.data = data 28 | } 29 | 30 | actual constructor(data: ByteBuffer, length: Int) : this( 31 | DirectByteBuffer(data.nativePointer, length) 32 | ) 33 | 34 | override fun getData(): ByteBuffer = data 35 | 36 | actual override operator fun get(offset: Int): Byte { 37 | return data[offset] 38 | } 39 | 40 | actual override fun clear() { 41 | data = DirectByteBuffer(emptyByte.ptr, 0) 42 | } 43 | 44 | actual override fun removePrefix(n: Int) { 45 | require(n < data.capacity) 46 | data = DirectByteBuffer(data.nativePointer.plus(n)!!, data.capacity - n) 47 | } 48 | 49 | override fun size(): Int = data.capacity 50 | 51 | override fun empty(): Boolean = data.capacity == 0 52 | 53 | @OptIn(ExperimentalStdlibApi::class) 54 | override fun toString(hex: Boolean): String { 55 | return data.nativePointer.toByteArray(data.capacity.toULong()).let { bytes -> 56 | if (hex) bytes.toHexString() else bytes.decodeToString().replace("\u0000", "") 57 | } 58 | } 59 | } 60 | private val emptyByte = nativeHeap.alloc() 61 | actual val DirectSliceNone = DirectSlice(DirectByteBuffer(emptyByte.ptr, 0)) 62 | -------------------------------------------------------------------------------- /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/nativeMain/kotlin/maryk/rocksdb/Env.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | import cnames.structs.rocksdb_env_t 4 | import kotlinx.cinterop.CPointer 5 | import rocksdb.rocksdb_create_default_env 6 | 7 | actual abstract class Env 8 | protected constructor(internal val native: CPointer?) 9 | : RocksObject() { 10 | actual fun getBackgroundThreads(priority: Priority): Int = 11 | rocksdb.rocksdb_env_get_background_threads_with_priority(native, priority.value.toInt()) 12 | 13 | actual fun setBackgroundThreads(number: Int, priority: Priority): Env { 14 | rocksdb.rocksdb_env_set_background_threads_with_priority(native, number, priority.value.toInt()) 15 | return this 16 | } 17 | 18 | actual fun getThreadPoolQueueLen(priority: Priority): Int = 19 | rocksdb.rocksdb_env_get_thread_pool_queue_length(native) 20 | 21 | actual fun incBackgroundThreadsIfNeeded(number: Int, priority: Priority): Env { 22 | rocksdb.rocksdb_env_inc_background_threads_if_needed(native, number, priority.value.toInt()) 23 | return this 24 | } 25 | 26 | actual fun lowerThreadPoolIOPriority(priority: Priority): Env { 27 | rocksdb.rocksdb_env_lower_with_priority_thread_pool_io_priority(native, priority.value.toInt()) 28 | return this 29 | } 30 | 31 | actual fun lowerThreadPoolCPUPriority(priority: Priority): Env { 32 | rocksdb.rocksdb_env_lower_with_priority_thread_pool_cpu_priority(native, priority.value.toInt()) 33 | return this 34 | } 35 | 36 | override fun close() { 37 | if (isOwningHandle()) { 38 | rocksdb.rocksdb_env_destroy(native) 39 | } 40 | super.close() 41 | } 42 | } 43 | 44 | actual fun getDefaultEnv(): Env = RocksEnv(rocksdb_create_default_env()) 45 | -------------------------------------------------------------------------------- /src/nativeMain/kotlin/maryk/rocksdb/FilterPolicy.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual abstract class FilterPolicy : RocksObject() 4 | -------------------------------------------------------------------------------- /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/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/HistogramType.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("unused") 2 | 3 | package maryk.rocksdb 4 | 5 | actual enum class HistogramType( 6 | internal val value: UInt 7 | ) { 8 | DB_GET(0x0u), 9 | DB_WRITE(0x1u), 10 | COMPACTION_TIME(0x2u), 11 | COMPACTION_CPU_TIME(0x3u), 12 | SUBCOMPACTION_SETUP_TIME(0x4u), 13 | TABLE_SYNC_MICROS(0x5u), 14 | COMPACTION_OUTFILE_SYNC_MICROS(0x6u), 15 | WAL_FILE_SYNC_MICROS(0x7u), 16 | MANIFEST_FILE_SYNC_MICROS(0x8u), 17 | TABLE_OPEN_IO_MICROS(0x9u), 18 | DB_MULTIGET(0xAu), 19 | READ_BLOCK_COMPACTION_MICROS(0xBu), 20 | READ_BLOCK_GET_MICROS(0xCu), 21 | WRITE_RAW_BLOCK_MICROS(0xDu), 22 | NUM_FILES_IN_SINGLE_COMPACTION(0xEu), 23 | DB_SEEK(0xFu), 24 | WRITE_STALL(0x10u), 25 | SST_READ_MICROS(0x11u), 26 | FILE_READ_FLUSH_MICROS(0x12u), 27 | FILE_READ_COMPACTION_MICROS(0x13u), 28 | FILE_READ_DB_OPEN_MICROS(0x14u), 29 | FILE_READ_GET_MICROS(0x15u), 30 | FILE_READ_MULTIGET_MICROS(0x16u), 31 | FILE_READ_DB_ITERATOR_MICROS(0x17u), 32 | FILE_READ_VERIFY_DB_CHECKSUM_MICROS(0x18u), 33 | FILE_READ_VERIFY_FILE_CHECKSUMS_MICROS(0x19u), 34 | SST_WRITE_MICROS(0x1Au), 35 | FILE_WRITE_FLUSH_MICROS(0x1Bu), 36 | FILE_WRITE_COMPACTION_MICROS(0x1Cu), 37 | FILE_WRITE_DB_OPEN_MICROS(0x1Du), 38 | NUM_SUBCOMPACTIONS_SCHEDULED(0x1Eu), 39 | BYTES_PER_READ(0x1Fu), 40 | BYTES_PER_WRITE(0x20u), 41 | BYTES_PER_MULTIGET(0x21u), 42 | COMPRESSION_TIMES_NANOS(0x22u), 43 | DECOMPRESSION_TIMES_NANOS(0x23u), 44 | READ_NUM_MERGE_OPERANDS(0x24u), 45 | BLOB_DB_KEY_SIZE(0x25u), 46 | BLOB_DB_VALUE_SIZE(0x26u), 47 | BLOB_DB_WRITE_MICROS(0x27u), 48 | BLOB_DB_GET_MICROS(0x28u), 49 | BLOB_DB_MULTIGET_MICROS(0x29u), 50 | BLOB_DB_SEEK_MICROS(0x2Au), 51 | BLOB_DB_NEXT_MICROS(0x2Bu), 52 | BLOB_DB_PREV_MICROS(0x2Cu), 53 | BLOB_DB_BLOB_FILE_WRITE_MICROS(0x2Du), 54 | BLOB_DB_BLOB_FILE_READ_MICROS(0x2Eu), 55 | BLOB_DB_BLOB_FILE_SYNC_MICROS(0x2Fu), 56 | BLOB_DB_COMPRESSION_MICROS(0x30u), 57 | BLOB_DB_DECOMPRESSION_MICROS(0x31u), 58 | FLUSH_TIME(0x32u), 59 | SST_BATCH_SIZE(0x33u), 60 | MULTIGET_IO_BATCH_SIZE(0x34u), 61 | NUM_INDEX_AND_FILTER_BLOCKS_READ_PER_LEVEL(0x35u), 62 | NUM_SST_READ_PER_LEVEL(0x36u), 63 | NUM_LEVEL_READ_PER_MULTIGET(0x37u), 64 | ERROR_HANDLER_AUTORESUME_RETRY_COUNT(0x38u), 65 | ASYNC_READ_BYTES(0x39u), 66 | POLL_WAIT_MICROS(0x3Au), 67 | PREFETCHED_BYTES_DISCARDED(0x3Bu), 68 | ASYNC_PREFETCH_ABORT_MICROS(0x3Cu), 69 | TABLE_OPEN_PREFETCH_TAIL_READ_BYTES(0x3Du), 70 | HISTOGRAM_ENUM_MAX(0x3Eu); 71 | } 72 | -------------------------------------------------------------------------------- /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/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/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/nativeMain/kotlin/maryk/rocksdb/LRUCache.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | import cnames.structs.rocksdb_lru_cache_options_t 4 | import kotlinx.cinterop.CPointer 5 | 6 | actual class LRUCache private constructor() : Cache() { 7 | lateinit var options: CPointer 8 | 9 | actual constructor(capacity: Long) : this(capacity, -1, false, 0.0, 0.0) 10 | 11 | actual constructor(capacity: Long, numShardBits: Int) : this(capacity, numShardBits, false, 0.0, 0.0) 12 | 13 | constructor(capacity: Long, numShardBits: Int, strictCapacityLimit: Boolean) : this(capacity, numShardBits, strictCapacityLimit, 0.0, 0.0) 14 | 15 | constructor( 16 | capacity: Long, 17 | numShardBits: Int, 18 | strictCapacityLimit: Boolean, 19 | highPriPoolRatio: Double 20 | ) : this(capacity, numShardBits, strictCapacityLimit, highPriPoolRatio, 0.0) 21 | 22 | constructor( 23 | capacity: Long, 24 | numShardBits: Int, 25 | strictCapacityLimit: Boolean, 26 | highPriPoolRatio: Double, 27 | lowPriPoolRatio: Double 28 | ) : this() { 29 | options = rocksdb.rocksdb_lru_cache_options_create()!!.apply { 30 | rocksdb.rocksdb_lru_cache_options_set_capacity(this, capacity.toULong()) 31 | rocksdb.rocksdb_lru_cache_options_set_num_shard_bits(this, numShardBits) 32 | } 33 | 34 | native = rocksdb.rocksdb_cache_create_lru_opts(options)!! 35 | } 36 | 37 | override fun close() { 38 | if (isOwningHandle()) { 39 | rocksdb.rocksdb_free(options) 40 | } 41 | super.close() 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /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/MemTableConfig.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual abstract class MemTableConfig actual constructor() 4 | -------------------------------------------------------------------------------- /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/nativeMain/kotlin/maryk/rocksdb/OptimisticTransactionDB.kt: -------------------------------------------------------------------------------- 1 | @file:OptIn(ExperimentalNativeApi::class) 2 | 3 | package maryk.rocksdb 4 | 5 | import cnames.structs.rocksdb_optimistictransactiondb_t 6 | import kotlinx.cinterop.* 7 | import kotlin.experimental.ExperimentalNativeApi 8 | 9 | actual open class OptimisticTransactionDB 10 | internal constructor( 11 | internal val tnative: CPointer, 12 | ) : RocksDB(rocksdb.rocksdb_optimistictransactiondb_get_base_db(tnative)!!) { 13 | val defaultTransactionOptions: OptimisticTransactionOptions = OptimisticTransactionOptions() 14 | 15 | override fun close() { 16 | if (isOwningHandle()) { 17 | defaultTransactionOptions.close() 18 | super.close() 19 | } 20 | } 21 | 22 | actual fun beginTransaction(writeOptions: WriteOptions): Transaction { 23 | return rocksdb.rocksdb_optimistictransaction_begin(tnative, writeOptions.native, defaultTransactionOptions.native, null)!!.let(::Transaction) 24 | } 25 | 26 | actual fun beginTransaction(writeOptions: WriteOptions, transactionOptions: OptimisticTransactionOptions): Transaction { 27 | return rocksdb.rocksdb_optimistictransaction_begin(tnative, writeOptions.native, transactionOptions.native, null)!!.let(::Transaction) 28 | } 29 | 30 | actual fun beginTransaction(writeOptions: WriteOptions, oldTransaction: Transaction): Transaction { 31 | rocksdb.rocksdb_optimistictransaction_begin(tnative, writeOptions.native, defaultTransactionOptions.native, oldTransaction.native) 32 | return oldTransaction 33 | } 34 | 35 | actual fun beginTransaction(writeOptions: WriteOptions, transactionOptions: OptimisticTransactionOptions, oldTransaction: Transaction): Transaction { 36 | rocksdb.rocksdb_optimistictransaction_begin(tnative, writeOptions.native, transactionOptions.native, oldTransaction.native) 37 | return oldTransaction 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /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/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/nativeMain/kotlin/maryk/rocksdb/Range.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual class Range actual constructor(start: Slice, limit: Slice) 4 | -------------------------------------------------------------------------------- /src/nativeMain/kotlin/maryk/rocksdb/ReadOptions.kt: -------------------------------------------------------------------------------- 1 | @file:OptIn(ExperimentalNativeApi::class) 2 | 3 | package maryk.rocksdb 4 | 5 | import cnames.structs.rocksdb_readoptions_t 6 | import kotlinx.cinterop.CPointer 7 | import maryk.toBoolean 8 | import maryk.toUByte 9 | import rocksdb.rocksdb_readoptions_create 10 | import rocksdb.rocksdb_readoptions_destroy 11 | import rocksdb.rocksdb_readoptions_get_fill_cache 12 | import rocksdb.rocksdb_readoptions_get_prefix_same_as_start 13 | import rocksdb.rocksdb_readoptions_get_verify_checksums 14 | import rocksdb.rocksdb_readoptions_set_fill_cache 15 | import rocksdb.rocksdb_readoptions_set_prefix_same_as_start 16 | import rocksdb.rocksdb_readoptions_set_verify_checksums 17 | import kotlin.experimental.ExperimentalNativeApi 18 | 19 | actual class ReadOptions private constructor(val native: CPointer?) : RocksObject() { 20 | actual constructor() : this(rocksdb_readoptions_create()) 21 | 22 | override fun close() { 23 | if (isOwningHandle()) { 24 | rocksdb_readoptions_destroy(native) 25 | super.close() 26 | } 27 | } 28 | 29 | actual fun verifyChecksums(): Boolean { 30 | assert(isOwningHandle()) 31 | return rocksdb_readoptions_get_verify_checksums(native).toBoolean() 32 | } 33 | 34 | actual fun setVerifyChecksums(verifyChecksums: Boolean): ReadOptions { 35 | assert(isOwningHandle()) 36 | rocksdb_readoptions_set_verify_checksums(native, verifyChecksums.toUByte()) 37 | return this 38 | } 39 | 40 | actual fun fillCache(): Boolean { 41 | assert(isOwningHandle()) 42 | return rocksdb_readoptions_get_fill_cache(native).toBoolean() 43 | } 44 | 45 | actual fun setFillCache(fillCache: Boolean): ReadOptions { 46 | assert(isOwningHandle()) 47 | rocksdb_readoptions_set_fill_cache(native, fillCache.toUByte()) 48 | return this 49 | } 50 | 51 | actual fun prefixSameAsStart(): Boolean { 52 | assert(isOwningHandle()) 53 | return rocksdb_readoptions_get_prefix_same_as_start(native).toBoolean() 54 | } 55 | 56 | actual fun setPrefixSameAsStart(prefixSameAsStart: Boolean): ReadOptions { 57 | assert(isOwningHandle()) 58 | rocksdb_readoptions_set_prefix_same_as_start(native, prefixSameAsStart.toUByte()) 59 | return this; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /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/nativeMain/kotlin/maryk/rocksdb/RemoveEmptyValueCompactionFilter.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual class RemoveEmptyValueCompactionFilter actual constructor() : AbstractCompactionFilter() 4 | -------------------------------------------------------------------------------- /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/RocksCallbackObject.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual abstract class RocksCallbackObject : AbstractImmutableNativeReference() 4 | -------------------------------------------------------------------------------- /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/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/nativeMain/kotlin/maryk/rocksdb/RocksIterator.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | import cnames.structs.rocksdb_iterator_t 4 | import kotlinx.cinterop.* 5 | import maryk.toByteArray 6 | import platform.posix.size_tVar 7 | import rocksdb.rocksdb_iter_key 8 | import rocksdb.rocksdb_iter_value 9 | 10 | actual class RocksIterator internal constructor( 11 | native: CPointer 12 | ) : AbstractRocksIterator(native) { 13 | actual fun key(): ByteArray = memScoped { 14 | val length = alloc() 15 | rocksdb_iter_key(native, length.ptr)!!.toByteArray(length.value) 16 | } 17 | 18 | actual fun value(): ByteArray = memScoped { 19 | val length = alloc() 20 | rocksdb_iter_value(native, length.ptr)!!.toByteArray(length.value) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /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/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/nativeMain/kotlin/maryk/rocksdb/RocksObject.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual abstract class RocksObject: AbstractImmutableNativeReference() 4 | -------------------------------------------------------------------------------- /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/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/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 | if (isOwningHandle()) { 13 | rocksdb.rocksdb_free(native) 14 | } 15 | super.close() 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/nativeMain/kotlin/maryk/rocksdb/SstFileMetaData.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual class SstFileMetaData( 4 | val fileName: String, 5 | val path: String, 6 | val size: ULong, 7 | val smallestKey: ByteArray, 8 | val largestKey: ByteArray, 9 | ) { 10 | actual fun fileName() = fileName 11 | 12 | actual fun path() = path 13 | 14 | actual fun size() = size.toLong() 15 | 16 | actual fun smallestKey(): ByteArray = smallestKey 17 | 18 | actual fun largestKey(): ByteArray = largestKey 19 | } 20 | -------------------------------------------------------------------------------- /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/nativeMain/kotlin/maryk/rocksdb/Status.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | import maryk.rocksdb.StatusSubCode.None 4 | import maryk.rocksdb.StatusSubCode.Undefined 5 | 6 | actual class Status actual constructor( 7 | private val code: StatusCode, 8 | private val subCode: StatusSubCode?, 9 | private val state: String? 10 | ) { 11 | 12 | actual fun getCode() = code 13 | 14 | actual fun getSubCode() = subCode 15 | 16 | actual fun getState() = state 17 | 18 | actual fun getCodeString() = 19 | code.name + if (subCode != null && subCode != None) { 20 | "(${subCode.name})" 21 | } else "" 22 | } 23 | 24 | actual enum class StatusCode( 25 | internal val value: Byte 26 | ) { 27 | Ok(0x0), 28 | NotFound(0x1), 29 | Corruption(0x2), 30 | NotSupported(0x3), 31 | InvalidArgument(0x4), 32 | IOError(0x5), 33 | MergeInProgress(0x6), 34 | Incomplete(0x7), 35 | ShutdownInProgress(0x8), 36 | TimedOut(0x9), 37 | Aborted(0xA), 38 | Busy(0xB), 39 | Expired(0xC), 40 | TryAgain(0xD), 41 | Undefined(0x7F) 42 | } 43 | 44 | fun getStatusCode(identifier: Byte): StatusCode { 45 | for (statusCode in StatusCode.entries) { 46 | if (statusCode.value == identifier) { 47 | return statusCode 48 | } 49 | } 50 | 51 | throw IllegalArgumentException("Illegal value provided for StatusCode.") 52 | } 53 | 54 | actual enum class StatusSubCode( 55 | internal val value: Byte 56 | ) { 57 | None(0x0), 58 | MutexTimeout(0x1), 59 | LockTimeout(0x2), 60 | LockLimit(0x3), 61 | NoSpace(0x4), 62 | Deadlock(0x5), 63 | StaleFile(0x6), 64 | MemoryLimit(0x7), 65 | SpaceLimit(0x8), 66 | PathNotFound(0x9), 67 | MaxSubCode(0x10), 68 | Undefined(0x7F) 69 | } 70 | 71 | fun getStatusSubCode(identifier: Byte): StatusSubCode { 72 | for (statusSubCode in StatusSubCode.entries) { 73 | if (statusSubCode.value == identifier) { 74 | return statusSubCode 75 | } 76 | } 77 | return Undefined 78 | } 79 | -------------------------------------------------------------------------------- /src/nativeMain/kotlin/maryk/rocksdb/TableFormatConfig.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual abstract class TableFormatConfig 4 | -------------------------------------------------------------------------------- /src/nativeMain/kotlin/maryk/rocksdb/TimedEnv.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual class TimedEnv actual constructor(baseEnv: Env) 4 | : Env(baseEnv.native) 5 | -------------------------------------------------------------------------------- /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/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/nativeMain/kotlin/maryk/rocksdb/TransactionDBOptions.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual class TransactionDBOptions actual constructor(): RocksObject() { 4 | val native = rocksdb.rocksdb_transactiondb_options_create() 5 | 6 | actual fun getMaxNumLocks(): Long { 7 | return rocksdb.rocksdb_transactiondb_options_get_max_num_locks(native) 8 | } 9 | 10 | actual fun setMaxNumLocks(maxNumLocks: Long): TransactionDBOptions { 11 | rocksdb.rocksdb_transactiondb_options_set_max_num_locks(native, maxNumLocks) 12 | return this 13 | } 14 | 15 | actual fun getNumStripes(): Long = rocksdb.rocksdb_transactiondb_options_get_num_stripes(native).toLong() 16 | 17 | actual fun setNumStripes(numStripes: Long): TransactionDBOptions { 18 | rocksdb.rocksdb_transactiondb_options_set_num_stripes(native, numStripes.toULong()) 19 | return this 20 | } 21 | 22 | actual fun getTransactionLockTimeout(): Long = rocksdb.rocksdb_transactiondb_options_get_transaction_lock_timeout(native) 23 | 24 | actual fun setTransactionLockTimeout(transactionLockTimeout: Long): TransactionDBOptions { 25 | rocksdb.rocksdb_transactiondb_options_set_transaction_lock_timeout(native, transactionLockTimeout) 26 | return this 27 | } 28 | 29 | actual fun getDefaultLockTimeout(): Long = rocksdb.rocksdb_transactiondb_options_get_default_lock_timeout(native).toLong() 30 | 31 | actual fun setDefaultLockTimeout(defaultLockTimeout: Long): TransactionDBOptions { 32 | rocksdb.rocksdb_transactiondb_options_set_default_lock_timeout(native, defaultLockTimeout) 33 | return this 34 | } 35 | 36 | actual fun getWritePolicy(): TxnDBWritePolicy { 37 | return getTxnDBWritePolicy(rocksdb.rocksdb_transactiondb_options_get_write_policy(native).toByte()) 38 | } 39 | 40 | actual fun setWritePolicy(writePolicy: TxnDBWritePolicy): TransactionDBOptions { 41 | rocksdb.rocksdb_transactiondb_options_set_write_policy(native, writePolicy.getValue().toInt()) 42 | return this 43 | } 44 | 45 | override fun close() { 46 | if (isOwningHandle()) { 47 | rocksdb.rocksdb_transactiondb_options_destroy(native) 48 | super.close() 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/nativeMain/kotlin/maryk/rocksdb/TransactionOptions.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | import maryk.toBoolean 4 | import maryk.toUByte 5 | 6 | actual class TransactionOptions actual constructor(): RocksObject() { 7 | val native = rocksdb.rocksdb_transaction_options_create() 8 | 9 | 10 | actual fun isSetSnapshot(): Boolean { 11 | return rocksdb.rocksdb_transaction_options_get_set_snapshot(native).toBoolean() 12 | } 13 | 14 | actual fun setSetSnapshot(setSnapshot: Boolean): TransactionOptions { 15 | rocksdb.rocksdb_transaction_options_set_set_snapshot(native, setSnapshot.toUByte()) 16 | return this 17 | } 18 | 19 | actual fun isDeadlockDetect(): Boolean { 20 | return rocksdb.rocksdb_transaction_options_get_deadlock_detect(native).toBoolean() 21 | } 22 | 23 | actual fun setDeadlockDetect(deadlockDetect: Boolean): TransactionOptions { 24 | rocksdb.rocksdb_transaction_options_set_deadlock_detect(native, deadlockDetect.toUByte()) 25 | return this 26 | } 27 | 28 | actual fun getLockTimeout(): Long { 29 | return rocksdb.rocksdb_transaction_options_get_lock_timeout(native).toLong() 30 | } 31 | 32 | actual fun setLockTimeout(lockTimeout: Long): TransactionOptions { 33 | rocksdb.rocksdb_transaction_options_set_lock_timeout(native, lockTimeout) 34 | return this 35 | } 36 | 37 | actual fun getExpiration(): Long { 38 | return rocksdb.rocksdb_transaction_options_get_expiration(native).toLong() 39 | } 40 | 41 | actual fun setExpiration(expiration: Long): TransactionOptions { 42 | rocksdb.rocksdb_transaction_options_set_expiration(native, expiration) 43 | return this 44 | } 45 | 46 | actual fun getDeadlockDetectDepth(): Long { 47 | return rocksdb.rocksdb_transaction_options_get_deadlock_detect_depth(native).toLong() 48 | } 49 | 50 | actual fun setDeadlockDetectDepth(deadlockDetectDepth: Long): TransactionOptions { 51 | rocksdb.rocksdb_transaction_options_set_deadlock_detect_depth(native, deadlockDetectDepth) 52 | return this 53 | } 54 | 55 | actual fun getMaxWriteBatchSize(): Long { 56 | return rocksdb.rocksdb_transaction_options_get_max_write_batch_size(native).toLong() 57 | } 58 | 59 | actual fun setMaxWriteBatchSize(maxWriteBatchSize: Long): TransactionOptions { 60 | rocksdb.rocksdb_transaction_options_set_max_write_batch_size(native, maxWriteBatchSize.toULong()) 61 | return this 62 | } 63 | 64 | override fun close() { 65 | if (isOwningHandle()) { 66 | rocksdb.rocksdb_transaction_options_destroy(native) 67 | super.close() 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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/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/WriteOptions.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | import cnames.structs.rocksdb_writeoptions_t 4 | import kotlinx.cinterop.CPointer 5 | import maryk.toBoolean 6 | import maryk.toUByte 7 | import rocksdb.rocksdb_writeoptions_create 8 | import rocksdb.rocksdb_writeoptions_destroy 9 | import rocksdb.rocksdb_writeoptions_disable_WAL 10 | import rocksdb.rocksdb_writeoptions_get_disable_WAL 11 | import rocksdb.rocksdb_writeoptions_get_ignore_missing_column_families 12 | import rocksdb.rocksdb_writeoptions_get_low_pri 13 | import rocksdb.rocksdb_writeoptions_get_no_slowdown 14 | import rocksdb.rocksdb_writeoptions_get_sync 15 | import rocksdb.rocksdb_writeoptions_set_ignore_missing_column_families 16 | import rocksdb.rocksdb_writeoptions_set_low_pri 17 | import rocksdb.rocksdb_writeoptions_set_no_slowdown 18 | import rocksdb.rocksdb_writeoptions_set_sync 19 | 20 | actual class WriteOptions internal constructor( 21 | internal val native: CPointer 22 | ) : RocksObject() { 23 | actual constructor() : this(rocksdb_writeoptions_create()!!) 24 | 25 | override fun close() { 26 | if (isOwningHandle()) { 27 | rocksdb_writeoptions_destroy(native) 28 | super.close() 29 | } 30 | } 31 | 32 | actual fun setSync(flag: Boolean): WriteOptions { 33 | rocksdb_writeoptions_set_sync(native, flag.toUByte()) 34 | return this 35 | } 36 | 37 | actual fun sync() = 38 | rocksdb_writeoptions_get_sync(native).toBoolean() 39 | 40 | actual fun setDisableWAL(flag: Boolean): WriteOptions { 41 | rocksdb_writeoptions_disable_WAL(native, if (flag) 1 else 0) 42 | return this 43 | } 44 | 45 | actual fun disableWAL() = rocksdb_writeoptions_get_disable_WAL(native).toBoolean() 46 | 47 | actual fun setIgnoreMissingColumnFamilies(ignoreMissingColumnFamilies: Boolean): WriteOptions { 48 | rocksdb_writeoptions_set_ignore_missing_column_families(native, ignoreMissingColumnFamilies.toUByte()) 49 | return this 50 | } 51 | 52 | actual fun ignoreMissingColumnFamilies() = 53 | rocksdb_writeoptions_get_ignore_missing_column_families(native).toBoolean() 54 | 55 | actual fun setNoSlowdown(noSlowdown: Boolean): WriteOptions { 56 | rocksdb_writeoptions_set_no_slowdown(native, noSlowdown.toUByte()) 57 | return this 58 | } 59 | 60 | actual fun noSlowdown() = 61 | rocksdb_writeoptions_get_no_slowdown(native).toBoolean() 62 | 63 | actual fun setLowPri(lowPri: Boolean): WriteOptions { 64 | rocksdb_writeoptions_set_low_pri(native, lowPri.toUByte()) 65 | return this 66 | } 67 | 68 | actual fun lowPri() = 69 | rocksdb_writeoptions_get_low_pri(native).toBoolean() 70 | } 71 | -------------------------------------------------------------------------------- /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/nativeMain/kotlin/maryk/rocksdb/loadRocksDBLibrary.kt: -------------------------------------------------------------------------------- 1 | package maryk.rocksdb 2 | 3 | actual fun loadRocksDBLibrary() { 4 | } 5 | -------------------------------------------------------------------------------- /src/nativeMain/kotlin/maryk/toByteArray.kt: -------------------------------------------------------------------------------- 1 | package maryk 2 | 3 | import kotlinx.cinterop.ByteVar 4 | import kotlinx.cinterop.CPointer 5 | import kotlinx.cinterop.get 6 | import kotlinx.cinterop.readBytes 7 | import platform.posix.size_t 8 | 9 | fun CPointer.toByteArray(value: size_t) = 10 | this.readBytes(value.toInt()) 11 | -------------------------------------------------------------------------------- /src/nativeMain/kotlin/maryk/wrapWithErrorThrower.kt: -------------------------------------------------------------------------------- 1 | package maryk 2 | 3 | import kotlinx.cinterop.ByteVar 4 | import kotlinx.cinterop.CPointerVar 5 | import kotlinx.cinterop.CValuesRef 6 | import kotlinx.cinterop.alloc 7 | import kotlinx.cinterop.memScoped 8 | import kotlinx.cinterop.ptr 9 | import kotlinx.cinterop.toKString 10 | import kotlinx.cinterop.value 11 | import maryk.rocksdb.RocksDBException 12 | import maryk.rocksdb.Status 13 | import maryk.rocksdb.StatusCode 14 | import maryk.rocksdb.StatusSubCode 15 | 16 | private fun checkAndThrowError(errorRef: CPointerVar) { 17 | val error = errorRef.value?.toKString() 18 | 19 | if (error != null) { 20 | throw RocksDBException(error, convertToStatus(error)) 21 | } 22 | } 23 | 24 | fun T.wrapWithErrorThrower(runnable: T.(CValuesRef>) -> R): R { 25 | memScoped { 26 | val errorRef = alloc>() 27 | try { 28 | val result = runnable(errorRef.ptr) 29 | checkAndThrowError(errorRef) 30 | return result 31 | } catch (e: Throwable) { 32 | checkAndThrowError(errorRef) 33 | throw RocksDBException(e.toString(), Status(StatusCode.Undefined, StatusSubCode.None, e.toString())) 34 | } 35 | } 36 | } 37 | 38 | fun T.wrapWithNullErrorThrower(runnable: T.(CValuesRef>) -> R?): R? { 39 | memScoped { 40 | val errorRef = alloc>() 41 | try { 42 | val result = runnable(errorRef.ptr) 43 | checkAndThrowError(errorRef) 44 | return result 45 | } catch (e: Throwable) { 46 | checkAndThrowError(errorRef) 47 | throw RocksDBException(e.toString(), Status(StatusCode.Undefined, StatusSubCode.None, e.toString())) 48 | } 49 | } 50 | } 51 | 52 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------