IGNITE-7493 .NET: WAL management API added
authorPavel Tupitsyn <ptupitsyn@apache.org>
Tue, 23 Jan 2018 11:24:37 +0000 (14:24 +0300)
committerPavel Tupitsyn <ptupitsyn@apache.org>
Tue, 23 Jan 2018 11:24:37 +0000 (14:24 +0300)
modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/PersistenceTest.cs
modules/platforms/dotnet/Apache.Ignite.Core/Cluster/ICluster.cs
modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs

index de51b3d..87ec97c 100644 (file)
@@ -69,6 +69,9 @@ import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
+import static org.apache.ignite.internal.processors.platform.PlatformAbstractTarget.FALSE;
+import static org.apache.ignite.internal.processors.platform.PlatformAbstractTarget.TRUE;
+
 /**
  * GridGain platform processor.
  */
@@ -152,6 +155,15 @@ public class PlatformProcessorImpl extends GridProcessorAdapter implements Platf
     /** */
     private static final int OP_GET_BASELINE_TOPOLOGY = 26;
 
+    /** */
+    private static final int OP_DISABLE_WAL = 27;
+
+    /** */
+    private static final int OP_ENABLE_WAL = 28;
+
+    /** */
+    private static final int OP_IS_WAL_ENABLED = 29;
+
     /** Start latch. */
     private final CountDownLatch startLatch = new CountDownLatch(1);
 
@@ -412,7 +424,7 @@ public class PlatformProcessorImpl extends GridProcessorAdapter implements Platf
     @Override public long processInLongOutLong(int type, long val) throws IgniteCheckedException {
         switch (type) {
             case OP_LOGGER_IS_LEVEL_ENABLED: {
-                return loggerIsLevelEnabled((int) val) ? PlatformAbstractTarget.TRUE : PlatformAbstractTarget.FALSE;
+                return loggerIsLevelEnabled((int) val) ? TRUE : FALSE;
             }
 
             case OP_RELEASE_START: {
@@ -468,6 +480,19 @@ public class PlatformProcessorImpl extends GridProcessorAdapter implements Platf
                 ctx.grid().addCacheConfiguration(cfg);
 
                 return 0;
+
+            case OP_DISABLE_WAL:
+                ctx.grid().cluster().disableWal(reader.readString());
+
+                return 0;
+
+            case OP_ENABLE_WAL:
+                ctx.grid().cluster().enableWal(reader.readString());
+
+                return 0;
+
+            case OP_IS_WAL_ENABLED:
+                return ctx.grid().cluster().isWalEnabled(reader.readString()) ? TRUE : FALSE;
         }
 
         return PlatformAbstractTarget.throwUnsupported(type);
index e3c0acf..1893a5a 100644 (file)
@@ -275,6 +275,43 @@ namespace Apache.Ignite.Core.Tests.Cache
         }
 
         /// <summary>
+        /// Tests the wal disable/enable functionality.
+        /// </summary>
+        [Test]
+        public void TestWalDisableEnable()
+        {
+            using (var ignite = Ignition.Start(GetPersistentConfiguration()))
+            {
+                var cluster = ignite.GetCluster();
+                cluster.SetActive(true);
+
+                var cache = ignite.CreateCache<int, int>("foo");
+                Assert.IsTrue(cluster.IsWalEnabled(cache.Name));
+                cache[1] = 1;
+
+                cluster.DisableWal(cache.Name);
+                Assert.IsFalse(cluster.IsWalEnabled(cache.Name));
+                cache[2] = 2;
+
+                cluster.EnableWal(cache.Name);
+                Assert.IsTrue(cluster.IsWalEnabled(cache.Name));
+
+                Assert.AreEqual(1, cache[1]);
+                Assert.AreEqual(2, cache[2]);
+
+                // Check exceptions.
+                var ex = Assert.Throws<IgniteException>(() => cluster.IsWalEnabled("bar"));
+                Assert.AreEqual("Cache not found: bar", ex.Message);
+
+                ex = Assert.Throws<IgniteException>(() => cluster.DisableWal("bar"));
+                Assert.AreEqual("Cache doesn't exist: bar", ex.Message);
+
+                ex = Assert.Throws<IgniteException>(() => cluster.EnableWal("bar"));
+                Assert.AreEqual("Cache doesn't exist: bar", ex.Message);
+            }
+        }
+
+        /// <summary>
         /// Checks active state.
         /// </summary>
         private static void CheckIsActive(IIgnite ignite, bool isActive)
index f9bbdf7..45e22e9 100644 (file)
@@ -121,5 +121,39 @@ namespace Apache.Ignite.Core.Cluster
         /// Returns null if <see cref="SetBaselineTopology(long)"/> has not been called.
         /// </summary>
         ICollection<IBaselineNode> GetBaselineTopology();
+
+        /// <summary>
+        /// Disables write-ahead logging for specified cache. When WAL is disabled, changes are not logged to disk.
+        /// This significantly improves cache update speed.The drawback is absence of local crash-recovery guarantees.
+        /// If node is crashed, local content of WAL-disabled cache will be cleared on restart
+        /// to avoid data corruption.
+        /// <para />
+        /// Internally this method will wait for all current cache operations to finish and prevent new cache 
+        /// operations from being executed.Then checkpoint is initiated to flush all data to disk.Control is returned
+        /// to the callee when all dirty pages are prepared for checkpoint, but not necessarily flushed to disk.
+        /// <para />
+        /// WAL state can be changed only for persistent caches.
+        /// </summary>
+        /// <param name="cacheName">Name of the cache.</param>
+        void DisableWal(string cacheName);
+
+        /// <summary>
+        /// Enables write-ahead logging for specified cache. Restoring crash-recovery guarantees of a previous call to
+        /// <see cref="DisableWal"/>.
+        /// <para />
+        /// Internally this method will wait for all current cache operations to finish and prevent new cache
+        /// operations from being executed. Then checkpoint is initiated to flush all data to disk.
+        /// Control is returned to the callee when all data is persisted to disk.
+        /// <para />
+        /// WAL state can be changed only for persistent caches.
+        /// </summary>
+        /// <param name="cacheName">Name of the cache.</param>
+        void EnableWal(string cacheName);
+
+        /// <summary>
+        /// Determines whether write-ahead logging is enabled for specified cache.
+        /// </summary>
+        /// <param name="cacheName">Name of the cache.</param>
+        bool IsWalEnabled(string cacheName);
     }
 }
