IGNITE-5793 - Fixed infinite TTL expire on cache gateway leave
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/355e8e83 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/355e8e83 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/355e8e83 Branch: refs/heads/ignite-5578 Commit: 355e8e83d0efcc2fcaacc8edc977b82b39c14d4e Parents: 6cff481 Author: Ivan Rakov <[email protected]> Authored: Mon Jul 31 10:37:11 2017 +0300 Committer: Alexey Goncharuk <[email protected]> Committed: Mon Jul 31 10:37:11 2017 +0300 ---------------------------------------------------------------------- .../apache/ignite/IgniteSystemProperties.java | 6 +++++ .../processors/cache/GridCacheUtils.java | 7 +++++- .../cache/IgniteCacheOffheapManagerImpl.java | 26 ++++++++++++-------- 3 files changed, 28 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/355e8e83/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java index 264fb4b..2fa52b6 100644 --- a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java +++ b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java @@ -614,6 +614,12 @@ public final class IgniteSystemProperties { public static final String IGNITE_REBALANCE_STATISTICS_TIME_INTERVAL = "IGNITE_REBALANCE_STATISTICS_TIME_INTERVAL"; /** + * When cache has entries with expired TTL, each user operation will also remove this amount of expired entries. + * Defaults to {@code 5}. + */ + public static final String IGNITE_TTL_EXPIRE_BATCH_SIZE = "IGNITE_TTL_EXPIRE_BATCH_SIZE"; + + /** * Indexing discovery history size. Protects from duplicate messages maintaining the list of IDs of recently * arrived discovery messages. * <p> http://git-wip-us.apache.org/repos/asf/ignite/blob/355e8e83/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java index c93b224..a07b166 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java @@ -42,6 +42,7 @@ import org.apache.ignite.IgniteCache; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteException; import org.apache.ignite.IgniteLogger; +import org.apache.ignite.IgniteSystemProperties; import org.apache.ignite.cache.CacheAtomicUpdateTimeoutException; import org.apache.ignite.cache.CachePartialUpdateException; import org.apache.ignite.cache.CacheServerNotFoundException; @@ -107,6 +108,10 @@ public class GridCacheUtils { /** Cheat cache ID for debugging and benchmarking purposes. */ public static final int cheatCacheId; + /** Each cache operation removes this amount of entries with expired TTL. */ + private static final int TTL_BATCH_SIZE = IgniteSystemProperties.getInteger( + IgniteSystemProperties.IGNITE_TTL_EXPIRE_BATCH_SIZE, 5); + /* * */ @@ -851,7 +856,7 @@ public class GridCacheUtils { public static void unwindEvicts(GridCacheContext ctx) { assert ctx != null; - ctx.ttl().expire(); + ctx.ttl().expire(TTL_BATCH_SIZE); } /** http://git-wip-us.apache.org/repos/asf/ignite/blob/355e8e83/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java index 6d16b60..ba6c89d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java @@ -975,30 +975,35 @@ public class IgniteCacheOffheapManagerImpl implements IgniteCacheOffheapManager assert !cctx.isNear() : cctx.name(); if (hasPendingEntries && pendingEntries != null) { - cctx.shared().database().checkpointReadLock(); - - try { - GridCacheVersion obsoleteVer = null; + GridCacheVersion obsoleteVer = null; - long now = U.currentTimeMillis(); + long now = U.currentTimeMillis(); - GridCursor<PendingRow> cur; + GridCursor<PendingRow> cur; if (grp.sharedGroup()) cur = pendingEntries.find(new PendingRow(cctx.cacheId()), new PendingRow(cctx.cacheId(), now, 0)); else cur = pendingEntries.find(null, new PendingRow(UNDEFINED_CACHE_ID, now, 0)); - int cleared = 0; + if (!cur.next()) + return false; + + int cleared = 0; - while (cur.next()) { + cctx.shared().database().checkpointReadLock(); + + try { + do { PendingRow row = cur.get(); if (amount != -1 && cleared > amount) return true; - if (row.key.partition() == -1) - row.key.partition(cctx.affinity().partition(row.key));assert row.key != null && row.link != 0 && row.expireTime != 0 : row; + if (row.key.partition() == -1) + row.key.partition(cctx.affinity().partition(row.key)); + + assert row.key != null && row.link != 0 && row.expireTime != 0 : row; if (pendingEntries.removex(row)) { if (obsoleteVer == null) @@ -1009,6 +1014,7 @@ public class IgniteCacheOffheapManagerImpl implements IgniteCacheOffheapManager cleared++; } + while (cur.next()); } finally { cctx.shared().database().checkpointReadUnlock();
