# ignite-1175: call 'onDeferredDelete' from innerRemover
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
index 4680994..a078bed 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
@@ -1232,7 +1232,9 @@
if (writeThrough)
cctx.store().remove(tx, keyValue(false));
- if (!cctx.deferredDelete()) {
+ if (cctx.deferredDelete() && !detached() && !isInternal())
+ cctx.onDeferredDelete(this, newVer);
+ else {
boolean marked = false;
synchronized (this) {
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheDhtLocalPartitionAfterRemoveSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheDhtLocalPartitionAfterRemoveSelfTest.java
new file mode 100644
index 0000000..a930d35
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheDhtLocalPartitionAfterRemoveSelfTest.java
@@ -0,0 +1,112 @@
+/*
+ * 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 org.apache.ignite.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.processors.cache.distributed.dht.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.*;
+
+/**
+ * Test for remove operation.
+ */
+public class CacheDhtLocalPartitionAfterRemoveSelfTest extends GridCommonAbstractTest {
+ /** Grid count. */
+ private static final int GRID_CNT = 3;
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ CacheConfiguration ccfg = new CacheConfiguration();
+
+ ccfg.setAtomicityMode(TRANSACTIONAL);
+ ccfg.setNearConfiguration(null);
+
+ cfg.setCacheConfiguration(ccfg);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ startGrids(GRID_CNT);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testMemoryUsage() throws Exception {
+ assertEquals(10_000, GridDhtLocalPartition.MAX_DELETE_QUEUE_SIZE);
+
+ IgniteCache<TestKey, Integer> cache = grid(0).cache(null);
+
+ for (int i = 0; i < 20_000; ++i)
+ cache.put(new TestKey(String.valueOf(i)), i);
+
+ for (int i = 0; i < 20_000; ++i)
+ assertEquals((Object)i, cache.getAndRemove(new TestKey(String.valueOf(i))));
+
+ assertEquals(0, cache.size());
+
+ for (int g = 0; g < GRID_CNT; g++) {
+ cache = grid(g).cache(null);
+
+ for (GridDhtLocalPartition p : dht(cache).topology().localPartitions()) {
+ int size = p.size();
+
+ assertTrue("Unexpected size: " + size, size <= 32);
+ }
+ }
+ }
+
+ /**
+ * Test key.
+ */
+ private static class TestKey {
+ /** Key. */
+ private String key;
+
+ /**
+ * @param key Key.
+ */
+ public TestKey(String key) {
+ this.key = key;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return key.hashCode();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object obj) {
+ if (obj == null || !(obj instanceof TestKey))
+ return false;
+
+ return key.equals(((TestKey)obj).key);
+ }
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java
index bf760f5..dcbab07 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java
@@ -98,6 +98,7 @@
suite.addTest(new TestSuite(GridCacheDhtPreloadPutGetSelfTest.class));
suite.addTest(new TestSuite(GridCacheDhtPreloadDisabledSelfTest.class));
suite.addTest(new TestSuite(GridCacheDhtPreloadMultiThreadedSelfTest.class));
+ suite.addTest(new TestSuite(CacheDhtLocalPartitionAfterRemoveSelfTest.class));
suite.addTest(new TestSuite(GridCacheColocatedPreloadRestartSelfTest.class));
suite.addTest(new TestSuite(GridCacheNearPreloadRestartSelfTest.class));
suite.addTest(new TestSuite(GridCacheDhtPreloadStartStopSelfTest.class));