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 A2118200C32 for ; Thu, 9 Mar 2017 16:12:21 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id A08CA160B67; Thu, 9 Mar 2017 15:12:21 +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 7847B160B64 for ; Thu, 9 Mar 2017 16:12:20 +0100 (CET) Received: (qmail 15829 invoked by uid 500); 9 Mar 2017 15:12:19 -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 15820 invoked by uid 99); 9 Mar 2017 15:12:19 -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; Thu, 09 Mar 2017 15:12:19 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 95EFEDFE1E; Thu, 9 Mar 2017 15:12:19 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: vozerov@apache.org To: commits@ignite.apache.org Message-Id: <2820628df3f4423db40a09a378a4631b@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: ignite git commit: Minors. Date: Thu, 9 Mar 2017 15:12:19 +0000 (UTC) archived-at: Thu, 09 Mar 2017 15:12:21 -0000 Repository: ignite Updated Branches: refs/heads/ignite-4565-ddl cd477c039 -> abf2f3389 Minors. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/abf2f338 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/abf2f338 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/abf2f338 Branch: refs/heads/ignite-4565-ddl Commit: abf2f3389ee9036039be58a1e3b18c30d52a8f20 Parents: cd477c0 Author: devozerov Authored: Thu Mar 9 18:12:12 2017 +0300 Committer: devozerov Committed: Thu Mar 9 18:12:12 2017 +0300 ---------------------------------------------------------------------- .../processors/query/GridQueryProcessor.java | 1 + .../processors/query/QueryIndexHandler.java | 328 ------------------- .../query/index/QueryIndexHandler.java | 270 +++++++++++++++ .../processors/query/index/QueryIndexKey.java | 80 +++++ 4 files changed, 351 insertions(+), 328 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/abf2f338/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java index 912b466..2c3ff47 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java @@ -67,6 +67,7 @@ import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProce import org.apache.ignite.internal.processors.cache.query.CacheQueryFuture; import org.apache.ignite.internal.processors.cache.query.CacheQueryType; import org.apache.ignite.internal.processors.cache.query.GridCacheQueryType; +import org.apache.ignite.internal.processors.query.index.QueryIndexHandler; import org.apache.ignite.internal.processors.query.property.QueryBinaryProperty; import org.apache.ignite.internal.processors.query.property.QueryClassProperty; import org.apache.ignite.internal.processors.query.property.QueryFieldAccessor; http://git-wip-us.apache.org/repos/asf/ignite/blob/abf2f338/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexHandler.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexHandler.java deleted file mode 100644 index fce9f7a..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexHandler.java +++ /dev/null @@ -1,328 +0,0 @@ -/* - * 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.query; - -import org.apache.ignite.IgniteException; -import org.apache.ignite.IgniteLogger; -import org.apache.ignite.cache.QueryEntity; -import org.apache.ignite.cache.QueryIndex; -import org.apache.ignite.internal.GridKernalContext; -import org.apache.ignite.internal.IgniteInternalFuture; -import org.apache.ignite.internal.util.future.GridFinishedFuture; -import org.apache.ignite.internal.util.future.GridFutureAdapter; -import org.apache.ignite.internal.util.typedef.F; -import org.apache.ignite.internal.util.typedef.internal.S; - -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.locks.ReadWriteLock; -import java.util.concurrent.locks.ReentrantReadWriteLock; - -/** - * Index state manager. - */ -public class QueryIndexHandler { - /** Kernal context. */ - private final GridKernalContext ctx; - - /** Logger. */ - private final IgniteLogger log; - - /** All indexes. */ - private final Map idxs = new ConcurrentHashMap<>(); - - /** Client futures. */ - // TODO: Special future which is aware of index key, handle it during cache, type undeploy and disconnect. - private final Map cliFuts = new ConcurrentHashMap<>(); - - /** RW lock. */ - private final ReadWriteLock lock = new ReentrantReadWriteLock(); - - /** - * Constructor. - * - * @param ctx Kernal context. - */ - public QueryIndexHandler(GridKernalContext ctx) { - this.ctx = ctx; - - log = ctx.log(QueryIndexHandler.class); - } - - /** - * Handle start. - */ - public void onStart() { - // TODO - } - - /** - * Handle kernal start callback. - */ - public void onKernalStart() { - // TODO - } - - /** - * Handle kernal stop callback. - */ - public void onKernalStop() { - // TODO - } - - /** - * Handle stop callback. - */ - public void onStop() { - // TODO - } - - /** - * Handle cache creation. - * - * @param space Space. - * @param typs Type descriptors. - */ - public void onCacheCreated(String space, Collection typs) { - lock.writeLock().lock(); - - try { - for (QueryTypeDescriptorImpl typ : typs) { - for (QueryIndexDescriptorImpl idx : typ.indexes0()) { - IndexKey idxKey = new IndexKey(space, idx.name()); - - Descriptor desc = idxs.get(idxKey); - - if (desc != null) { - throw new IgniteException("Duplicate index name [space=" + space + ", idxName=" + idx.name() + - ", existingTable=" + desc.type().tableName() + ", table=" + typ.tableName() + ']'); - } - - idxs.put(idxKey, new Descriptor(typ, idx)); - } - } - } - finally { - lock.writeLock().unlock(); - } - } - - /** - * Handle cache stop. - * - * @param space Space. - */ - public void onCacheStopped(String space) { - lock.writeLock().lock(); - - try { - Iterator> iter = idxs.entrySet().iterator(); - - while (iter.hasNext()) { - Map.Entry entry = iter.next(); - - if (F.eq(space, entry.getValue().type().space())) - iter.remove(); - } - } - finally { - lock.writeLock().unlock(); - } - } - - /** - * Handle type unregister. - * - * @param desc Descriptor. - */ - public void onTypeUnregistered(QueryTypeDescriptorImpl desc) { - lock.writeLock().lock(); - - try { - Iterator> iter = idxs.entrySet().iterator(); - - while (iter.hasNext()) { - Map.Entry entry = iter.next(); - - if (F.eq(desc, entry.getValue().type())) - iter.remove(); - } - } - finally { - lock.writeLock().unlock(); - } - } - - /** - * Handle disconnect. - */ - public void onDisconnected() { - // TODO - } - - /** - * Handle dynamic index creation. - * - * @param space Space. - * @param tblName Table name. - * @param idx Index. - * @param ifNotExists IF-NOT-EXISTS flag. - * @return Future completed when index is created. - */ - public IgniteInternalFuture onCreateIndex(String space, String tblName, QueryIndex idx, - boolean ifNotExists) { - String idxName = idx.getName() != null ? idx.getName() : QueryEntity.defaultIndexName(idx); - - IndexKey idxKey = new IndexKey(space, idxName); - - lock.readLock().lock(); - - try { - Descriptor oldIdxDesc = idxs.get(idxKey); - - if (oldIdxDesc != null) { - // Make sure that index is bound to the same table. - String oldTblName = oldIdxDesc.type().tableName(); - - if (!F.eq(oldTblName, tblName)) { - return new GridFinishedFuture<>(new IgniteException("Index already exists and is bound to " + - "another table [space=" + space + ", idxName=" + idxName + ", expTblName=" + oldTblName + - ", actualTblName=" + tblName + ']')); - } - - if (ifNotExists) - return new GridFinishedFuture<>(); - else - return new GridFinishedFuture<>(new IgniteException("Index already exists [space=" + space + - ", idxName=" + idxName + ']')); - } - - UUID opId = UUID.randomUUID(); - GridFutureAdapter fut = new GridFutureAdapter(); - - GridFutureAdapter oldFut = cliFuts.put(opId, fut); - - assert oldFut == null; - - // TODO: Start discovery. - - return fut; - } - finally { - lock.readLock().unlock(); - } - } - - /** - * Index key. - */ - private static class IndexKey { - /** Space. */ - private final String space; - - /** Name. */ - private final String name; - - /** - * Constructor. - * - * @param space Space. - * @param name Name. - */ - public IndexKey(String space, String name) { - this.space = space; - this.name = name; - } - - /** - * @return Space. - */ - public String space() { - return space; - } - - /** - * @return Name. - */ - public String name() { - return name; - } - - /** {@inheritDoc} */ - @Override public int hashCode() { - return 31 * (space != null ? space.hashCode() : 0) + (name != null ? name.hashCode() : 0); - } - - /** {@inheritDoc} */ - @Override public boolean equals(Object o) { - if (this == o) - return true; - - if (o == null || getClass() != o.getClass()) - return false; - - IndexKey other = (IndexKey)o; - - return F.eq(name, other.name) && F.eq(space, other.space); - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(IndexKey.class, this); - } - } - - /** - * Type and index descriptor. - */ - private static class Descriptor { - /** Type. */ - private final QueryTypeDescriptorImpl typ; - - /** Index. */ - private final QueryIndexDescriptorImpl idx; - - /** - * Constructor. - * - * @param typ Type. - * @param idx Index. - */ - private Descriptor(QueryTypeDescriptorImpl typ, QueryIndexDescriptorImpl idx) { - this.typ = typ; - this.idx = idx; - } - - /** - * @return Type. - */ - public QueryTypeDescriptorImpl type() { - return typ; - } - - /** - * @return Index. - */ - public QueryIndexDescriptorImpl index() { - return idx; - } - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/abf2f338/modules/core/src/main/java/org/apache/ignite/internal/processors/query/index/QueryIndexHandler.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/index/QueryIndexHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/index/QueryIndexHandler.java new file mode 100644 index 0000000..ce28a87 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/index/QueryIndexHandler.java @@ -0,0 +1,270 @@ +/* + * 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.query.index; + +import org.apache.ignite.IgniteException; +import org.apache.ignite.IgniteLogger; +import org.apache.ignite.cache.QueryEntity; +import org.apache.ignite.cache.QueryIndex; +import org.apache.ignite.internal.GridKernalContext; +import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.internal.processors.query.QueryIndexDescriptorImpl; +import org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl; +import org.apache.ignite.internal.util.future.GridFinishedFuture; +import org.apache.ignite.internal.util.future.GridFutureAdapter; +import org.apache.ignite.internal.util.typedef.F; + +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; + +/** + * Index state manager. + */ +public class QueryIndexHandler { + /** Kernal context. */ + private final GridKernalContext ctx; + + /** Logger. */ + private final IgniteLogger log; + + /** All indexes. */ + private final Map idxs = new ConcurrentHashMap<>(); + + /** Client futures. */ + // TODO: Special future which is aware of index key, handle it during cache, type undeploy and disconnect. + private final Map cliFuts = new ConcurrentHashMap<>(); + + /** RW lock. */ + private final ReadWriteLock lock = new ReentrantReadWriteLock(); + + /** + * Constructor. + * + * @param ctx Kernal context. + */ + public QueryIndexHandler(GridKernalContext ctx) { + this.ctx = ctx; + + log = ctx.log(QueryIndexHandler.class); + } + + /** + * Handle start. + */ + public void onStart() { + // TODO + } + + /** + * Handle kernal start callback. + */ + public void onKernalStart() { + // TODO + } + + /** + * Handle kernal stop callback. + */ + public void onKernalStop() { + // TODO + } + + /** + * Handle stop callback. + */ + public void onStop() { + // TODO + } + + /** + * Handle cache creation. + * + * @param space Space. + * @param typs Type descriptors. + */ + public void onCacheCreated(String space, Collection typs) { + lock.writeLock().lock(); + + try { + for (QueryTypeDescriptorImpl typ : typs) { + for (QueryIndexDescriptorImpl idx : typ.indexes0()) { + QueryIndexKey idxKey = new QueryIndexKey(space, idx.name()); + + Descriptor desc = idxs.get(idxKey); + + if (desc != null) { + throw new IgniteException("Duplicate index name [space=" + space + ", idxName=" + idx.name() + + ", existingTable=" + desc.type().tableName() + ", table=" + typ.tableName() + ']'); + } + + idxs.put(idxKey, new Descriptor(typ, idx)); + } + } + } + finally { + lock.writeLock().unlock(); + } + } + + /** + * Handle cache stop. + * + * @param space Space. + */ + public void onCacheStopped(String space) { + lock.writeLock().lock(); + + try { + Iterator> iter = idxs.entrySet().iterator(); + + while (iter.hasNext()) { + Map.Entry entry = iter.next(); + + if (F.eq(space, entry.getValue().type().space())) + iter.remove(); + } + } + finally { + lock.writeLock().unlock(); + } + } + + /** + * Handle type unregister. + * + * @param desc Descriptor. + */ + public void onTypeUnregistered(QueryTypeDescriptorImpl desc) { + lock.writeLock().lock(); + + try { + Iterator> iter = idxs.entrySet().iterator(); + + while (iter.hasNext()) { + Map.Entry entry = iter.next(); + + if (F.eq(desc, entry.getValue().type())) + iter.remove(); + } + } + finally { + lock.writeLock().unlock(); + } + } + + /** + * Handle disconnect. + */ + public void onDisconnected() { + // TODO + } + + /** + * Handle dynamic index creation. + * + * @param space Space. + * @param tblName Table name. + * @param idx Index. + * @param ifNotExists IF-NOT-EXISTS flag. + * @return Future completed when index is created. + */ + public IgniteInternalFuture onCreateIndex(String space, String tblName, QueryIndex idx, + boolean ifNotExists) { + String idxName = idx.getName() != null ? idx.getName() : QueryEntity.defaultIndexName(idx); + + QueryIndexKey idxKey = new QueryIndexKey(space, idxName); + + lock.readLock().lock(); + + try { + Descriptor oldIdxDesc = idxs.get(idxKey); + + if (oldIdxDesc != null) { + // Make sure that index is bound to the same table. + String oldTblName = oldIdxDesc.type().tableName(); + + if (!F.eq(oldTblName, tblName)) { + return new GridFinishedFuture<>(new IgniteException("Index already exists and is bound to " + + "another table [space=" + space + ", idxName=" + idxName + ", expTblName=" + oldTblName + + ", actualTblName=" + tblName + ']')); + } + + if (ifNotExists) + return new GridFinishedFuture<>(); + else + return new GridFinishedFuture<>(new IgniteException("Index already exists [space=" + space + + ", idxName=" + idxName + ']')); + } + + UUID opId = UUID.randomUUID(); + GridFutureAdapter fut = new GridFutureAdapter(); + + GridFutureAdapter oldFut = cliFuts.put(opId, fut); + + assert oldFut == null; + + // TODO: Start discovery. + + return fut; + } + finally { + lock.readLock().unlock(); + } + } + + /** + * Type and index descriptor. + */ + private static class Descriptor { + /** Type. */ + private final QueryTypeDescriptorImpl typ; + + /** Index. */ + private final QueryIndexDescriptorImpl idx; + + /** + * Constructor. + * + * @param typ Type. + * @param idx Index. + */ + private Descriptor(QueryTypeDescriptorImpl typ, QueryIndexDescriptorImpl idx) { + this.typ = typ; + this.idx = idx; + } + + /** + * @return Type. + */ + public QueryTypeDescriptorImpl type() { + return typ; + } + + /** + * @return Index. + */ + public QueryIndexDescriptorImpl index() { + return idx; + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/abf2f338/modules/core/src/main/java/org/apache/ignite/internal/processors/query/index/QueryIndexKey.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/index/QueryIndexKey.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/index/QueryIndexKey.java new file mode 100644 index 0000000..adf5df9 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/index/QueryIndexKey.java @@ -0,0 +1,80 @@ +/* + * 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.query.index; + +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.internal.S; + +/** + * Index key. + */ +public class QueryIndexKey { + /** Space. */ + private final String space; + + /** Name. */ + private final String name; + + /** + * Constructor. + * + * @param space Space. + * @param name Name. + */ + public QueryIndexKey(String space, String name) { + this.space = space; + this.name = name; + } + + /** + * @return Space. + */ + public String space() { + return space; + } + + /** + * @return Name. + */ + public String name() { + return name; + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return 31 * (space != null ? space.hashCode() : 0) + (name != null ? name.hashCode() : 0); + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + + if (o == null || getClass() != o.getClass()) + return false; + + QueryIndexKey other = (QueryIndexKey)o; + + return F.eq(name, other.name) && F.eq(space, other.space); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(QueryIndexKey.class, this); + } +}