ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [1/4] ignite git commit: ignite-db - Fixed clear() and size() methods.
Date Wed, 20 Apr 2016 13:02:19 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-db-x-10884 3e88d8bf8 -> 38ead2a78


ignite-db - Fixed clear() and size() methods.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/b66c1eca
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/b66c1eca
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/b66c1eca

Branch: refs/heads/ignite-db-x-10884
Commit: b66c1ecaa5e1acf3af28e9eda708bca7d7bb46cb
Parents: ddccaaf
Author: Alexey Goncharuk <alexey.goncharuk@gmail.com>
Authored: Tue Apr 12 16:37:56 2016 -0700
Committer: Alexey Goncharuk <alexey.goncharuk@gmail.com>
Committed: Tue Apr 12 16:37:56 2016 -0700

----------------------------------------------------------------------
 .../processors/cache/GridCacheAdapter.java      |  8 +-
 .../cache/GridCacheClearAllRunnable.java        |  3 +
 .../cache/IgniteCacheNoopDatabaseManager.java   |  9 ++
 .../database/IgniteCacheDatabaseManager.java    | 16 +++-
 .../database/IgniteCacheH2DatabaseManager.java  | 89 ++++++++++++++++++++
 .../IgniteDbSingleNodePutGetSelfTest.java       | 37 ++++++++
 6 files changed, 159 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/b66c1eca/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
index 2da297e..03de08f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
@@ -3915,8 +3915,12 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K,
V
             if (modes.swap)
                 size += swapMgr.swapEntriesCount(modes.primary, modes.backup, topVer);
 
-            if (modes.offheap)
-                size += swapMgr.offheapEntriesCount(modes.primary, modes.backup, topVer);
+            if (modes.offheap) {
+                if (ctx.isDatabaseEnabled())
+                    size += ctx.database().entriesCount(modes.primary, modes.backup, topVer);
+                else
+                    size += swapMgr.offheapEntriesCount(modes.primary, modes.backup, topVer);
+            }
         }
 
         return size;

