tkalkirill commented on code in PR #1800:
URL: https://github.com/apache/ignite-3/pull/1800#discussion_r1144819741
##########
modules/storage-rocksdb/src/main/java/org/apache/ignite/internal/storage/rocksdb/RocksDbMetaStorage.java:
##########
@@ -103,13 +112,85 @@ void putPartitionId(int partitionId) {
}
}
+ /**
+ * Puts last row ID for which the index was built, {@code null} means
index building is finished.
+ *
+ * @param partitionId Partition ID.
+ * @param indexId Index ID.
+ * @param rowId Row ID.
+ */
+ public void putIndexLastBuildRowId(int partitionId, UUID indexId,
@Nullable RowId rowId) {
+ try {
+ metaColumnFamily.put(indexMetaKey(partitionId, indexId),
indexLastBuildRowId(rowId));
+ } catch (RocksDBException e) {
+ throw new StorageException(
+ "Failed to save last row ID for which the index was built:
[partitionId={}, indexId={}, rowId={}]",
+ e,
+ partitionId, indexId, rowId
+ );
+ }
+ }
+
+ /**
+ * Reads last row ID for which the index was built, {@code null} means
index building is finished.
+ *
+ * @param partitionId Partition ID.
+ * @param indexId Index ID.
+ * @param ifAbsent Will be returned if last row ID for which the index was
built has never been saved.
+ */
+ public @Nullable RowId readIndexLastBuildRowId(int partitionId, UUID
indexId, RowId ifAbsent) {
+ try {
+ byte[] lastBuildRowIdBytes =
metaColumnFamily.get(indexMetaKey(partitionId, indexId));
+
+ if (lastBuildRowIdBytes == null) {
+ return ifAbsent;
+ }
+
+ if (lastBuildRowIdBytes.length == 0) {
+ return null;
+ }
+
+ return new RowId(partitionId,
readUuid(ByteBuffer.wrap(lastBuildRowIdBytes), 0));
+ } catch (RocksDBException e) {
+ throw new StorageException(
+ "Failed to read last row ID for which the index was built:
[partitionId={}, indexId={}]",
+ e,
+ partitionId, indexId
+ );
+ }
+ }
+
static byte[] partitionIdKey(int partitionId) {
assert partitionId >= 0 && partitionId <= 0xFFFF : partitionId;
- return ByteBuffer.allocate(PARTITION_ID_PREFIX.length + Short.BYTES)
- .order(ByteOrder.BIG_ENDIAN)
+ return ByteBuffer.allocate(PARTITION_ID_PREFIX.length +
PARTITION_ID_SIZE)
+ .order(KEY_BYTE_ORDER)
.put(PARTITION_ID_PREFIX)
.putShort((short) partitionId)
.array();
}
+
+ static byte[] indexMetaKey(int partitionId, UUID indexId) {
Review Comment:
Fix it
##########
modules/storage-rocksdb/src/main/java/org/apache/ignite/internal/storage/rocksdb/RocksDbMetaStorage.java:
##########
@@ -103,13 +112,85 @@ void putPartitionId(int partitionId) {
}
}
+ /**
+ * Puts last row ID for which the index was built, {@code null} means
index building is finished.
+ *
+ * @param partitionId Partition ID.
+ * @param indexId Index ID.
+ * @param rowId Row ID.
+ */
+ public void putIndexLastBuildRowId(int partitionId, UUID indexId,
@Nullable RowId rowId) {
+ try {
+ metaColumnFamily.put(indexMetaKey(partitionId, indexId),
indexLastBuildRowId(rowId));
+ } catch (RocksDBException e) {
+ throw new StorageException(
+ "Failed to save last row ID for which the index was built:
[partitionId={}, indexId={}, rowId={}]",
+ e,
+ partitionId, indexId, rowId
+ );
+ }
+ }
+
+ /**
+ * Reads last row ID for which the index was built, {@code null} means
index building is finished.
+ *
+ * @param partitionId Partition ID.
+ * @param indexId Index ID.
+ * @param ifAbsent Will be returned if last row ID for which the index was
built has never been saved.
+ */
+ public @Nullable RowId readIndexLastBuildRowId(int partitionId, UUID
indexId, RowId ifAbsent) {
+ try {
+ byte[] lastBuildRowIdBytes =
metaColumnFamily.get(indexMetaKey(partitionId, indexId));
+
+ if (lastBuildRowIdBytes == null) {
+ return ifAbsent;
+ }
+
+ if (lastBuildRowIdBytes.length == 0) {
+ return null;
+ }
+
+ return new RowId(partitionId,
readUuid(ByteBuffer.wrap(lastBuildRowIdBytes), 0));
+ } catch (RocksDBException e) {
+ throw new StorageException(
+ "Failed to read last row ID for which the index was built:
[partitionId={}, indexId={}]",
+ e,
+ partitionId, indexId
+ );
+ }
+ }
+
static byte[] partitionIdKey(int partitionId) {
assert partitionId >= 0 && partitionId <= 0xFFFF : partitionId;
- return ByteBuffer.allocate(PARTITION_ID_PREFIX.length + Short.BYTES)
- .order(ByteOrder.BIG_ENDIAN)
+ return ByteBuffer.allocate(PARTITION_ID_PREFIX.length +
PARTITION_ID_SIZE)
+ .order(KEY_BYTE_ORDER)
.put(PARTITION_ID_PREFIX)
.putShort((short) partitionId)
.array();
}
+
+ static byte[] indexMetaKey(int partitionId, UUID indexId) {
+ assert partitionId >= 0 && partitionId <= 0xFFFF : partitionId;
+
+ ByteBuffer buffer =
ByteBuffer.allocate(INDEX_META_KEY_SIZE).order(KEY_BYTE_ORDER);
+
+ buffer.put(INDEX_META_KEY_PREFIX).putShort((short) partitionId);
+
+ putUuid(buffer, indexId);
+
+ return buffer.array();
+ }
+
+ static byte[] indexLastBuildRowId(@Nullable RowId rowId) {
Review Comment:
Fix it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]