Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-629 520eef1c5 -> b1faf559f


#ignite-629: revert CacheFlag.SYNC_COMMIT and CacheFlag.INVALIDATE.


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

Branch: refs/heads/ignite-629
Commit: b1faf559fd6bf18dd7b8eac0f1f2e24f101e63e4
Parents: 520eef1
Author: ivasilinets <ivasilin...@gridgain.com>
Authored: Fri Mar 27 17:40:01 2015 +0300
Committer: ivasilinets <ivasilin...@gridgain.com>
Committed: Fri Mar 27 17:40:01 2015 +0300

----------------------------------------------------------------------
 .../internal/processors/cache/CacheFlag.java    | 15 ++-
 .../processors/cache/GridCacheAdapter.java      | 13 ++-
 .../processors/cache/GridCacheContext.java      |  4 +-
 .../cache/GridCacheSharedContext.java           |  6 ++
 .../handlers/cache/GridCacheCommandHandler.java |  6 ++
 .../cache/GridCacheAbstractFlagsTest.java       | 97 ++++++++++++++++++++
 .../near/GridCachePartitionedFlagsTest.java     | 41 +++++++++
 .../GridCacheReplicatedFlagsTest.java           | 28 ++++++
 8 files changed, 204 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b1faf559/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheFlag.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheFlag.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheFlag.java
index ba026a6..6744d76 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheFlag.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheFlag.java
@@ -47,7 +47,20 @@ public enum CacheFlag {
     SKIP_STORE,
 
     /** Skip swap space for reads and writes. */
-    SKIP_SWAP;
+    SKIP_SWAP,
+
+    /** Synchronous commit. */
+    SYNC_COMMIT,
+
+    /**
+     * Switches a cache projection to work in {@code 'invalidation'} mode.
+     * Instead of updating remote entries with new values, small invalidation
+     * messages will be sent to set the values to {@code null}.
+     *
+     * @see Transaction#isInvalidate()
+     * @see org.apache.ignite.configuration.CacheConfiguration#isInvalidate()
+     */
+    INVALIDATE;
 
     /** */
     private static final CacheFlag[] VALS = values();

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b1faf559/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 7f6be72..492c07a 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
@@ -4448,13 +4448,16 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
                 OPTIMISTIC,
                 READ_COMMITTED,
                 tCfg.getDefaultTxTimeout(),
-                false,
+                ctx.hasFlag(INVALIDATE),
                 !ctx.hasFlag(SKIP_STORE),
                 0,
                 /** group lock keys */null,
                 /** partition lock */false
             );
 
