tkalkirill commented on code in PR #1506:
URL: https://github.com/apache/ignite-3/pull/1506#discussion_r1072470190
##########
modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/index/hash/PageMemoryHashIndexStorage.java:
##########
@@ -203,19 +187,68 @@ public void destroy() throws StorageException {
* Closes the hash index storage.
*/
public void close() {
- if (!CLOSED.compareAndSet(this, false, true)) {
+ if (!state.compareAndSet(StorageState.RUNNABLE, StorageState.CLOSED)) {
+ StorageState state = this.state.get();
+
+ assert state == StorageState.CLOSED : state;
+
return;
}
- closeBusyLock.block();
+ busyLock.block();
hashIndexTree.close();
}
/**
- * Throws an exception that the storage is already closed.
+ * Prepares storage for rebalancing.
+ *
+ * <p>Stops ongoing index operations.
+ *
+ * @throws StorageRebalanceException If there was an error when starting
the rebalance.
+ */
+ public void startRebalance() {
+ if (!state.compareAndSet(StorageState.RUNNABLE,
StorageState.REBALANCE)) {
+ throwExceptionDependingOnStorageStateOnRebalance(state.get(),
createStorageInfo());
+ }
+
+ // Stops ongoing operations on the storage.
+ busyLock.block();
+ busyLock.unblock();
+ }
+
+ /**
+ * Completes the rebalancing of the storage.
+ *
+ * @throws StorageRebalanceException If there is an error while completing
the storage rebalance.
*/
- private void throwStorageClosedException() {
- throw new StorageClosedException();
+ public void completeRebalance() {
+ if (!state.compareAndSet(StorageState.REBALANCE,
StorageState.RUNNABLE)) {
+ throwExceptionDependingOnStorageStateOnRebalance(state.get(),
createStorageInfo());
+ }
+ }
+
+ /**
+ * Updates the internal data structures of the storage on rebalance.
+ *
+ * @param freeList Free list to store index columns.
+ * @param hashIndexTree Hash index tree instance.
+ * @throws StorageRebalanceException If the storage is not in the process
of rebalancing.
+ */
+ public void updateDataStructuresOnRebalance(IndexColumnsFreeList freeList,
HashIndexTree hashIndexTree) {
+ throwExceptionIfStorageNotInProgressOfRebalance(state.get(),
this::createStorageInfo);
+
+ this.freeList = freeList;
+
+ this.hashIndexTree.close();
Review Comment:
I'll try to close them at the beginning of the rebalancing.
--
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]