tkalkirill commented on code in PR #1478:
URL: https://github.com/apache/ignite-3/pull/1478#discussion_r1058744868


##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbStorage.java:
##########
@@ -479,40 +515,52 @@ private UUID keyToTxId(byte[] bytes) {
 
     @Override
     public void close() {
-        close0();
+        tryToCloseStorageAndResources();
     }
 
     @Override
     public CompletableFuture<Void> startRebalance() {
-        if (!STATE.compareAndSet(this, StorageState.RUNNABLE, 
StorageState.REBALANCE)) {
-            throwExceptionIfStorageClosedOrRebalance();
+        CompletableFuture<Void> rebalanceFuture = new CompletableFuture<>();
+
+        if (!REBALANCE_FUTURE.compareAndSet(this, null, rebalanceFuture)) {
+            throw createStorageInProgressOfRebalanceException();
         }
 
-        busyLock.block();
+        try {
+            if (!STATE.compareAndSet(this, StorageState.RUNNABLE, 
StorageState.REBALANCE)) {
+                throwExceptionIfStorageClosedOrRebalance();
+            }
 
-        try (WriteBatch writeBatch = new WriteBatch()) {
-            writeBatch.deleteRange(partitionStartPrefix(), 
partitionEndPrefix());
-            writeBatch.put(lastAppliedIndexAndTermKey, 
indexAndTermToBytes(REBALANCE_IN_PROGRESS, REBALANCE_IN_PROGRESS));
+            busyLock.block();
 
-            db.write(writeOptions, writeBatch);
+            try (WriteBatch writeBatch = new WriteBatch()) {
+                writeBatch.deleteRange(partitionStartPrefix(), 
partitionEndPrefix());
+                writeBatch.put(lastAppliedIndexAndTermKey, 
indexAndTermToBytes(REBALANCE_IN_PROGRESS, REBALANCE_IN_PROGRESS));
 
-            lastAppliedIndex = REBALANCE_IN_PROGRESS;
-            lastAppliedTerm = REBALANCE_IN_PROGRESS;
-            persistedIndex = REBALANCE_IN_PROGRESS;
+                db.write(writeOptions, writeBatch);
 
-            CompletableFuture<Void> rebalanceFuture = completedFuture(null);
+                lastAppliedIndex = REBALANCE_IN_PROGRESS;
+                lastAppliedTerm = REBALANCE_IN_PROGRESS;
+                persistedIndex = REBALANCE_IN_PROGRESS;
 
-            this.rebalanceFuture = rebalanceFuture;
+                rebalanceFuture.complete(null);
 
-            return rebalanceFuture;
-        } catch (Exception e) {
-            throw new IgniteInternalException(
-                    TX_STATE_STORAGE_REBALANCE_ERR,
-                    IgniteStringFormatter.format("Failed to clear storage for 
partition {} of table {}", partitionId, getTableName()),
-                    e
-            );
-        } finally {
-            busyLock.unblock();
+                return rebalanceFuture;
+            } catch (Exception e) {
+                throw new IgniteInternalException(
+                        TX_STATE_STORAGE_REBALANCE_ERR,
+                        IgniteStringFormatter.format("Failed to clear storage 
for partition {} of table {}", partitionId, getTableName()),
+                        e
+                );
+            } finally {
+                busyLock.unblock();
+            }
+        } catch (IgniteInternalException e) {

Review Comment:
   This is the handling of exceptions from lines 531 and 550. Yes, it is 
necessary to deal with standing, I will correct it a little.



-- 
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]

Reply via email to