\ No newline at end of file
index 10b083b..ffab09f 100644 (file)
@@ -87,7 +87,10 @@ namespace Apache.Ignite.Core.Impl
             AddCacheConfiguration = 23,
             SetBaselineTopologyVersion = 24,
             SetBaselineTopologyNodes = 25,
-            GetBaselineTopology = 26
+            GetBaselineTopology = 26,
+            DisableWal = 27,
+            EnableWal = 28,
+            IsWalEnabled = 29
         }
 
         /** */
@@ -818,6 +821,30 @@ namespace Apache.Ignite.Core.Impl
         }
 
         /** <inheritdoc /> */
+        public void DisableWal(string cacheName)
+        {
+            IgniteArgumentCheck.NotNull(cacheName, "cacheName");
+
+            DoOutOp((int) Op.DisableWal, w => w.WriteString(cacheName));
+        }
+
+        /** <inheritdoc /> */
+        public void EnableWal(string cacheName)
+        {
+            IgniteArgumentCheck.NotNull(cacheName, "cacheName");
+            
+            DoOutOp((int) Op.EnableWal, w => w.WriteString(cacheName));
+        }
+
+        /** <inheritdoc /> */
+        public bool IsWalEnabled(string cacheName)
+        {
+            IgniteArgumentCheck.NotNull(cacheName, "cacheName");
+
+            return DoOutOp((int) Op.IsWalEnabled, w => w.WriteString(cacheName)) == True;
+        }
+
+        /** <inheritdoc /> */
 #pragma warning disable 618
         public IPersistentStoreMetrics GetPersistentStoreMetrics()
         {