tkalkirill commented on code in PR #1673: URL: https://github.com/apache/ignite-3/pull/1673#discussion_r1109529141
########## modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/mv/RemoveWriteOnGcInvokeClosure.java: ########## @@ -0,0 +1,180 @@ +/* + * 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.storage.pagememory.mv.AbstractPageMemoryMvPartitionStorage.ALWAYS_LOAD_VALUE; +import static org.apache.ignite.internal.storage.pagememory.mv.FindRowVersion.RowVersionFilter.equalsByNextLink; +import static org.apache.ignite.internal.storage.pagememory.mv.FindRowVersion.RowVersionFilter.equalsByTimestamp; + +import java.util.List; +import org.apache.ignite.internal.hlc.HybridTimestamp; +import org.apache.ignite.internal.pagememory.tree.BplusTree; +import org.apache.ignite.internal.pagememory.tree.IgniteTree.InvokeClosure; +import org.apache.ignite.internal.pagememory.tree.IgniteTree.OperationType; +import org.apache.ignite.internal.storage.RowId; +import org.apache.ignite.internal.storage.StorageException; +import org.apache.ignite.lang.IgniteInternalCheckedException; +import org.jetbrains.annotations.Nullable; + +/** + * Implementation of {@link InvokeClosure} for deleting a row version in version chain on garbage collection in + * {@link AbstractPageMemoryMvPartitionStorage#pollForVacuum(HybridTimestamp)}. + * + * <p>See {@link AbstractPageMemoryMvPartitionStorage} about synchronization. + * + * <p>Operation may throw {@link StorageException} which will cause form {@link BplusTree#invoke(Object, Object, InvokeClosure)}. + */ +public class RemoveWriteOnGcInvokeClosure implements InvokeClosure<VersionChain> { + private final RowId rowId; + + private final HybridTimestamp timestamp; + + private final AbstractPageMemoryMvPartitionStorage storage; + + private OperationType operationType; + + private @Nullable VersionChain newRow; + + private List<RowVersion> toRemove; + + private RowVersion result; + + private @Nullable RowVersion toUpdate; + + RemoveWriteOnGcInvokeClosure(RowId rowId, HybridTimestamp timestamp, AbstractPageMemoryMvPartitionStorage storage) { + this.rowId = rowId; + this.timestamp = timestamp; + this.storage = storage; + } + + @Override + public void call(@Nullable VersionChain oldRow) throws IgniteInternalCheckedException { + assert oldRow != null : "rowId=" + rowId + ", storage=" + storage.createStorageInfo(); + assert oldRow.hasNextLink() : oldRow; + + RowVersion rowVersion = findRowVersionLinkWithChecks(oldRow); + RowVersion nextRowVersion = storage.readRowVersion(rowVersion.nextLink(), ALWAYS_LOAD_VALUE, true); + + result = nextRowVersion; + + // If the found version is a tombstone, then we must remove it as well. + if (rowVersion.isTombstone()) { + toRemove = List.of(nextRowVersion, rowVersion); + + // If the found version is the head of the chain, then delete the entire chain. + if (oldRow.headLink() == rowVersion.link()) { + operationType = OperationType.REMOVE; + } else if (oldRow.nextLink() == rowVersion.link()) { + operationType = OperationType.PUT; Review Comment: But then **RemoveWriteOnGcInvokeClosure#onUpdate** will not invoke. -- 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]
