ignite-4535 : Removed redundant code related to synchronous evictions.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/ea64bdd8 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/ea64bdd8 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/ea64bdd8 Branch: refs/heads/ignite-3477-master Commit: ea64bdd8ab4d87cad8c0c018bd9ea437a15e33a8 Parents: d433800 Author: Ilya Lantukh <[email protected]> Authored: Fri Apr 7 15:33:42 2017 +0300 Committer: Ilya Lantukh <[email protected]> Committed: Fri Apr 7 15:33:42 2017 +0300 ---------------------------------------------------------------------- .../communication/GridIoMessageFactory.java | 12 - .../cache/GridCacheEvictionManager.java | 226 ----------------- .../cache/GridCacheEvictionRequest.java | 248 ------------------- .../cache/GridCacheEvictionResponse.java | 225 ----------------- .../processors/cache/GridCacheIoManager.java | 14 -- 5 files changed, 725 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/ea64bdd8/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.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 ac3858c..8488d70 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 @@ -45,8 +45,6 @@ import org.apache.ignite.internal.processors.cache.CacheInvokeDirectResult; import org.apache.ignite.internal.processors.cache.CacheObjectByteArrayImpl; import org.apache.ignite.internal.processors.cache.CacheObjectImpl; import org.apache.ignite.internal.processors.cache.GridCacheEntryInfo; -import org.apache.ignite.internal.processors.cache.GridCacheEvictionRequest; -import org.apache.ignite.internal.processors.cache.GridCacheEvictionResponse; import org.apache.ignite.internal.processors.cache.GridCacheReturn; import org.apache.ignite.internal.processors.cache.KeyCacheObjectImpl; import org.apache.ignite.internal.processors.cache.binary.MetadataRequestMessage; @@ -371,16 +369,6 @@ public class GridIoMessageFactory implements MessageFactory { break; - case 14: - msg = new GridCacheEvictionRequest(); - - break; - - case 15: - msg = new GridCacheEvictionResponse(); - - break; - case 16: msg = new GridCacheTxRecoveryRequest(); http://git-wip-us.apache.org/repos/asf/ignite/blob/ea64bdd8/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java index 27d628b..b9b78cd 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java @@ -101,9 +101,6 @@ import static org.jsr166.ConcurrentLinkedDeque8.Node; * TODO GG-11140 (old evictions implementation, now created for near cache, evictions to be reconsidered as part of GG-11140). */ public class GridCacheEvictionManager extends GridCacheManagerAdapter implements CacheEvictionManager { - /** Attribute name used to queue node in entry metadata. */ - private static final int META_KEY = GridMetadataAwareAdapter.EntryKey.CACHE_EVICTION_MANAGER_KEY.key(); - /** Eviction policy. */ private EvictionPolicy plc; @@ -170,144 +167,6 @@ public class GridCacheEvictionManager extends GridCacheManagerAdapter implements } /** - * @param nodeId Node ID. - * @param res Response. - */ - private void sendEvictionResponse(UUID nodeId, GridCacheEvictionResponse res) { - try { - cctx.io().send(nodeId, res, cctx.ioPolicy()); - - if (log.isDebugEnabled()) - log.debug("Sent eviction response [node=" + nodeId + ", localNode=" + cctx.nodeId() + - ", res" + res + ']'); - } - catch (ClusterTopologyCheckedException ignored) { - if (log.isDebugEnabled()) - log.debug("Failed to send eviction response since initiating node left grid " + - "[node=" + nodeId + ", localNode=" + cctx.nodeId() + ']'); - } - catch (IgniteCheckedException e) { - U.error(log, "Failed to send eviction response to node [node=" + nodeId + - ", localNode=" + cctx.nodeId() + ", res" + res + ']', e); - } - } - - /** - * @param key Key. - * @param ver Version. - * @param p Partition ID. - */ - private void saveEvictionInfo(KeyCacheObject key, GridCacheVersion ver, int p) { - assert cctx.rebalanceEnabled(); - - if (!cctx.isNear()) { - try { - GridDhtLocalPartition part = cctx.dht().topology().localPartition(p, - AffinityTopologyVersion.NONE, false); - - assert part != null; - - part.onEntryEvicted(key, ver); - } - catch (GridDhtInvalidPartitionException ignored) { - if (log.isDebugEnabled()) - log.debug("Partition does not belong to local node [part=" + p + - ", nodeId" + cctx.localNode().id() + ']'); - } - } - else - assert false : "Failed to save eviction info: " + cctx.namexx(); - } - - /** - * @param p Partition ID. - * @return {@code True} if partition has been actually locked, - * {@code false} if preloading is finished or disabled and no lock is needed. - */ - private boolean lockPartition(int p) { - if (!cctx.rebalanceEnabled()) - return false; - - if (!cctx.isNear()) { - try { - GridDhtLocalPartition part = cctx.dht().topology().localPartition(p, AffinityTopologyVersion.NONE, - false); - - if (part != null && part.reserve()) { - part.lock(); - - if (part.state() != MOVING) { - part.unlock(); - - part.release(); - - return false; - } - - return true; - } - } - catch (GridDhtInvalidPartitionException ignored) { - if (log.isDebugEnabled()) - log.debug("Partition does not belong to local node [part=" + p + - ", nodeId" + cctx.localNode().id() + ']'); - } - } - - // No lock is needed. - return false; - } - - /** - * @param p Partition ID. - */ - private void unlockPartition(int p) { - if (!cctx.rebalanceEnabled()) - return; - - if (!cctx.isNear()) { - try { - GridDhtLocalPartition part = cctx.dht().topology().localPartition(p, AffinityTopologyVersion.NONE, - false); - - if (part != null) { - part.unlock(); - - part.release(); - } - } - catch (GridDhtInvalidPartitionException ignored) { - if (log.isDebugEnabled()) - log.debug("Partition does not belong to local node [part=" + p + - ", nodeId" + cctx.localNode().id() + ']'); - } - } - } - - /** - * Locks topology (for DHT cache only) and returns its version. - * - * @return Topology version after lock. - */ - private AffinityTopologyVersion lockTopology() { - if (!cctx.isNear()) { - cctx.dht().topology().readLock(); - - return cctx.dht().topology().topologyVersion(); - } - - return AffinityTopologyVersion.ZERO; - } - - /** - * Unlocks topology. - */ - private void unlockTopology() { - if (!cctx.isNear()) - cctx.dht().topology().readUnlock(); - } - - /** * @param cache Cache from which to evict entry. * @param entry Entry to evict. * @param obsoleteVer Obsolete version. @@ -553,28 +412,6 @@ public class GridCacheEvictionManager extends GridCacheManagerAdapter implements } /** - * @param info Eviction info. - * @return Version aware filter. - */ - private CacheEntryPredicate[] versionFilter(final EvictionInfo info) { - // If version has changed since we started the whole process - // then we should not evict entry. - return new CacheEntryPredicate[] { - new CacheEntryPredicateAdapter() { - @Override public boolean apply(GridCacheEntryEx e) { - try { - GridCacheVersion ver = e.version(); - - return info.version().equals(ver) && F.isAll(info.filter()); - } - catch (GridCacheEntryRemovedException ignored) { - return false; - } - } - }}; - } - - /** * @param e Entry to notify eviction policy. */ @SuppressWarnings({"IfMayBeConditional", "RedundantIfStatement"}) @@ -590,73 +427,10 @@ public class GridCacheEvictionManager extends GridCacheManagerAdapter implements plc.onEntryAccessed(e.obsoleteOrDeleted(), e.wrapEviction()); } - /** - * Prints out eviction stats. - */ - public void printStats() { - X.println("Eviction stats [igniteInstanceName=" + cctx.igniteInstanceName() + - ", cache=" + cctx.cache().name() + ']'); - } - /** {@inheritDoc} */ @Override public void printMemoryStats() { X.println(">>> "); X.println(">>> Eviction manager memory stats [igniteInstanceName=" + cctx.igniteInstanceName() + ", cache=" + cctx.name() + ']'); } - - /** - * Wrapper around an entry to be put into queue. - */ - private class EvictionInfo { - /** Cache entry. */ - private GridCacheEntryEx entry; - - /** Start version. */ - private GridCacheVersion ver; - - /** Filter to pass before entry will be evicted. */ - private CacheEntryPredicate[] filter; - - /** - * @param entry Entry. - * @param ver Version. - * @param filter Filter. - */ - EvictionInfo(GridCacheEntryEx entry, GridCacheVersion ver, - CacheEntryPredicate[] filter) { - assert entry != null; - assert ver != null; - - this.entry = entry; - this.ver = ver; - this.filter = filter; - } - - /** - * @return Entry. - */ - GridCacheEntryEx entry() { - return entry; - } - - /** - * @return Version. - */ - GridCacheVersion version() { - return ver; - } - - /** - * @return Filter. - */ - CacheEntryPredicate[] filter() { - return filter; - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(EvictionInfo.class, this); - } - } } http://git-wip-us.apache.org/repos/asf/ignite/blob/ea64bdd8/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionRequest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionRequest.java deleted file mode 100644 index cb454f8..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionRequest.java +++ /dev/null @@ -1,248 +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; - -import java.io.Externalizable; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.Collection; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.GridDirectCollection; -import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; -import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; -import org.apache.ignite.internal.util.tostring.GridToStringInclude; -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; -import org.jetbrains.annotations.NotNull; - -/** - * Cache eviction request. - */ -public class GridCacheEvictionRequest extends GridCacheMessage implements GridCacheDeployable { - /** */ - private static final long serialVersionUID = 0L; - - /** Future id. */ - private long futId; - - /** Entries to clear from near and backup nodes. */ - @GridToStringInclude - @GridDirectCollection(CacheEvictionEntry.class) - private Collection<CacheEvictionEntry> entries; - - /** Topology version. */ - private AffinityTopologyVersion topVer; - - /** - * Required by {@link Externalizable}. - */ - public GridCacheEvictionRequest() { - // No-op. - } - - /** - * @param cacheId Cache ID. - * @param futId Future id. - * @param size Size. - * @param topVer Topology version. - * @param addDepInfo Deployment info flag. - */ - GridCacheEvictionRequest(int cacheId, long futId, int size, @NotNull AffinityTopologyVersion topVer, - boolean addDepInfo) { - assert futId > 0; - assert size > 0; - assert topVer.topologyVersion() > 0; - - this.cacheId = cacheId; - this.futId = futId; - this.addDepInfo = addDepInfo; - - entries = new ArrayList<>(size); - - this.topVer = topVer; - } - - /** {@inheritDoc} - * @param ctx*/ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); - - if (entries != null) { - GridCacheContext cctx = ctx.cacheContext(cacheId); - - for (CacheEvictionEntry e : entries) { - e.prepareMarshal(cctx); - - if (addDepInfo) - prepareObject(e.key().value(cctx.cacheObjectContext(), false), cctx); - } - } - } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - if (entries != null) { - GridCacheContext cctx = ctx.cacheContext(cacheId); - - for (CacheEvictionEntry e : entries) - e.finishUnmarshal(cctx, ldr); - } - } - - /** {@inheritDoc} */ - @Override public boolean addDeploymentInfo() { - return addDepInfo; - } - - /** - * @return Future id. - */ - long futureId() { - return futId; - } - - /** - * @return Entries - {{Key, Version, Boolean (near or not)}, ...}. - */ - Collection<CacheEvictionEntry> entries() { - return entries; - } - - /** - * @return Topology version. - */ - @Override public AffinityTopologyVersion topologyVersion() { - return topVer; - } - - /** - * Add key to request. - * - * @param key Key to evict. - * @param ver Entry version. - * @param near {@code true} if key should be evicted from near cache. - */ - void addKey(KeyCacheObject key, GridCacheVersion ver, boolean near) { - assert key != null; - assert ver != null; - - entries.add(new CacheEvictionEntry(key, ver, near)); - } - - /** {@inheritDoc} */ - @Override public boolean ignoreClassErrors() { - return true; - } - - /** {@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 3: - if (!writer.writeCollection("entries", entries, MessageCollectionItemType.MSG)) - return false; - - writer.incrementState(); - - case 4: - if (!writer.writeLong("futId", futId)) - return false; - - writer.incrementState(); - - case 5: - if (!writer.writeMessage("topVer", topVer)) - 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 3: - entries = reader.readCollection("entries", MessageCollectionItemType.MSG); - - if (!reader.isLastRead()) - return false; - - reader.incrementState(); - - case 4: - futId = reader.readLong("futId"); - - if (!reader.isLastRead()) - return false; - - reader.incrementState(); - - case 5: - topVer = reader.readMessage("topVer"); - - if (!reader.isLastRead()) - return false; - - reader.incrementState(); - - } - - return reader.afterMessageRead(GridCacheEvictionRequest.class); - } - - /** {@inheritDoc} */ - @Override public short directType() { - return 14; - } - - /** {@inheritDoc} */ - @Override public byte fieldsCount() { - return 6; - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(GridCacheEvictionRequest.class, this); - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/ea64bdd8/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionResponse.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionResponse.java deleted file mode 100644 index 69ec09f..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionResponse.java +++ /dev/null @@ -1,225 +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; - -import java.io.Externalizable; -import java.nio.ByteBuffer; -import java.util.Collection; -import java.util.HashSet; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.GridDirectCollection; -import org.apache.ignite.internal.util.tostring.GridToStringInclude; -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; - -/** - * Cache eviction response. - */ -public class GridCacheEvictionResponse extends GridCacheMessage { - /** */ - private static final long serialVersionUID = 0L; - - /** Future ID. */ - private long futId; - - /** Rejected keys. */ - @GridToStringInclude - @GridDirectCollection(KeyCacheObject.class) - private Collection<KeyCacheObject> rejectedKeys = new HashSet<>(); - - /** Flag to indicate whether request processing has finished with error. */ - private boolean err; - - /** - * Required by {@link Externalizable}. - */ - public GridCacheEvictionResponse() { - // No-op. - } - - /** - * @param cacheId Cache ID. - * @param futId Future ID. - */ - GridCacheEvictionResponse(int cacheId, long futId) { - this(cacheId, futId, false); - } - - /** - * @param cacheId Cache ID. - * @param futId Future ID. - * @param err {@code True} if request processing has finished with error. - */ - GridCacheEvictionResponse(int cacheId, long futId, boolean err) { - this.cacheId = cacheId; - this.futId = futId; - this.err = err; - } - - /** {@inheritDoc} - * @param ctx*/ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); - - prepareMarshalCacheObjects(rejectedKeys, ctx.cacheContext(cacheId)); - } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - finishUnmarshalCacheObjects(rejectedKeys, ctx.cacheContext(cacheId), ldr); - } - - /** {@inheritDoc} */ - @Override public boolean addDeploymentInfo() { - return false; - } - - /** - * @return Future ID. - */ - long futureId() { - return futId; - } - - /** - * @return Rejected keys. - */ - Collection<KeyCacheObject> rejectedKeys() { - return rejectedKeys; - } - - /** - * Add rejected key to response. - * - * @param key Evicted key. - */ - void addRejected(KeyCacheObject key) { - assert key != null; - - rejectedKeys.add(key); - } - - /** - * @return {@code True} if request processing has finished with error. - */ - boolean evictError() { - return err; - } - - /** {@inheritDoc} */ - @Override public boolean ignoreClassErrors() { - return true; - } - - /** {@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 3: - if (!writer.writeBoolean("err", err)) - return false; - - writer.incrementState(); - - case 4: - if (!writer.writeLong("futId", futId)) - return false; - - writer.incrementState(); - - case 5: - if (!writer.writeCollection("rejectedKeys", rejectedKeys, 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 3: - err = reader.readBoolean("err"); - - if (!reader.isLastRead()) - return false; - - reader.incrementState(); - - case 4: - futId = reader.readLong("futId"); - - if (!reader.isLastRead()) - return false; - - reader.incrementState(); - - case 5: - rejectedKeys = reader.readCollection("rejectedKeys", MessageCollectionItemType.MSG); - - if (!reader.isLastRead()) - return false; - - reader.incrementState(); - - } - - return reader.afterMessageRead(GridCacheEvictionResponse.class); - } - - /** {@inheritDoc} */ - @Override public short directType() { - return 15; - } - - /** {@inheritDoc} */ - @Override public byte fieldsCount() { - return 6; - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(GridCacheEvictionResponse.class, this); - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/ea64bdd8/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java index 99878ec..fdd29e4 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java @@ -523,20 +523,6 @@ public class GridCacheIoManager extends GridCacheSharedManagerAdapter { GridCacheContext ctx = cctx.cacheContext(msg.cacheId()); switch (msg.directType()) { - case 14: { - GridCacheEvictionRequest req = (GridCacheEvictionRequest)msg; - - GridCacheEvictionResponse res = new GridCacheEvictionResponse( - ctx.cacheId(), - req.futureId(), - req.classError() != null - ); - - sendResponseOnFailedMessage(nodeId, res, cctx, ctx.ioPolicy()); - } - - break; - case 30: { GridDhtLockRequest req = (GridDhtLockRequest)msg;