+            if (ctx.hasFlag(SYNC_COMMIT))
+                tx.syncCommit(true);
+
             assert tx != null;
 
             try {
@@ -4512,7 +4515,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
 
         IgniteTxLocalAdapter tx = ctx.tm().threadLocalTx(ctx);
 
-        if (tx == null || tx.implicit())
+        if (tx == null || tx.implicit()) {
             tx = ctx.tm().newTx(
                 true,
                 op.single(),
@@ -4520,12 +4523,16 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
                 OPTIMISTIC,
                 READ_COMMITTED,
                 
ctx.kernalContext().config().getTransactionConfiguration().getDefaultTxTimeout(),
-                false,
+                ctx.hasFlag(INVALIDATE),
                 !ctx.hasFlag(SKIP_STORE),
                 0,
                 null,
                 false);
 
+            if (ctx.hasFlag(SYNC_COMMIT))
+                tx.syncCommit(true);
+        }
+
         return asyncOp(tx, op);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b1faf559/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
index fe836be..5cdefcf 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
@@ -1524,14 +1524,14 @@ public class GridCacheContext<K, V> implements 
Externalizable {
      * @return {@code True} if invalidation is enabled.
      */
     public boolean isInvalidate() {
-        return cacheCfg.isInvalidate();
+        return cacheCfg.isInvalidate() || hasFlag(INVALIDATE);
     }
 
     /**
      * @return {@code True} if synchronous commit is enabled.
      */
     public boolean syncCommit() {
-        return cacheCfg.getWriteSynchronizationMode() == FULL_SYNC;
+        return cacheCfg.getWriteSynchronizationMode() == FULL_SYNC || 
hasFlag(SYNC_COMMIT);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b1faf559/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSharedContext.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSharedContext.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSharedContext.java
index 449dc63..382c6be 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSharedContext.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSharedContext.java
@@ -463,6 +463,12 @@ public class GridCacheSharedContext<K, V> {
             return;
 
         assert flags != null;
+
+        if (flags.contains(INVALIDATE) && !tx.isInvalidate())
+            throw new CacheFlagException(INVALIDATE);
+
+        if (flags.contains(SYNC_COMMIT) && !tx.syncCommit())
+            throw new CacheFlagException(SYNC_COMMIT);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b1faf559/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
index d9330b0..af373a4 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
@@ -114,6 +114,12 @@ public class GridCacheCommandHandler extends 
GridRestCommandHandlerAdapter {
         if ((cacheFlagsBits & (1 << 1)) != 0)
             flagSet.add(CacheFlag.SKIP_SWAP);
 
+        if ((cacheFlagsBits & (1 << 4)) != 0)
+            flagSet.add(CacheFlag.INVALIDATE);
+
+        if ((cacheFlagsBits & (1 << 2)) != 0)
+            flagSet.add(CacheFlag.SYNC_COMMIT);
+
         return flagSet.toArray(new CacheFlag[flagSet.size()]);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b1faf559/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFlagsTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFlagsTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFlagsTest.java
new file mode 100644
index 0000000..72a8cfe
--- /dev/null
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFlagsTest.java
@@ -0,0 +1,97 @@
+/*
+ * 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.cache.*;
+import org.apache.ignite.cache.store.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.*;
+
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.*;
+
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*;
+
+/**
+ * Tests cache flags.
+ */
+public abstract class GridCacheAbstractFlagsTest extends 
GridCacheAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 6;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheWriteSynchronizationMode writeSynchronization() {
+        return FULL_ASYNC;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheConfiguration cacheConfiguration(String gridName) 
throws Exception {
+        CacheConfiguration c = super.cacheConfiguration(gridName);
+
+        if (cacheMode() == CacheMode.PARTITIONED)
+            c.setBackups(1);
+
+        c.setCacheStoreFactory(null);
+
+        return c;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean swapEnabled() {
+        return false;
+    }
+
+    /**
+     * Tests SYNC_COMMIT cache flag.
+     *
+     * @throws Exception If failed.
+     */
+    public void testTestSyncCommitFlag() throws Exception {
+        for (int i = 0; i < 10; i++) {
+            final String key = "k" + i;
+            final Integer val = i;
+
+            final CountDownLatch l = new CountDownLatch(1);
+
+            final AtomicInteger cntr = new AtomicInteger();
+
+            IgniteInternalFuture<?> f = multithreadedAsync(new Callable() {
+                @Override public Object call() throws Exception {
+                    int idx = cntr.getAndIncrement() % gridCount();
+
+                    IgniteCache<String, Integer> c = jcache(idx);
+
+                    l.await();
+
+                    assertEquals(val, c.get(key));
+
+                    return null;
+                }
+            }, gridCount() * 3);
+
+            
((IgniteCacheProxy)jcache(0)).flagOn(CacheFlag.SYNC_COMMIT).put(key, val);
+
+            l.countDown();
+
+            f.get();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b1faf559/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedFlagsTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedFlagsTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedFlagsTest.java
new file mode 100644
index 0000000..d68f476
--- /dev/null
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedFlagsTest.java
@@ -0,0 +1,41 @@
+/*
+ * 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.distributed.near;
+
+import org.apache.ignite.cache.*;
+import org.apache.ignite.internal.processors.cache.*;
+
+import java.text.*;
+import java.util.*;
+
+public class GridCachePartitionedFlagsTest extends GridCacheAbstractFlagsTest {
+
+    @Override
+    protected CacheMode cacheMode() {
+        return CacheMode.PARTITIONED;
+    }
+
+    @Override
+    public void testTestSyncCommitFlag() throws Exception {
+        // Temporary disable test run.
+        if (new Date().compareTo(new 
SimpleDateFormat("dd.MM.yyyy").parse("01.06.2012")) < 0)
+            return;
+
+        super.testTestSyncCommitFlag();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b1faf559/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedFlagsTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedFlagsTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedFlagsTest.java
new file mode 100644
index 0000000..b9a321d
--- /dev/null
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedFlagsTest.java
@@ -0,0 +1,28 @@
+/*
+ * 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.distributed.replicated;
+
+import org.apache.ignite.cache.*;
+import org.apache.ignite.internal.processors.cache.*;
+
+public class GridCacheReplicatedFlagsTest extends GridCacheAbstractFlagsTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return CacheMode.REPLICATED;
+    }
+}

Reply via email to