Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ val rocksDBJVMVersion = "10.4.2"
val rocksDBAndroidVersion = "10.4.2"

val kotlinXDateTimeVersion = "0.7.1"
val kotlinXCoroutinesVersion = "1.10.2"
val rocksdbPrebuiltBaseUrlValue = providers.gradleProperty("rocksdbPrebuiltBaseUrl").orElse("https://github.com/marykdb/build-rocksdb/releases/download").get()
val rocksdbPrebuiltVersionValue = providers.gradleProperty("rocksdbPrebuiltVersion").get()
val rocksdbSupportedNativeTargets = setOf(
Expand Down Expand Up @@ -466,7 +467,11 @@ kotlin {
optIn("kotlinx.cinterop.BetaInteropApi")
}
}
commonMain {}
nativeMain {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinXCoroutinesVersion")
}
}
commonTest {
dependencies {
implementation(kotlin("test"))
Expand Down
34 changes: 17 additions & 17 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ kotlin.mpp.stability.nowarn=true
kotlin.mpp.androidSourceSetLayoutVersion=2

rocksdbPrebuiltBaseUrl=https://github.com/marykdb/build-rocksdb/releases/download
rocksdbPrebuiltVersion=rocksdb-10.4.2-20251003T152203Z
rocksdbPrebuiltSha.androidNativeArm32=2fffb2241b268162220fac8d421f2180825ba8d8ff1de0642fc6dc7c94d0fd03
rocksdbPrebuiltSha.androidNativeArm64=94af5ca2ec2f2b96c7bd131eb856b954c219f42a906e6964ec84bbe69bb5adda
rocksdbPrebuiltSha.androidNativeX64=e741bcaee362e8b80602418e4002aae2c47a7fcc34ca232855223d96ed15dfde
rocksdbPrebuiltSha.androidNativeX86=5d460f5ef17d22347fbb1c3687487ebe248f6faa2ac4803257030c75f94934e2
rocksdbPrebuiltSha.iosArm64=48d9afa60ede390b4a542c48b2bebec84ca0824395af718992664313208a224a
rocksdbPrebuiltSha.iosSimulatorArm64=4ae02136f5a6ca82eac861cdfd1ea6798278769981438cccfac89fa671cecc01
rocksdbPrebuiltSha.linuxArm64=5e1c044744c3562d46dc6f46d3b62a76269a38a15079109173dfedae3fc4d90a
rocksdbPrebuiltSha.linuxX64=cc26a9808f5c16eaa9f1e1cd5f848c4b1db6690f65b287643ea860661276cd32
rocksdbPrebuiltSha.macosArm64=1b55fdb0b7a2de0950d50c1a4b6dc9b8ba1b7d51d766c35b481a5db05247ec99
rocksdbPrebuiltSha.macosX64=cf38d8de6f8e93cbeda7b90d070fc840a91a4abf1455b25d9be567be9ea37dba
rocksdbPrebuiltSha.mingwX64=a273f4700b3a51c33c07e6513ac3fb4a3a1a8a62087e251a8436a91e79316051
rocksdbPrebuiltSha.tvosArm64=5238480990e42bfd3c7d64dba816a1aa9843d2dc53cbb70ad4c35a63a8a1324f
rocksdbPrebuiltSha.tvosSimulatorArm64=ac66c0da022ae779776a2198d8c43d4367cc1cc98a9eec565095638461236475
rocksdbPrebuiltSha.watchosArm64=c72dd92b7134a1c0889e4e42008c6f2a789f9dfe2ec8a7c93b6fc8a7458568e3
rocksdbPrebuiltSha.watchosDeviceArm64=671548911290e2e155d55b291693d82e1d7083e579e30d0a7700badd7a84ecfb
rocksdbPrebuiltSha.watchosSimulatorArm64=bf3e16bbfbcc7d26790058efb8b9b503245ad3f37a9e5f9db755587637ce402b
rocksdbPrebuiltVersion=rocksdb-10.4.2-20251006T132725Z
rocksdbPrebuiltSha.androidNativeArm32=086741b47085232a8463c54aba807c66a8e6c50ebf66b75a7f5539f634cb3f0a
rocksdbPrebuiltSha.androidNativeArm64=3abe3546d0ac14f1fcc85acdc165e8b7f38a695b7b6b41e8216feee014e55d3b
rocksdbPrebuiltSha.androidNativeX64=43a0bb7e99d8f5c3a4f9a08660b1fcb8de302240ef04f4a2fe9a3f7064d57d4e
rocksdbPrebuiltSha.androidNativeX86=51051ec151d80b0340e3f8877e3b8407b5d330cf8633ca34204552fbd7d5ec6a
rocksdbPrebuiltSha.iosArm64=236dfb211fafa2dd815c95f4829afd06e96a4560b9b53dd037a6ba6f946ce6c8
rocksdbPrebuiltSha.iosSimulatorArm64=07eb51903f6d6ff65651dbdd86f46e3c8c9d73636acde28a439d03ced3304478
rocksdbPrebuiltSha.linuxArm64=b15d05d0c698f451e4f95a6fe2dd621b969fc6b5d2cbd703a64918300af896eb
rocksdbPrebuiltSha.linuxX64=eb78ad46d9b8cdfe654ee2a9ab94bbfad34a7fb658c3fc24383e411d7ea047c5
rocksdbPrebuiltSha.macosArm64=79cf3a19649f731c5b0bc7fc86d2a3c9d869a5e4c89a19ac346928c308516542
rocksdbPrebuiltSha.macosX64=8aac542c00e7d391318948cec489b9ee5c02616d54c29934b47f16e2c144cd4e
rocksdbPrebuiltSha.mingwX64=5da2b842f30d8e97bb8c4320399f4199c86c087af0af6e2969a95c31dffa0272
rocksdbPrebuiltSha.tvosArm64=1c21646cf19c1eb821fdde1e9fc3f04383d2dc1072ec4a7a72205cf09d8e611b
rocksdbPrebuiltSha.tvosSimulatorArm64=01d72237647a908284c5cc60ab33e64dd98c991fca0398d9087d0e9eb20bf1c7
rocksdbPrebuiltSha.watchosArm64=f9f6c5913761bc1ae79a00e0334b8389cd66878ad68be70f419dda40fe2f286f
rocksdbPrebuiltSha.watchosDeviceArm64=10f3ff980f5e143826a7aeb6a2048cf6d0a224fd1b2791e2c15c7e7e5d8e0149
rocksdbPrebuiltSha.watchosSimulatorArm64=5613374c51237bcd38db901519478802cc3a13dc10cb4234cfbaab329ad94d00
89 changes: 89 additions & 0 deletions src/commonMain/kotlin/maryk/rocksdb/BackupEngineOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,93 @@ expect class BackupEngineOptions
: RocksObject {
/** Returns the path to the BackupableDB directory. */
fun backupDir(): String

/**
* Backup Env object. It will be used for backup file I/O. If it's
* null, backups will be written out using DBs Env. Otherwise,
* backup's I/O will be performed using this object.
*
* Default: null
*
* @param env The environment to use
* @return instance of current BackupEngineOptions.
*/
fun setBackupEnv(env: Env): BackupEngineOptions

/** Returns the environment used for backup I/O. */
fun backupEnv(): Env?

/** Share table files between backups. */
fun setShareTableFiles(shareTableFiles: Boolean): BackupEngineOptions

/** Returns true if SST files are shared between backups. */
fun shareTableFiles(): Boolean

/** Enable or disable synchronous backups. */
fun setSync(sync: Boolean): BackupEngineOptions

/** Returns true if synchronous backups are enabled. */
fun sync(): Boolean

/** Configure whether existing backups should be destroyed. */
fun setDestroyOldData(destroyOldData: Boolean): BackupEngineOptions

/** Returns true if old backup data will be destroyed. */
fun destroyOldData(): Boolean

/**
* Configure whether log files are copied into the backup.
*/
fun setBackupLogFiles(backupLogFiles: Boolean): BackupEngineOptions

/** Returns true if log files are backed up. */
fun backupLogFiles(): Boolean

/**
* Limit the rate at which data is copied during a backup. A value of 0
* disables throttling.
*/
fun setBackupRateLimit(backupRateLimit: Long): BackupEngineOptions

/** Returns the configured backup rate limit in bytes per second. */
fun backupRateLimit(): Long

/** Attach a rate limiter that governs backup throughput. */
fun setBackupRateLimiter(rateLimiter: RateLimiter): BackupEngineOptions

/** Returns the configured backup rate limiter, if any. */
fun backupRateLimiter(): RateLimiter?

/** Configure the restore rate limit in bytes per second. */
fun setRestoreRateLimit(restoreRateLimit: Long): BackupEngineOptions

/** Returns the configured restore rate limit in bytes per second. */
fun restoreRateLimit(): Long

/** Attach a rate limiter that governs restore throughput. */
fun setRestoreRateLimiter(rateLimiter: RateLimiter): BackupEngineOptions

/** Returns the configured restore rate limiter, if any. */
fun restoreRateLimiter(): RateLimiter?

/** Configure whether SSTs are identified by checksum metadata. */
fun setShareFilesWithChecksum(shareFilesWithChecksum: Boolean): BackupEngineOptions

/** Returns true if file sharing is keyed by checksum metadata. */
fun shareFilesWithChecksum(): Boolean

/** Sets the number of background threads used for backup/restore. */
fun setMaxBackgroundOperations(maxBackgroundOperations: Int): BackupEngineOptions

/** Returns the number of background threads used for backup/restore. */
fun maxBackgroundOperations(): Int

/**
* Configures how many bytes are copied between callbacks when a
* progress listener is attached.
*/
fun setCallbackTriggerIntervalSize(callbackTriggerIntervalSize: Long): BackupEngineOptions

/** Returns the current callback trigger interval size. */
fun callbackTriggerIntervalSize(): Long
}
8 changes: 8 additions & 0 deletions src/commonMain/kotlin/maryk/rocksdb/BloomFilter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package maryk.rocksdb

/** Bloom filter wrapper used by [BlockBasedTableConfig]. */
expect class BloomFilter : FilterPolicy {
constructor()
constructor(bitsPerKey: Double)
constructor(bitsPerKey: Double, useBlockBasedBuilder: Boolean)
}
51 changes: 51 additions & 0 deletions src/commonMain/kotlin/maryk/rocksdb/CompactionJobInfo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package maryk.rocksdb

/**
* Snapshot of metadata describing a compaction job.
*/
expect class CompactionJobInfo {
/** Column family name the compaction operated on. */
fun columnFamilyName(): ByteArray

/** Smallest input level participating in the compaction. */
fun baseInputLevel(): Int

/** Target output level for the compaction results. */
fun outputLevel(): Int

/** Absolute paths of SST files consumed by the compaction. */
fun inputFiles(): List<String>

/** Absolute paths of SST files generated by the compaction. */
fun outputFiles(): List<String>

/** Wall clock duration of the job in microseconds. */
fun elapsedMicros(): Long

/** Number of corrupt keys encountered. */
fun numCorruptKeys(): Long

/** Logical records read from inputs. */
fun inputRecords(): Long

/** Logical records written to outputs. */
fun outputRecords(): Long

/** Total bytes of input SST data processed. */
fun totalInputBytes(): Long

/** Total bytes written to output SST files. */
fun totalOutputBytes(): Long

/** Reason RocksDB scheduled this compaction. */
fun compactionReason(): CompactionReason

/** Count of input files across all levels. */
fun numInputFiles(): Long

/** Count of input files already residing at the output level. */
fun numInputFilesAtOutputLevel(): Long

/** Aggregated statistics describing the compaction run. */
fun compactionStats(): CompactionJobStats
}
60 changes: 60 additions & 0 deletions src/commonMain/kotlin/maryk/rocksdb/CompactionJobStats.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package maryk.rocksdb

/**
* Aggregated statistics captured for a single compaction job.
*/
class CompactionJobStats internal constructor(
private val elapsedMicrosValue: Long,
private val numInputRecordsValue: Long,
private val numOutputRecordsValue: Long,
private val totalInputBytesValue: Long,
private val totalOutputBytesValue: Long,
private val numInputFilesValue: Long,
private val numInputFilesAtOutputLevelValue: Long,
private val numOutputFilesValue: Long,
private val numCorruptKeysValue: Long,
) {
/** Duration of the compaction in microseconds. */
fun elapsedMicros(): Long = elapsedMicrosValue

/** Number of logical records consumed from inputs. */
fun numInputRecords(): Long = numInputRecordsValue

/** Number of logical records produced in the outputs. */
fun numOutputRecords(): Long = numOutputRecordsValue

/** Total size of input SST data processed. */
fun totalInputBytes(): Long = totalInputBytesValue

/** Total size of SST data generated as output. */
fun totalOutputBytes(): Long = totalOutputBytesValue

/** Number of input files processed across all levels. */
fun numInputFiles(): Long = numInputFilesValue

/** Number of input files that already lived at the target level. */
fun numInputFilesAtOutputLevel(): Long = numInputFilesAtOutputLevelValue

/** Number of output files generated. */
fun numOutputFiles(): Long = numOutputFilesValue

/** Corrupt keys encountered while compacting. */
fun numCorruptKeys(): Long = numCorruptKeysValue

internal companion object {
internal fun empty(
numInputFilesFallback: Long,
numOutputFilesFallback: Long,
) = CompactionJobStats(
elapsedMicrosValue = 0,
numInputRecordsValue = 0,
numOutputRecordsValue = 0,
totalInputBytesValue = 0,
totalOutputBytesValue = 0,
numInputFilesValue = numInputFilesFallback,
numInputFilesAtOutputLevelValue = 0,
numOutputFilesValue = numOutputFilesFallback,
numCorruptKeysValue = 0,
)
}
}
32 changes: 32 additions & 0 deletions src/commonMain/kotlin/maryk/rocksdb/CompactionOptions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package maryk.rocksdb

expect class CompactionOptions() : RocksObject {
fun compression(): CompressionType
fun setCompression(compression: CompressionType): CompactionOptions
fun outputFileSizeLimit(): Long
fun setOutputFileSizeLimit(limit: Long): CompactionOptions
fun maxSubcompactions(): Int
fun setMaxSubcompactions(count: Int): CompactionOptions
}

expect class CompactionOptionsFIFO() : RocksObject {
fun setMaxTableFilesSize(size: Long): CompactionOptionsFIFO
fun maxTableFilesSize(): Long
fun setAllowCompaction(allow: Boolean): CompactionOptionsFIFO
fun allowCompaction(): Boolean
}

expect class CompactionOptionsUniversal() : RocksObject {
fun setSizeRatio(sizeRatio: Int): CompactionOptionsUniversal
fun sizeRatio(): Int
fun setMinMergeWidth(width: Int): CompactionOptionsUniversal
fun minMergeWidth(): Int
fun setMaxMergeWidth(width: Int): CompactionOptionsUniversal
fun maxMergeWidth(): Int
fun setMaxSizeAmplificationPercent(percent: Int): CompactionOptionsUniversal
fun maxSizeAmplificationPercent(): Int
fun setCompressionSizePercent(percent: Int): CompactionOptionsUniversal
fun compressionSizePercent(): Int
fun setStopStyle(stopStyle: CompactionStopStyle): CompactionOptionsUniversal
fun stopStyle(): CompactionStopStyle
}
12 changes: 12 additions & 0 deletions src/commonMain/kotlin/maryk/rocksdb/CompressionOptions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package maryk.rocksdb

expect class CompressionOptions() : RocksObject {
fun setWindowBits(windowBits: Int): CompressionOptions
fun windowBits(): Int
fun setLevel(level: Int): CompressionOptions
fun level(): Int
fun setStrategy(strategy: Int): CompressionOptions
fun strategy(): Int
fun setMaxDictBytes(bytes: Int): CompressionOptions
fun maxDictBytes(): Int
}
12 changes: 12 additions & 0 deletions src/commonMain/kotlin/maryk/rocksdb/ConfigOptions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package maryk.rocksdb

/**
* Options for configuring how RocksDB parses options files and strings.
*/
expect class ConfigOptions() : RocksObject {
fun setDelimiter(delimiter: String): ConfigOptions
fun setIgnoreUnknownOptions(ignore: Boolean): ConfigOptions
fun setEnv(env: Env): ConfigOptions
fun setInputStringsEscaped(escaped: Boolean): ConfigOptions
fun setSanityLevel(level: SanityLevel): ConfigOptions
}
14 changes: 14 additions & 0 deletions src/commonMain/kotlin/maryk/rocksdb/DBOptions.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package maryk.rocksdb

expect fun DBOptions.addEventListener(listener: EventListener): DBOptions

expect fun Options.addEventListener(listener: EventListener): Options

expect class DBOptions() : RocksObject {
/**
* If this value is set to true, then the database will be created
Expand Down Expand Up @@ -267,4 +271,14 @@ expect class DBOptions() : RocksObject {
* @see .walSizeLimitMB
*/
fun walSizeLimitMB(): Long

/**
* Sets the recovery policy when replaying the WAL during open.
*/
fun setWalRecoveryMode(mode: WALRecoveryMode): DBOptions

/**
* Returns the configured recovery policy for WAL replay.
*/
fun walRecoveryMode(): WALRecoveryMode
}
19 changes: 19 additions & 0 deletions src/commonMain/kotlin/maryk/rocksdb/EventListener.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package maryk.rocksdb

/** Receives callbacks for background RocksDB operations. */
expect abstract class EventListener : RocksCallbackObject {
/** Invoked before a flush job starts. */
open fun onFlushBeginEvent(db: RocksDB, flushJobInfo: FlushJobInfo)

/** Invoked after a flush completes. */
open fun onFlushCompletedEvent(db: RocksDB, flushJobInfo: FlushJobInfo)

/** Invoked before a compaction job begins. */
open fun onCompactionBeginEvent(db: RocksDB, compactionJobInfo: CompactionJobInfo)

/** Invoked when a compaction job finishes. */
open fun onCompactionCompletedEvent(db: RocksDB, compactionJobInfo: CompactionJobInfo)

/** Invoked after an external SST file has been ingested into the database. */
open fun onExternalFileIngested(db: RocksDB, ingestionInfo: ExternalFileIngestionInfo)
}
19 changes: 19 additions & 0 deletions src/commonMain/kotlin/maryk/rocksdb/ExternalFileIngestionInfo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package maryk.rocksdb

/** Metadata describing an external SST file that was ingested into a RocksDB instance. */
expect class ExternalFileIngestionInfo {
/** Column family the file was ingested into. */
fun columnFamilyName(): String

/** Absolute path of the file before ingestion. */
fun externalFilePath(): String

/** Relative path of the file within the RocksDB data directory. */
fun internalFilePath(): String

/** Global sequence number assigned to keys contained in the file. */
fun globalSequenceNumber(): Long

/** Table properties associated with the ingested file. */
fun tableProperties(): TableProperties?
}
Loading