From 2a8c1a1fc37fe46c1eead906f36fb2be39f8d9c2 Mon Sep 17 00:00:00 2001 From: Ilya Shishkov Date: Tue, 10 Sep 2024 14:21:29 +0300 Subject: [PATCH] IGNITE-23037 Remove GridDhtUnlockRequest#nearKeys --- .../communication/GridIoMessageFactory.java | 2 - .../dht/GridDhtTransactionalCacheAdapter.java | 22 +-- .../distributed/dht/GridDhtUnlockRequest.java | 160 ------------------ .../near/GridNearTransactionalCache.java | 93 ---------- .../resources/META-INF/classnames.properties | 1 - 5 files changed, 5 insertions(+), 273 deletions(-) delete mode 100644 modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtUnlockRequest.java diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java index bde21451deb69..dbc9d0b81a014 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java @@ -71,7 +71,6 @@ import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxOnePhaseCommitAckRequest; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareRequest; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareResponse; -import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtUnlockRequest; import org.apache.ignite.internal.processors.cache.distributed.dht.PartitionUpdateCountersMessage; import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicDeferredUpdateResponse; import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicNearResponse; @@ -232,7 +231,6 @@ public class GridIoMessageFactory implements MessageFactoryProvider { factory.register((short)33, GridDhtTxFinishResponse::new); factory.register((short)34, GridDhtTxPrepareRequest::new); factory.register((short)35, GridDhtTxPrepareResponse::new); - factory.register((short)36, GridDhtUnlockRequest::new); factory.register((short)37, GridDhtAtomicDeferredUpdateResponse::new); factory.register((short)38, GridDhtAtomicUpdateRequest::new); factory.register((short)39, GridDhtAtomicUpdateResponse::new); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java index 4f19378c1cbf0..ace0fdb382c62 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java @@ -144,8 +144,8 @@ protected GridDhtTransactionalCacheAdapter(GridCacheContext ctx, GridCache ctx.io().addCacheHandler(ctx.cacheId(), ctx.startTopologyVersion(), GridNearUnlockRequest.class, (CI2)this::processNearUnlockRequest); - ctx.io().addCacheHandler(ctx.cacheId(), ctx.startTopologyVersion(), GridDhtUnlockRequest.class, - (CI2)this::processDhtUnlockRequest); + ctx.io().addCacheHandler(ctx.cacheId(), ctx.startTopologyVersion(), GridDistributedUnlockRequest.class, + (CI2)this::processDistributedUnlockRequest); ctx.io().addCacheHandler(ctx.cacheId(), ctx.startTopologyVersion(), GridDhtForceKeysRequest.class, new MessageHandler() { @@ -577,11 +577,8 @@ private void processDhtLockRequest0(UUID nodeId, GridDhtLockRequest req) { * @param nodeId Node ID. * @param req Request. */ - private void processDhtUnlockRequest(UUID nodeId, GridDhtUnlockRequest req) { + private void processDistributedUnlockRequest(UUID nodeId, GridDistributedUnlockRequest req) { clearLocks(nodeId, req); - - if (isNearEnabled(cacheCfg)) - near().clearLocks(nodeId, req); } /** @@ -1668,7 +1665,7 @@ else if (log.isDebugEnabled()) List keyBytes = entry.getValue(); - GridDhtUnlockRequest req = new GridDhtUnlockRequest(ctx.cacheId(), keyBytes.size(), + GridDistributedUnlockRequest req = new GridDistributedUnlockRequest(ctx.cacheId(), keyBytes.size(), ctx.deploymentEnabled()); req.version(dhtVer); @@ -1677,12 +1674,6 @@ else if (log.isDebugEnabled()) for (KeyCacheObject key : keyBytes) req.addKey(key); - keyBytes = nearMap.get(n); - - if (keyBytes != null) - for (KeyCacheObject key : keyBytes) - req.addNearKey(key); - req.completedVersions(committed, rolledback); ctx.io().send(n, req, ctx.ioPolicy()); @@ -1703,15 +1694,12 @@ else if (log.isDebugEnabled()) if (!dhtMap.containsKey(n)) { List keyBytes = entry.getValue(); - GridDhtUnlockRequest req = new GridDhtUnlockRequest(ctx.cacheId(), keyBytes.size(), + GridDistributedUnlockRequest req = new GridDistributedUnlockRequest(ctx.cacheId(), keyBytes.size(), ctx.deploymentEnabled()); req.version(dhtVer); try { - for (KeyCacheObject key : keyBytes) - req.addNearKey(key); - req.completedVersions(committed, rolledback); ctx.io().send(n, req, ctx.ioPolicy()); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtUnlockRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtUnlockRequest.java deleted file mode 100644 index 9dec4122bc655..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtUnlockRequest.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * 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.processors.cache.distributed.dht; - -import java.io.Externalizable; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.List; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.GridDirectCollection; -import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; -import org.apache.ignite.internal.processors.cache.KeyCacheObject; -import org.apache.ignite.internal.processors.cache.distributed.GridDistributedUnlockRequest; -import org.apache.ignite.internal.util.typedef.internal.S; -import org.apache.ignite.plugin.extensions.communication.MessageCollectionItemType; -import org.apache.ignite.plugin.extensions.communication.MessageReader; -import org.apache.ignite.plugin.extensions.communication.MessageWriter; - -/** - * DHT cache unlock request. - */ -public class GridDhtUnlockRequest extends GridDistributedUnlockRequest { - /** */ - private static final long serialVersionUID = 0L; - - /** Near keys. */ - @GridDirectCollection(KeyCacheObject.class) - private List nearKeys; - - /** - * Empty constructor required by {@link Externalizable}. - */ - public GridDhtUnlockRequest() { - // No-op. - } - - /** - * @param cacheId Cache ID. - * @param dhtCnt Key count. - * @param addDepInfo Deployment info flag. - */ - public GridDhtUnlockRequest(int cacheId, int dhtCnt, boolean addDepInfo) { - super(cacheId, dhtCnt, addDepInfo); - } - - /** - * @return Near keys. - */ - public List nearKeys() { - return nearKeys; - } - - /** - * Adds a Near key. - * - * @param key Key. - * @throws IgniteCheckedException If failed. - */ - public void addNearKey(KeyCacheObject key) - throws IgniteCheckedException { - if (nearKeys == null) - nearKeys = new ArrayList<>(); - - nearKeys.add(key); - } - - /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); - - prepareMarshalCacheObjects(nearKeys, ctx.cacheContext(cacheId)); - } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - finishUnmarshalCacheObjects(nearKeys, ctx.cacheContext(cacheId), ldr); - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(GridDhtUnlockRequest.class, this); - } - - /** {@inheritDoc} */ - @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) { - writer.setBuffer(buf); - - if (!super.writeTo(buf, writer)) - return false; - - if (!writer.isHeaderWritten()) { - if (!writer.writeHeader(directType(), fieldsCount())) - return false; - - writer.onHeaderWritten(); - } - - switch (writer.state()) { - case 9: - if (!writer.writeCollection("nearKeys", nearKeys, MessageCollectionItemType.MSG)) - return false; - - writer.incrementState(); - - } - - return true; - } - - /** {@inheritDoc} */ - @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) { - reader.setBuffer(buf); - - if (!reader.beforeMessageRead()) - return false; - - if (!super.readFrom(buf, reader)) - return false; - - switch (reader.state()) { - case 9: - nearKeys = reader.readCollection("nearKeys", MessageCollectionItemType.MSG); - - if (!reader.isLastRead()) - return false; - - reader.incrementState(); - - } - - return reader.afterMessageRead(GridDhtUnlockRequest.class); - } - - /** {@inheritDoc} */ - @Override public short directType() { - return 36; - } - - /** {@inheritDoc} */ - @Override public byte fieldsCount() { - return 10; - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java index f4cdf274b98c0..f8e504d85c59f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java @@ -21,7 +21,6 @@ import java.util.Collection; import java.util.Collections; import java.util.LinkedList; -import java.util.List; import java.util.Map; import java.util.UUID; import org.apache.ignite.IgniteCheckedException; @@ -39,7 +38,6 @@ import org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheEntry; import org.apache.ignite.internal.processors.cache.distributed.GridDistributedUnlockRequest; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCache; -import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtUnlockRequest; import org.apache.ignite.internal.processors.cache.transactions.IgniteTxLocalEx; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; import org.apache.ignite.internal.util.future.GridFinishedFuture; @@ -204,67 +202,6 @@ IgniteInternalFuture> txLoadAsync(GridNearTxLocal tx, return fut; } - /** - * @param nodeId Node ID. - * @param req Request. - */ - public void clearLocks(UUID nodeId, GridDhtUnlockRequest req) { - assert nodeId != null; - - GridCacheVersion obsoleteVer = nextVersion(); - - List keys = req.nearKeys(); - - if (keys != null) { - AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion(); - - for (KeyCacheObject key : keys) { - while (true) { - GridDistributedCacheEntry entry = peekExx(key); - - try { - if (entry != null) { - entry.doneRemote( - req.version(), - req.version(), - null, - req.committedVersions(), - req.rolledbackVersions(), - /*system invalidate*/false); - - // Note that we don't reorder completed versions here, - // as there is no point to reorder relative to the version - // we are about to remove. - if (entry.removeLock(req.version())) { - if (log.isDebugEnabled()) - log.debug("Removed lock [lockId=" + req.version() + ", key=" + key + ']'); - - // Try to evict near entry dht-mapped locally. - evictNearEntry(entry, obsoleteVer, topVer); - } - else { - if (log.isDebugEnabled()) - log.debug("Received unlock request for unknown candidate " + - "(added to cancelled locks set): " + req); - } - - entry.touch(); - } - else if (log.isDebugEnabled()) - log.debug("Received unlock request for entry that could not be found: " + req); - - break; - } - catch (GridCacheEntryRemovedException ignored) { - if (log.isDebugEnabled()) - log.debug("Received remove lock request for removed entry (will retry) [entry=" + entry + - ", req=" + req + ']'); - } - } - } - } - } - /** * @param nodeId Node ID. * @param res Response. @@ -311,36 +248,6 @@ private void processLockResponse(UUID nodeId, GridNearLockResponse res) { return fut; } - /** - * @param e Transaction entry. - * @param topVer Topology version. - * @return {@code True} if entry is locally mapped as a primary or back up node. - */ - protected boolean isNearLocallyMapped(GridCacheEntryEx e, AffinityTopologyVersion topVer) { - return ctx.affinity().partitionBelongs(ctx.localNode(), e.partition(), topVer); - } - - /** - * - * @param e Entry to evict if it qualifies for eviction. - * @param obsoleteVer Obsolete version. - * @param topVer Topology version. - * @return {@code True} if attempt was made to evict the entry. - */ - protected boolean evictNearEntry(GridCacheEntryEx e, GridCacheVersion obsoleteVer, AffinityTopologyVersion topVer) { - assert e != null; - assert obsoleteVer != null; - - if (isNearLocallyMapped(e, topVer)) { - if (log.isDebugEnabled()) - log.debug("Evicting dht-local entry from near cache [entry=" + e + ", tx=" + this + ']'); - - return e.markObsolete(obsoleteVer); - } - - return false; - } - /** {@inheritDoc} */ @Override public void unlockAll(Collection keys) { if (keys.isEmpty()) diff --git a/modules/core/src/main/resources/META-INF/classnames.properties b/modules/core/src/main/resources/META-INF/classnames.properties index 63d8fd49495ba..2d3bacfac066d 100644 --- a/modules/core/src/main/resources/META-INF/classnames.properties +++ b/modules/core/src/main/resources/META-INF/classnames.properties @@ -918,7 +918,6 @@ org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareFutu org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareFuture$4 org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareRequest org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareResponse -org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtUnlockRequest org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtUnreservedPartitionException org.apache.ignite.internal.processors.cache.distributed.dht.GridPartitionedGetFuture$1 org.apache.ignite.internal.processors.cache.distributed.dht.GridPartitionedSingleGetFuture$1