This is an automated email from the ASF dual-hosted git repository.
nizhikov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 27b93ae IGNITE-12185: New metric. Index rebuild in progress flag for
caches and tables. (#6983)
27b93ae is described below
commit 27b93ae84cb8dfadd3d6dcb3426f9399f5b7da08
Author: Nikita Amelchev <[email protected]>
AuthorDate: Tue Nov 26 17:52:01 2019 +0300
IGNITE-12185: New metric. Index rebuild in progress flag for caches and
tables. (#6983)
---
.../ignite/jdbc/thin/JdbcThinMetadataSelfTest.java | 3 +-
.../processors/cache/CacheMetricsImpl.java | 7 +
.../systemview/walker/SqlTableViewWalker.java | 4 +-
.../ignite/spi/systemview/view/SqlTableView.java | 5 +
.../cache/index/AbstractIndexingCommonTest.java | 75 ++++++++++
.../processors/cache/index/BasicIndexTest.java | 35 +----
.../processors/cache/index/IndexMetricsTest.java | 153 +++++++++++++++++++++
.../processors/query/SqlSystemViewsSelfTest.java | 109 ++++++++++++++-
.../IgniteBinaryCacheQueryTestSuite.java | 2 +
9 files changed, 356 insertions(+), 37 deletions(-)
diff --git
a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinMetadataSelfTest.java
b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinMetadataSelfTest.java
index 2caf3c6..7b3acf1 100644
---
a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinMetadataSelfTest.java
+++
b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinMetadataSelfTest.java
@@ -49,8 +49,8 @@ import org.apache.ignite.internal.jdbc2.JdbcUtils;
import org.apache.ignite.internal.processors.query.QueryEntityEx;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.spi.metric.sql.SqlViewMetricExporterSpi;
-import org.junit.Assert;
import org.apache.ignite.testframework.GridTestUtils;
+import org.junit.Assert;
import org.junit.Test;
import static java.sql.Types.DATE;
@@ -752,6 +752,7 @@ public class JdbcThinMetadataSelfTest extends
JdbcThinAbstractSelfTest {
"SYS.TABLES.VALUE_ALIAS.null.2147483647",
"SYS.TABLES.KEY_TYPE_NAME.null.2147483647",
"SYS.TABLES.VALUE_TYPE_NAME.null.2147483647",
+ "SYS.TABLES.IS_INDEX_REBUILD_IN_PROGRESS.null.1",
"SYS.METRICS.NAME.null.2147483647",
"SYS.METRICS.VALUE.null.2147483647",
"SYS.METRICS.DESCRIPTION.null.2147483647",
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsImpl.java
index eefcb19..0d0be4c 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsImpl.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsImpl.java
@@ -21,6 +21,7 @@ import org.apache.ignite.IgniteSystemProperties;
import org.apache.ignite.cache.CacheMetrics;
import org.apache.ignite.cache.CachePeekMode;
import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.IgniteInternalFuture;
import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
import
org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture;
import
org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition;
@@ -311,6 +312,12 @@ public class CacheMetricsImpl implements CacheMetrics {
rebalanceClearingPartitions =
mreg.longMetric("RebalanceClearingPartitionsLeft",
"Number of partitions need to be cleared before actual rebalance
start.");
+
+ mreg.register("IsIndexRebuildInProgress", () -> {
+ IgniteInternalFuture fut =
cctx.shared().database().indexRebuildFuture(cctx.cacheId());
+
+ return fut != null && !fut.isDone();
+ }, "True if index rebuild is in progress.");
}
/**
diff --git
a/modules/indexing/src/main/java/org/apache/ignite/internal/managers/systemview/walker/SqlTableViewWalker.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/managers/systemview/walker/SqlTableViewWalker.java
index a1339d3..8fd2cb2 100644
---
a/modules/indexing/src/main/java/org/apache/ignite/internal/managers/systemview/walker/SqlTableViewWalker.java
+++
b/modules/indexing/src/main/java/org/apache/ignite/internal/managers/systemview/walker/SqlTableViewWalker.java
@@ -38,6 +38,7 @@ public class SqlTableViewWalker implements
SystemViewRowAttributeWalker<SqlTable
v.accept(6, "valueAlias", String.class);
v.accept(7, "keyTypeName", String.class);
v.accept(8, "valueTypeName", String.class);
+ v.accept(9, "isIndexRebuildInProgress", boolean.class);
}
/** {@inheritDoc} */
@@ -51,10 +52,11 @@ public class SqlTableViewWalker implements
SystemViewRowAttributeWalker<SqlTable
v.accept(6, "valueAlias", String.class, row.valueAlias());
v.accept(7, "keyTypeName", String.class, row.keyTypeName());
v.accept(8, "valueTypeName", String.class, row.valueTypeName());
+ v.acceptBoolean(9, "isIndexRebuildInProgress",
row.isIndexRebuildInProgress());
}
/** {@inheritDoc} */
@Override public int count() {
- return 9;
+ return 10;
}
}
diff --git
a/modules/indexing/src/main/java/org/apache/ignite/spi/systemview/view/SqlTableView.java
b/modules/indexing/src/main/java/org/apache/ignite/spi/systemview/view/SqlTableView.java
index 7eab6f2..cc2a511 100644
---
a/modules/indexing/src/main/java/org/apache/ignite/spi/systemview/view/SqlTableView.java
+++
b/modules/indexing/src/main/java/org/apache/ignite/spi/systemview/view/SqlTableView.java
@@ -100,4 +100,9 @@ public class SqlTableView {
public String valueTypeName() {
return tbl.rowDescriptor().type().valueTypeName();
}
+
+ /** @return {@code True} if index rebuild is in progress. */
+ public boolean isIndexRebuildInProgress() {
+ return tbl.rebuildFromHashInProgress();
+ }
}
diff --git
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/AbstractIndexingCommonTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/AbstractIndexingCommonTest.java
index 3c8b61a..30fefc5 100644
---
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/AbstractIndexingCommonTest.java
+++
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/AbstractIndexingCommonTest.java
@@ -17,7 +17,23 @@
package org.apache.ignite.internal.processors.cache.index;
+import java.io.File;
+import java.nio.file.Path;
+import java.util.List;
import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CountDownLatch;
+import java.util.stream.Collectors;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.cache.GridCacheContext;
+import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
+import
org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager;
+import org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing;
+import
org.apache.ignite.internal.processors.query.schema.SchemaIndexCacheVisitorClosure;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.testframework.GridTestUtils;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
import org.h2.engine.Session;
@@ -58,4 +74,63 @@ public class AbstractIndexingCommonTest extends
GridCommonAbstractTest {
}
}
+ /**
+ * Collects index file paths from all grids for given cache. Must be
called when the grid is up.
+ *
+ * @param cacheName Cache name.
+ */
+ protected List<Path> getIndexBinPaths(String cacheName) {
+ return G.allGrids().stream()
+ .map(grid -> (IgniteEx) grid)
+ .map(grid -> {
+ IgniteInternalCache<Object, Object> cachex =
grid.cachex(cacheName);
+
+ assertNotNull(cachex);
+
+ FilePageStoreManager pageStoreMgr = (FilePageStoreManager)
cachex.context().shared().pageStore();
+
+ assertNotNull(pageStoreMgr);
+
+ File cacheWorkDir =
pageStoreMgr.cacheWorkDir(cachex.configuration());
+
+ return cacheWorkDir.toPath().resolve("index.bin");
+ })
+ .collect(Collectors.toList());
+ }
+
+ /**
+ * Blocking indexing processor.
+ * <p>
+ * Blocks the indexes rebuilding until unblocked via {@link
#stopBlock(String)}.
+ */
+ protected static class BlockingIndexing extends IgniteH2Indexing {
+ /** */
+ private final ConcurrentHashMap<String, CountDownLatch> latches = new
ConcurrentHashMap<>();
+
+ /** {@inheritDoc} */
+ @Override protected void rebuildIndexesFromHash0(GridCacheContext
cctx, SchemaIndexCacheVisitorClosure clo)
+ throws IgniteCheckedException {
+ String cacheName = cctx.name();
+
+ latches.computeIfAbsent(cacheName, l -> new CountDownLatch(1));
+
+ U.await(latches.get(cacheName));
+
+ super.rebuildIndexesFromHash0(cctx, clo);
+ }
+
+ /**
+ * Stops the indexes rebuilding block for given cache.
+ *
+ * @param cacheName Cache name.
+ */
+ public void stopBlock(String cacheName) {
+ CountDownLatch latch = latches.get(cacheName);
+
+ if (latch == null)
+ throw new IgniteException("Cache wasn't start index rebuild
yet. [cacheName=" + cacheName + ']');
+
+ latch.countDown();
+ }
+ }
}
diff --git
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/BasicIndexTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/BasicIndexTest.java
index 404bbe5..dd07d46 100644
---
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/BasicIndexTest.java
+++
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/BasicIndexTest.java
@@ -17,7 +17,6 @@
package org.apache.ignite.internal.processors.cache.index;
-import java.io.File;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collection;
@@ -27,7 +26,6 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Objects;
import java.util.regex.Pattern;
-import java.util.stream.Collectors;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.cache.QueryEntity;
@@ -39,11 +37,8 @@ import
org.apache.ignite.configuration.DataRegionConfiguration;
import org.apache.ignite.configuration.DataStorageConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.IgniteEx;
-import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
-import
org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager;
import org.apache.ignite.internal.processors.query.GridQueryProcessor;
import org.apache.ignite.internal.processors.query.QueryUtils;
-import org.apache.ignite.internal.util.typedef.G;
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.testframework.ListeningTestLogger;
@@ -52,8 +47,8 @@ import
org.apache.ignite.testframework.junits.WithSystemProperty;
import org.jetbrains.annotations.Nullable;
import org.junit.Test;
-import static
org.apache.ignite.internal.processors.query.h2.opt.H2TableScanIndex.SCAN_INDEX_NAME_SUFFIX;
import static
org.apache.ignite.internal.processors.query.h2.database.H2Tree.IGNITE_THROTTLE_INLINE_SIZE_CALCULATION;
+import static
org.apache.ignite.internal.processors.query.h2.opt.H2TableScanIndex.SCAN_INDEX_NAME_SUFFIX;
/**
* A set of basic tests for caches with indexes.
@@ -1028,7 +1023,7 @@ public class BasicIndexTest extends
AbstractIndexingCommonTest {
checkAll();
- List<Path> idxPaths = getIndexBinPaths();
+ List<Path> idxPaths = getIndexBinPaths(DEFAULT_CACHE_NAME);
// Shutdown gracefully to ensure there is a checkpoint with
index.bin.
// Otherwise index.bin rebuilding may not work.
@@ -1077,7 +1072,7 @@ public class BasicIndexTest extends
AbstractIndexingCommonTest {
checkAll();
- List<Path> idxPaths = getIndexBinPaths();
+ List<Path> idxPaths = getIndexBinPaths(DEFAULT_CACHE_NAME);
// Shutdown gracefully to ensure there is a checkpoint with
index.bin.
// Otherwise index.bin rebuilding may not work.
@@ -1126,7 +1121,7 @@ public class BasicIndexTest extends
AbstractIndexingCommonTest {
checkAll();
- List<Path> idxPaths = getIndexBinPaths();
+ List<Path> idxPaths = getIndexBinPaths(DEFAULT_CACHE_NAME);
// Shutdown gracefully to ensure there is a checkpoint with
index.bin.
// Otherwise index.bin rebuilding may not work.
@@ -1305,28 +1300,6 @@ public class BasicIndexTest extends
AbstractIndexingCommonTest {
}
}
- /**
- * Must be called when the grid is up.
- */
- private List<Path> getIndexBinPaths() {
- return G.allGrids().stream()
- .map(grid -> (IgniteEx) grid)
- .map(grid -> {
- IgniteInternalCache<Object, Object> cachex =
grid.cachex(DEFAULT_CACHE_NAME);
-
- assertNotNull(cachex);
-
- FilePageStoreManager pageStoreMgr = (FilePageStoreManager)
cachex.context().shared().pageStore();
-
- assertNotNull(pageStoreMgr);
-
- File cacheWorkDir =
pageStoreMgr.cacheWorkDir(cachex.configuration());
-
- return cacheWorkDir.toPath().resolve("index.bin");
- })
- .collect(Collectors.toList());
- }
-
/** */
private void createDynamicIndexes(String... cols) {
IgniteCache<Key, Val> cache = grid(0).cache(DEFAULT_CACHE_NAME);
diff --git
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/IndexMetricsTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/IndexMetricsTest.java
new file mode 100644
index 0000000..ff6f0ee
--- /dev/null
+++
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/IndexMetricsTest.java
@@ -0,0 +1,153 @@
+/*
+ * 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.index;
+
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.List;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.QueryEntity;
+import org.apache.ignite.cache.QueryIndex;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.metric.MetricRegistry;
+import org.apache.ignite.internal.processors.query.GridQueryProcessor;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.spi.metric.BooleanMetric;
+import org.junit.Test;
+
+import static
org.apache.ignite.internal.processors.cache.index.AbstractSchemaSelfTest.KeyClass;
+import static
org.apache.ignite.internal.processors.cache.index.AbstractSchemaSelfTest.ValueClass;
+import static
org.apache.ignite.internal.processors.metric.impl.MetricUtils.cacheMetricsRegistryName;
+
+/**
+ * Tests index metrics.
+ */
+public class IndexMetricsTest extends AbstractIndexingCommonTest {
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String
igniteInstanceName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+ cfg.setDataStorageConfiguration(new DataStorageConfiguration()
+ .setDefaultDataRegionConfiguration(
+ new
DataRegionConfiguration().setPersistenceEnabled(true).setMaxSize(10 * 1024 *
1024)
+ )
+ );
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ cleanPersistenceDir();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ stopAllGrids();
+
+ cleanPersistenceDir();
+
+ GridQueryProcessor.idxCls = null;
+ }
+
+ /**
+ * @return Default cache configuration.
+ */
+ private CacheConfiguration<KeyClass, ValueClass> cacheConfiguration(String
cacheName) {
+ CacheConfiguration<KeyClass, ValueClass> ccfg = new
CacheConfiguration<>(cacheName);
+
+ QueryEntity entity = new QueryEntity();
+
+ entity.setKeyType(KeyClass.class.getName());
+ entity.setValueType(ValueClass.class.getName());
+
+ entity.setKeyFieldName("key");
+
+ entity.addQueryField("key", entity.getKeyType(), null);
+
+ entity.setIndexes(Collections.singletonList(
+ new QueryIndex("key", true, cacheName + "_index")
+ ));
+
+ ccfg.setQueryEntities(Collections.singletonList(entity));
+
+ return ccfg;
+ }
+
+ /** @throws Exception If failed. */
+ @Test
+ public void testIndexRebuildingMetric() throws Exception {
+ IgniteEx ignite = startGrid(0);
+
+ ignite.cluster().active(true);
+
+ String cacheName1 = "cache1";
+ String cacheName2 = "cache2";
+
+ IgniteCache<KeyClass, ValueClass> cache1 =
ignite.getOrCreateCache(cacheConfiguration(cacheName1));
+ IgniteCache<KeyClass, ValueClass> cache2 =
ignite.getOrCreateCache(cacheConfiguration(cacheName2));
+
+ cache1.put(new KeyClass(1), new ValueClass(1L));
+ cache2.put(new KeyClass(1), new ValueClass(1L));
+
+ List<Path> idxPaths = getIndexBinPaths(cacheName1);
+
+ idxPaths.addAll(getIndexBinPaths(cacheName2));
+
+ stopAllGrids();
+
+ idxPaths.forEach(idxPath -> assertTrue(U.delete(idxPath)));
+
+ GridQueryProcessor.idxCls = BlockingIndexing.class;
+
+ ignite = startGrid(0);
+
+ BooleanMetric indexRebuildCache1 =
isIndexRebuildInProgressMetric(ignite, cacheName1);
+ BooleanMetric indexRebuildCache2 =
isIndexRebuildInProgressMetric(ignite, cacheName2);
+
+ ignite.cluster().active(true);
+
+ assertTrue(indexRebuildCache1.value());
+ assertTrue(indexRebuildCache2.value());
+
+
((BlockingIndexing)ignite.context().query().getIndexing()).stopBlock(cacheName1);
+
+ ignite.cache(cacheName1).indexReadyFuture().get(30_000);
+
+ assertFalse(indexRebuildCache1.value());
+ assertTrue(indexRebuildCache2.value());
+
+
((BlockingIndexing)ignite.context().query().getIndexing()).stopBlock(cacheName2);
+
+ ignite.cache(cacheName2).indexReadyFuture().get(30_000);
+
+ assertFalse(indexRebuildCache1.value());
+ assertFalse(indexRebuildCache2.value());
+ }
+
+ /** @return Gets {@code IsIndexRebuildInProgress} metric for given cache.
*/
+ private BooleanMetric isIndexRebuildInProgressMetric(IgniteEx ignite,
String cacheName) {
+ MetricRegistry mreg =
ignite.context().metric().registry(cacheMetricsRegistryName(cacheName, false));
+
+ return mreg.findMetric("IsIndexRebuildInProgress");
+ }
+}
diff --git
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlSystemViewsSelfTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlSystemViewsSelfTest.java
index e762d9f..29b471c 100644
---
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlSystemViewsSelfTest.java
+++
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlSystemViewsSelfTest.java
@@ -19,6 +19,7 @@ package org.apache.ignite.internal.processors.query;
import com.google.common.collect.Sets;
import java.lang.reflect.Field;
+import java.nio.file.Path;
import java.sql.Timestamp;
import java.time.Instant;
import java.util.Collection;
@@ -68,6 +69,7 @@ import org.apache.ignite.internal.util.lang.GridNodePredicate;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.G;
import org.apache.ignite.internal.util.typedef.X;
+import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteFuture;
import org.apache.ignite.lang.IgnitePredicate;
import org.apache.ignite.lang.IgniteRunnable;
@@ -89,6 +91,9 @@ public class SqlSystemViewsSelfTest extends
AbstractIndexingCommonTest {
/** Metrics check attempts. */
private static final int METRICS_CHECK_ATTEMPTS = 10;
+ /** */
+ private boolean isPersistenceEnabled;
+
/** {@inheritDoc} */
@Override protected void beforeTest() throws Exception {
super.beforeTest();
@@ -101,6 +106,10 @@ public class SqlSystemViewsSelfTest extends
AbstractIndexingCommonTest {
stopAllGrids();
cleanPersistenceDir();
+
+ isPersistenceEnabled = false;
+
+ GridQueryProcessor.idxCls = null;
}
/** @return System schema name. */
@@ -211,7 +220,6 @@ public class SqlSystemViewsSelfTest extends
AbstractIndexingCommonTest {
Assert.assertEquals(expSchemasCli, schemasCli);
}
-
/**
* Test indexes system view.
*
@@ -308,6 +316,90 @@ public class SqlSystemViewsSelfTest extends
AbstractIndexingCommonTest {
}
/**
+ * Tests {@link SqlTableView#isIndexRebuildInProgress()}.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testTableViewDuringRebuilding() throws Exception {
+ isPersistenceEnabled = true;
+
+ IgniteEx srv = startGrid(getConfiguration());
+
+ srv.cluster().active(true);
+
+ String cacheName1 = "CACHE_1";
+ String cacheSqlName1 = "SQL_PUBLIC_" + cacheName1;
+
+ String cacheName2 = "CACHE_2";
+ String cacheSqlName2 = "SQL_PUBLIC_" + cacheName2;
+
+ execSql("CREATE TABLE " + cacheName1 + " (ID1 INT PRIMARY KEY, MY_VAL
VARCHAR)");
+ execSql("CREATE INDEX IDX_1 ON "+ cacheName1 + " (MY_VAL DESC)");
+
+ execSql("CREATE TABLE " + cacheName2 + " (ID INT PRIMARY KEY, MY_VAL
VARCHAR)");
+ execSql("CREATE INDEX IDX_2 ON " + cacheName2 + " (ID DESC)");
+
+ // Put data to create indexes.
+ execSql("INSERT INTO " + cacheName1 + " VALUES(?, ?)", 1, "12345");
+ execSql("INSERT INTO " + cacheName2 + " VALUES(?, ?)", 1, "12345");
+
+ List<Path> idxPaths = getIndexBinPaths(cacheSqlName1);
+
+ idxPaths.addAll(getIndexBinPaths(cacheSqlName2));
+
+ stopAllGrids();
+
+ idxPaths.forEach(idxPath -> assertTrue(U.delete(idxPath)));
+
+ GridQueryProcessor.idxCls = BlockingIndexing.class;
+
+ srv = startGrid(getConfiguration());
+
+ srv.cluster().active(true);
+
+ checkIndexRebuild(cacheName1, true);
+ checkIndexRebuild(cacheName2, true);
+
+
((BlockingIndexing)srv.context().query().getIndexing()).stopBlock(cacheSqlName1);
+
+ srv.cache(cacheSqlName1).indexReadyFuture().get(30_000);
+
+ checkIndexRebuild(cacheName1, false);
+ checkIndexRebuild(cacheName2, true);
+
+
((BlockingIndexing)srv.context().query().getIndexing()).stopBlock(cacheSqlName2);
+
+ srv.cache(cacheSqlName2).indexReadyFuture().get(30_000);
+
+ checkIndexRebuild(cacheName1, false);
+ checkIndexRebuild(cacheName2, false);
+ }
+
+ /**
+ * Checks index rebuilding for given cache.
+ *
+ * @param cacheName Cache name.
+ * @param rebuild Is indexes rebuild in progress.
+ */
+ private void checkIndexRebuild(String cacheName, boolean rebuild) {
+ String idxSql = "SELECT IS_INDEX_REBUILD_IN_PROGRESS FROM " +
systemSchemaName() + ".TABLES " +
+ "WHERE TABLE_NAME = ?";
+
+ List<List<?>> res = execSql(grid(), idxSql, cacheName);
+
+ assertFalse(res.isEmpty());
+
+ assertTrue(res.stream().allMatch(row -> {
+ assertEquals(1, row.size());
+
+ Boolean isIndexRebuildInProgress = (Boolean)row.get(0);
+
+ return isIndexRebuildInProgress == rebuild;
+ }));
+ }
+
+ /**
* @return Default cache configuration.
*/
protected CacheConfiguration<AbstractSchemaSelfTest.KeyClass,
AbstractSchemaSelfTest.ValueClass> cacheConfiguration(String cacheName) throws
Exception {
@@ -900,6 +992,14 @@ public class SqlSystemViewsSelfTest extends
AbstractIndexingCommonTest {
.setCacheConfiguration(new
CacheConfiguration().setName(DEFAULT_CACHE_NAME))
.setMetricExporterSpi(new SqlViewMetricExporterSpi());
+ if (isPersistenceEnabled) {
+ cfg.setDataStorageConfiguration(new DataStorageConfiguration()
+ .setDefaultDataRegionConfiguration(
+ new
DataRegionConfiguration().setPersistenceEnabled(true).setMaxSize(10 * 1024 *
1024)
+ )
+ );
+ }
+
return cfg;
}
@@ -970,8 +1070,8 @@ public class SqlSystemViewsSelfTest extends
AbstractIndexingCommonTest {
"ID", // KEY_ALIAS
null, // VALUE_ALIAS
"java.lang.Integer", // KEY_TYPE_NAME
- "random_name" // VALUE_TYPE_NAME
-
+ "random_name", // VALUE_TYPE_NAME
+ false // IS_INDEX_REBUILD_IN_PROGRESS
);
assertEquals("Returned incorrect info. ", expRow,
cacheSqlInfos.get(0));
@@ -992,7 +1092,8 @@ public class SqlSystemViewsSelfTest extends
AbstractIndexingCommonTest {
null, // KEY_ALIAS
"MY_VAL", // VALUE_ALIAS
"random_name", // KEY_TYPE_NAME
- "java.lang.String" // VALUE_TYPE_NAME
+ "java.lang.String", // VALUE_TYPE_NAME
+ false // IS_INDEX_REBUILD_IN_PROGRESS
)
);
diff --git
a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java
b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java
index 0e1edb9..53166e1 100644
---
a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java
+++
b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java
@@ -158,6 +158,7 @@ import
org.apache.ignite.internal.processors.cache.index.H2RowCachePageEvictionT
import org.apache.ignite.internal.processors.cache.index.H2RowCacheSelfTest;
import
org.apache.ignite.internal.processors.cache.index.H2RowExpireTimeIndexSelfTest;
import org.apache.ignite.internal.processors.cache.index.IgniteDecimalSelfTest;
+import org.apache.ignite.internal.processors.cache.index.IndexMetricsTest;
import org.apache.ignite.internal.processors.cache.index.LongIndexNameTest;
import
org.apache.ignite.internal.processors.cache.index.OptimizedMarshallerIndexNameTest;
import
org.apache.ignite.internal.processors.cache.index.QueryEntityValidationSelfTest;
@@ -293,6 +294,7 @@ import org.junit.runners.Suite;
BasicIndexTest.class,
ArrayIndexTest.class,
BasicIndexMultinodeTest.class,
+ IndexMetricsTest.class,
// Misc tests.
QueryEntityValidationSelfTest.class,