ibessonov commented on code in PR #7019: URL: https://github.com/apache/ignite-3/pull/7019#discussion_r2579953670
########## 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: > But why are you talking about double checked locking? Because it immediately produces a certain image and a certain type of data race in your hear :) "just a single lock" is enough here -- 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]
