tkalkirill commented on code in PR #1578:
URL: https://github.com/apache/ignite-3/pull/1578#discussion_r1088177090
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbStorage.java:
##########
@@ -562,6 +536,57 @@ public CompletableFuture<Void> finishRebalance(long
lastAppliedIndex, long lastA
return completedFuture(null);
}
+ @Override
+ public CompletableFuture<Void> clear() {
+ if (!state.compareAndSet(StorageState.RUNNABLE, StorageState.CLEANUP))
{
+ throwExceptionDependingOnStorageState();
+ }
+
+ // We changed the status and wait for all current operations (together
with cursors) with the storage to be completed.
+ busyLock.block();
+
+ try (WriteBatch writeBatch = new WriteBatch()) {
+ clearStorageData(writeBatch);
+
+ updateLastAppliedAndPersistentIndex(writeBatch, 0, 0);
+
+ db.write(writeOptions, writeBatch);
+
+ return completedFuture(null);
+ } catch (RocksDBException e) {
+ throw new IgniteInternalException(
+ TX_STATE_STORAGE_ERR,
+ IgniteStringFormatter.format("Failed to cleanup storage:
[{}]", createStorageInfo()),
+ e
+ );
+ } finally {
+ state.set(StorageState.RUNNABLE);
+
+ busyLock.unblock();
+ }
+ }
+
+ private void clearStorageData(WriteBatch writeBatch) throws
RocksDBException {
+ writeBatch.deleteRange(partitionStartPrefix(), partitionEndPrefix());
+ }
+
+ private void updateLastApplied(WriteBatch writeBatch, long
lastAppliedIndex, long lastAppliedTerm) throws RocksDBException {
+ writeBatch.put(lastAppliedIndexAndTermKey,
indexAndTermToBytes(lastAppliedIndex, lastAppliedTerm));
+
+ this.lastAppliedIndex = lastAppliedIndex;
+ this.lastAppliedTerm = lastAppliedTerm;
+ }
+
+ private void updateLastAppliedAndPersistentIndex(
Review Comment:
fix
--
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]