-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not create new write actions for RocksDB if values exist in both t…
…he new as old version.
- Loading branch information
Showing
4 changed files
with
177 additions
and
74 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...ksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/getCurrentValues.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package maryk.datastore.rocksdb.processors.helpers | ||
|
||
import maryk.core.properties.types.Key | ||
import maryk.datastore.rocksdb.TableColumnFamilies | ||
import maryk.datastore.rocksdb.Transaction | ||
import maryk.lib.extensions.compare.compareDefinedTo | ||
import org.rocksdb.ReadOptions | ||
|
||
internal fun getCurrentValues( | ||
transaction: Transaction, | ||
columnFamilies: TableColumnFamilies, | ||
key: Key<*>, | ||
referenceAsBytes: ByteArray | ||
): List<Pair<ByteArray, ByteArray>> { | ||
val prefix = key.bytes + referenceAsBytes | ||
val currentValues = mutableListOf<Pair<ByteArray, ByteArray>>() | ||
|
||
val iterator = transaction.getIterator(ReadOptions(), columnFamilies.table) | ||
iterator.seek(prefix) | ||
|
||
while (iterator.isValid() && prefix.compareDefinedTo(iterator.key()) == 0) { | ||
currentValues.add(iterator.key() to iterator.value()) | ||
iterator.next() | ||
} | ||
|
||
return currentValues | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/unsetNonChangedValues.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package maryk.datastore.rocksdb.processors.helpers | ||
|
||
import maryk.core.properties.types.Key | ||
import maryk.datastore.rocksdb.TableColumnFamilies | ||
import maryk.datastore.rocksdb.Transaction | ||
import maryk.datastore.shared.TypeIndicator | ||
import maryk.lib.extensions.compare.compareTo | ||
import maryk.lib.extensions.compare.compareToWithOffsetLength | ||
|
||
internal fun unsetNonChangedValues( | ||
transaction: Transaction, | ||
columnFamilies: TableColumnFamilies, | ||
key: Key<*>, | ||
currentValues: List<Pair<ByteArray, ByteArray>>, | ||
qualifiersToKeep: List<ByteArray>, | ||
versionBytes: ByteArray | ||
) { | ||
val sortedQualifiersToKeep = qualifiersToKeep.sortedWith { o1, o2 -> o1.compareTo(o2) } | ||
var minIndex = 0 | ||
|
||
for ((qualifier, _) in currentValues) { | ||
val index = sortedQualifiersToKeep.binarySearch(fromIndex = minIndex) { | ||
it.compareToWithOffsetLength(qualifier, key.bytes.size, qualifier.size - key.bytes.size) | ||
} | ||
if (index < 0) { | ||
// Delete the value by setting it to the DeletedIndicator | ||
setValue(transaction, columnFamilies, qualifier, versionBytes, TypeIndicator.DeletedIndicator.byteArray) | ||
} else { | ||
// Start next time comparing with next value in qualifiersToKeep as they are ordered | ||
minIndex = index + 1 | ||
} | ||
} | ||
} |
Oops, something went wrong.