IGNITE-8110 GridCacheWriteBehindStore.Flusher thread uses the wrong transformation from milliseconds to nanoseconds. - Fixes #3742.
Signed-off-by: dpavlov <dpav...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/adaedb44 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/adaedb44 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/adaedb44 Branch: refs/heads/ignite-7708 Commit: adaedb44b767da49c4ec6c57c655b13caa3edd35 Parents: 47ca3e0 Author: Anton Kurbanov <antkr....@gmail.com> Authored: Thu Apr 12 20:31:50 2018 +0300 Committer: dpavlov <dpav...@apache.org> Committed: Thu Apr 12 20:31:50 2018 +0300 ---------------------------------------------------------------------- .../cache/store/GridCacheWriteBehindStore.java | 2 +- .../GridCacheWriteBehindStoreSelfTest.java | 41 +++++++++++++++++++- 2 files changed, 40 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/adaedb44/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/store/GridCacheWriteBehindStore.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/store/GridCacheWriteBehindStore.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/store/GridCacheWriteBehindStore.java index 44cadd6..82ff3aa 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/store/GridCacheWriteBehindStore.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/store/GridCacheWriteBehindStore.java @@ -895,7 +895,7 @@ public class GridCacheWriteBehindStore<K, V> implements CacheStore<K, V>, Lifecy protected Thread thread; /** Cache flushing frequence in nanos. */ - protected long cacheFlushFreqNanos = cacheFlushFreq * 1000; + protected long cacheFlushFreqNanos = cacheFlushFreq * 1000 * 1000; /** Writer lock. */ private final Lock flusherWriterLock = new ReentrantLock(); http://git-wip-us.apache.org/repos/asf/ignite/blob/adaedb44/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/store/GridCacheWriteBehindStoreSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/store/GridCacheWriteBehindStoreSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/store/GridCacheWriteBehindStoreSelfTest.java index 9a487a4..af21fc8 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/store/GridCacheWriteBehindStoreSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/store/GridCacheWriteBehindStoreSelfTest.java @@ -107,6 +107,43 @@ public class GridCacheWriteBehindStoreSelfTest extends GridCacheWriteBehindStore } /** + * Checks that write behind cache flush frequency was correctly adjusted to nanos expecting putAllCnt to be + * less or equal than elapsed time divided by flush frequency. + * + * @throws Exception If failed. + */ + public void testSimpleStoreFlushFrequencyWithoutCoalescing() throws Exception { + initStore(1, false); + + long writeBehindFlushFreqNanos = FLUSH_FREQUENCY * 1000 * 1000; + + int threshold = store.getWriteBehindStoreBatchSize() / 10; + + try { + long start = System.nanoTime(); + + for (int i = 0; i < threshold / 2; i++) + store.write(new CacheEntryImpl<>(i, "v" + i)); + + U.sleep(FLUSH_FREQUENCY + 300); + + for (int i = threshold / 2; i < threshold; i++) + store.write(new CacheEntryImpl<>(i, "v" + i)); + + long elapsed = System.nanoTime() - start; + + U.sleep(FLUSH_FREQUENCY + 300); + + int expFlushOps = (int)(1 + elapsed / writeBehindFlushFreqNanos); + + assertTrue(delegate.getPutAllCount() <= expFlushOps); + } + finally { + shutdownStore(); + } + } + + /** * Simple store test. * * @param writeCoalescing Write coalescing flag. @@ -254,7 +291,6 @@ public class GridCacheWriteBehindStoreSelfTest extends GridCacheWriteBehindStore int delegatePutCnt = delegate.getPutAllCount(); - fut.get(); log().info(">>> [putCnt = " + actualPutCnt.get() + ", delegatePutCnt=" + delegatePutCnt + "]"); @@ -262,7 +298,8 @@ public class GridCacheWriteBehindStoreSelfTest extends GridCacheWriteBehindStore assertTrue("No puts were made to the underlying store", delegatePutCnt > 0); if (store.getWriteCoalescing()) { assertTrue("Too many puts were made to the underlying store", delegatePutCnt < actualPutCnt.get() / 10); - } else { + } + else { assertTrue("Too few puts cnt=" + actualPutCnt.get() + " << storePutCnt=" + delegatePutCnt, delegatePutCnt > actualPutCnt.get() / 2); } }