sashapolo commented on code in PR #6238: URL: https://github.com/apache/ignite-3/pull/6238#discussion_r2204318470
########## modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/TxStatePartitionStorage.java: ########## @@ -139,7 +139,8 @@ public interface TxStatePartitionStorage extends ManuallyCloseable { void close(); /** - * Closes and removes all data from the storage. + * Closes and removes all data from the storage. The destruction is not guaranteed to be durable (that is, if a node Review Comment: I would suggest to add a paragraph for "The destruction is...". Also applicable to similar places. ########## modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbSharedStorage.java: ########## @@ -274,13 +286,57 @@ public ColumnFamily txStateMetaColumnFamily() { * @param tableOrZoneId ID of the table or zone. */ public void destroyStorage(int tableOrZoneId) { - byte[] start = ByteBuffer.allocate(TABLE_OR_ZONE_PREFIX_SIZE_BYTES).order(BIG_ENDIAN).putInt(tableOrZoneId).array(); - byte[] end = ByteBuffer.allocate(TABLE_OR_ZONE_PREFIX_SIZE_BYTES).order(BIG_ENDIAN).putInt(tableOrZoneId + 1).array(); + byte[] dataStart = ByteBuffer.allocate(TxStateRocksDbStorage.TABLE_OR_ZONE_PREFIX_SIZE_BYTES) + .order(BYTE_ORDER) + .putInt(tableOrZoneId) + .array(); + byte[] dataEnd = ByteBuffer.allocate(TxStateRocksDbStorage.TABLE_OR_ZONE_PREFIX_SIZE_BYTES) + .order(BYTE_ORDER) + .putInt(tableOrZoneId + 1) + .array(); - try { - db.deleteRange(start, end); + try (WriteBatch writeBatch = new WriteBatch()) { + writeBatch.deleteRange(txStateColumnFamily.handle(), dataStart, dataEnd); + + TxStateMetaRocksDbPartitionStorage.clearForTableOrZone(writeBatch, txStateMetaColumnFamily().handle(), tableOrZoneId); + + db.write(writeOptions, writeBatch); } catch (Exception e) { throw new TxStateStorageException("Failed to destroy the transaction state storage [tableOrZoneId={}]", e, tableOrZoneId); } } + + /** + * Returns IDs of tables/zones for which there are tx state partition storages on disk. Those were created and flushed to disk; either + * destruction was not started for them, or it failed. + */ + public Set<Integer> tableOrZoneIdsOnDisk() { + Set<Integer> ids = new HashSet<>(); + + byte[] lastAppliedGlobalPrefix = {TxStateMetaRocksDbPartitionStorage.LAST_APPLIED_PREFIX}; + + try ( + var upperBound = new Slice(incrementPrefix(lastAppliedGlobalPrefix)); + var readOptions = new ReadOptions().setIterateUpperBound(upperBound); + RocksIterator it = txStateMetaColumnFamily.newIterator(readOptions) + ) { + it.seek(lastAppliedGlobalPrefix); + + while (it.isValid()) { + byte[] key = it.key(); + int tableOrZoneId = ByteUtils.bytesToInt(key, lastAppliedGlobalPrefix.length); + ids.add(tableOrZoneId); + + it.next(); + } + + // Doing this to make an exception thrown if the iteration was stopped due to an error and not due to exhausting + // the iteration space. + it.status(); + } catch (RocksDBException e) { + throw new IgniteInternalException(INTERNAL_ERR, "Cannot get table/zone IDs", e); Review Comment: Why not `StorageException`? ########## modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbSharedStorage.java: ########## @@ -274,13 +286,57 @@ public ColumnFamily txStateMetaColumnFamily() { * @param tableOrZoneId ID of the table or zone. */ public void destroyStorage(int tableOrZoneId) { - byte[] start = ByteBuffer.allocate(TABLE_OR_ZONE_PREFIX_SIZE_BYTES).order(BIG_ENDIAN).putInt(tableOrZoneId).array(); - byte[] end = ByteBuffer.allocate(TABLE_OR_ZONE_PREFIX_SIZE_BYTES).order(BIG_ENDIAN).putInt(tableOrZoneId + 1).array(); + byte[] dataStart = ByteBuffer.allocate(TxStateRocksDbStorage.TABLE_OR_ZONE_PREFIX_SIZE_BYTES) + .order(BYTE_ORDER) + .putInt(tableOrZoneId) + .array(); + byte[] dataEnd = ByteBuffer.allocate(TxStateRocksDbStorage.TABLE_OR_ZONE_PREFIX_SIZE_BYTES) Review Comment: can we use `incrementPrefix` here? -- 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: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org