You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "rpuch (via GitHub)" <gi...@apache.org> on 2023/05/02 08:35:22 UTC

[GitHub] [ignite-3] rpuch commented on a diff in pull request #1976: IGNITE-19269 Implemented methods to explicitly lock rows in MV storage.

rpuch commented on code in PR #1976:
URL: https://github.com/apache/ignite-3/pull/1976#discussion_r1182249152


##########
modules/storage-api/src/main/java/org/apache/ignite/internal/storage/MvPartitionStorage.java:
##########
@@ -47,14 +48,41 @@ public interface MvPartitionStorage extends ManuallyCloseable {
     long REBALANCE_IN_PROGRESS = -1;
 
     /**
-     * Closure for executing write operations on the storage.
+     * Closure for executing write operations on the storage. All write operations, such as
+     * {@link #addWrite(RowId, BinaryRow, UUID, UUID, int)} or {@link #commitWrite(RowId, HybridTimestamp)},
+     * as well as {@link #scanVersions(RowId)}, and operations like {@link #committedGroupConfiguration(byte[])}, must be executed inside
+     * of the write closure. Also, each operation that involves modifying rows (and {@link #scanVersions(RowId)} must hold lock on
+     * corresponding row ID, by either calling {@link Locker#lock(RowId)} or calling {@link Locker#tryLock(RowId)} and checking the
+     * result.
      *
      * @param <V> Type of the result returned from the closure.
      */
     @SuppressWarnings("PublicInnerClass")
     @FunctionalInterface
     interface WriteClosure<V> {
-        V execute() throws StorageException;
+        V execute(Locker locker) throws StorageException;
+    }
+
+    /**
+     * Parameter type for {@link WriteClosure#execute(Locker)}. Used to lock row IDs before updating the data. All acquired locks are
+     * released automatically after {@code execute} call is completed.
+     */
+    @SuppressWarnings("PublicInnerClass")
+    interface Locker {
+        /**
+         * Locks passed row ID until the {@link WriteClosure#execute(Locker)} is completed.
+         *
+         * @param rowId Row ID to lock.
+         */
+        void lock(RowId rowId);
+
+        /**
+         * Tries to lock passed row ID. If successful, lock will be released when the {@link WriteClosure#execute(Locker)} is completed.
+         *
+         * @param rowId Row ID to lock.
+         * @return {@code true} if row ID has been locked successfully, or the lock has already been held by current thread.

Review Comment:
   It's about explicitness. If you think it's already obvious, ok.



-- 
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-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org