rpuch commented on code in PR #1976:
URL: https://github.com/apache/ignite-3/pull/1976#discussion_r1180334361
##########
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:
Oh, I've misread the second half. Still, it seems that explicit mention of
what `false` means should be useful.
--
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]