diff --git a/lib/src/commonMain/kotlin/maryk/lib/bytes/combineToByteArray.kt b/lib/src/commonMain/kotlin/maryk/lib/bytes/combineToByteArray.kt new file mode 100644 index 00000000..25150101 --- /dev/null +++ b/lib/src/commonMain/kotlin/maryk/lib/bytes/combineToByteArray.kt @@ -0,0 +1,29 @@ +package maryk.lib.bytes + +fun combineToByteArray(vararg elements: Any): ByteArray { + val totalSize = elements.sumOf { element -> + when (element) { + is ByteArray -> element.size + is Byte -> 1 + else -> throw IllegalArgumentException("Unsupported type: ${element::class.simpleName}") + } + } + + val result = ByteArray(totalSize) + var offset = 0 + + elements.forEach { element -> + when (element) { + is ByteArray -> { + element.copyInto(result, offset) + offset += element.size + } + is Byte -> { + result[offset] = element + offset++ + } + } + } + + return result +} diff --git a/lib/src/commonTest/kotlin/maryk/lib/bytes/CombineToByteArrayTest.kt b/lib/src/commonTest/kotlin/maryk/lib/bytes/CombineToByteArrayTest.kt new file mode 100644 index 00000000..c73601f3 --- /dev/null +++ b/lib/src/commonTest/kotlin/maryk/lib/bytes/CombineToByteArrayTest.kt @@ -0,0 +1,48 @@ +package maryk.lib.bytes + +import kotlin.test.Test +import kotlin.test.assertContentEquals +import kotlin.test.assertFailsWith +import kotlin.test.expect + +class CombineToByteArrayTest { + @Test + fun testCombineByteArrays() { + val result = combineToByteArray( + byteArrayOf(1, 2, 3), + byteArrayOf(4, 5), + byteArrayOf(6) + ) + assertContentEquals(byteArrayOf(1, 2, 3, 4, 5, 6), result) + } + + @Test + fun testCombineBytes() { + val result = combineToByteArray(1.toByte(), 2.toByte(), 3.toByte()) + assertContentEquals(byteArrayOf(1, 2, 3), result) + } + + @Test + fun testCombineMixed() { + val result = combineToByteArray( + byteArrayOf(1, 2), + 3.toByte(), + byteArrayOf(4, 5), + 6.toByte() + ) + assertContentEquals(byteArrayOf(1, 2, 3, 4, 5, 6), result) + } + + @Test + fun testEmptyInput() { + val result = combineToByteArray() + expect(0) { result.size } + } + + @Test + fun testUnsupportedType() { + assertFailsWith { + combineToByteArray(byteArrayOf(1, 2), "unsupported") + } + } +} diff --git a/store/hbase/src/commonMain/kotlin/maryk/datastore/hbase/processors/processChange.kt b/store/hbase/src/commonMain/kotlin/maryk/datastore/hbase/processors/processChange.kt index 8f2f75f5..5af0edd5 100644 --- a/store/hbase/src/commonMain/kotlin/maryk/datastore/hbase/processors/processChange.kt +++ b/store/hbase/src/commonMain/kotlin/maryk/datastore/hbase/processors/processChange.kt @@ -236,7 +236,7 @@ private suspend fun applyChanges( if (validationExceptions == null) { validationExceptions = mutableListOf() } - validationExceptions!!.add(ve) + validationExceptions.add(ve) } var isChanged = false @@ -734,14 +734,14 @@ private suspend fun applyChanges( if (newValue == null) { if (oldValue != null) { dependentPuts += Put(oldValue).setTimestamp(version.timestamp.toLong()).addColumn(family, key.bytes, softDeleteIndicator) - indexUpdates.add(IndexDelete(index.referenceStorageByteArray, Bytes(byteArrayOf(*oldValue, *key.bytes)))) + indexUpdates.add(IndexDelete(index.referenceStorageByteArray, Bytes(oldValue + key.bytes))) } // else ignore since did not exist } else if (oldValue == null || !newValue.contentEquals(oldValue)) { if (oldValue != null) { dependentPuts += Put(oldValue).setTimestamp(version.timestamp.toLong()).addColumn(family, key.bytes, softDeleteIndicator) } dependentPuts += Put(newValue).setTimestamp(version.timestamp.toLong()).addColumn(family, key.bytes, trueIndicator) - indexUpdates.add(IndexUpdate(index.referenceStorageByteArray, Bytes(byteArrayOf(*newValue, *key.bytes)), oldValue?.let { Bytes(byteArrayOf(*oldValue, *key.bytes)) })) + indexUpdates.add(IndexUpdate(index.referenceStorageByteArray, Bytes(newValue + key.bytes), oldValue?.let { Bytes(oldValue + key.bytes) })) } } diff --git a/store/hbase/src/commonMain/kotlin/maryk/datastore/hbase/processors/scanIndex.kt b/store/hbase/src/commonMain/kotlin/maryk/datastore/hbase/processors/scanIndex.kt index 5d291222..966e61a0 100644 --- a/store/hbase/src/commonMain/kotlin/maryk/datastore/hbase/processors/scanIndex.kt +++ b/store/hbase/src/commonMain/kotlin/maryk/datastore/hbase/processors/scanIndex.kt @@ -143,7 +143,7 @@ internal suspend fun scanIndex( add( Get(cell.qualifierArray, cell.qualifierOffset, cell.qualifierLength).apply { - sortingKeys.add(byteArrayOf(*result.row, *this.row)) + sortingKeys.add(result.row + this.row) addFamily(dataColumnFamily) readVersions(if (scanRequest is IsChangesRequest<*, *>) scanRequest.maxVersions.toInt() else 1) diff --git a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/DBAccessorStoreValuesGetter.kt b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/DBAccessorStoreValuesGetter.kt index fe767f11..38901fd7 100644 --- a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/DBAccessorStoreValuesGetter.kt +++ b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/DBAccessorStoreValuesGetter.kt @@ -40,7 +40,7 @@ internal class DBAccessorStoreValuesGetter( override fun , C : Any> get(propertyReference: IsPropertyReference): T? { @Suppress("UNCHECKED_CAST") return cache.getOrPut(propertyReference) { - dbAccessor.getValue(columnFamilies, readOptions, this.toVersion, byteArrayOf(*key, *propertyReference.toStorageByteArray())) { valueAsBytes, offset, length -> + dbAccessor.getValue(columnFamilies, readOptions, this.toVersion, key + propertyReference.toStorageByteArray()) { valueAsBytes, offset, length -> (valueAsBytes.convertToValue(propertyReference, offset, length) as T?)?.also { if (captureVersion) { val version = valueAsBytes.readVersionBytes() diff --git a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/HistoricStoreIndexValuesGetter.kt b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/HistoricStoreIndexValuesGetter.kt index 26a3509e..9bd75ea0 100644 --- a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/HistoricStoreIndexValuesGetter.kt +++ b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/HistoricStoreIndexValuesGetter.kt @@ -59,7 +59,7 @@ internal class HistoricStoreIndexValuesWalker( bytes.invert(versionIndex) } handleIndexReference(historicIndexReference) - } catch (e: Throwable) { + } catch (_: Throwable) { // skip failing index reference generation } } while (getter.gotoNextVersion()) @@ -134,7 +134,7 @@ private class HistoricStoreIndexValuesGetter( } val iterator = iterableReference.iterator val reference = iterableReference.referenceAsBytes - val keyAndReference = byteArrayOf(*key, *iterableReference.referenceAsBytes) + val keyAndReference = key + iterableReference.referenceAsBytes // Only seek the first time if (iterableReference.lastVersion == null) { diff --git a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/StoreValuesGetter.kt b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/StoreValuesGetter.kt index 06635b71..de3a82ee 100644 --- a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/StoreValuesGetter.kt +++ b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/StoreValuesGetter.kt @@ -33,7 +33,7 @@ internal class StoreValuesGetter( override fun , C : Any> get(propertyReference: IsPropertyReference): T? { key?.let { currentKey -> val valueAsBytes = cache.getOrPut(propertyReference) { - val reference = byteArrayOf(*currentKey, *propertyReference.toStorageByteArray()) + val reference = currentKey + propertyReference.toStorageByteArray() db.get(columnFamilies.table, readOptions, reference) } diff --git a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/createCountUpdater.kt b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/createCountUpdater.kt index e312a04c..69cdf1ec 100644 --- a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/createCountUpdater.kt +++ b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/createCountUpdater.kt @@ -9,7 +9,7 @@ import maryk.datastore.rocksdb.Transaction import org.rocksdb.ReadOptions /** - * Set count for [reference] at [version] by applying [countChange] to current count read with [readOptions] + * Set count for [reference] at [versionBytes] by applying [countChange] to current count read with [readOptions] */ internal fun createCountUpdater( transaction: Transaction, @@ -23,7 +23,7 @@ internal fun createCountUpdater( ) { val referenceToCompareTo = reference.toStorageByteArray() - val previousCount = transaction.getValue(columnFamilies, readOptions, null, byteArrayOf(*key.bytes, *referenceToCompareTo)) { b, o, _ -> + val previousCount = transaction.getValue(columnFamilies, readOptions, null, key.bytes + referenceToCompareTo) { b, o, _ -> var readIndex = o initIntByVar { b[readIndex++] } } ?: 0 diff --git a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/deleteByReference.kt b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/deleteByReference.kt index e261cca0..be3ef023 100644 --- a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/deleteByReference.kt +++ b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/deleteByReference.kt @@ -47,7 +47,7 @@ internal fun deleteByReference( version: ByteArray, handlePreviousValue: ((ByteArray, T?) -> Unit)? ): Boolean { - val referenceToCompareTo = byteArrayOf(*key.bytes, *referenceAsBytes) + val referenceToCompareTo = key.bytes + referenceAsBytes var referenceOfParent: ByteArray? = null var toShiftListCount = 0u diff --git a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/deleteIndexValue.kt b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/deleteIndexValue.kt index 4312399b..b657fc26 100644 --- a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/deleteIndexValue.kt +++ b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/deleteIndexValue.kt @@ -5,6 +5,7 @@ import maryk.datastore.rocksdb.HistoricTableColumnFamilies import maryk.datastore.rocksdb.TableColumnFamilies import maryk.datastore.rocksdb.Transaction import maryk.datastore.rocksdb.processors.FALSE_ARRAY +import maryk.lib.bytes.combineToByteArray /** Delete the [indexReference] and [valueAndKey] for [version] */ internal fun deleteIndexValue( @@ -15,11 +16,11 @@ internal fun deleteIndexValue( version: ByteArray, hardDelete: Boolean = false ) { - transaction.delete(columnFamilies.index, byteArrayOf(*indexReference, *valueAndKey)) + transaction.delete(columnFamilies.index, indexReference + valueAndKey) // Only delete with non hard deletes since with hard deletes all values are deleted if (!hardDelete && columnFamilies is HistoricTableColumnFamilies) { - val historicReference = byteArrayOf(*indexReference, *valueAndKey, *version) + val historicReference = combineToByteArray(indexReference, valueAndKey, version) // Invert so the time is sorted in reverse order with newest on top historicReference.invert(historicReference.size - version.size) diff --git a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/deleteUniqueIndexValue.kt b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/deleteUniqueIndexValue.kt index c62cf425..e11852df 100644 --- a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/deleteUniqueIndexValue.kt +++ b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/deleteUniqueIndexValue.kt @@ -24,7 +24,7 @@ internal fun deleteUniqueIndexValue( // Only add a delete marker when not a hard delete. With hard delete all historic values are deleted if (!hardDelete && columnFamilies is HistoricTableColumnFamilies) { - val historicReference = byteArrayOf(*reference, *version) + val historicReference = reference + version // Invert so the time is sorted in reverse order with newest on top historicReference.invert(reference.size) diff --git a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/deleteValue.kt b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/deleteValue.kt index 741676da..fd183ad2 100644 --- a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/deleteValue.kt +++ b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/deleteValue.kt @@ -19,7 +19,7 @@ internal fun deleteValue( ) if (columnFamilies is HistoricTableColumnFamilies) { - val historicReference = byteArrayOf(*keyAndReference, *version) + val historicReference = keyAndReference + version // Invert so the time is sorted in reverse order with newest on top historicReference.invert(historicReference.size - version.size) diff --git a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/getKeyByUniqueValue.kt b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/getKeyByUniqueValue.kt index 40be996e..37051652 100644 --- a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/getKeyByUniqueValue.kt +++ b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/getKeyByUniqueValue.kt @@ -36,7 +36,7 @@ internal fun getKeyByUniqueValue( val versionBytes = toVersion.toReversedVersionBytes() dbAccessor.getIterator(readOptions, columnFamilies.historic.unique).use { iterator -> - val toSeek = byteArrayOf(*reference, *versionBytes) + val toSeek = reference + versionBytes iterator.seek(toSeek) while (iterator.isValid()) { val key = iterator.key() diff --git a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/getValue.kt b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/getValue.kt index 7e15995e..537ecfb0 100644 --- a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/getValue.kt +++ b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/getValue.kt @@ -43,7 +43,7 @@ internal fun DBAccessor.getValue( } this.getIterator(readOptions, columnFamilies.historic.table).use { iterator -> - val toSeek = byteArrayOf(*keyAndReference, *versionBytes) + val toSeek = keyAndReference + versionBytes iterator.seek(toSeek) while (iterator.isValid()) { val key = iterator.key() diff --git a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/iterateValues.kt b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/iterateValues.kt index b4c7714f..5cd92785 100644 --- a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/iterateValues.kt +++ b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/iterateValues.kt @@ -41,7 +41,7 @@ internal fun DBAccessor.iterateValues( } this.getIterator(readOptions, columnFamilies.historic.table).use { iterator -> val toVersionBytes = toVersion.toReversedVersionBytes() - val toSeek = byteArrayOf(*reference, *toVersionBytes) + val toSeek = reference + toVersionBytes iterator.seek(toSeek) while (iterator.isValid()) { val referenceBytes = iterator.key() diff --git a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/setIndexValue.kt b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/setIndexValue.kt index 5d9601fc..6fa4fb30 100644 --- a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/setIndexValue.kt +++ b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/setIndexValue.kt @@ -5,6 +5,7 @@ import maryk.datastore.rocksdb.HistoricTableColumnFamilies import maryk.datastore.rocksdb.TableColumnFamilies import maryk.datastore.rocksdb.Transaction import maryk.datastore.rocksdb.processors.EMPTY_ARRAY +import maryk.lib.bytes.combineToByteArray /** Set the [indexReference] and [valueAndKey] for [version] */ internal fun setIndexValue( @@ -14,9 +15,9 @@ internal fun setIndexValue( valueAndKey: ByteArray, version: ByteArray ) { - transaction.put(columnFamilies.index, byteArrayOf(*indexReference, *valueAndKey), version) + transaction.put(columnFamilies.index, indexReference + valueAndKey, version) if (columnFamilies is HistoricTableColumnFamilies) { - val historicReference = byteArrayOf(*indexReference, *valueAndKey, *version) + val historicReference = combineToByteArray(indexReference, valueAndKey, version) // Invert so the time is sorted in reverse order with newest on top historicReference.invert(historicReference.size - version.size) diff --git a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/setLatestVersion.kt b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/setLatestVersion.kt index b9702cdc..a44bb986 100644 --- a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/setLatestVersion.kt +++ b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/setLatestVersion.kt @@ -2,8 +2,8 @@ package maryk.datastore.rocksdb.processors.helpers import maryk.core.properties.types.Key import maryk.datastore.rocksdb.TableColumnFamilies -import maryk.datastore.rocksdb.processors.LAST_VERSION_INDICATOR import maryk.datastore.rocksdb.Transaction +import maryk.datastore.rocksdb.processors.LAST_VERSION_INDICATOR /** Set the latest [version] for [key] */ internal fun setLatestVersion( @@ -12,6 +12,6 @@ internal fun setLatestVersion( key: Key<*>, version: ByteArray ) { - val lastVersionRef = byteArrayOf(*key.bytes, LAST_VERSION_INDICATOR) + val lastVersionRef = key.bytes + LAST_VERSION_INDICATOR transaction.put(columnFamilies.table, lastVersionRef, version) } diff --git a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/setUniqueIndexValue.kt b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/setUniqueIndexValue.kt index 86a2a2d1..dc93596d 100644 --- a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/setUniqueIndexValue.kt +++ b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/setUniqueIndexValue.kt @@ -14,10 +14,10 @@ internal fun setUniqueIndexValue( version: ByteArray, key: Key<*> ) { - transaction.put(columnFamilies.unique, uniqueReferenceWithValue, byteArrayOf(*version, *key.bytes)) + transaction.put(columnFamilies.unique, uniqueReferenceWithValue, version + key.bytes) if (columnFamilies is HistoricTableColumnFamilies) { - val historicReference = byteArrayOf(*uniqueReferenceWithValue, *version) + val historicReference = uniqueReferenceWithValue + version // Invert so the time is sorted in reverse order with newest on top historicReference.invert(historicReference.size - version.size) diff --git a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/setValue.kt b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/setValue.kt index 7df8c2aa..51f7046a 100644 --- a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/setValue.kt +++ b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/setValue.kt @@ -5,6 +5,7 @@ import maryk.core.properties.types.Key import maryk.datastore.rocksdb.HistoricTableColumnFamilies import maryk.datastore.rocksdb.TableColumnFamilies import maryk.datastore.rocksdb.Transaction +import maryk.lib.bytes.combineToByteArray /** Set [reference] = [value] (ByteArray) at [version] for object at [key] */ internal fun setValue( @@ -17,12 +18,12 @@ internal fun setValue( ) { transaction.put( columnFamilies.table, - byteArrayOf(*key.bytes, *reference), - byteArrayOf(*version, *value) + key.bytes + reference, + version + value ) if (columnFamilies is HistoricTableColumnFamilies) { - val historicReference = byteArrayOf(*key.bytes, *reference, *version) + val historicReference = combineToByteArray(key.bytes, reference, version) // Invert so the time is sorted in reverse order with newest on top historicReference.invert(historicReference.size - version.size) diff --git a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/setValueWithKeyReference.kt b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/setValueWithKeyReference.kt index 8273bea0..16e0fef0 100644 --- a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/setValueWithKeyReference.kt +++ b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/helpers/setValueWithKeyReference.kt @@ -5,7 +5,7 @@ import maryk.datastore.rocksdb.HistoricTableColumnFamilies import maryk.datastore.rocksdb.TableColumnFamilies import maryk.datastore.rocksdb.Transaction -/** Set [keyAndReference] = [value] (ByteArray) at [version] for object at [key] */ +/** Set [keyAndReference] = [value] (ByteArray) at [version] for object at [keyAndReference] */ internal fun setValue( transaction: Transaction, columnFamilies: TableColumnFamilies, @@ -26,7 +26,7 @@ internal fun setValue( ) if (columnFamilies is HistoricTableColumnFamilies) { - val historicReference = byteArrayOf(*keyAndReference, *version) + val historicReference = keyAndReference + version // Invert so the time is sorted in reverse order with newest on top historicReference.invert(historicReference.size - version.size) diff --git a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/processAdd.kt b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/processAdd.kt index 04031881..da85816e 100644 --- a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/processAdd.kt +++ b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/processAdd.kt @@ -89,7 +89,7 @@ internal suspend fun processAdd( // If a unique index, check if exists, and then write if ((definition is IsComparableDefinition<*, *>) && definition.unique) { - val uniqueReference = byteArrayOf(*reference, *valueBytes) + val uniqueReference = reference + valueBytes checksBeforeWrite.add { val uniqueCount = diff --git a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/processChange.kt b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/processChange.kt index 9bdf2988..9e2b6f26 100644 --- a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/processChange.kt +++ b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/processChange.kt @@ -797,7 +797,7 @@ private fun createValueWriter( columnFamilies, dataStore.defaultReadOptions, null, - byteArrayOf(*key.bytes, *reference) + key.bytes + reference ) { b, o, l -> deleteUniqueIndexValue(transaction, columnFamilies, reference, b, o, l, versionBytes, false) } diff --git a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/processDelete.kt b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/processDelete.kt index 8c08ad0b..9f46ebce 100644 --- a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/processDelete.kt +++ b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/processDelete.kt @@ -20,6 +20,7 @@ import maryk.datastore.rocksdb.processors.helpers.setLatestVersion import maryk.datastore.shared.Cache import maryk.datastore.shared.updates.IsUpdateAction import maryk.datastore.shared.updates.Update.Deletion +import maryk.lib.bytes.combineToByteArray import maryk.lib.extensions.compare.matchPart import maryk.lib.extensions.compare.nextByteInSameLength import maryk.lib.recyclableByteArray @@ -54,7 +55,7 @@ internal suspend fun processDelete( for (reference in dataStore.getUniqueIndices( dbIndex, columnFamilies.unique )) { - val referenceAndKey = byteArrayOf(*key.bytes, *reference) + val referenceAndKey = key.bytes + reference val valueLength = transaction.get( columnFamilies.table, dataStore.defaultReadOptions, @@ -147,13 +148,13 @@ internal suspend fun processDelete( transaction.put( columnFamilies.table, - byteArrayOf(*key.bytes, SOFT_DELETE_INDICATOR), - byteArrayOf(*versionBytes, TRUE) + key.bytes + SOFT_DELETE_INDICATOR, + versionBytes + TRUE ) if (columnFamilies is HistoricTableColumnFamilies) { val historicReference = - byteArrayOf(*key.bytes, SOFT_DELETE_INDICATOR, *versionBytes) + combineToByteArray(key.bytes, SOFT_DELETE_INDICATOR, versionBytes) // Invert so the time is sorted in reverse order with newest on top historicReference.invert(historicReference.size - versionBytes.size) diff --git a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/scanIndex.kt b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/scanIndex.kt index 8f023f58..f5223a30 100644 --- a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/scanIndex.kt +++ b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/processors/scanIndex.kt @@ -62,7 +62,7 @@ internal fun scanIndex( for (indexRange in indexScanRange.ranges) { val indexStartKey = indexRange.getAscendingStartKey(startKey, keyScanRange.includeStart) - iterator.seek(byteArrayOf(*indexReference, *indexStartKey)) + iterator.seek(indexReference + indexStartKey) checkAndProcess( dbAccessor, @@ -97,7 +97,7 @@ internal fun scanIndex( iterator.seekToLast() } } else { - iterator.seekForPrev(byteArrayOf(*indexReference, *indexStartKey)) + iterator.seekForPrev(indexReference + indexStartKey) } checkAndProcess( diff --git a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/walkDataRecordsAndFillIndex.kt b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/walkDataRecordsAndFillIndex.kt index 0e53bc8e..b9301ccd 100644 --- a/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/walkDataRecordsAndFillIndex.kt +++ b/store/rocksdb/src/commonMain/kotlin/maryk/datastore/rocksdb/walkDataRecordsAndFillIndex.kt @@ -39,7 +39,7 @@ internal fun walkDataRecordsAndFillIndex( storeGetter.lastVersion = null // Store non-historic value index.toStorageByteArrayForIndex(storeGetter, key)?.let { indexValue -> - transaction.put(columnFamilies.index, byteArrayOf(*index.referenceStorageByteArray.bytes, *indexValue), storeGetter.lastVersion!!.toByteArray()) + transaction.put(columnFamilies.index, index.referenceStorageByteArray.bytes + indexValue, storeGetter.lastVersion!!.toByteArray()) } // Process historical values for historical index