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


##########
modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/mv/AddWriteLinkingWiInvokeClosure.java:
##########
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.storage.pagememory.mv;
+
+import static org.apache.ignite.internal.pagememory.util.PageIdUtils.NULL_LINK;
+
+import java.util.UUID;
+import org.apache.ignite.internal.lang.IgniteInternalCheckedException;
+import org.apache.ignite.internal.pagememory.freelist.FreeList;
+import org.apache.ignite.internal.pagememory.tree.BplusTree;
+import org.apache.ignite.internal.pagememory.tree.IgniteTree.InvokeClosure;
+import org.apache.ignite.internal.schema.BinaryRow;
+import org.apache.ignite.internal.storage.RowId;
+import org.apache.ignite.internal.storage.StorageException;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Implementation of {@link InvokeClosure} for {@link 
AbstractPageMemoryMvPartitionStorage#addWrite(RowId, BinaryRow, UUID, int, int)}
+ * which additionally maintains links between write intents.
+ *
+ * <p>See {@link AbstractPageMemoryMvPartitionStorage} about synchronization.
+ *
+ * <p>Operation may throw {@link StorageException} which will cause form 
{@link BplusTree#invoke(Object, Object, InvokeClosure)}.
+ */
+class AddWriteLinkingWiInvokeClosure extends AddWriteInvokeClosure {
+    private final PersistentPageMemoryMvPartitionStorage persistentStorage;
+
+    private final FreeList freeList;
+
+    AddWriteLinkingWiInvokeClosure(
+            RowId rowId,
+            @Nullable BinaryRow row,
+            UUID txId,
+            int commitZoneId,
+            int commitPartitionId,
+            PersistentPageMemoryMvPartitionStorage storage
+    ) {
+        super(rowId, row, txId, commitZoneId, commitPartitionId, storage);
+
+        persistentStorage = storage;
+
+        this.freeList = storage.renewableState.freeList();
+    }
+
+    @Override
+    protected RowVersion insertFirstRowVersion() {
+        long wiListHeadLink = persistentStorage.lockWriteIntentListHead();
+        long newWiListHeadLink = wiListHeadLink;
+
+        try {
+            WiLinkableRowVersion newVersion = insertRowVersion(NULL_LINK, 
wiListHeadLink, NULL_LINK);
+
+            newWiListHeadLink = newVersion.link();
+
+            updateWiListLinks(newVersion);

Review Comment:
   > Why do we update links in a linked list if it's a first element?
   
   `updateWiListLinks()` updates links from *other* (existing) WI list elements 
to the one we are adding. We are adding the first element to THIS row, but 
there are other WI list elements which need to be updated (in this case, the 
one that is pointed to by the `head` needs its `prev` link to be updated)
   
   > what would be the difference between first and another insertions
   
   1. With `another` insertion, we set the `nextLink` pointing to the previous 
version of the same row, while with`first` insertion we set it to 0
   2. (this one brings more changes) With `another` insertion, we need to 
handle not just the insertion itself; it might be a replacement instead. This 
requires more code to handle WI list maintenance
   
   > Shouldn't we implement a double-checked locking anyway
   
   I changed the way we take the WI head lock: now it's taken before we make a 
decision whether it's `first` or `another` version addition.
   
   But why are you talking about *double checked* locking?



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