You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ag...@apache.org on 2017/03/24 14:12:32 UTC
[42/50] [abbrv] ignite git commit: Merge branch master ignite-2.0 to
ignite-3477
http://git-wip-us.apache.org/repos/asf/ignite/blob/81ae2d83/modules/core/src/main/java/org/apache/ignite/internal/processors/marshaller/MarshallerMappingTransport.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/processors/marshaller/MarshallerMappingTransport.java
index 0000000,b974882..0db2b22
mode 000000,100644..100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/marshaller/MarshallerMappingTransport.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/marshaller/MarshallerMappingTransport.java
@@@ -1,0 -1,212 +1,212 @@@
+ /*
+ * 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.marshaller;
+
+ import java.util.concurrent.ConcurrentMap;
+ import org.apache.ignite.IgniteCheckedException;
+ import org.apache.ignite.internal.GridKernalContext;
+ import org.apache.ignite.internal.MarshallerContextImpl;
+ import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage;
+ import org.apache.ignite.internal.managers.discovery.GridDiscoveryManager;
+ import org.apache.ignite.internal.util.future.GridFutureAdapter;
+ import org.jetbrains.annotations.Nullable;
+
+ /**
+ * Provides capabilities of sending custom discovery events to propose new mapping
+ * or request missing mapping to {@link MarshallerContextImpl}.
+ *
+ * For more information about particular events see documentation of {@link GridMarshallerMappingProcessor}.
+ */
+ public final class MarshallerMappingTransport {
+ /** */
+ private final GridKernalContext ctx;
+
+ /** */
+ private final GridDiscoveryManager discoMgr;
+
+ /** */
+ private final ConcurrentMap<MarshallerMappingItem, GridFutureAdapter<MappingExchangeResult>> mappingExchSyncMap;
+
+ /** */
+ private final ConcurrentMap<MarshallerMappingItem, ClientRequestFuture> clientReqSyncMap;
+
+ /** */
+ private volatile boolean stopping;
+
+ /**
+ * @param ctx Context.
+ * @param mappingExchSyncMap Mapping exch sync map.
+ * @param clientReqSyncMap Client request sync map.
+ */
+ MarshallerMappingTransport(
+ GridKernalContext ctx,
+ ConcurrentMap<MarshallerMappingItem, GridFutureAdapter<MappingExchangeResult>> mappingExchSyncMap,
+ ConcurrentMap<MarshallerMappingItem, ClientRequestFuture> clientReqSyncMap
+ ) {
+ this.ctx = ctx;
+ discoMgr = ctx.discovery();
+ this.mappingExchSyncMap = mappingExchSyncMap;
+ this.clientReqSyncMap = clientReqSyncMap;
+
+ stopping = false;
+ }
+
+ /**
+ * @param item Item.
+ * @param cache Cache.
+ */
+ public GridFutureAdapter<MappingExchangeResult> awaitMappingAcceptance(
+ MarshallerMappingItem item, ConcurrentMap<Integer,
+ MappedName> cache
+ ) {
+ GridFutureAdapter<MappingExchangeResult> fut = new MappingExchangeResultFuture(item);
+
+ GridFutureAdapter<MappingExchangeResult> oldFut = mappingExchSyncMap.putIfAbsent(item, fut);
+
+ if (oldFut != null)
+ return oldFut;
+
+ MappedName mappedName = cache.get(item.typeId());
+
+ assert mappedName != null;
+
+ //double check whether mapping is accepted, first check was in MarshallerContextImpl::registerClassName
+ if (mappedName.accepted())
+ fut.onDone(MappingExchangeResult.createSuccessfulResult(mappedName.className()));
+
+ return fut;
+ }
+
+ /**
+ * @param item Item.
+ * @param cache Cache.
+ */
+ public GridFutureAdapter<MappingExchangeResult> proposeMapping(MarshallerMappingItem item, ConcurrentMap<Integer, MappedName> cache) throws IgniteCheckedException {
+ GridFutureAdapter<MappingExchangeResult> fut = new MappingExchangeResultFuture(item);
+
+ GridFutureAdapter<MappingExchangeResult> oldFut = mappingExchSyncMap.putIfAbsent(item, fut);
+
+ if (oldFut != null)
+ return oldFut;
+ else {
+ //double check, first check was in caller: MarshallerContextImpl::registerClassName
+ MappedName mapping = cache.get(item.typeId());
+
+ if (mapping != null) {
+ String mappedClsName = mapping.className();
+
+ if (!mappedClsName.equals(item.className()))
+ fut.onDone(MappingExchangeResult.createFailureResult(duplicateMappingException(item, mappedClsName)));
+ else if (mapping.accepted())
+ fut.onDone(MappingExchangeResult.createSuccessfulResult(mappedClsName));
+ else if (stopping)
+ fut.onDone(MappingExchangeResult.createExchangeDisabledResult());
+
+ return fut;
+ }
+ }
+
+ DiscoveryCustomMessage msg = new MappingProposedMessage(item, discoMgr.localNode().id());
+ discoMgr.sendCustomEvent(msg);
+
+ return fut;
+ }
+
+ /**
+ * @param item Item.
+ * @param cache Cache.
+ */
+ public GridFutureAdapter<MappingExchangeResult> requestMapping(
+ MarshallerMappingItem item,
+ ConcurrentMap<Integer, MappedName> cache
+ ) {
+ ClientRequestFuture newFut = new ClientRequestFuture(ctx, item, clientReqSyncMap);
+
+ ClientRequestFuture oldFut = clientReqSyncMap.putIfAbsent(item, newFut);
+
+ if (oldFut != null)
+ return oldFut;
+
+ MappedName mappedName = cache.get(item.typeId());
+
+ if (mappedName != null) {
+ newFut.onDone(MappingExchangeResult.createSuccessfulResult(mappedName.className()));
+
+ return newFut;
+ }
+
+ newFut.requestMapping();
+
+ return newFut;
+ }
+
+ /**
+ * @param item Item.
+ * @param mappedClsName Mapped class name.
+ */
+ private IgniteCheckedException duplicateMappingException(MarshallerMappingItem item, String mappedClsName) {
+ return new IgniteCheckedException("Duplicate ID [platformId="
- + item.platformId()
- + ", typeId="
- + item.typeId()
- + ", oldCls="
- + mappedClsName
- + ", newCls="
- + item.className() + "]");
++ + item.platformId()
++ + ", typeId="
++ + item.typeId()
++ + ", oldCls="
++ + mappedClsName
++ + ", newCls="
++ + item.className() + "]");
+ }
+
+ /** */
+ public void markStopping() {
+ stopping = true;
+ }
+
+ /** */
+ public boolean stopping() {
+ return stopping;
+ }
+
+ /**
+ * Future to wait for mapping exchange result to arrive. Removes itself from map when completed.
+ */
+ private class MappingExchangeResultFuture extends GridFutureAdapter<MappingExchangeResult> {
+ /** */
+ private static final long serialVersionUID = 0L;
+
+ /** */
+ private final MarshallerMappingItem mappingItem;
+
+ /**
+ * @param mappingItem Mapping item.
+ */
+ private MappingExchangeResultFuture(MarshallerMappingItem mappingItem) {
+ this.mappingItem = mappingItem;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean onDone(@Nullable MappingExchangeResult res, @Nullable Throwable err) {
+ assert res != null;
+
+ boolean done = super.onDone(res, null);
+
+ if (done)
+ mappingExchSyncMap.remove(mappingItem, this);
+
+ return done;
+ }
+ }
+ }
http://git-wip-us.apache.org/repos/asf/ignite/blob/81ae2d83/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcProcessor.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/81ae2d83/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/81ae2d83/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/plugin/cache/PlatformCachePluginConfiguration.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/processors/platform/plugin/cache/PlatformCachePluginConfiguration.java
index 0000000,d055f00..1cb17c7
mode 000000,100644..100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/plugin/cache/PlatformCachePluginConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/plugin/cache/PlatformCachePluginConfiguration.java
@@@ -1,0 -1,58 +1,51 @@@
+ /*
+ * 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.platform.plugin.cache;
+
+ import org.apache.ignite.plugin.CachePluginConfiguration;
-import org.apache.ignite.plugin.CachePluginContext;
-import org.apache.ignite.plugin.CachePluginProvider;
+
+ /**
+ * Platform cache plugin configuration.
+ */
+ public class PlatformCachePluginConfiguration implements CachePluginConfiguration {
+ /** */
+ private static final long serialVersionUID = 0L;
+
+ /** Native configuration object. */
+ private final Object nativeCfg;
+
+ /**
+ * Ctor.
+ *
+ * @param nativeCfg Native configuration object.
+ */
+ public PlatformCachePluginConfiguration(Object nativeCfg) {
+ assert nativeCfg != null;
+
+ this.nativeCfg = nativeCfg;
+ }
+
- /** {@inheritDoc} */
- @Override public CachePluginProvider createProvider(CachePluginContext ctx) {
- return new PlatformCachePluginProvider(ctx, nativeCfg);
- }
-
+ /**
+ * Gets the native configuration object.
+ *
+ * @return Native configuration object.
+ */
+ public Object nativeCfg() {
+ return nativeCfg;
+ }
+ }
http://git-wip-us.apache.org/repos/asf/ignite/blob/81ae2d83/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/plugin/cache/PlatformCachePluginProvider.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/processors/platform/plugin/cache/PlatformCachePluginProvider.java
index 0000000,d23bd8b..3e3b223
mode 000000,100644..100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/plugin/cache/PlatformCachePluginProvider.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/plugin/cache/PlatformCachePluginProvider.java
@@@ -1,0 -1,123 +1,121 @@@
+ /*
+ * 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.platform.plugin.cache;
+
++import javax.cache.Cache;
+ import org.apache.ignite.IgniteCheckedException;
+ import org.apache.ignite.cluster.ClusterNode;
+ import org.apache.ignite.configuration.CacheConfiguration;
+ import org.apache.ignite.internal.binary.BinaryRawWriterEx;
+ import org.apache.ignite.internal.processors.platform.PlatformContext;
+ import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
+ import org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream;
+ import org.apache.ignite.internal.processors.platform.utils.PlatformConfigurationUtils;
+ import org.apache.ignite.internal.processors.platform.utils.PlatformUtils;
-import org.apache.ignite.plugin.CachePluginConfiguration;
+ import org.apache.ignite.plugin.CachePluginContext;
+ import org.apache.ignite.plugin.CachePluginProvider;
+ import org.jetbrains.annotations.Nullable;
+
-import javax.cache.Cache;
-
+ /**
+ * Platform cache plugin provider.
+ */
+ class PlatformCachePluginProvider implements CachePluginProvider {
+ /** Context. */
+ private final CachePluginContext ctx;
+
+ /** Native config. */
+ private final Object nativeCfg;
+
+ /** Pointer to native plugin. */
+ protected long ptr;
+
+ /**
+ * Ctor.
+ *
+ * @param ctx Context.
+ */
+ PlatformCachePluginProvider(CachePluginContext ctx, Object nativeCfg) {
+ assert ctx != null;
+ assert nativeCfg != null;
+
+ this.ctx = ctx;
+ this.nativeCfg = nativeCfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void start() throws IgniteCheckedException {
+ PlatformContext platformCtx = PlatformUtils.platformContext(ctx.grid());
+
+ try (PlatformMemory mem = platformCtx.memory().allocate()) {
+ PlatformOutputStream out = mem.output();
+
+ BinaryRawWriterEx writer = platformCtx.writer(out);
+
+ writer.writeObjectDetached(nativeCfg);
+
+ PlatformConfigurationUtils.writeIgniteConfiguration(writer, ctx.igniteConfiguration());
+ PlatformConfigurationUtils.writeCacheConfiguration(writer, ctx.igniteCacheConfiguration());
+
+ out.synchronize();
+
+ ptr = platformCtx.gateway().cachePluginCreate(mem.pointer());
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public void stop(boolean cancel) {
+ PlatformContext platformCtx = PlatformUtils.platformContext(ctx.grid());
+
+ platformCtx.gateway().cachePluginDestroy(ptr, cancel);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void onIgniteStart() throws IgniteCheckedException {
+ PlatformContext platformCtx = PlatformUtils.platformContext(ctx.grid());
+
+ platformCtx.gateway().cachePluginIgniteStart(ptr);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void onIgniteStop(boolean cancel) {
+ PlatformContext platformCtx = PlatformUtils.platformContext(ctx.grid());
+
+ platformCtx.gateway().cachePluginIgniteStop(ptr, cancel);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void validate() throws IgniteCheckedException {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
- @Override public void validateRemote(CacheConfiguration locCfg, CachePluginConfiguration locPluginCcfg,
- CacheConfiguration rmtCfg, ClusterNode rmtNode) throws IgniteCheckedException {
++ @Override public void validateRemote(CacheConfiguration locCfg, CacheConfiguration rmtCfg, ClusterNode rmtNode)
++ throws IgniteCheckedException {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public Object unwrapCacheEntry(Cache.Entry entry, Class cls) {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public Object createComponent(Class cls) {
+ return null;
+ }
+ }
http://git-wip-us.apache.org/repos/asf/ignite/blob/81ae2d83/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
index 545a6ed,bce3735..e137d75
--- 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
@@@ -17,18 -17,7 +17,23 @@@
package org.apache.ignite.internal.processors.platform.utils;
+import java.lang.management.ManagementFactory;
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
++import java.security.AccessController;
++import java.security.PrivilegedAction;
++import java.util.Collections;
++import java.util.ServiceLoader;
+import javax.cache.configuration.Factory;
+import javax.cache.expiry.ExpiryPolicy;
+ import org.apache.ignite.IgniteException;
import org.apache.ignite.binary.BinaryArrayIdentityResolver;
import org.apache.ignite.binary.BinaryFieldIdentityResolver;
import org.apache.ignite.binary.BinaryIdentityResolver;
@@@ -64,6 -55,11 +69,12 @@@ import org.apache.ignite.platform.dotne
import org.apache.ignite.platform.dotnet.PlatformDotNetBinaryTypeConfiguration;
import org.apache.ignite.platform.dotnet.PlatformDotNetCacheStoreFactoryNative;
import org.apache.ignite.platform.dotnet.PlatformDotNetConfiguration;
++import org.apache.ignite.internal.processors.platform.plugin.cache.PlatformCachePluginConfiguration;
+ import org.apache.ignite.plugin.CachePluginConfiguration;
+ import org.apache.ignite.plugin.platform.PlatformCachePluginConfigurationClosure;
+ import org.apache.ignite.plugin.platform.PlatformCachePluginConfigurationClosureFactory;
+ import org.apache.ignite.plugin.platform.PlatformPluginConfigurationClosure;
+ import org.apache.ignite.plugin.platform.PlatformPluginConfigurationClosureFactory;
import org.apache.ignite.spi.communication.CommunicationSpi;
import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi;
import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpiMBean;
@@@ -606,6 -651,29 +639,8 @@@ public class PlatformConfigurationUtil
cfg.setTransactionConfiguration(tx);
}
+
- byte swapType = in.readByte();
-
- switch (swapType) {
- case SWAP_TYP_FILE: {
- FileSwapSpaceSpi swap = new FileSwapSpaceSpi();
-
- swap.setBaseDirectory(in.readString());
- swap.setMaximumSparsity(in.readFloat());
- swap.setMaxWriteQueueSize(in.readInt());
- swap.setReadStripesNumber(in.readInt());
- swap.setWriteBufferSize(in.readInt());
-
- cfg.setSwapSpaceSpi(swap);
-
- break;
- }
-
- default:
- assert swapType == SWAP_TYP_NONE;
- }
-
+ readPluginConfiguration(cfg, in);
}
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/81ae2d83/modules/core/src/main/java/org/apache/ignite/internal/processors/plugin/CachePluginManager.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/processors/plugin/CachePluginManager.java
index 772813f,fa33d3a..d721e9b
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/plugin/CachePluginManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/plugin/CachePluginManager.java
@@@ -99,9 -97,9 +99,9 @@@ public class CachePluginManager extend
}
/** {@inheritDoc} */
- @Override protected void stop0(boolean cancel) {
+ @Override protected void stop0(boolean cancel, boolean destroy) {
- for (ListIterator<CachePluginProvider> iter = providersList.listIterator(); iter.hasPrevious();)
- iter.previous().stop(cancel);
+ for (int i = providersList.size() - 1; i >= 0; i--)
+ providersList.get(i).stop(cancel);
}
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/81ae2d83/modules/core/src/main/java/org/apache/ignite/internal/processors/plugin/IgnitePluginProcessor.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/81ae2d83/modules/core/src/main/java/org/apache/ignite/internal/processors/port/GridPortProcessor.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/81ae2d83/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexDescriptor.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexDescriptor.java
index bed2ffe,134a61c..7f64dd7
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexDescriptor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexDescriptor.java
@@@ -46,12 -48,5 +48,12 @@@ public interface GridQueryIndexDescript
*
* @return Type.
*/
- public GridQueryIndexType type();
+ public QueryIndexType type();
+
+ /**
+ * Gets inline size for SORTED index.
+ *
+ * @return Inline size.
+ */
+ public int inlineSize();
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/81ae2d83/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
index a492c9b,4c32776..d49ea57
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
@@@ -225,34 -212,7 +227,25 @@@ public interface GridQueryIndexing
* @param val Value.
* @throws IgniteCheckedException If failed.
*/
- public void onUnswap(@Nullable String spaceName, CacheObject key, CacheObject val) throws IgniteCheckedException;
+ public void onUnswap(@Nullable String spaceName, KeyCacheObject key, int partId, CacheObject val) throws IgniteCheckedException;
+
+ /**
- * Rebuilds all indexes of given type.
- *
- * @param spaceName Space name.
- * @param type Type descriptor.
- */
- public void rebuildIndexes(@Nullable String spaceName, GridQueryTypeDescriptor type);
-
- /**
+ * Rebuilds all indexes of given type from hash index.
+ *
+ * @param spaceName Space name.
+ * @param type Type descriptor.
+ * @throws IgniteCheckedException If failed.
+ */
+ public void rebuildIndexesFromHash(@Nullable String spaceName,
+ GridQueryTypeDescriptor type) throws IgniteCheckedException;
+
+ /**
+ * Marks all indexes of given type for rebuild from hash index, making them unusable until rebuild finishes.
+ *
+ * @param spaceName Space name.
+ * @param type Type descriptor.
- * @throws IgniteCheckedException If failed.
+ */
+ public void markForRebuildFromHash(@Nullable String spaceName, GridQueryTypeDescriptor type);
/**
* Returns backup filter.
http://git-wip-us.apache.org/repos/asf/ignite/blob/81ae2d83/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
index 3fdea50,a58ca53..5ed3853
--- 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
@@@ -61,42 -40,23 +40,33 @@@ import org.apache.ignite.cache.query.Sq
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.events.CacheQueryExecutedEvent;
import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.NodeStoppingException;
- import org.apache.ignite.internal.binary.BinaryMarshaller;
- import org.apache.ignite.internal.binary.BinaryObjectEx;
import org.apache.ignite.internal.processors.GridProcessorAdapter;
import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
- import org.apache.ignite.internal.processors.cache.CacheEntryImpl;
import org.apache.ignite.internal.processors.cache.CacheObject;
import org.apache.ignite.internal.processors.cache.CacheObjectContext;
import org.apache.ignite.internal.processors.cache.GridCacheContext;
- import org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper;
import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
+import org.apache.ignite.internal.processors.cache.KeyCacheObject;
import org.apache.ignite.internal.processors.cache.QueryCursorImpl;
- import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
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.cache.query.QueryCursorEx;
+import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
import org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor;
import org.apache.ignite.internal.util.GridSpinBusyLock;
+import org.apache.ignite.internal.util.future.GridCompoundFuture;
+import org.apache.ignite.internal.util.future.GridFinishedFuture;
import org.apache.ignite.internal.util.lang.GridCloseableIterator;
import org.apache.ignite.internal.util.lang.GridClosureException;
import org.apache.ignite.internal.util.lang.IgniteOutClosureX;
- import org.apache.ignite.internal.util.tostring.GridToStringExclude;
- import org.apache.ignite.internal.util.tostring.GridToStringInclude;
import org.apache.ignite.internal.util.typedef.F;
- import org.apache.ignite.internal.util.typedef.T2;
- import org.apache.ignite.internal.util.typedef.internal.A;
+import org.apache.ignite.internal.util.typedef.internal.CU;
- import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.internal.util.worker.GridWorker;
+import org.apache.ignite.internal.util.worker.GridWorkerFuture;
import org.apache.ignite.lang.IgniteBiTuple;
import org.apache.ignite.lang.IgniteFuture;
import org.apache.ignite.spi.indexing.IndexingQueryFilter;
@@@ -168,6 -94,6 +104,9 @@@ public class GridQueryProcessor extend
/** */
private static final ThreadLocal<AffinityTopologyVersion> requestTopVer = new ThreadLocal<>();
++ /** */
++ private boolean skipFieldLookup;
++
/**
* @param ctx Kernal context.
*/
@@@ -565,149 -271,43 +288,131 @@@
return;
try {
- idx.unregisterCache(cctx.config());
+ unregisterCache0(cctx.name());
+ }
+ finally {
+ busyLock.leaveBusy();
+ }
+ }
- Iterator<Map.Entry<TypeId, TypeDescriptor>> it = types.entrySet().iterator();
+ /**
++ * @return Skip field lookup flag.
++ */
++ public boolean skipFieldLookup() {
++ return skipFieldLookup;
++ }
++
++ /**
++ * @param skipFieldLookup Skip field lookup flag.
++ */
++ public void skipFieldLookup(boolean skipFieldLookup) {
++ this.skipFieldLookup = skipFieldLookup;
++ }
++
++ /**
+ * Unregister cache.
+ *
+ * @param space Space.
+ */
+ private void unregisterCache0(String space) {
+ assert idx != null;
+
+ try {
+ idx.unregisterCache(space);
+ }
+ catch (Exception e) {
+ U.error(log, "Failed to clear indexing on cache unregister (will ignore): " + space, e);
+ }
+ finally {
+ Iterator<Map.Entry<QueryTypeIdKey, QueryTypeDescriptorImpl>> it = types.entrySet().iterator();
while (it.hasNext()) {
- Map.Entry<TypeId, TypeDescriptor> entry = it.next();
+ Map.Entry<QueryTypeIdKey, QueryTypeDescriptorImpl> entry = it.next();
- if (F.eq(cctx.name(), entry.getKey().space)) {
+ if (F.eq(space, entry.getKey().space())) {
it.remove();
- typesByName.remove(new TypeName(cctx.name(), entry.getValue().name()));
+ typesByName.remove(new QueryTypeNameKey(space, entry.getValue().name()));
}
}
}
}
/**
- * Rebuilds all search indexes of given value type for given space of spi.
++ * Rebuilds indexes for provided caches from corresponding hash indexes.
+ *
- * @param space Space.
- * @param valTypeName Value type name.
- * @return Future that will be completed when rebuilding of all indexes is finished.
++ * @param cacheIds Cache IDs.
++ * @return Future that will be completed when rebuilding is finished.
+ */
- public IgniteInternalFuture<?> rebuildIndexes(@Nullable final String space, String valTypeName) {
++ public IgniteInternalFuture<?> rebuildIndexesFromHash(Collection<Integer> cacheIds) {
+ if (!busyLock.enterBusy())
- throw new IllegalStateException("Failed to rebuild indexes (grid is stopping).");
++ throw new IllegalStateException("Failed to get space size (grid is stopping).");
+
+ try {
- return rebuildIndexes(space, typesByName.get(new TypeName(space, valTypeName)), false);
++ GridCompoundFuture<Object, ?> fut = new GridCompoundFuture<Object, Object>();
++
++ for (Map.Entry<QueryTypeIdKey, QueryTypeDescriptorImpl> e : types.entrySet()) {
++ if (cacheIds.contains(CU.cacheId(e.getKey().space())))
++ fut.add(rebuildIndexesFromHash(e.getKey().space(), e.getValue()));
++ }
++
++ fut.markInitialized();
++
++ return fut;
+ }
+ finally {
+ busyLock.leaveBusy();
+ }
+ }
+
+ /**
+ * @param space Space.
+ * @param desc Type descriptor.
+ * @return Future that will be completed when rebuilding of all indexes is finished.
+ */
- private IgniteInternalFuture<?> rebuildIndexes(@Nullable final String space, @Nullable final TypeDescriptor desc,
- final boolean fromHash) {
++ private IgniteInternalFuture<Object> rebuildIndexesFromHash(
++ @Nullable final String space,
++ @Nullable final QueryTypeDescriptorImpl desc
++ ) {
+ if (idx == null)
+ return new GridFinishedFuture<>(new IgniteCheckedException("Indexing is disabled."));
+
+ if (desc == null || !desc.registered())
- return new GridFinishedFuture<Void>();
++ return new GridFinishedFuture<>();
+
- final GridWorkerFuture<?> fut = new GridWorkerFuture<Void>();
++ final GridWorkerFuture<Object> fut = new GridWorkerFuture<>();
+
- if (fromHash)
- idx.markForRebuildFromHash(space, desc);
++ idx.markForRebuildFromHash(space, desc);
+
- GridWorker w = new GridWorker(ctx.gridName(), "index-rebuild-worker", log) {
++ GridWorker w = new GridWorker(ctx.igniteInstanceName(), "index-rebuild-worker", log) {
+ @Override protected void body() {
+ try {
- if (fromHash)
- idx.rebuildIndexesFromHash(space, desc);
- else
- idx.rebuildIndexes(space, desc);
++ idx.rebuildIndexesFromHash(space, desc);
+
+ fut.onDone();
+ }
+ catch (Exception e) {
+ fut.onDone(e);
+ }
+ catch (Throwable e) {
+ log.error("Failed to rebuild indexes for type: " + desc.name(), e);
+
+ fut.onDone(e);
+
+ if (e instanceof Error)
+ throw e;
+ }
+ }
+ };
+
+ fut.setWorker(w);
+
- execSvc.execute(w);
++ ctx.getExecutorService().execute(w);
+
+ return fut;
+ }
+
+ /**
- * Rebuilds all search indexes for given spi.
- *
- * @return Future that will be completed when rebuilding of all indexes is finished.
- */
- @SuppressWarnings("unchecked")
- public IgniteInternalFuture<?> rebuildAllIndexes() {
- if (!busyLock.enterBusy())
- throw new IllegalStateException("Failed to get space size (grid is stopping).");
-
- try {
- GridCompoundFuture<?, ?> fut = new GridCompoundFuture<Object, Object>();
-
- for (Map.Entry<TypeId, TypeDescriptor> e : types.entrySet())
- fut.add((IgniteInternalFuture)rebuildIndexes(e.getKey().space, e.getValue(), false));
-
- fut.markInitialized();
-
- return fut;
- }
- finally {
- busyLock.leaveBusy();
- }
- }
-
- /**
- * Rebuilds indexes for provided caches from corresponding hash indexes.
- *
- * @param cacheIds Cache IDs.
- * @return Future that will be completed when rebuilding is finished.
- */
- public IgniteInternalFuture<?> rebuildIndexesFromHash(Collection<Integer> cacheIds) {
- if (!busyLock.enterBusy())
- throw new IllegalStateException("Failed to get space size (grid is stopping).");
-
- try {
- GridCompoundFuture<?, ?> fut = new GridCompoundFuture<Object, Object>();
-
- for (Map.Entry<TypeId, TypeDescriptor> e : types.entrySet()) {
- if (cacheIds.contains(CU.cacheId(e.getKey().space)))
- fut.add((IgniteInternalFuture)rebuildIndexes(e.getKey().space, e.getValue(), true));
- }
-
- fut.markInitialized();
-
- return fut;
- }
- finally {
- busyLock.leaveBusy();
- }
- }
-
- /**
* @param space Space name.
* @return Cache object context.
*/
@@@ -725,16 -325,9 +430,16 @@@
* @param expirationTime Expiration time or 0 if never expires.
* @throws IgniteCheckedException In case of error.
*/
- @SuppressWarnings("unchecked")
+ @SuppressWarnings({"unchecked", "ConstantConditions"})
- public void store(final String space, final CacheObject key, final CacheObject val,
- byte[] ver, long expirationTime) throws IgniteCheckedException {
+ public void store(final String space,
+ final KeyCacheObject key,
+ int partId,
+ @Nullable CacheObject prevVal,
+ @Nullable GridCacheVersion prevVer,
+ final CacheObject val,
+ GridCacheVersion ver,
+ long expirationTime,
+ long link) throws IgniteCheckedException {
assert key != null;
assert val != null;
@@@ -747,67 -338,33 +450,66 @@@
return;
if (!busyLock.enterBusy())
- return;
+ throw new NodeStoppingException("Operation has been cancelled (node is stopping).");
try {
- if (coctx == null)
- coctx = cacheObjectContext(space);
+ CacheObjectContext coctx = cacheObjectContext(space);
- TypeDescriptor desc = typeByValue(coctx, key, val, true);
- Class<?> valCls = null;
++ QueryTypeDescriptorImpl desc = typeByValue(coctx, key, val, true);
- QueryTypeIdKey id;
+ if (prevVal != null) {
- TypeDescriptor prevValDesc = typeByValue(coctx, key, prevVal, false);
++ QueryTypeDescriptorImpl prevValDesc = typeByValue(coctx, key, prevVal, false);
- boolean binaryVal = ctx.cacheObjects().isBinaryObject(val);
+ if (prevValDesc != null && prevValDesc != desc)
+ idx.remove(space, prevValDesc, key, partId, prevVal, prevVer);
+ }
- if (binaryVal) {
- int typeId = ctx.cacheObjects().typeId(val);
+ if (desc == null)
+ return;
- id = new QueryTypeIdKey(space, typeId);
- }
- else {
- valCls = val.value(coctx, false).getClass();
+ idx.store(space, desc, key, partId, val, ver, expirationTime, link);
+ }
+ finally {
+ busyLock.leaveBusy();
+ }
+ }
- id = new QueryTypeIdKey(space, valCls);
- }
+ /**
+ * @param coctx Cache context.
+ * @param key Key.
+ * @param val Value.
+ * @param checkType If {@code true} checks that key and value type correspond to found TypeDescriptor.
+ * @return Type descriptor if found.
+ * @throws IgniteCheckedException If type check failed.
+ */
- @Nullable private TypeDescriptor typeByValue(CacheObjectContext coctx,
++ @Nullable private QueryTypeDescriptorImpl typeByValue(CacheObjectContext coctx,
+ KeyCacheObject key,
+ CacheObject val,
+ boolean checkType)
+ throws IgniteCheckedException {
+ Class<?> valCls = null;
- TypeId id;
- QueryTypeDescriptorImpl desc = types.get(id);
++ QueryTypeIdKey id;
- if (desc == null || !desc.registered())
- return;
+ boolean binaryVal = ctx.cacheObjects().isBinaryObject(val);
+
+ if (binaryVal) {
+ int typeId = ctx.cacheObjects().typeId(val);
+
- id = new TypeId(coctx.cacheName(), typeId);
++ id = new QueryTypeIdKey(coctx.cacheName(), typeId);
+ }
+ else {
+ valCls = val.value(coctx, false).getClass();
- id = new TypeId(coctx.cacheName(), valCls);
++ id = new QueryTypeIdKey(coctx.cacheName(), valCls);
+ }
+
- TypeDescriptor desc = types.get(id);
++ QueryTypeDescriptorImpl desc = types.get(id);
+
+ if (desc == null || !desc.registered())
+ return null;
+
+ if (checkType) {
if (!binaryVal && !desc.valueClass().isAssignableFrom(valCls))
throw new IgniteCheckedException("Failed to update index due to class name conflict" +
"(multiple classes with same simple name are stored in the same cache) " +
@@@ -1098,7 -633,8 +776,8 @@@
}, cancel) {
@Override public List<GridQueryFieldMetadata> fieldsMeta() {
if (cursor instanceof QueryCursorImpl)
-- return ((QueryCursorImpl)cursor).fieldsMeta();
++ return ((QueryCursorEx)cursor).fieldsMeta();
+
return super.fieldsMeta();
}
};
@@@ -1131,14 -667,7 +810,14 @@@
throw new IllegalStateException("Failed to remove from index (grid is stopping).");
try {
- idx.remove(space, key, val);
+ CacheObjectContext coctx = cacheObjectContext(space);
+
- TypeDescriptor desc = typeByValue(coctx, key, val, false);
++ QueryTypeDescriptorImpl desc = typeByValue(coctx, key, val, false);
+
+ if (desc == null)
+ return;
+
+ idx.remove(space, desc, key, partId, val, ver);
}
finally {
busyLock.leaveBusy();
http://git-wip-us.apache.org/repos/asf/ignite/blob/81ae2d83/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexDescriptorImpl.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexDescriptorImpl.java
index 0000000,53a0dfe..9d2d20c
mode 000000,100644..100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexDescriptorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexDescriptorImpl.java
@@@ -1,0 -1,102 +1,111 @@@
+ /*
+ * 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.cache.QueryIndexType;
+ import org.apache.ignite.internal.util.typedef.T2;
+ import org.apache.ignite.internal.util.typedef.internal.S;
+
+ import java.util.ArrayList;
+ import java.util.Collection;
+ import java.util.Comparator;
+ import java.util.HashSet;
+ import java.util.TreeSet;
+
+ /**
+ * Index descriptor.
+ */
+ public class QueryIndexDescriptorImpl implements GridQueryIndexDescriptor {
+ /** Fields sorted by order number. */
+ private final Collection<T2<String, Integer>> fields = new TreeSet<>(
+ new Comparator<T2<String, Integer>>() {
+ @Override public int compare(T2<String, Integer> o1, T2<String, Integer> o2) {
+ if (o1.get2().equals(o2.get2())) // Order is equal, compare field names to avoid replace in Set.
+ return o1.get1().compareTo(o2.get1());
+
+ return o1.get2() < o2.get2() ? -1 : 1;
+ }
+ });
+
+ /** Fields which should be indexed in descending order. */
+ private Collection<String> descendings;
+
+ /** */
+ private final QueryIndexType type;
+
++ /** */
++ private int inlineSize;
++
+ /**
+ * @param type Type.
+ */
- public QueryIndexDescriptorImpl(QueryIndexType type) {
++ public QueryIndexDescriptorImpl(QueryIndexType type, int inlineSize) {
+ assert type != null;
+
+ this.type = type;
++ this.inlineSize = inlineSize;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Collection<String> fields() {
+ Collection<String> res = new ArrayList<>(fields.size());
+
+ for (T2<String, Integer> t : fields)
+ res.add(t.get1());
+
+ return res;
+ }
+
+ /** {@inheritDoc} */
++ @Override public int inlineSize() {
++ return inlineSize;
++ }
++
++ /** {@inheritDoc} */
+ @Override public boolean descending(String field) {
+ return descendings != null && descendings.contains(field);
+ }
+
+ /**
+ * Adds field to this index.
+ *
+ * @param field Field name.
+ * @param orderNum Field order number in this index.
+ * @param descending Sort order.
+ */
+ public void addField(String field, int orderNum, boolean descending) {
+ fields.add(new T2<>(field, orderNum));
+
+ if (descending) {
+ if (descendings == null)
+ descendings = new HashSet<>();
+
+ descendings.add(field);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public QueryIndexType type() {
+ return type;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(QueryIndexDescriptorImpl.class, this);
+ }
+ }
http://git-wip-us.apache.org/repos/asf/ignite/blob/81ae2d83/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryTypeDescriptorImpl.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryTypeDescriptorImpl.java
index 0000000,f22cc11..a4da5e1
mode 000000,100644..100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryTypeDescriptorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryTypeDescriptorImpl.java
@@@ -1,0 -1,337 +1,359 @@@
+ /*
+ * 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.IgniteCheckedException;
+ import org.apache.ignite.cache.QueryIndexType;
+ import org.apache.ignite.internal.util.tostring.GridToStringExclude;
+ import org.apache.ignite.internal.util.tostring.GridToStringInclude;
+ import org.apache.ignite.internal.util.typedef.internal.A;
+ import org.apache.ignite.internal.util.typedef.internal.S;
+
+ import java.util.Collections;
+ import java.util.HashMap;
+ import java.util.LinkedHashMap;
+ import java.util.Map;
+
+ /**
+ * Descriptor of type.
+ */
+ public class QueryTypeDescriptorImpl implements GridQueryTypeDescriptor {
+ /** */
+ private String name;
+
+ /** */
+ private String tblName;
+
+ /** Value field names and types with preserved order. */
+ @GridToStringInclude
+ private final Map<String, Class<?>> fields = new LinkedHashMap<>();
+
+ /** */
+ @GridToStringExclude
+ private final Map<String, GridQueryProperty> props = new HashMap<>();
+
+ /** Map with upper cased property names to help find properties based on SQL INSERT and MERGE queries. */
+ private final Map<String, GridQueryProperty> uppercaseProps = new HashMap<>();
+
+ /** */
+ @GridToStringInclude
+ private final Map<String, QueryIndexDescriptorImpl> indexes = new HashMap<>();
+
+ /** */
+ private QueryIndexDescriptorImpl fullTextIdx;
+
+ /** */
+ private Class<?> keyCls;
+
+ /** */
+ private Class<?> valCls;
+
+ /** */
+ private String keyTypeName;
+
+ /** */
+ private String valTypeName;
+
+ /** */
+ private boolean valTextIdx;
+
+ /** */
++ private int typeId;
++
++ /** */
+ private String affKey;
+
+ /** SPI can decide not to register this type. */
+ private boolean registered;
+
+ /**
+ * @return {@code True} if type registration in SPI was finished and type was not rejected.
+ */
+ public boolean registered() {
+ return registered;
+ }
+
+ /**
+ * @param registered Sets registered flag.
+ */
+ public void registered(boolean registered) {
+ this.registered = registered;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String name() {
+ return name;
+ }
+
+ /**
+ * Sets type name.
+ *
+ * @param name Name.
+ */
+ public void name(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Gets table name for type.
+ * @return Table name.
+ */
- public String tableName() {
++ @Override public String tableName() {
+ return tblName;
+ }
+
+ /**
+ * Sets table name for type.
+ *
+ * @param tblName Table name.
+ */
+ public void tableName(String tblName) {
+ this.tblName = tblName;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Map<String, Class<?>> fields() {
+ return fields;
+ }
+
+ /** {@inheritDoc} */
+ @Override public GridQueryProperty property(String name) {
+ GridQueryProperty res = props.get(name);
+
+ if (res == null)
+ res = uppercaseProps.get(name.toUpperCase());
+
+ return res;
+ }
+
+ /**
+ * @return Properties.
+ */
+ public Map<String, GridQueryProperty> properties() {
+ return props;
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Override public <T> T value(String field, Object key, Object val) throws IgniteCheckedException {
+ assert field != null;
+
+ GridQueryProperty prop = property(field);
+
+ if (prop == null)
+ throw new IgniteCheckedException("Failed to find field '" + field + "' in type '" + name + "'.");
+
+ return (T)prop.value(key, val);
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Override public void setValue(String field, Object key, Object val, Object propVal)
+ throws IgniteCheckedException {
+ assert field != null;
+
+ GridQueryProperty prop = property(field);
+
+ if (prop == null)
+ throw new IgniteCheckedException("Failed to find field '" + field + "' in type '" + name + "'.");
+
+ prop.setValue(key, val, propVal);
+ }
+
+ /** {@inheritDoc} */
+ @Override public Map<String, GridQueryIndexDescriptor> indexes() {
+ return Collections.<String, GridQueryIndexDescriptor>unmodifiableMap(indexes);
+ }
+
++ /** {@inheritDoc} */
++ @Override public int typeId() {
++ return typeId;
++ }
++
++ /**
++ * @param typeId Type ID.
++ */
++ public void typeId(int typeId) {
++ this.typeId = typeId;
++ }
++
+ /**
+ * Adds index.
+ *
+ * @param idxName Index name.
+ * @param type Index type.
++ * @param inlineSize Inline size.
+ * @return Index descriptor.
+ * @throws IgniteCheckedException In case of error.
+ */
- public QueryIndexDescriptorImpl addIndex(String idxName, QueryIndexType type) throws IgniteCheckedException {
- QueryIndexDescriptorImpl idx = new QueryIndexDescriptorImpl(type);
++ public QueryIndexDescriptorImpl addIndex(String idxName, QueryIndexType type, int inlineSize) throws IgniteCheckedException {
++ QueryIndexDescriptorImpl idx = new QueryIndexDescriptorImpl(type, inlineSize);
+
+ if (indexes.put(idxName, idx) != null)
+ throw new IgniteCheckedException("Index with name '" + idxName + "' already exists.");
+
+ return idx;
+ }
+
+ /**
+ * Adds field to index.
+ *
+ * @param idxName Index name.
+ * @param field Field name.
+ * @param orderNum Fields order number in index.
++ * @param inlineSize Inline size.
+ * @param descending Sorting order.
+ * @throws IgniteCheckedException If failed.
+ */
- public void addFieldToIndex(String idxName, String field, int orderNum,
- boolean descending) throws IgniteCheckedException {
++ public void addFieldToIndex(
++ String idxName,
++ String field,
++ int orderNum,
++ int inlineSize,
++ boolean descending
++ ) throws IgniteCheckedException {
+ QueryIndexDescriptorImpl desc = indexes.get(idxName);
+
+ if (desc == null)
- desc = addIndex(idxName, QueryIndexType.SORTED);
++ desc = addIndex(idxName, QueryIndexType.SORTED, inlineSize);
+
+ desc.addField(field, orderNum, descending);
+ }
+
+ /**
+ * Adds field to text index.
+ *
+ * @param field Field name.
+ */
+ public void addFieldToTextIndex(String field) {
+ if (fullTextIdx == null) {
- fullTextIdx = new QueryIndexDescriptorImpl(QueryIndexType.FULLTEXT);
++ fullTextIdx = new QueryIndexDescriptorImpl(QueryIndexType.FULLTEXT, 0);
+
+ indexes.put(null, fullTextIdx);
+ }
+
+ fullTextIdx.addField(field, 0, false);
+ }
+
+ /** {@inheritDoc} */
+ @Override public Class<?> valueClass() {
+ return valCls;
+ }
+
+ /**
+ * Sets value class.
+ *
+ * @param valCls Value class.
+ */
+ public void valueClass(Class<?> valCls) {
+ A.notNull(valCls, "Value class must not be null");
+ this.valCls = valCls;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Class<?> keyClass() {
+ return keyCls;
+ }
+
+ /**
+ * Set key class.
+ *
+ * @param keyCls Key class.
+ */
+ public void keyClass(Class<?> keyCls) {
+ this.keyCls = keyCls;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String keyTypeName() {
+ return keyTypeName;
+ }
+
+ /**
+ * Set key type name.
+ *
+ * @param keyTypeName Key type name.
+ */
+ public void keyTypeName(String keyTypeName) {
+ this.keyTypeName = keyTypeName;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String valueTypeName() {
+ return valTypeName;
+ }
+
+ /**
+ * Set value type name.
+ *
+ * @param valTypeName Value type name.
+ */
+ public void valueTypeName(String valTypeName) {
+ this.valTypeName = valTypeName;
+ }
+
+ /**
+ * Adds property to the type descriptor.
+ *
+ * @param prop Property.
+ * @param failOnDuplicate Fail on duplicate flag.
+ * @throws IgniteCheckedException In case of error.
+ */
+ public void addProperty(GridQueryProperty prop, boolean failOnDuplicate) throws IgniteCheckedException {
+ String name = prop.name();
+
+ if (props.put(name, prop) != null && failOnDuplicate)
+ throw new IgniteCheckedException("Property with name '" + name + "' already exists.");
+
+ if (uppercaseProps.put(name.toUpperCase(), prop) != null && failOnDuplicate)
+ throw new IgniteCheckedException("Property with upper cased name '" + name + "' already exists.");
+
+ fields.put(name, prop.type());
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean valueTextIndex() {
+ return valTextIdx;
+ }
+
+ /**
+ * Sets if this value should be text indexed.
+ *
+ * @param valTextIdx Flag value.
+ */
+ public void valueTextIndex(boolean valTextIdx) {
+ this.valTextIdx = valTextIdx;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String affinityKey() {
+ return affKey;
+ }
+
+ /**
+ * @param affKey Affinity key field.
+ */
+ public void affinityKey(String affKey) {
+ this.affKey = affKey;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(QueryTypeDescriptorImpl.class, this);
+ }
+ }