You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2016/03/16 11:12:49 UTC
[6/8] ignite git commit: IGNITE-2843 .NET: Added
CacheConfiguration.WriteThrough/ReadThrough properties. This closes #556.
IGNITE-2843 .NET: Added CacheConfiguration.WriteThrough/ReadThrough properties. This closes #556.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/c638f1e7
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/c638f1e7
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/c638f1e7
Branch: refs/heads/ignite-1786
Commit: c638f1e7e9a6994cf38de4d444354a0938de0d31
Parents: ad6bbd9
Author: Pavel Tupitsyn <pt...@gridgain.com>
Authored: Wed Mar 16 13:11:05 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Wed Mar 16 13:11:05 2016 +0300
----------------------------------------------------------------------
.../utils/PlatformConfigurationUtils.java | 4 +
.../Apache.Ignite.Core.Tests.csproj | 1 +
.../Cache/CacheConfigurationTest.cs | 5 +-
.../Cache/Store/CacheStoreTest.cs | 5 +-
.../Cache/Store/CacheStoreTestCodeConfig.cs | 106 +++++++++++++++++++
.../IgniteConfigurationSerializerTest.cs | 4 +-
.../Cache/Configuration/CacheConfiguration.cs | 36 +++++++
.../IgniteConfigurationSection.xsd | 2 +
8 files changed, 158 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/c638f1e7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
index 50728a1..e08d1ba 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
@@ -140,6 +140,8 @@ import java.util.Map;
ccfg.setWriteBehindFlushSize(in.readInt());
ccfg.setWriteBehindFlushThreadCount(in.readInt());
ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.fromOrdinal(in.readInt()));
+ ccfg.setReadThrough(in.readBoolean());
+ ccfg.setWriteThrough(in.readBoolean());
Object storeFactory = in.readObjectDetached();
@@ -419,6 +421,8 @@ import java.util.Map;
writer.writeInt(ccfg.getWriteBehindFlushSize());
writer.writeInt(ccfg.getWriteBehindFlushThreadCount());
writer.writeInt(ccfg.getWriteSynchronizationMode() == null ? 0 : ccfg.getWriteSynchronizationMode().ordinal());
+ writer.writeBoolean(ccfg.isReadThrough());
+ writer.writeBoolean(ccfg.isWriteThrough());
if (ccfg.getCacheStoreFactory() instanceof PlatformDotNetCacheStoreFactoryNative)
writer.writeObject(((PlatformDotNetCacheStoreFactoryNative)ccfg.getCacheStoreFactory()).getNativeFactory());
http://git-wip-us.apache.org/repos/asf/ignite/blob/c638f1e7/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
index 8c266d7..0dcd1f0 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
@@ -91,6 +91,7 @@
<Compile Include="Cache\Store\CacheParallelLoadStoreTest.cs" />
<Compile Include="Cache\Store\CacheStoreSessionTest.cs" />
<Compile Include="Cache\Store\CacheStoreTest.cs" />
+ <Compile Include="Cache\Store\CacheStoreTestCodeConfig.cs" />
<Compile Include="Cache\Store\CacheTestParallelLoadStore.cs" />
<Compile Include="Cache\Store\CacheTestStore.cs" />
<Compile Include="Compute\CancellationTest.cs" />
http://git-wip-us.apache.org/repos/asf/ignite/blob/c638f1e7/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs
index 9f019832..bc259e5 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs
@@ -24,8 +24,6 @@ namespace Apache.Ignite.Core.Tests.Cache
using Apache.Ignite.Core.Cache.Configuration;
using Apache.Ignite.Core.Cache.Store;
using Apache.Ignite.Core.Common;
- using Apache.Ignite.Core.Discovery.Tcp;
- using Apache.Ignite.Core.Discovery.Tcp.Static;
using NUnit.Framework;
/// <summary>
@@ -436,6 +434,9 @@ namespace Apache.Ignite.Core.Tests.Cache
WriteBehindBatchSize = 18,
WriteBehindEnabled = false,
WriteSynchronizationMode = CacheWriteSynchronizationMode.PrimarySync,
+ CacheStoreFactory = new CacheStoreFactoryTest(),
+ ReadThrough = true,
+ WriteThrough = true,
QueryEntities = new[]
{
new QueryEntity
http://git-wip-us.apache.org/repos/asf/ignite/blob/c638f1e7/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreTest.cs
index b48cdc9..cc46642 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreTest.cs
@@ -15,6 +15,7 @@
* limitations under the License.
*/
+#pragma warning disable 618
namespace Apache.Ignite.Core.Tests.Cache.Store
{
using System;
@@ -134,7 +135,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
///
/// </summary>
[TestFixtureSetUp]
- public void BeforeTests()
+ public virtual void BeforeTests()
{
TestUtils.KillProcesses();
@@ -156,7 +157,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
///
/// </summary>
[TestFixtureTearDown]
- public virtual void AfterTests()
+ public void AfterTests()
{
Ignition.StopAll(true);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/c638f1e7/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreTestCodeConfig.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreTestCodeConfig.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreTestCodeConfig.cs
new file mode 100644
index 0000000..0b6f771
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreTestCodeConfig.cs
@@ -0,0 +1,106 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Tests.Cache.Store
+{
+ using System;
+ using Apache.Ignite.Core.Binary;
+ using Apache.Ignite.Core.Cache.Configuration;
+ using Apache.Ignite.Core.Cache.Store;
+ using Apache.Ignite.Core.Common;
+ using NUnit.Framework;
+
+ /// <summary>
+ /// Tests cache store without Spring.
+ /// </summary>
+ public class CacheStoreTestCodeConfig : CacheStoreTest
+ {
+ /// <summary>
+ /// Fixture setup.
+ /// </summary>
+ [TestFixtureSetUp]
+ public override void BeforeTests()
+ {
+ var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration())
+ {
+ BinaryConfiguration = new BinaryConfiguration(typeof(Key), typeof(Value)),
+ CacheConfiguration = new[]
+ {
+ new CacheConfiguration
+ {
+ Name = "binary_store",
+ CacheMode = CacheMode.Local,
+ AtomicityMode = CacheAtomicityMode.Transactional,
+ WriteThrough = true,
+ ReadThrough = true,
+ KeepBinaryInStore = true,
+ CacheStoreFactory = new StoreFactory()
+ },
+ new CacheConfiguration
+ {
+ Name = "object_store",
+ CacheMode = CacheMode.Local,
+ AtomicityMode = CacheAtomicityMode.Transactional,
+ WriteThrough = true,
+ ReadThrough = true,
+ KeepBinaryInStore = false,
+ CacheStoreFactory = new StoreFactory()
+ },
+ new CacheConfiguration
+ {
+ Name = "template_store*",
+ CacheMode = CacheMode.Local,
+ AtomicityMode = CacheAtomicityMode.Transactional,
+ WriteThrough = true,
+ ReadThrough = true,
+ KeepBinaryInStore = false,
+ CacheStoreFactory = new StoreFactory()
+ },
+ new CacheConfiguration
+ {
+ Name = "custom_store",
+ CacheMode = CacheMode.Local,
+ AtomicityMode = CacheAtomicityMode.Transactional,
+ WriteThrough = true,
+ ReadThrough = true,
+ CacheStoreFactory = new CustomStoreFactory()
+ },
+ }
+ };
+
+ Ignition.Start(cfg);
+ }
+
+ [Serializable]
+ private class StoreFactory : IFactory<ICacheStore>
+ {
+ public ICacheStore CreateInstance()
+ {
+ return new CacheTestStore();
+ }
+ }
+
+ [Serializable]
+ private class CustomStoreFactory : IFactory<ICacheStore>
+ {
+ public ICacheStore CreateInstance()
+ {
+ return new CacheTestStore {IntProperty = 42, StringProperty = "String value"};
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/c638f1e7/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs
index d944a04..e221a55 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs
@@ -68,7 +68,7 @@ namespace Apache.Ignite.Core.Tests
<iLifecycleBean type='Apache.Ignite.Core.Tests.IgniteConfigurationSerializerTest+LifecycleBean, Apache.Ignite.Core.Tests' foo='15' />
</lifecycleBeans>
<cacheConfiguration>
- <cacheConfiguration cacheMode='Replicated'>
+ <cacheConfiguration cacheMode='Replicated' readThrough='true' writeThrough='true'>
<queryEntities>
<queryEntity keyType='System.Int32' valueType='System.String'>
<fields>
@@ -120,6 +120,8 @@ namespace Apache.Ignite.Core.Tests
var cacheCfg = cfg.CacheConfiguration.First();
Assert.AreEqual(CacheMode.Replicated, cacheCfg.CacheMode);
+ Assert.IsTrue(cacheCfg.ReadThrough);
+ Assert.IsTrue(cacheCfg.WriteThrough);
var queryEntity = cacheCfg.QueryEntities.Single();
Assert.AreEqual(typeof(int), queryEntity.KeyType);
http://git-wip-us.apache.org/repos/asf/ignite/blob/c638f1e7/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs
index b319be9..ba509fc 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs
@@ -135,6 +135,12 @@ namespace Apache.Ignite.Core.Cache.Configuration
/// <summary> Default value for 'copyOnRead' flag. </summary>
public const bool DefaultCopyOnRead = true;
+ /// <summary> Default value for read-through behavior. </summary>
+ public const bool DefaultReadThrough = false;
+
+ /// <summary> Default value for write-through behavior. </summary>
+ public const bool DefaultWriteThrough = false;
+
/// <summary>
/// Gets or sets the cache name.
/// </summary>
@@ -255,6 +261,8 @@ namespace Apache.Ignite.Core.Cache.Configuration
WriteBehindFlushSize = reader.ReadInt();
WriteBehindFlushThreadCount = reader.ReadInt();
WriteSynchronizationMode = (CacheWriteSynchronizationMode) reader.ReadInt();
+ ReadThrough = reader.ReadBoolean();
+ WriteThrough = reader.ReadBoolean();
CacheStoreFactory = reader.ReadObject<IFactory<ICacheStore>>();
var count = reader.ReadInt();
@@ -303,6 +311,8 @@ namespace Apache.Ignite.Core.Cache.Configuration
writer.WriteInt(WriteBehindFlushSize);
writer.WriteInt(WriteBehindFlushThreadCount);
writer.WriteInt((int) WriteSynchronizationMode);
+ writer.WriteBoolean(ReadThrough);
+ writer.WriteBoolean(WriteThrough);
writer.WriteObject(CacheStoreFactory);
if (QueryEntities != null)
@@ -589,10 +599,36 @@ namespace Apache.Ignite.Core.Cache.Configuration
/// <summary>
/// Gets or sets the factory for underlying persistent storage for read-through and write-through operations.
+ /// <para />
+ /// See <see cref="ReadThrough"/> and <see cref="WriteThrough"/> properties to enable read-through and
+ /// write-through behavior so that cache store is invoked on get and/or put operations.
+ /// <para />
+ /// If both <see cref="ReadThrough"/> and <see cref="WriteThrough"/> are <code>false</code>, cache store
+ /// will be invoked only on <see cref="ICache{TK,TV}.LoadCache"/> calls.
/// </summary>
public IFactory<ICacheStore> CacheStoreFactory { get; set; }
/// <summary>
+ /// Gets or sets a value indicating whether read-through should be enabled for cache operations.
+ /// <para />
+ /// When in read-through mode, cache misses that occur due to cache entries not existing
+ /// as a result of performing a "get" operations will appropriately cause the
+ /// configured <see cref="ICacheStore"/> (see <see cref="CacheStoreFactory"/>) to be invoked.
+ /// </summary>
+ [DefaultValue(DefaultReadThrough)]
+ public bool ReadThrough { get; set; }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether write-through should be enabled for cache operations.
+ /// <para />
+ /// When in "write-through" mode, cache updates that occur as a result of performing "put" operations
+ /// will appropriately cause the configured
+ /// <see cref="ICacheStore"/> (see <see cref="CacheStoreFactory"/>) to be invoked.
+ /// </summary>
+ [DefaultValue(DefaultWriteThrough)]
+ public bool WriteThrough { get; set; }
+
+ /// <summary>
/// Gets or sets the query entity configuration.
/// </summary>
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
http://git-wip-us.apache.org/repos/asf/ignite/blob/c638f1e7/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd
index 12a4660..8902d3a 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd
@@ -190,6 +190,8 @@
<xs:attribute name="longQueryWarningTimeout" type="xs:string" />
<xs:attribute name="sqlEscapeAll" type="xs:boolean" />
<xs:attribute name="sqlOnheapRowCacheSize" type="xs:int" />
+ <xs:attribute name="readThrough" type="xs:boolean" />
+ <xs:attribute name="writeThrough" type="xs:boolean" />
</xs:complexType>
</xs:element>
</xs:sequence>