http://git-wip-us.apache.org/repos/asf/ignite/blob/b66c1eca/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheClearAllRunnable.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheClearAllRunnable.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheClearAllRunnable.java
index 77c5a55..a35ca0f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheClearAllRunnable.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheClearAllRunnable.java
@@ -87,6 +87,9 @@ public class GridCacheClearAllRunnable<K, V> implements Runnable {
 
         // Clear swapped entries.
         if (!ctx.isNear()) {
+            if (ctx.isDatabaseEnabled())
+                ctx.database().clear(readers);
+
             if (ctx.swap().offHeapEnabled()) {
                 if (GridQueryProcessor.isEnabled(ctx.config())) {
                     for (Iterator<KeyCacheObject> it =

http://git-wip-us.apache.org/repos/asf/ignite/blob/b66c1eca/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheNoopDatabaseManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheNoopDatabaseManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheNoopDatabaseManager.java
index ed48b40..24db0d0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheNoopDatabaseManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheNoopDatabaseManager.java
@@ -17,11 +17,20 @@
 
 package org.apache.ignite.internal.processors.cache;
 
+import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseManager;
 
 /**
  *
  */
 public class IgniteCacheNoopDatabaseManager extends GridCacheManagerAdapter implements IgniteCacheDatabaseManager
{
+    /** {@inheritDoc} */
+    @Override public void clear(boolean readers) {
+        // No-op.
+    }
 
+    /** {@inheritDoc} */
+    @Override public long entriesCount(boolean primary, boolean backup, AffinityTopologyVersion
topVer) {
+        return 0;
+    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/b66c1eca/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseManager.java
index e38a457..1d0b50a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseManager.java
@@ -17,11 +17,25 @@
 
 package org.apache.ignite.internal.processors.cache.database;
 
+import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.cache.GridCacheManager;
 
 /**
  *
  */
 public interface IgniteCacheDatabaseManager extends GridCacheManager {
-    // No-op.
+    /**
+     * Clears the database entries.
+     *
+     * @param readers {@code True} to clear readers.
+     */
+    public void clear(boolean readers);
+
+    /**
+     * @param primary Include primary node keys.
+     * @param backup Include backup node kets.
+     * @param topVer Topology version.
+     * @return Entries count.
+     */
+    public long entriesCount(boolean primary, boolean backup, AffinityTopologyVersion topVer);
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/b66c1eca/modules/indexing/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheH2DatabaseManager.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheH2DatabaseManager.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheH2DatabaseManager.java
index aad6798..d9135d2 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheH2DatabaseManager.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheH2DatabaseManager.java
@@ -18,14 +18,28 @@
 package org.apache.ignite.internal.processors.cache.database;
 
 import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.internal.pagemem.FullPageId;
+import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
 import org.apache.ignite.internal.processors.cache.GridCacheManagerAdapter;
+import org.apache.ignite.internal.processors.cache.KeyCacheObject;
+import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException;
+import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
 import org.apache.ignite.internal.processors.query.h2.database.BPlusTreeRefIndex;
+import org.apache.ignite.internal.processors.query.h2.opt.GridH2Row;
 import org.apache.ignite.internal.processors.query.h2.opt.GridH2Table;
+import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteBiTuple;
+import org.h2.engine.Session;
+import org.h2.index.Cursor;
 import org.h2.index.Index;
 import org.h2.table.IndexColumn;
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
 /**
  *
  */
@@ -85,4 +99,79 @@ public class IgniteCacheH2DatabaseManager extends GridCacheManagerAdapter
implem
 
         return idx;
     }
+
+    /** {@inheritDoc} */
+    @Override public void clear(boolean readers) {
+        if (primaryIdx == null)
+            throw new IllegalStateException("Primary index should be always created.");
+
+        Cursor cur = primaryIdx.find((Session)null, null, null);
+
+        Collection<KeyCacheObject> keys = new ArrayList<>();
+
+        while (cur.next()) {
+
+            GridH2Row row = (GridH2Row)cur.get();
+
+            try {
+                KeyCacheObject key = row.key instanceof KeyCacheObject ? (KeyCacheObject)row.key
:
+                    cctx.toCacheKeyObject(row.key.valueBytes(cctx.cacheObjectContext()));
+
+                keys.add(key);
+            }
+            catch (IgniteCheckedException e) {
+                U.error(log, "Failed to obtain cache key: " + row.key, e);
+            }
+        }
+
+        GridCacheVersion obsoleteVer = null;
+
+        for (KeyCacheObject key : keys) {
+            try {
+                if (obsoleteVer == null)
+                    obsoleteVer = cctx.versions().next();
+
+                GridCacheEntryEx entry = cctx.cache().entryEx(key);
+
+                entry.clear(obsoleteVer, readers, null);
+            }
+            catch (GridDhtInvalidPartitionException ignore) {
+                // Ignore.
+            }
+            catch (IgniteCheckedException e) {
+                U.error(log, "Failed to clear cache entry: " + key, e);
+            }
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public long entriesCount(boolean primary, boolean backup, AffinityTopologyVersion
topVer) {
+        if (primaryIdx == null)
+            throw new IllegalStateException("Primary index should be always created.");
+
+        Cursor cur = primaryIdx.find((Session)null, null, null);
+
+        ClusterNode locNode = cctx.localNode();
+
+        long cnt = 0;
+
+        while (cur.next()) {
+            GridH2Row row = (GridH2Row)cur.get();
+
+            if (primary) {
+                if (cctx.affinity().primary(locNode, row.key, topVer)) {
+                    cnt++;
+
+                    continue;
+                }
+            }
+
+            if (backup) {
+                if (cctx.affinity().backup(locNode, cctx.affinity().partition(row.key), topVer))
+                    cnt++;
+            }
+        }
+
+        return cnt;
+    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/b66c1eca/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbSingleNodePutGetSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbSingleNodePutGetSelfTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbSingleNodePutGetSelfTest.java
index 575ccaf..ea6c3b6 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbSingleNodePutGetSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/IgniteDbSingleNodePutGetSelfTest.java
@@ -16,6 +16,7 @@ import java.util.Map;
 import java.util.Random;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CachePeekMode;
 import org.apache.ignite.cache.CacheRebalanceMode;
 import org.apache.ignite.cache.CacheWriteSynchronizationMode;
 import org.apache.ignite.cache.query.SqlFieldsQuery;
@@ -270,7 +271,43 @@ public class IgniteDbSingleNodePutGetSelfTest extends GridCommonAbstractTest
{
         assertTrue(plan, plan.contains("iVal_idx"));
     }
 
+    /**
+     * @throws Exception if failed.
+     */
+    public void testSizeClear() throws Exception {
+        IgniteEx ig = grid(0);
+
+        final IgniteCache<Integer, DbValue> cache = ig.cache(null);
+
+        GridCacheAdapter<Object, Object> internalCache = ig.context().cache().internalCache();
+
+        int cnt = 5000;
+
+        X.println("Put start");
+
+        for (int i = 0; i < cnt; i++) {
+            DbValue v0 = new DbValue(i, "test-value", i);
+
+            cache.put(i, v0);
+
+            checkEmpty(internalCache, i);
+
+            assertEquals(v0, cache.get(i));
+        }
+
+        awaitPartitionMapExchange();
 
+        assertEquals(cnt, cache.size(CachePeekMode.OFFHEAP));
+
+        X.println("Clear start.");
+
+        cache.clear();
+
+        assertEquals(0, cache.size(CachePeekMode.OFFHEAP));
+
+        for (int i = 0; i < cnt; i++)
+            assertNull(cache.get(i));
+    }
 
     /**
      * @throws Exception if failed.


Mime
View raw message