Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 8EDE1200C7E for ; Tue, 23 May 2017 14:09:53 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 8D974160BB6; Tue, 23 May 2017 12:09:53 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 37315160BDB for ; Tue, 23 May 2017 14:09:52 +0200 (CEST) Received: (qmail 65195 invoked by uid 500); 23 May 2017 12:09:51 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 65115 invoked by uid 99); 23 May 2017 12:09:50 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 23 May 2017 12:09:50 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 082D2E00B3; Tue, 23 May 2017 12:09:50 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.apache.org Date: Tue, 23 May 2017 12:09:52 -0000 Message-Id: <74908ae96cb54e83b1cea4f933ffdc62@git.apache.org> In-Reply-To: <47e386cd4cae47f9b8b6a5181f3e1cde@git.apache.org> References: <47e386cd4cae47f9b8b6a5181f3e1cde@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [4/8] ignite git commit: IGNITE-5257 .NET: SQL query timeouts archived-at: Tue, 23 May 2017 12:09:53 -0000 IGNITE-5257 .NET: SQL query timeouts This closes #1985 Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/ca94cf3d Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/ca94cf3d Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/ca94cf3d Branch: refs/heads/ignite-5075-pds Commit: ca94cf3d6c708218ef22aa40c07c436c75360bc6 Parents: c4bb996 Author: Pavel Tupitsyn Authored: Mon May 22 17:45:10 2017 +0300 Committer: Pavel Tupitsyn Committed: Mon May 22 17:45:10 2017 +0300 ---------------------------------------------------------------------- .../platform/cache/PlatformCache.java | 28 +++++++-- .../core/include/ignite/cache/query/query_sql.h | 2 + .../ignite/cache/query/query_sql_fields.h | 3 + .../Cache/Query/CacheLinqTest.cs | 36 ++++++++++-- .../Cache/Query/CacheQueriesTest.cs | 60 +++++++++++++++++--- .../Cache/Query/SqlFieldsQuery.cs | 29 +++++++++- .../Apache.Ignite.Core/Cache/Query/SqlQuery.cs | 31 ++++++++++ .../Apache.Ignite.Core/Impl/Cache/CacheImpl.cs | 3 + .../Apache.Ignite.Linq/CacheExtensions.cs | 10 ++++ .../Impl/CacheFieldsQueryExecutor.cs | 42 ++++++-------- .../Apache.Ignite.Linq/Impl/CacheQueryable.cs | 3 +- .../dotnet/Apache.Ignite.Linq/QueryOptions.cs | 23 ++++++++ 12 files changed, 224 insertions(+), 46 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/ca94cf3d/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java index c61b75e..13a8ca1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java @@ -1282,8 +1282,16 @@ public class PlatformCache extends PlatformAbstractTarget { Object[] args = readQueryArgs(reader); boolean distrJoins = reader.readBoolean(); - - return new SqlQuery(typ, sql).setPageSize(pageSize).setArgs(args).setLocal(loc).setDistributedJoins(distrJoins); + int timeout = reader.readInt(); + boolean replicated = reader.readBoolean(); + + return new SqlQuery(typ, sql) + .setPageSize(pageSize) + .setArgs(args) + .setLocal(loc) + .setDistributedJoins(distrJoins) + .setTimeout(timeout, TimeUnit.MILLISECONDS) + .setReplicatedOnly(replicated); } /** @@ -1301,9 +1309,19 @@ public class PlatformCache extends PlatformAbstractTarget { boolean distrJoins = reader.readBoolean(); boolean enforceJoinOrder = reader.readBoolean(); - - return new SqlFieldsQuery(sql).setPageSize(pageSize).setArgs(args).setLocal(loc) - .setDistributedJoins(distrJoins).setEnforceJoinOrder(enforceJoinOrder); + int timeout = reader.readInt(); + boolean replicated = reader.readBoolean(); + boolean collocated = reader.readBoolean(); + + return new SqlFieldsQuery(sql) + .setPageSize(pageSize) + .setArgs(args) + .setLocal(loc) + .setDistributedJoins(distrJoins) + .setEnforceJoinOrder(enforceJoinOrder) + .setTimeout(timeout, TimeUnit.MILLISECONDS) + .setReplicatedOnly(replicated) + .setCollocated(collocated); } /** http://git-wip-us.apache.org/repos/asf/ignite/blob/ca94cf3d/modules/platforms/cpp/core/include/ignite/cache/query/query_sql.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/ignite/cache/query/query_sql.h b/modules/platforms/cpp/core/include/ignite/cache/query/query_sql.h index d733476..eb0606a 100644 --- a/modules/platforms/cpp/core/include/ignite/cache/query/query_sql.h +++ b/modules/platforms/cpp/core/include/ignite/cache/query/query_sql.h @@ -272,6 +272,8 @@ namespace ignite (*it)->Write(writer); writer.WriteBool(distributedJoins); + writer.WriteInt32(0); // Timeout, ms + writer.WriteBool(false); // ReplicatedOnly } private: http://git-wip-us.apache.org/repos/asf/ignite/blob/ca94cf3d/modules/platforms/cpp/core/include/ignite/cache/query/query_sql_fields.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/ignite/cache/query/query_sql_fields.h b/modules/platforms/cpp/core/include/ignite/cache/query/query_sql_fields.h index 954cf43..db26fc4 100644 --- a/modules/platforms/cpp/core/include/ignite/cache/query/query_sql_fields.h +++ b/modules/platforms/cpp/core/include/ignite/cache/query/query_sql_fields.h @@ -295,6 +295,9 @@ namespace ignite writer.WriteBool(distributedJoins); writer.WriteBool(enforceJoinOrder); + writer.WriteInt32(0); // Timeout, ms + writer.WriteBool(false); // ReplicatedOnly + writer.WriteBool(false); // Colocated } private: http://git-wip-us.apache.org/repos/asf/ignite/blob/ca94cf3d/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs index 265a149..cb3fece 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs @@ -1273,7 +1273,10 @@ namespace Apache.Ignite.Core.Tests.Cache.Query { Local = true, PageSize = 999, - EnforceJoinOrder = true + EnforceJoinOrder = true, + Timeout = TimeSpan.FromSeconds(2.5), + ReplicatedOnly = true, + Colocated = true }).Where(x => x.Key > 10); Assert.AreEqual(cache.Name, query.CacheName); @@ -1288,12 +1291,16 @@ namespace Apache.Ignite.Core.Tests.Cache.Query Assert.AreEqual(999, fq.PageSize); Assert.IsFalse(fq.EnableDistributedJoins); Assert.IsTrue(fq.EnforceJoinOrder); + Assert.IsTrue(fq.ReplicatedOnly); + Assert.IsTrue(fq.Colocated); + Assert.AreEqual(TimeSpan.FromSeconds(2.5), fq.Timeout); var str = query.ToString(); Assert.AreEqual("CacheQueryable [CacheName=person_org, TableName=Person, Query=SqlFieldsQuery " + "[Sql=select _T0._key, _T0._val from \"person_org\".Person as _T0 where " + "(_T0._key > ?), Arguments=[10], " + - "Local=True, PageSize=999, EnableDistributedJoins=False, EnforceJoinOrder=True]]", str); + "Local=True, PageSize=999, EnableDistributedJoins=False, EnforceJoinOrder=True, " + + "Timeout=00:00:02.5000000, ReplicatedOnly=True, Colocated=True]]", str); // Check fields query var fieldsQuery = (ICacheQueryable) cache.AsCacheQueryable().Select(x => x.Value.Name); @@ -1311,7 +1318,8 @@ namespace Apache.Ignite.Core.Tests.Cache.Query str = fieldsQuery.ToString(); Assert.AreEqual("CacheQueryable [CacheName=person_org, TableName=Person, Query=SqlFieldsQuery " + "[Sql=select _T0.Name from \"person_org\".Person as _T0, Arguments=[], Local=False, " + - "PageSize=1024, EnableDistributedJoins=False, EnforceJoinOrder=False]]", str); + "PageSize=1024, EnableDistributedJoins=False, EnforceJoinOrder=False, " + + "Timeout=00:00:00, ReplicatedOnly=False, Colocated=False]]", str); // Check distributed joins flag propagation var distrQuery = cache.AsCacheQueryable(new QueryOptions {EnableDistributedJoins = true}) @@ -1326,7 +1334,8 @@ namespace Apache.Ignite.Core.Tests.Cache.Query "[Sql=select _T0._key, _T0._val from \"person_org\".Person as _T0 where " + "(((_T0._key > ?) and (_T0.age1 > ?)) " + "and (_T0.Name like \'%\' || ? || \'%\') ), Arguments=[10, 20, x], Local=False, " + - "PageSize=1024, EnableDistributedJoins=True, EnforceJoinOrder=False]]", str); + "PageSize=1024, EnableDistributedJoins=True, EnforceJoinOrder=False, " + + "Timeout=00:00:00, ReplicatedOnly=False, Colocated=False]]", str); } /// @@ -1396,6 +1405,25 @@ namespace Apache.Ignite.Core.Tests.Cache.Query } /// + /// Tests the query timeout. + /// + [Test] + public void TestTimeout() + { + var persons = GetPersonCache().AsCacheQueryable(new QueryOptions + { + Timeout = TimeSpan.FromMilliseconds(1), + EnableDistributedJoins = true + }); + + // ReSharper disable once ReturnValueOfPureMethodIsNotUsed + var ex = Assert.Throws(() => + persons.SelectMany(p => GetRoleCache().AsCacheQueryable()).ToArray()); + + Assert.IsTrue(ex.ToString().Contains("QueryCancelledException: The query was cancelled while executing.")); + } + + /// /// Gets the person cache. /// /// http://git-wip-us.apache.org/repos/asf/ignite/blob/ca94cf3d/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesTest.cs index 01277e1..60d2fdf 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesTest.cs @@ -105,8 +105,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query for (int i = 0; i < GridCnt; i++) { - for (int j = 0; j < MaxItemCnt; j++) - cache.Remove(j); + cache.Clear(); Assert.IsTrue(cache.IsEmpty()); } @@ -352,9 +351,15 @@ namespace Apache.Ignite.Core.Tests.Cache.Query // 2. Validate results. var qry = new SqlQuery(typeof(QueryPerson), "age < 50", loc) { - EnableDistributedJoins = distrJoin + EnableDistributedJoins = distrJoin, + ReplicatedOnly = false, + Timeout = TimeSpan.FromSeconds(3) }; + Assert.AreEqual(string.Format("SqlQuery [Sql=age < 50, Arguments=[], Local={0}, " + + "PageSize=1024, EnableDistributedJoins={1}, Timeout={2}, " + + "ReplicatedOnly=False]", loc, distrJoin, qry.Timeout), qry.ToString()); + ValidateQueryResults(cache, qry, exp, keepBinary); } @@ -376,7 +381,10 @@ namespace Apache.Ignite.Core.Tests.Cache.Query var qry = new SqlFieldsQuery("SELECT name, age FROM QueryPerson WHERE age < 50", loc) { EnableDistributedJoins = distrJoin, - EnforceJoinOrder = enforceJoinOrder + EnforceJoinOrder = enforceJoinOrder, + Colocated = !distrJoin, + ReplicatedOnly = false, + Timeout = TimeSpan.FromSeconds(2) }; using (IQueryCursor cursor = cache.QueryFields(qry)) @@ -673,6 +681,44 @@ namespace Apache.Ignite.Core.Tests.Cache.Query } /// + /// Tests query timeouts. + /// + [Test] + public void TestSqlQueryTimeout() + { + var cache = Cache(); + PopulateCache(cache, false, 20000, x => true); + + var sqlQry = new SqlQuery(typeof(QueryPerson), "WHERE age < 500 AND name like '%1%'") + { + Timeout = TimeSpan.FromMilliseconds(2) + }; + + // ReSharper disable once ReturnValueOfPureMethodIsNotUsed + var ex = Assert.Throws(() => cache.Query(sqlQry).ToArray()); + Assert.IsTrue(ex.ToString().Contains("QueryCancelledException: The query was cancelled while executing.")); + } + + /// + /// Tests fields query timeouts. + /// + [Test] + public void TestSqlFieldsQueryTimeout() + { + var cache = Cache(); + PopulateCache(cache, false, 20000, x => true); + + var fieldsQry = new SqlFieldsQuery("SELECT * FROM QueryPerson WHERE age < 5000 AND name like '%0%'") + { + Timeout = TimeSpan.FromMilliseconds(3) + }; + + // ReSharper disable once ReturnValueOfPureMethodIsNotUsed + var ex = Assert.Throws(() => cache.QueryFields(fieldsQry).ToArray()); + Assert.IsTrue(ex.ToString().Contains("QueryCancelledException: The query was cancelled while executing.")); + } + + /// /// Validates the query results. /// /// Cache. @@ -820,7 +866,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query for (var i = 0; i < cnt; i++) { - var val = rand.Next(100); + var val = rand.Next(cnt); cache.Put(val, new QueryPerson(val.ToString(), val)); @@ -845,8 +891,8 @@ namespace Apache.Ignite.Core.Tests.Cache.Query public QueryPerson(string name, int age) { Name = name; - Age = age; - Birthday = DateTime.UtcNow.AddYears(-age); + Age = age % 2000; + Birthday = DateTime.UtcNow.AddYears(-Age); } /// http://git-wip-us.apache.org/repos/asf/ignite/blob/ca94cf3d/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Query/SqlFieldsQuery.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Query/SqlFieldsQuery.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Query/SqlFieldsQuery.cs index aab2bfe..4809574 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Query/SqlFieldsQuery.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Query/SqlFieldsQuery.cs @@ -17,6 +17,7 @@ namespace Apache.Ignite.Core.Cache.Query { + using System; using System.Diagnostics.CodeAnalysis; using System.Linq; @@ -105,6 +106,28 @@ namespace Apache.Ignite.Core.Cache.Query public bool EnforceJoinOrder { get; set; } /// + /// Gets or sets the query timeout. Query will be automatically cancelled if the execution timeout is exceeded. + /// Default is , which means no timeout. + /// + public TimeSpan Timeout { get; set; } + + /// + /// Gets or sets a value indicating whether this query contains only replicated tables. + /// This is a hint for potentially more effective execution. + /// + public bool ReplicatedOnly { get; set; } + + /// + /// Gets or sets a value indicating whether this query operates on colocated data. + /// + /// Whenever Ignite executes a distributed query, it sends sub-queries to individual cluster members. + /// If you know in advance that the elements of your query selection are colocated together on the same + /// node and you group by colocated key (primary or affinity key), then Ignite can make significant + /// performance and network optimizations by grouping data on remote nodes. + /// + public bool Colocated { get; set; } + + /// /// Returns a that represents this instance. /// /// @@ -115,8 +138,10 @@ namespace Apache.Ignite.Core.Cache.Query var args = string.Join(", ", Arguments.Select(x => x == null ? "null" : x.ToString())); return string.Format("SqlFieldsQuery [Sql={0}, Arguments=[{1}], Local={2}, PageSize={3}, " + - "EnableDistributedJoins={4}, EnforceJoinOrder={5}]", Sql, args, Local, - PageSize, EnableDistributedJoins, EnforceJoinOrder); + "EnableDistributedJoins={4}, EnforceJoinOrder={5}, Timeout={6}, ReplicatedOnly={7}" + + ", Colocated={8}]", Sql, args, Local, + PageSize, EnableDistributedJoins, EnforceJoinOrder, Timeout, ReplicatedOnly, + Colocated); } } } http://git-wip-us.apache.org/repos/asf/ignite/blob/ca94cf3d/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Query/SqlQuery.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Query/SqlQuery.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Query/SqlQuery.cs index 70e08b2..7d8e8fb 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Query/SqlQuery.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Query/SqlQuery.cs @@ -19,6 +19,7 @@ namespace Apache.Ignite.Core.Cache.Query { using System; using System.Diagnostics.CodeAnalysis; + using System.Linq; using Apache.Ignite.Core.Impl.Binary; using Apache.Ignite.Core.Impl.Cache; using Apache.Ignite.Core.Impl.Common; @@ -108,6 +109,18 @@ namespace Apache.Ignite.Core.Cache.Query /// public bool EnableDistributedJoins { get; set; } + /// + /// Gets or sets the query timeout. Query will be automatically cancelled if the execution timeout is exceeded. + /// Default is , which means no timeout. + /// + public TimeSpan Timeout { get; set; } + + /// + /// Gets or sets a value indicating whether this query contains only replicated tables. + /// This is a hint for potentially more effective execution. + /// + public bool ReplicatedOnly { get; set; } + /** */ internal override void Write(BinaryWriter writer, bool keepBinary) { @@ -126,6 +139,8 @@ namespace Apache.Ignite.Core.Cache.Query WriteQueryArgs(writer, Arguments); writer.WriteBoolean(EnableDistributedJoins); + writer.WriteInt((int) Timeout.TotalMilliseconds); + writer.WriteBoolean(ReplicatedOnly); } /** */ @@ -133,5 +148,21 @@ namespace Apache.Ignite.Core.Cache.Query { get { return CacheOp.QrySql; } } + + /// + /// Returns a that represents this instance. + /// + /// + /// A that represents this instance. + /// + public override string ToString() + { + var args = string.Join(", ", Arguments.Select(x => x == null ? "null" : x.ToString())); + + return string.Format("SqlQuery [Sql={0}, Arguments=[{1}], Local={2}, PageSize={3}, " + + "EnableDistributedJoins={4}, Timeout={5}, ReplicatedOnly={6}]", Sql, args, Local, + PageSize, EnableDistributedJoins, Timeout, ReplicatedOnly); + } + } } http://git-wip-us.apache.org/repos/asf/ignite/blob/ca94cf3d/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheImpl.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheImpl.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheImpl.cs index 749409c..95787eb 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheImpl.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheImpl.cs @@ -1086,6 +1086,9 @@ namespace Apache.Ignite.Core.Impl.Cache writer.WriteBoolean(qry.EnableDistributedJoins); writer.WriteBoolean(qry.EnforceJoinOrder); + writer.WriteInt((int) qry.Timeout.TotalMilliseconds); + writer.WriteBoolean(qry.ReplicatedOnly); + writer.WriteBoolean(qry.Colocated); }); return new FieldsQueryCursor(cursor, Marshaller, _flagKeepBinary, readerFunc); http://git-wip-us.apache.org/repos/asf/ignite/blob/ca94cf3d/modules/platforms/dotnet/Apache.Ignite.Linq/CacheExtensions.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Linq/CacheExtensions.cs b/modules/platforms/dotnet/Apache.Ignite.Linq/CacheExtensions.cs index 4b536f4..2c609c6 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Linq/CacheExtensions.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Linq/CacheExtensions.cs @@ -20,6 +20,7 @@ namespace Apache.Ignite.Linq using System.Linq; using Apache.Ignite.Core.Cache; using Apache.Ignite.Core.Cache.Configuration; + using Apache.Ignite.Core.Impl.Common; using Apache.Ignite.Linq.Impl; /// @@ -43,6 +44,8 @@ namespace Apache.Ignite.Linq public static IQueryable> AsCacheQueryable( this ICache cache) { + IgniteArgumentCheck.NotNull(cache, "cache"); + return cache.AsCacheQueryable(false, null); } @@ -64,6 +67,8 @@ namespace Apache.Ignite.Linq public static IQueryable> AsCacheQueryable( this ICache cache, bool local) { + IgniteArgumentCheck.NotNull(cache, "cache"); + return cache.AsCacheQueryable(local, null); } @@ -92,6 +97,8 @@ namespace Apache.Ignite.Linq public static IQueryable> AsCacheQueryable( this ICache cache, bool local, string tableName) { + IgniteArgumentCheck.NotNull(cache, "cache"); + return cache.AsCacheQueryable(new QueryOptions {Local = local, TableName = tableName}); } @@ -114,6 +121,9 @@ namespace Apache.Ignite.Linq public static IQueryable> AsCacheQueryable( this ICache cache, QueryOptions queryOptions) { + IgniteArgumentCheck.NotNull(cache, "cache"); + IgniteArgumentCheck.NotNull(queryOptions, "queryOptions"); + return new CacheQueryable(cache, queryOptions); } } http://git-wip-us.apache.org/repos/asf/ignite/blob/ca94cf3d/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheFieldsQueryExecutor.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheFieldsQueryExecutor.cs b/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheFieldsQueryExecutor.cs index 8dfddc7..27082bd 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheFieldsQueryExecutor.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheFieldsQueryExecutor.cs @@ -38,41 +38,26 @@ namespace Apache.Ignite.Linq.Impl { /** */ private readonly ICacheInternal _cache; + + /** */ + private readonly QueryOptions _options; /** */ private static readonly CopyOnWriteConcurrentDictionary CtorCache = new CopyOnWriteConcurrentDictionary(); - /** */ - private readonly bool _local; - - /** */ - private readonly int _pageSize; - - /** */ - private readonly bool _enableDistributedJoins; - - /** */ - private readonly bool _enforceJoinOrder; - /// /// Initializes a new instance of the class. /// /// The executor function. - /// Local flag. - /// Size of the page. - /// Distributed joins flag. - /// Enforce join order flag. - public CacheFieldsQueryExecutor(ICacheInternal cache, bool local, int pageSize, bool enableDistributedJoins, - bool enforceJoinOrder) + /// Query options. + public CacheFieldsQueryExecutor(ICacheInternal cache, QueryOptions options) { Debug.Assert(cache != null); + Debug.Assert(options != null); _cache = cache; - _local = local; - _pageSize = pageSize; - _enableDistributedJoins = enableDistributedJoins; - _enforceJoinOrder = enforceJoinOrder; + _options = options; } /** */ @@ -252,11 +237,16 @@ namespace Apache.Ignite.Linq.Impl /// internal SqlFieldsQuery GetFieldsQuery(string text, object[] args) { - return new SqlFieldsQuery(text, _local, args) + return new SqlFieldsQuery(text) { - EnableDistributedJoins = _enableDistributedJoins, - PageSize = _pageSize, - EnforceJoinOrder = _enforceJoinOrder + EnableDistributedJoins = _options.EnableDistributedJoins, + PageSize = _options.PageSize, + EnforceJoinOrder = _options.EnforceJoinOrder, + Timeout = _options.Timeout, + ReplicatedOnly = _options.ReplicatedOnly, + Colocated = _options.Colocated, + Local = _options.Local, + Arguments = args }; } http://git-wip-us.apache.org/repos/asf/ignite/blob/ca94cf3d/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheQueryable.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheQueryable.cs b/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheQueryable.cs index 7372776..e271363 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheQueryable.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheQueryable.cs @@ -33,8 +33,7 @@ namespace Apache.Ignite.Linq.Impl /// The query options. public CacheQueryable(ICache cache, QueryOptions queryOptions) : base(new CacheFieldsQueryProvider(CacheQueryParser.Instance, - new CacheFieldsQueryExecutor((ICacheInternal) cache, queryOptions.Local, queryOptions.PageSize, - queryOptions.EnableDistributedJoins, queryOptions.EnforceJoinOrder), + new CacheFieldsQueryExecutor((ICacheInternal) cache, queryOptions), cache.Ignite, cache.GetConfiguration(), queryOptions.TableName, typeof(TValue))) { // No-op. http://git-wip-us.apache.org/repos/asf/ignite/blob/ca94cf3d/modules/platforms/dotnet/Apache.Ignite.Linq/QueryOptions.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Linq/QueryOptions.cs b/modules/platforms/dotnet/Apache.Ignite.Linq/QueryOptions.cs index c70152e..17b3705 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Linq/QueryOptions.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Linq/QueryOptions.cs @@ -17,6 +17,7 @@ namespace Apache.Ignite.Linq { + using System; using System.ComponentModel; using Apache.Ignite.Core.Cache.Configuration; using Apache.Ignite.Core.Cache.Query; @@ -87,5 +88,27 @@ namespace Apache.Ignite.Linq /// true if join order should be enforced; otherwise, false. /// public bool EnforceJoinOrder { get; set; } + + /// + /// Gets or sets the query timeout. Query will be automatically cancelled if the execution timeout is exceeded. + /// Default is , which means no timeout. + /// + public TimeSpan Timeout { get; set; } + + /// + /// Gets or sets a value indicating whether this query contains only replicated tables. + /// This is a hint for potentially more effective execution. + /// + public bool ReplicatedOnly { get; set; } + + /// + /// Gets or sets a value indicating whether this query operates on colocated data. + /// + /// Whenever Ignite executes a distributed query, it sends sub-queries to individual cluster members. + /// If you know in advance that the elements of your query selection are colocated together on the same + /// node and you group by colocated key (primary or affinity key), then Ignite can make significant + /// performance and network optimizations by grouping data on remote nodes. + /// + public bool Colocated { get; set; } } }