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/06/06 10:34:19 UTC
ignite git commit: IGNITE-5267 - Store sql created flag for cache
Repository: ignite
Updated Branches:
refs/heads/ignite-5267 70eea2aa6 -> 9c22c716b
IGNITE-5267 - Store sql created flag for cache
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/9c22c716
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/9c22c716
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/9c22c716
Branch: refs/heads/ignite-5267
Commit: 9c22c716b5902a5d21277c8a1ae88e4dd59d3b66
Parents: 70eea2a
Author: Konstantin Dudkov <kd...@ya.ru>
Authored: Tue Jun 6 13:33:32 2017 +0300
Committer: Alexey Goncharuk <al...@gmail.com>
Committed: Tue Jun 6 13:34:11 2017 +0300
----------------------------------------------------------------------
.../org/apache/ignite/cache/QueryEntity.java | 28 +-
.../org/apache/ignite/cache/QueryIndex.java | 28 +-
.../pagemem/store/IgnitePageStoreManager.java | 16 +-
.../cache/CacheJoinNodeDiscoveryData.java | 15 +-
.../processors/cache/ClusterCachesInfo.java | 30 +-
.../processors/cache/GridCacheProcessor.java | 24 +-
.../processors/cache/StoredCacheData.java | 76 +++++
.../cluster/GridClusterStateProcessor.java | 18 +-
.../processors/query/GridQueryProcessor.java | 62 ++--
.../GridCacheDatabaseSharedManager.java | 15 +-
.../database/file/FilePageStoreManager.java | 53 ++--
.../IgnitePersistentStoreSchemaLoadTest.java | 297 +++++++++++++++++++
.../database/pagemem/NoOpPageStoreManager.java | 13 +-
.../ignite/testsuites/IgnitePdsTestSuite2.java | 2 +
14 files changed, 568 insertions(+), 109 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/9c22c716/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java b/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java
index 31d89a3..955e7d2 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java
@@ -25,9 +25,10 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
-
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
+import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.internal.A;
import org.apache.ignite.internal.util.typedef.internal.S;
@@ -351,6 +352,31 @@ public class QueryEntity implements Serializable {
}
/** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+ QueryEntity entity = (QueryEntity)o;
+
+ return F.eq(keyType, entity.keyType) &&
+ F.eq(valType, entity.valType) &&
+ F.eq(keyFieldName, entity.keyFieldName) &&
+ F.eq(valueFieldName, entity.valueFieldName) &&
+ F.eq(fields, entity.fields) &&
+ F.eq(keyFields, entity.keyFields) &&
+ F.eq(aliases, entity.aliases) &&
+ F.eqNotOrdered(idxs, entity.idxs) &&
+ F.eq(tableName, entity.tableName);
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return Objects.hash(keyType, valType, keyFieldName, valueFieldName, fields, keyFields, aliases, idxs, tableName);
+ }
+
+ /** {@inheritDoc} */
@Override public String toString() {
return S.toString(QueryEntity.class, this);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/9c22c716/modules/core/src/main/java/org/apache/ignite/cache/QueryIndex.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/QueryIndex.java b/modules/core/src/main/java/org/apache/ignite/cache/QueryIndex.java
index 555a006..6e73049 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/QueryIndex.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/QueryIndex.java
@@ -16,13 +16,14 @@
*/
package org.apache.ignite.cache;
-import org.apache.ignite.internal.util.tostring.GridToStringInclude;
-import org.apache.ignite.internal.util.typedef.internal.S;
-
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashMap;
+import java.util.Objects;
+import org.apache.ignite.internal.util.tostring.GridToStringInclude;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.S;
/**
* Contains list of fields to be indexed. It is possible to provide field name
@@ -266,6 +267,27 @@ public class QueryIndex implements Serializable {
}
/** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ QueryIndex index = (QueryIndex)o;
+
+ return inlineSize == index.inlineSize &&
+ F.eq(name, index.name) &&
+ F.eq(fields, index.fields) &&
+ type == index.type;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return Objects.hash(name, fields, type, inlineSize);
+ }
+
+ /** {@inheritDoc} */
@Override public String toString() {
return S.toString(QueryIndex.class, this);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/9c22c716/modules/core/src/main/java/org/apache/ignite/internal/pagemem/store/IgnitePageStoreManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/store/IgnitePageStoreManager.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/store/IgnitePageStoreManager.java
index 11a3804..f3e3aa4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/store/IgnitePageStoreManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/store/IgnitePageStoreManager.java
@@ -20,11 +20,11 @@ package org.apache.ignite.internal.pagemem.store;
import java.nio.ByteBuffer;
import java.util.Map;
import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.internal.pagemem.PageMemory;
import org.apache.ignite.internal.processors.cache.CacheGroupContext;
import org.apache.ignite.internal.processors.cache.CacheGroupDescriptor;
import org.apache.ignite.internal.processors.cache.GridCacheSharedManager;
+import org.apache.ignite.internal.processors.cache.StoredCacheData;
import org.apache.ignite.internal.processors.cluster.IgniteChangeGlobalStateSupport;
/**
@@ -45,10 +45,11 @@ public interface IgnitePageStoreManager extends GridCacheSharedManager, IgniteCh
* Callback called when a cache is starting.
*
* @param grpDesc Cache group descriptor.
- * @param ccfg Cache configuration of the cache being started.
+ * @param cacheData Cache data of the cache being started.
* @throws IgniteCheckedException If failed to handle cache start callback.
*/
- public void initializeForCache(CacheGroupDescriptor grpDesc, CacheConfiguration ccfg) throws IgniteCheckedException;
+ public void initializeForCache(CacheGroupDescriptor grpDesc,
+ StoredCacheData cacheData) throws IgniteCheckedException;
/**
* Callback called when a cache is stopping. After this callback is invoked, no data associated with
@@ -178,7 +179,14 @@ public interface IgnitePageStoreManager extends GridCacheSharedManager, IgniteCh
* @return Saved cache configurations.
* @throws IgniteCheckedException If failed.
*/
- public Map<String, CacheConfiguration> readCacheConfigurations() throws IgniteCheckedException;
+ public Map<String, StoredCacheData> readCacheConfigurations() throws IgniteCheckedException;
+
+ /**
+ * @param grpDesc Cache group descriptor.
+ * @param cacheData Cache configuration.
+ * @throws IgniteCheckedException If failed.
+ */
+ public void storeCacheData(CacheGroupDescriptor grpDesc, StoredCacheData cacheData) throws IgniteCheckedException;
/**
* @param grpId Cache group ID.
http://git-wip-us.apache.org/repos/asf/ignite/blob/9c22c716/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheJoinNodeDiscoveryData.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheJoinNodeDiscoveryData.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheJoinNodeDiscoveryData.java
index 58c9d82..3f99134 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheJoinNodeDiscoveryData.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheJoinNodeDiscoveryData.java
@@ -19,7 +19,6 @@ package org.apache.ignite.internal.processors.cache;
import java.io.Serializable;
import java.util.Map;
-import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.lang.IgniteUuid;
@@ -100,7 +99,7 @@ class CacheJoinNodeDiscoveryData implements Serializable {
/** */
@GridToStringInclude
- private final CacheConfiguration ccfg;
+ private final StoredCacheData cacheData;
/** */
@GridToStringInclude
@@ -114,23 +113,23 @@ class CacheJoinNodeDiscoveryData implements Serializable {
private final long flags;
/**
- * @param ccfg Cache configuration.
+ * @param cacheData Cache data.
* @param cacheType Cache type.
* @param sql SQL flag - {@code true} if cache was created with {@code CREATE TABLE}.
* @param flags Flags (for future usage).
*/
- CacheInfo(CacheConfiguration ccfg, CacheType cacheType, boolean sql, long flags) {
- this.ccfg = ccfg;
+ CacheInfo(StoredCacheData cacheData, CacheType cacheType, boolean sql, long flags) {
+ this.cacheData = cacheData;
this.cacheType = cacheType;
this.sql = sql;
this.flags = flags;
}
/**
- * @return Cache configuration.
+ * @return Cache data.
*/
- CacheConfiguration config() {
- return ccfg;
+ StoredCacheData cacheData() {
+ return cacheData;
}
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/9c22c716/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java
index 0fcc740..e584701 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java
@@ -109,15 +109,15 @@ class ClusterCachesInfo {
Map<String, CacheConfiguration> grpCfgs = new HashMap<>();
for (CacheJoinNodeDiscoveryData.CacheInfo info : joinDiscoData.caches().values()) {
- if (info.config().getGroupName() == null)
+ if (info.cacheData().config().getGroupName() == null)
continue;
- CacheConfiguration ccfg = grpCfgs.get(info.config().getGroupName());
+ CacheConfiguration ccfg = grpCfgs.get(info.cacheData().config().getGroupName());
if (ccfg == null)
- grpCfgs.put(info.config().getGroupName(), info.config());
+ grpCfgs.put(info.cacheData().config().getGroupName(), info.cacheData().config());
else
- validateCacheGroupConfiguration(ccfg, info.config());
+ validateCacheGroupConfiguration(ccfg, info.cacheData().config());
}
String conflictErr = processJoiningNode(joinDiscoData, ctx.localNodeId(), true);
@@ -147,7 +147,7 @@ class ClusterCachesInfo {
if (checkConsistency && joinDiscoData != null && gridData != null) {
for (CacheJoinNodeDiscoveryData.CacheInfo locCacheInfo : joinDiscoData.caches().values()) {
- CacheConfiguration locCfg = locCacheInfo.config();
+ CacheConfiguration locCfg = locCacheInfo.cacheData().config();
CacheData cacheData = gridData.gridData.caches().get(locCfg.getName());
@@ -173,7 +173,7 @@ class ClusterCachesInfo {
private void checkCache(CacheJoinNodeDiscoveryData.CacheInfo locInfo, CacheData rmtData, UUID rmt)
throws IgniteCheckedException {
GridCacheAttributes rmtAttr = new GridCacheAttributes(rmtData.cacheConfiguration(), rmtData.sql());
- GridCacheAttributes locAttr = new GridCacheAttributes(locInfo.config(), locInfo.sql());
+ GridCacheAttributes locAttr = new GridCacheAttributes(locInfo.cacheData().config(), locInfo.sql());
CU.checkAttributeMismatch(log, rmtAttr.cacheName(), rmt, "cacheMode", "Cache mode",
locAttr.cacheMode(), rmtAttr.cacheMode(), true);
@@ -199,7 +199,7 @@ class ClusterCachesInfo {
ClusterNode rmtNode = ctx.discovery().node(rmt);
- if (CU.affinityNode(ctx.discovery().localNode(), locInfo.config().getNodeFilter())
+ if (CU.affinityNode(ctx.discovery().localNode(), locInfo.cacheData().config().getNodeFilter())
&& rmtNode != null && CU.affinityNode(rmtNode, rmtData.cacheConfiguration().getNodeFilter())) {
CU.checkAttributeMismatch(log, rmtAttr.cacheName(), rmt, "storeFactory", "Store factory",
locAttr.storeFactoryClassName(), rmtAttr.storeFactoryClassName(), true);
@@ -860,7 +860,7 @@ class ClusterCachesInfo {
if (joinDiscoData != null) {
for (Map.Entry<String, CacheJoinNodeDiscoveryData.CacheInfo> e : joinDiscoData.caches().entrySet()) {
if (!registeredCaches.containsKey(e.getKey())) {
- conflictErr = checkCacheConflict(e.getValue().config());
+ conflictErr = checkCacheConflict(e.getValue().cacheData().config());
if (conflictErr != null) {
conflictErr = "Failed to start configured cache due to conflict with started caches. " +
@@ -900,10 +900,10 @@ class ClusterCachesInfo {
NearCacheConfiguration nearCfg = null;
if (locCfg != null) {
- nearCfg = locCfg.config().getNearConfiguration();
+ nearCfg = locCfg.cacheData().config().getNearConfiguration();
DynamicCacheDescriptor desc0 = new DynamicCacheDescriptor(ctx,
- locCfg.config(),
+ locCfg.cacheData().config(),
desc.cacheType(),
desc.groupDescriptor(),
desc.template(),
@@ -911,7 +911,7 @@ class ClusterCachesInfo {
desc.staticallyConfigured(),
desc.sql(),
desc.deploymentId(),
- desc.schema());
+ new QuerySchema(locCfg.cacheData().queryEntities()));
desc0.startTopologyVersion(desc.startTopologyVersion());
desc0.receivedFromStartVersion(desc.receivedFromStartVersion());
@@ -1029,7 +1029,7 @@ class ClusterCachesInfo {
*/
private String processJoiningNode(CacheJoinNodeDiscoveryData joinData, UUID nodeId, boolean locJoin) {
for (CacheJoinNodeDiscoveryData.CacheInfo cacheInfo : joinData.templates().values()) {
- CacheConfiguration<?, ?> cfg = cacheInfo.config();
+ CacheConfiguration<?, ?> cfg = cacheInfo.cacheData().config();
if (!registeredTemplates.containsKey(cfg.getName())) {
DynamicCacheDescriptor desc = new DynamicCacheDescriptor(ctx,
@@ -1041,7 +1041,7 @@ class ClusterCachesInfo {
true,
false,
joinData.cacheDeploymentId(),
- new QuerySchema(cfg.getQueryEntities()));
+ new QuerySchema(cacheInfo.cacheData().queryEntities()));
DynamicCacheDescriptor old = registeredTemplates.put(cfg.getName(), desc);
@@ -1050,7 +1050,7 @@ class ClusterCachesInfo {
}
for (CacheJoinNodeDiscoveryData.CacheInfo cacheInfo : joinData.caches().values()) {
- CacheConfiguration<?, ?> cfg = cacheInfo.config();
+ CacheConfiguration<?, ?> cfg = cacheInfo.cacheData().config();
if (!registeredCaches.containsKey(cfg.getName())) {
String conflictErr = checkCacheConflict(cfg);
@@ -1087,7 +1087,7 @@ class ClusterCachesInfo {
true,
cacheInfo.sql(),
joinData.cacheDeploymentId(),
- new QuerySchema(cfg.getQueryEntities()));
+ new QuerySchema(cacheInfo.cacheData().queryEntities()));
DynamicCacheDescriptor old = registeredCaches.put(cfg.getName(), desc);
http://git-wip-us.apache.org/repos/asf/ignite/blob/9c22c716/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
index 577bfb9..e968074 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
@@ -689,15 +689,17 @@ public class GridCacheProcessor extends GridProcessorAdapter {
}
/**
- * @param cfg Cache configuration.
+ * @param cacheData Cache data.
* @param sql SQL flag - {@code true} if cache was created with {@code CREATE TABLE}.
* @param caches Caches map.
* @param templates Templates map.
* @throws IgniteCheckedException If failed.
*/
- private void addCacheOnJoin(CacheConfiguration cfg, boolean sql,
+ private void addCacheOnJoin(StoredCacheData cacheData, boolean sql,
Map<String, CacheJoinNodeDiscoveryData.CacheInfo> caches,
Map<String, CacheJoinNodeDiscoveryData.CacheInfo> templates) throws IgniteCheckedException {
+ CacheConfiguration<?, ?> cfg = cacheData.config();
+
CU.validateCacheName(cfg.getName());
cloneCheckSerializable(cfg);
@@ -732,10 +734,10 @@ public class GridCacheProcessor extends GridProcessorAdapter {
else
stopSeq.addFirst(cfg.getName());
- caches.put(cfg.getName(), new CacheJoinNodeDiscoveryData.CacheInfo(cfg, cacheType, sql, 0));
+ caches.put(cfg.getName(), new CacheJoinNodeDiscoveryData.CacheInfo(cacheData, cacheType, sql, 0));
}
else
- templates.put(cfg.getName(), new CacheJoinNodeDiscoveryData.CacheInfo(cfg, CacheType.USER, false, 0));
+ templates.put(cfg.getName(), new CacheJoinNodeDiscoveryData.CacheInfo(cacheData, CacheType.USER, false, 0));
}
/**
@@ -756,7 +758,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
cfgs[i] = cfg; // Replace original configuration value.
- addCacheOnJoin(cfg, false, caches, templates);
+ addCacheOnJoin(new StoredCacheData(cfg), false, caches, templates);
}
}
@@ -772,7 +774,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
assert !ctx.config().isDaemon();
if (sharedCtx.pageStore() != null && sharedCtx.database().persistenceEnabled()) {
- Map<String, CacheConfiguration> ccfgs = sharedCtx.pageStore().readCacheConfigurations();
+ Map<String, StoredCacheData> ccfgs = sharedCtx.pageStore().readCacheConfigurations();
for (String cache : caches.keySet())
ccfgs.remove(cache);
@@ -785,7 +787,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
log.info("Register persistent caches: " + ccfgs.keySet());
// TODO IGNITE-5306 - set correct SQL flag below.
- for (CacheConfiguration ccfg : ccfgs.values())
+ for (StoredCacheData ccfg : ccfgs.values())
addCacheOnJoin(ccfg, false, caches, templates);
}
}
@@ -1888,7 +1890,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
}
if (sharedCtx.pageStore() != null && affNode)
- sharedCtx.pageStore().initializeForCache(grpDesc, startCfg);
+ sharedCtx.pageStore().initializeForCache(grpDesc, new StoredCacheData(startCfg));
String grpName = startCfg.getGroupName();
@@ -2747,10 +2749,10 @@ public class GridCacheProcessor extends GridProcessorAdapter {
if (!ctx.config().isDaemon() &&
sharedCtx.pageStore() != null &&
sharedCtx.database().persistenceEnabled()) {
- Map<String, CacheConfiguration> savedCaches = sharedCtx.pageStore().readCacheConfigurations();
+ Map<String, StoredCacheData> savedCaches = sharedCtx.pageStore().readCacheConfigurations();
- for (CacheConfiguration cfg : savedCaches.values())
- reqs.add(createRequest(cfg, false));
+ for (StoredCacheData cfg : savedCaches.values())
+ reqs.add(createRequest(cfg.config(), false));
for (CacheConfiguration cfg : ctx.config().getCacheConfiguration()) {
if (!savedCaches.containsKey(cfg.getName()))
http://git-wip-us.apache.org/repos/asf/ignite/blob/9c22c716/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/StoredCacheData.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/StoredCacheData.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/StoredCacheData.java
new file mode 100644
index 0000000..2b3dcdc
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/StoredCacheData.java
@@ -0,0 +1,76 @@
+/*
+ * 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.cache;
+
+import java.io.Serializable;
+import java.util.Collection;
+import org.apache.ignite.cache.QueryEntity;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager;
+import org.apache.ignite.internal.util.typedef.internal.A;
+import org.apache.ignite.marshaller.jdk.JdkMarshaller;
+
+/**
+ * Cache data to write to and read from {@link IgnitePageStoreManager}. In a nutshell, contains (most importantly)
+ * {@link CacheConfiguration} and additional information about cache which is not a part of configuration.
+ * This class is {@link Serializable} and is intended to be read-written with {@link JdkMarshaller}
+ * in order to be serialization wise agnostic to further additions or removals of fields.
+ */
+public class StoredCacheData implements Serializable {
+ /** */
+ private static final long serialVersionUID = 0L;
+
+ /** Cache configuration. */
+ private final CacheConfiguration<?, ?> ccfg;
+
+ /** Query entities. */
+ private Collection<QueryEntity> qryEntities;
+
+ /**
+ * Constructor.
+ *
+ * @param ccfg Cache configuration.
+ */
+ public StoredCacheData(CacheConfiguration<?, ?> ccfg) {
+ A.notNull(ccfg, "ccfg");
+
+ this.ccfg = ccfg;
+ this.qryEntities = ccfg.getQueryEntities();
+ }
+
+ /**
+ * @return Cache configuration.
+ */
+ public CacheConfiguration<?, ?> config() {
+ return ccfg;
+ }
+
+ /**
+ * @return Query entities.
+ */
+ public Collection<QueryEntity> queryEntities() {
+ return qryEntities;
+ }
+
+ /**
+ * @param qryEntities Query entities.
+ */
+ public void queryEntities(Collection<QueryEntity> qryEntities) {
+ this.qryEntities = qryEntities;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/9c22c716/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java
index 730fab5..3c500a4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java
@@ -33,7 +33,6 @@ import org.apache.ignite.IgniteCompute;
import org.apache.ignite.IgniteException;
import org.apache.ignite.IgniteLogger;
import org.apache.ignite.cluster.ClusterNode;
-import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.events.DiscoveryEvent;
import org.apache.ignite.events.Event;
import org.apache.ignite.internal.GridKernalContext;
@@ -53,6 +52,7 @@ import org.apache.ignite.internal.processors.cache.ExchangeActions;
import org.apache.ignite.internal.processors.cache.GridCacheProcessor;
import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
import org.apache.ignite.internal.processors.cache.GridChangeGlobalStateMessageResponse;
+import org.apache.ignite.internal.processors.cache.StoredCacheData;
import org.apache.ignite.internal.util.future.GridFinishedFuture;
import org.apache.ignite.internal.util.future.GridFutureAdapter;
import org.apache.ignite.internal.util.tostring.GridToStringExclude;
@@ -431,11 +431,11 @@ public class GridClusterStateProcessor extends GridProcessorAdapter {
log.info("Start activation process [nodeId=" + this.ctx.localNodeId() + ", client=" + client +
", topVer=" + cgsCtx.topVer + "]");
- Collection<CacheConfiguration> cfgs = new ArrayList<>();
+ Collection<StoredCacheData> cfgs = new ArrayList<>();
for (DynamicCacheChangeRequest req : cgsCtx.batch.requests()) {
if (req.startCacheConfiguration() != null)
- cfgs.add(req.startCacheConfiguration());
+ cfgs.add(new StoredCacheData(req.startCacheConfiguration()));
}
try {
@@ -453,16 +453,16 @@ public class GridClusterStateProcessor extends GridProcessorAdapter {
sharedCtx.database().initDataBase();
// TODO IGNITE-5075 group descriptors.
- for (CacheConfiguration cfg : cfgs) {
- if (CU.isSystemCache(cfg.getName()))
+ for (StoredCacheData cacheData : cfgs) {
+ if (CU.isSystemCache(cacheData.config().getName()))
if (pageStore != null)
- pageStore.initializeForCache(ctx.cache().cacheDescriptors().get(cfg.getName()).groupDescriptor(), cfg);
+ pageStore.initializeForCache(ctx.cache().cacheDescriptors().get(cacheData.config().getName()).groupDescriptor(), cacheData);
}
- for (CacheConfiguration cfg : cfgs) {
- if (!CU.isSystemCache(cfg.getName()))
+ for (StoredCacheData cacheData : cfgs) {
+ if (!CU.isSystemCache(cacheData.config().getName()))
if (pageStore != null)
- pageStore.initializeForCache(ctx.cache().cacheDescriptors().get(cfg.getName()).groupDescriptor(), cfg);
+ pageStore.initializeForCache(ctx.cache().cacheDescriptors().get(cacheData.config().getName()).groupDescriptor(), cacheData);
}
sharedCtx.database().onActivate(ctx);
http://git-wip-us.apache.org/repos/asf/ignite/blob/9c22c716/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 6197dd9..e2238fa 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
@@ -17,6 +17,25 @@
package org.apache.ignite.internal.processors.query;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+import javax.cache.Cache;
+import javax.cache.CacheException;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteDataStreamer;
import org.apache.ignite.IgniteException;
@@ -34,16 +53,18 @@ 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.managers.communication.GridMessageListener;
import org.apache.ignite.internal.NodeStoppingException;
+import org.apache.ignite.internal.managers.communication.GridMessageListener;
import org.apache.ignite.internal.processors.GridProcessorAdapter;
import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.apache.ignite.internal.processors.cache.CacheGroupDescriptor;
import org.apache.ignite.internal.processors.cache.CacheObject;
import org.apache.ignite.internal.processors.cache.CacheObjectContext;
import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor;
import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
import org.apache.ignite.internal.processors.cache.GridCacheContext;
import org.apache.ignite.internal.processors.cache.KeyCacheObject;
+import org.apache.ignite.internal.processors.cache.StoredCacheData;
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;
@@ -71,9 +92,9 @@ 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.typedef.F;
-import org.apache.ignite.internal.util.typedef.internal.CU;
import org.apache.ignite.internal.util.typedef.T2;
import org.apache.ignite.internal.util.typedef.T3;
+import org.apache.ignite.internal.util.typedef.internal.CU;
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;
@@ -87,26 +108,6 @@ import org.apache.ignite.spi.indexing.IndexingQueryFilter;
import org.apache.ignite.thread.IgniteThread;
import org.jetbrains.annotations.Nullable;
-import javax.cache.Cache;
-import javax.cache.CacheException;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.atomic.AtomicBoolean;
-
import static org.apache.ignite.events.EventType.EVT_CACHE_QUERY_EXECUTED;
import static org.apache.ignite.internal.GridTopic.TOPIC_SCHEMA;
import static org.apache.ignite.internal.IgniteComponentType.INDEXING;
@@ -502,6 +503,23 @@ public class GridQueryProcessor extends GridProcessorAdapter {
if (cacheDesc != null && F.eq(cacheDesc.deploymentId(), proposeMsg.deploymentId()))
cacheDesc.schemaChangeFinish(msg);
+
+ if (ctx.cache().context().pageStore() != null &&
+ ctx.cache().context().database().persistenceEnabled()) {
+
+ StoredCacheData cacheData = new StoredCacheData(cacheDesc.cacheConfiguration());
+
+ cacheData.queryEntities(cacheDesc.schema().entities());
+
+ CacheGroupDescriptor grpDesc = ctx.cache().cacheDescriptors().get(cacheData.config().getName()).groupDescriptor();
+
+ try {
+ ctx.cache().context().pageStore().storeCacheData(grpDesc, cacheData);
+ }
+ catch (IgniteCheckedException e) {
+ throw new IllegalStateException("Failed to persist cache data: " + cacheData.config().getName(), e);
+ }
+ }
}
// Propose message will be used from exchange thread to
http://git-wip-us.apache.org/repos/asf/ignite/blob/9c22c716/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java
----------------------------------------------------------------------
diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java
index f43a31e..9f51750 100755
--- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java
+++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/GridCacheDatabaseSharedManager.java
@@ -96,8 +96,10 @@ import org.apache.ignite.internal.pagemem.wal.record.delta.PartitionMetaStateRec
import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
import org.apache.ignite.internal.processors.cache.CacheGroupContext;
import org.apache.ignite.internal.processors.cache.ClusterState;
+import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor;
import org.apache.ignite.internal.processors.cache.GridCacheContext;
import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
+import org.apache.ignite.internal.processors.cache.StoredCacheData;
import org.apache.ignite.internal.processors.cache.database.file.FilePageStoreManager;
import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryEx;
import org.apache.ignite.internal.processors.cache.database.pagemem.PageMemoryImpl;
@@ -413,7 +415,7 @@ public class GridCacheDatabaseSharedManager extends IgniteCacheDatabaseSharedMan
// TODO IGNITE-5075 group descriptors.
for (CacheConfiguration ccfg : cctx.kernalContext().config().getCacheConfiguration()) {
if (CU.isSystemCache(ccfg.getName())) {
- storeMgr.initializeForCache(cctx.cache().cacheDescriptors().get(ccfg.getName()).groupDescriptor(), ccfg);
+ storeMgr.initializeForCache(cctx.cache().cacheDescriptors().get(ccfg.getName()).groupDescriptor(), new StoredCacheData(ccfg));
cacheNames.add(ccfg.getName());
}
@@ -421,14 +423,17 @@ public class GridCacheDatabaseSharedManager extends IgniteCacheDatabaseSharedMan
for (CacheConfiguration ccfg : cctx.kernalContext().config().getCacheConfiguration())
if (!CU.isSystemCache(ccfg.getName())) {
- storeMgr.initializeForCache(cctx.cache().cacheDescriptors().get(ccfg.getName()).groupDescriptor(), ccfg);
+ DynamicCacheDescriptor cacheDesc = cctx.cache().cacheDescriptors().get(ccfg.getName());
+
+ if (cacheDesc != null)
+ storeMgr.initializeForCache(cacheDesc.groupDescriptor(), new StoredCacheData(ccfg));
cacheNames.add(ccfg.getName());
}
- for (CacheConfiguration ccfg : cctx.pageStore().readCacheConfigurations().values()) {
- if (!cacheNames.contains(ccfg.getName()))
- storeMgr.initializeForCache(cctx.cache().cacheDescriptors().get(ccfg.getName()).groupDescriptor(), ccfg);
+ for (StoredCacheData cacheData : cctx.pageStore().readCacheConfigurations().values()) {
+ if (!cacheNames.contains(cacheData.config().getName()))
+ storeMgr.initializeForCache(cctx.cache().cacheDescriptors().get(cacheData.config().getName()).groupDescriptor(), cacheData);
}
readCheckpointAndRestoreMemory();
http://git-wip-us.apache.org/repos/asf/ignite/blob/9c22c716/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java
----------------------------------------------------------------------
diff --git a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java
index 1343589..f91c47f 100755
--- a/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java
+++ b/modules/pds/src/main/java/org/apache/ignite/internal/processors/cache/database/file/FilePageStoreManager.java
@@ -46,6 +46,7 @@ import org.apache.ignite.internal.pagemem.store.PageStore;
import org.apache.ignite.internal.processors.cache.CacheGroupContext;
import org.apache.ignite.internal.processors.cache.CacheGroupDescriptor;
import org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter;
+import org.apache.ignite.internal.processors.cache.StoredCacheData;
import org.apache.ignite.internal.processors.cache.database.IgniteCacheSnapshotManager;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.marshaller.Marshaller;
@@ -75,7 +76,7 @@ public class FilePageStoreManager extends GridCacheSharedManagerAdapter implemen
public static final String CACHE_GRP_DIR_PREFIX = "cacheGroup-";
/** */
- public static final String CACHE_CONF_FILENAME = "conf.dat";
+ public static final String CACHE_DATA_FILENAME = "cache_data.dat";
/** Marshaller. */
private static final Marshaller marshaller = new JdkMarshaller();
@@ -192,48 +193,44 @@ public class FilePageStoreManager extends GridCacheSharedManagerAdapter implemen
}
/** {@inheritDoc} */
- @Override public void initializeForCache(CacheGroupDescriptor grpDesc, CacheConfiguration ccfg)
+ @Override public void initializeForCache(CacheGroupDescriptor grpDesc, StoredCacheData cacheData)
throws IgniteCheckedException {
int grpId = grpDesc.groupId();
if (!idxCacheStores.containsKey(grpId)) {
- CacheStoreHolder holder = initForCache(grpDesc, ccfg);
+ CacheStoreHolder holder = initForCache(grpDesc, cacheData.config());
CacheStoreHolder old = idxCacheStores.put(grpId, holder);
- assert old == null : "Non-null old store holder for cache: " + ccfg.getName();
+ assert old == null : "Non-null old store holder for cache: " + cacheData.config().getName();
}
- storeCacheConfiguration(grpDesc, ccfg);
+ storeCacheData(grpDesc, cacheData);
}
- /**
- * @param grpDesc Cache group descriptor.
- * @param ccfg Cache configuration.
- * @throws IgniteCheckedException If failed.
- */
- private void storeCacheConfiguration(CacheGroupDescriptor grpDesc, CacheConfiguration ccfg)
+ /** {@inheritDoc} */
+ @Override public void storeCacheData(CacheGroupDescriptor grpDesc, StoredCacheData cacheData)
throws IgniteCheckedException {
- File cacheWorkDir = cacheWorkDirectory(grpDesc, ccfg);
+ File cacheWorkDir = cacheWorkDirectory(grpDesc, cacheData.config());
File file;
assert cacheWorkDir.exists() : "Work directory does not exist: " + cacheWorkDir;
if (grpDesc.sharedGroup())
- file = new File(cacheWorkDir, ccfg.getName() + CACHE_CONF_FILENAME);
+ file = new File(cacheWorkDir, cacheData.config().getName() + CACHE_DATA_FILENAME);
else
- file = new File(cacheWorkDir, CACHE_CONF_FILENAME);
+ file = new File(cacheWorkDir, CACHE_DATA_FILENAME);
if (!file.exists() || file.length() == 0) {
try {
file.createNewFile();
try (OutputStream stream = new BufferedOutputStream(new FileOutputStream(file))) {
- marshaller.marshal(ccfg, stream);
+ marshaller.marshal(cacheData, stream);
}
}
catch (IOException ex) {
- throw new IgniteCheckedException("Failed to persist cache configuration: " + ccfg.getName(), ex);
+ throw new IgniteCheckedException("Failed to persist cache configuration: " + cacheData.config().getName(), ex);
}
}
}
@@ -473,7 +470,7 @@ public class FilePageStoreManager extends GridCacheSharedManagerAdapter implemen
}
/** {@inheritDoc} */
- @Override public Map<String, CacheConfiguration> readCacheConfigurations() throws IgniteCheckedException {
+ @Override public Map<String, StoredCacheData> readCacheConfigurations() throws IgniteCheckedException {
if (cctx.kernalContext().clientNode())
return Collections.emptyMap();
@@ -482,17 +479,17 @@ public class FilePageStoreManager extends GridCacheSharedManagerAdapter implemen
if (files == null)
return Collections.emptyMap();
- Map<String, CacheConfiguration> ccfgs = new HashMap<>();
+ Map<String, StoredCacheData> ccfgs = new HashMap<>();
for (File file : files) {
if (file.isDirectory()) {
if (file.getName().startsWith(CACHE_DIR_PREFIX)) {
- File conf = new File(file, CACHE_CONF_FILENAME);
+ File conf = new File(file, CACHE_DATA_FILENAME);
if (conf.exists() && conf.length() > 0) {
- CacheConfiguration ccfg = readCacheConfig(conf);
+ StoredCacheData cacheData = readCacheData(conf);
- ccfgs.put(ccfg.getName(), ccfg);
+ ccfgs.put(cacheData.config().getName(), cacheData);
}
}
else if (file.getName().startsWith(CACHE_GRP_DIR_PREFIX))
@@ -508,27 +505,27 @@ public class FilePageStoreManager extends GridCacheSharedManagerAdapter implemen
* @param ccfgs Cache configurations.
* @throws IgniteCheckedException If failed.
*/
- private void readCacheGroupCaches(File grpDir, Map<String, CacheConfiguration> ccfgs) throws IgniteCheckedException {
+ private void readCacheGroupCaches(File grpDir, Map<String, StoredCacheData> ccfgs) throws IgniteCheckedException {
File[] files = grpDir.listFiles();
if (files == null)
return;
for (File file : files) {
- if (!file.isDirectory() && file.getName().endsWith(CACHE_CONF_FILENAME) && file.length() > 0) {
- CacheConfiguration ccfg = readCacheConfig(file);
+ if (!file.isDirectory() && file.getName().endsWith(CACHE_DATA_FILENAME) && file.length() > 0) {
+ StoredCacheData cacheData = readCacheData(file);
- ccfgs.put(ccfg.getName(), ccfg);
+ ccfgs.put(cacheData.config().getName(), cacheData);
}
}
}
/**
- * @param conf File with stored configuration.
- * @return Cache configuration.
+ * @param conf File with stored cache data.
+ * @return Cache data.
* @throws IgniteCheckedException If failed.
*/
- private CacheConfiguration readCacheConfig(File conf) throws IgniteCheckedException {
+ private StoredCacheData readCacheData(File conf) throws IgniteCheckedException {
try (InputStream stream = new BufferedInputStream(new FileInputStream(conf))) {
return marshaller.unmarshal(stream, U.resolveClassLoader(igniteCfg));
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/9c22c716/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSchemaLoadTest.java
----------------------------------------------------------------------
diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSchemaLoadTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSchemaLoadTest.java
new file mode 100644
index 0000000..a93e8d5
--- /dev/null
+++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/IgnitePersistentStoreSchemaLoadTest.java
@@ -0,0 +1,297 @@
+/*
+ * 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.cache.database;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheRebalanceMode;
+import org.apache.ignite.cache.QueryEntity;
+import org.apache.ignite.cache.QueryIndex;
+import org.apache.ignite.cache.QueryIndexType;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.PersistentStoreConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.IgniteInterruptedCheckedException;
+import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor;
+import org.apache.ignite.internal.processors.cache.database.DbCheckpointListener;
+import org.apache.ignite.internal.processors.cache.database.GridCacheDatabaseSharedManager;
+import org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing;
+import org.apache.ignite.internal.util.lang.GridAbsPredicate;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK;
+
+/**
+ *
+ */
+public class IgnitePersistentStoreSchemaLoadTest extends GridCommonAbstractTest {
+ /** */
+ private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+ /** Index name. */
+ private static final String IDX_NAME = "my_idx";
+
+ /** Cache name. */
+ private static final String TMPL_NAME = "test_cache*";
+
+ /** Table name. */
+ private static final String TBL_NAME = Person.class.getSimpleName();
+
+ /** Schema name. */
+ private static final String SCHEMA_NAME = TBL_NAME;
+
+ /** Cache name. */
+ private static final String CACHE_NAME = TBL_NAME;
+
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder);
+
+ cfg.setCacheConfiguration(cacheCfg(TMPL_NAME));
+
+ PersistentStoreConfiguration pCfg = new PersistentStoreConfiguration();
+
+ pCfg.setCheckpointingFrequency(1000);
+
+ cfg.setPersistentStoreConfiguration(pCfg);
+
+ return cfg;
+ }
+
+ /** */
+ private CacheConfiguration cacheCfg(String name) {
+ CacheConfiguration<?, ?> cfg = new CacheConfiguration<>();
+
+ cfg.setName(name);
+
+ cfg.setRebalanceMode(CacheRebalanceMode.NONE);
+
+ cfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
+
+ return cfg;
+ }
+
+ /** */
+ private QueryEntity getEntity() {
+ LinkedHashMap<String, String> fields = new LinkedHashMap<>();
+
+ fields.put("id", Integer.class.getName());
+ fields.put("name", String.class.getName());
+
+ QueryEntity entity = new QueryEntity(Integer.class.getName(), Person.class.getName());
+ entity.setFields(fields);
+ entity.setTableName(TBL_NAME);
+
+ return entity;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ System.setProperty(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK, "true");
+
+ stopAllGrids();
+
+ deleteWorkFiles();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ stopAllGrids();
+
+ deleteWorkFiles();
+
+ System.clearProperty(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK);
+ }
+
+ /** */
+ public void testPersistIndex() throws Exception {
+ IgniteEx ig0 = startGrid(0);
+ startGrid(1);
+
+ final AtomicInteger cnt = new AtomicInteger();
+
+ GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager)ig0.context().cache().context().database();
+
+ db.addCheckpointListener(new DbCheckpointListener() {
+ @Override public void onCheckpointBegin(Context context) throws IgniteCheckedException {
+ cnt.incrementAndGet();
+ }
+ });
+
+ QueryIndex idx = new QueryIndex("name");
+
+ idx.setName(IDX_NAME);
+
+ ig0.context().query().dynamicTableCreate(SCHEMA_NAME, getEntity(), TMPL_NAME, true);
+
+ assert indexCnt(ig0, CACHE_NAME) == 0;
+
+ ig0.context().query().dynamicIndexCreate(CACHE_NAME, SCHEMA_NAME, TBL_NAME, idx, false).get();
+
+ assert indexCnt(ig0, CACHE_NAME) == 1;
+
+ waitForCheckpoint(cnt);
+
+ stopGrid(1);
+
+ IgniteEx ig1 = startGrid(1);
+
+ assert indexCnt(ig1, CACHE_NAME) == 1;
+ }
+
+ /** */
+ public void testPersistCompositeIndex() throws Exception {
+ IgniteEx ig0 = startGrid(0);
+ startGrid(1);
+
+ final AtomicInteger cnt = new AtomicInteger();
+
+ GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager)ig0.context().cache().context().database();
+
+ db.addCheckpointListener(new DbCheckpointListener() {
+ @Override public void onCheckpointBegin(Context context) throws IgniteCheckedException {
+ cnt.incrementAndGet();
+ }
+ });
+
+ ig0.context().query().dynamicTableCreate(SCHEMA_NAME, getEntity(), TMPL_NAME, true);
+
+ assert indexCnt(ig0, CACHE_NAME) == 0;
+
+ QueryIndex idx = new QueryIndex(Arrays.asList("id", "name"), QueryIndexType.SORTED);
+
+ idx.setName(IDX_NAME);
+
+ ig0.context().query().dynamicIndexCreate(CACHE_NAME, SCHEMA_NAME, TBL_NAME, idx, false).get();
+
+ assert indexCnt(ig0, CACHE_NAME) == 1;
+
+ waitForCheckpoint(cnt);
+
+ stopGrid(1);
+
+ IgniteEx ig1 = startGrid(1);
+
+ assert indexCnt(ig1, CACHE_NAME) == 1;
+ }
+
+ /** */
+ private void waitForCheckpoint(final AtomicInteger cnt) throws IgniteInterruptedCheckedException {
+ final int i = cnt.get();
+
+ GridTestUtils.waitForCondition(new GridAbsPredicate() {
+ @Override public boolean apply() {
+ return cnt.get() > i;
+ }
+ }, 2000);
+ }
+
+ /** */
+ private int indexCnt(IgniteEx node, String cacheName) {
+
+ DynamicCacheDescriptor desc = node.context().cache().cacheDescriptor(cacheName);
+
+ int cnt = 0;
+
+ for (QueryEntity entity : desc.schema().entities()) {
+ cnt += entity.getIndexes().size();
+ }
+
+ return cnt;
+ }
+
+ /**
+ * @return Indexing.
+ */
+ private IgniteH2Indexing getIndexing(IgniteEx ignite) {
+ return U.field(ignite.context().query(), "idx");
+ }
+
+ /**
+ *
+ */
+ private void deleteWorkFiles() throws IgniteCheckedException {
+ deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false));
+ }
+
+ /**
+ *
+ */
+ protected static class Person implements Serializable {
+ /** */
+ private static final long serialVersionUID = 0L;
+
+ /** */
+ @SuppressWarnings("unused")
+ private Person() {
+ // No-op.
+ }
+
+ /** */
+ public Person(int id) {
+ this.id = id;
+ }
+
+ /** */
+ @QuerySqlField
+ protected int id;
+
+ /** */
+ @QuerySqlField
+ protected String name;
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ IgnitePersistentStoreSchemaLoadTest.Person person = (IgnitePersistentStoreSchemaLoadTest.Person)o;
+
+ if (id != person.id)
+ return false;
+
+ return name != null ? name.equals(person.name) : person.name == null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ int result = id;
+
+ result = 31 * result + (name != null ? name.hashCode() : 0);
+
+ return result;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/9c22c716/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpPageStoreManager.java
----------------------------------------------------------------------
diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpPageStoreManager.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpPageStoreManager.java
index 783faf8..997eef5 100644
--- a/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpPageStoreManager.java
+++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/pagemem/NoOpPageStoreManager.java
@@ -24,7 +24,6 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.pagemem.FullPageId;
import org.apache.ignite.internal.pagemem.PageIdUtils;
@@ -32,6 +31,7 @@ import org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager;
import org.apache.ignite.internal.processors.cache.CacheGroupContext;
import org.apache.ignite.internal.processors.cache.CacheGroupDescriptor;
import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
+import org.apache.ignite.internal.processors.cache.StoredCacheData;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.lang.IgniteFuture;
@@ -53,7 +53,8 @@ public class NoOpPageStoreManager implements IgnitePageStoreManager {
}
/** {@inheritDoc} */
- @Override public void initializeForCache(CacheGroupDescriptor grpDesc, CacheConfiguration ccfg) throws IgniteCheckedException {
+ @Override public void initializeForCache(CacheGroupDescriptor grpDesc,
+ StoredCacheData cacheData) throws IgniteCheckedException {
// No-op.
}
@@ -171,11 +172,17 @@ public class NoOpPageStoreManager implements IgnitePageStoreManager {
}
/** {@inheritDoc} */
- @Override public Map<String, CacheConfiguration> readCacheConfigurations() throws IgniteCheckedException {
+ @Override public Map<String, StoredCacheData> readCacheConfigurations() throws IgniteCheckedException {
return Collections.emptyMap();
}
/** {@inheritDoc} */
+ @Override public void storeCacheData(CacheGroupDescriptor grpDesc,
+ StoredCacheData cacheData) throws IgniteCheckedException {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
@Override public boolean hasIndexStore(int grpId) {
return false;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/9c22c716/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java
----------------------------------------------------------------------
diff --git a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java
index 2db7ff7..88d4d0d 100644
--- a/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java
+++ b/modules/pds/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java
@@ -23,6 +23,7 @@ import org.apache.ignite.cache.database.IgnitePersistentStoreContinuousRestartSe
import org.apache.ignite.cache.database.IgnitePersistentStoreDataStructuresTest;
import org.apache.ignite.cache.database.IgnitePersistentStorePageSizesTest;
import org.apache.ignite.cache.database.IgnitePersistentStoreRecoveryAfterFileCorruptionTest;
+import org.apache.ignite.cache.database.IgnitePersistentStoreSchemaLoadTest;
import org.apache.ignite.cache.database.IgnitePersistentStoreTxCacheRebalancingTest;
import org.apache.ignite.cache.database.db.DbPageEvictionDuringPartitionClearSelfTest;
import org.apache.ignite.cache.database.db.IgniteDbWholeClusterRestartSelfTest;
@@ -71,6 +72,7 @@ public class IgnitePdsTestSuite2 extends TestSuite {
suite.addTestSuite(IgnitePersistentStoreContinuousRestartSelfTest.class);
+ suite.addTestSuite(IgnitePersistentStoreSchemaLoadTest.class);
suite.addTestSuite(IgnitePersistentStoreDataStructuresTest.class);
return suite;