ibessonov commented on a change in pull request #9223:
URL: https://github.com/apache/ignite/pull/9223#discussion_r664286279
##########
File path:
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManager.java
##########
@@ -569,6 +569,23 @@ public void storeEntries(int partId,
Iterator<GridCacheEntryInfo> infos,
*/
public void dropRootPageForIndex(int cacheId, String idxName, int segment)
throws IgniteCheckedException;
+ /**
+ * Renaming the root page of the index tree.
+ *
+ * @param cacheId Cache id.
+ * @param oldIdxName Old name of the index tree.
+ * @param newIdxName New name of the index tree.
+ * @param segment Segment number.
Review comment:
Please clarify the comment. Segment index or something like that would
be more clear.
##########
File path:
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManager.java
##########
@@ -569,6 +569,23 @@ public void storeEntries(int partId,
Iterator<GridCacheEntryInfo> infos,
*/
public void dropRootPageForIndex(int cacheId, String idxName, int segment)
throws IgniteCheckedException;
+ /**
+ * Renaming the root page of the index tree.
+ *
+ * @param cacheId Cache id.
+ * @param oldIdxName Old name of the index tree.
+ * @param newIdxName New name of the index tree.
+ * @param segment Segment number.
+ * @return Renamed root page of the index tree.
+ * @throws IgniteCheckedException If failed.
+ */
+ @Nullable RootPage renameRootPageForIndex(
Review comment:
You're not renaming root page, you're renaming reference to the root
page. Name is confusing
##########
File path:
modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/RenameIndexTreeTest.java
##########
@@ -0,0 +1,242 @@
+/*
+ * 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.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.UUID;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.client.Person;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.cache.query.index.Index;
+import
org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition;
+import org.apache.ignite.internal.processors.cache.GridCacheContext;
+import org.apache.ignite.internal.processors.cache.persistence.RootPage;
+import org.jetbrains.annotations.Nullable;
+import org.junit.Test;
+
+import static
org.apache.ignite.internal.processors.cache.persistence.IndexStorageImpl.MAX_IDX_NAME_LEN;
+import static org.apache.ignite.testframework.GridTestUtils.assertThrows;
+import static org.apache.ignite.testframework.GridTestUtils.cacheContext;
+import static org.apache.ignite.testframework.GridTestUtils.getFieldValue;
+
+/**
+ * Class for testing index tree renaming.
+ */
+public class RenameIndexTreeTest extends AbstractRebuildIndexTest {
+ /**
+ * Checking the correct renaming of the index root pages.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testRenamingIndexRootPage() throws Exception {
+ IgniteEx n = startGrid(0);
+
+ IgniteCache<Integer, Person> cache = n.cache(DEFAULT_CACHE_NAME);
+ populate(cache, 100);
+
+ String idxName = "IDX0";
+ createIdx(cache, idxName);
+
+ SortedIndexDefinition idxDef = indexDefinition(index(n, cache,
idxName));
+
+ int segments = idxDef.segments();
+
+ String oldTreeName = idxDef.treeName();
+ assertExistIndexRoot(cache, oldTreeName, segments, true);
+
+ String newTreeName = UUID.randomUUID().toString();
+
+ // There will be no renaming.
+ assertExistIndexRoot(cache, newTreeName, segments, false);
+ assertTrue(renameIndexRoot(cache, newTreeName, newTreeName,
segments).isEmpty());
+
+ // Checking the validation of the new index name.
+ String moreMaxLenName = Arrays.toString(new byte[MAX_IDX_NAME_LEN +
1]);
+ assertThrows(log, () -> renameIndexRoot(cache, oldTreeName,
moreMaxLenName, segments), Exception.class, null);
+
+ assertEquals(segments, renameIndexRoot(cache, oldTreeName,
newTreeName, segments).size());
+
+ assertExistIndexRoot(cache, oldTreeName, segments, false);
+ assertExistIndexRoot(cache, newTreeName, segments, true);
+ }
+
+ /**
+ * Checking that the renamed index root pages after the checkpoint will be
+ * correctly restored and found after the node is restarted.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testPersistRenamingIndexRootPage() throws Exception {
+ IgniteEx n = startGrid(0);
+
+ IgniteCache<Integer, Person> cache = n.cache(DEFAULT_CACHE_NAME);
+ populate(cache, 100);
+
+ String idxName = "IDX0";
+ createIdx(cache, idxName);
+
+ SortedIndexDefinition idxDef = indexDefinition(index(n, cache,
idxName));
+
+ String oldTreeName = idxDef.treeName();
+ String newTreeName = UUID.randomUUID().toString();
+
+ int segments = idxDef.segments();
+ assertEquals(segments, renameIndexRoot(cache, oldTreeName,
newTreeName, segments).size());
+
+ forceCheckpoint();
+
+ stopGrid(0);
+
+ n = startGrid(0);
+ cache = n.cache(DEFAULT_CACHE_NAME);
+
+ assertExistIndexRoot(cache, oldTreeName, segments, true);
+ assertExistIndexRoot(cache, newTreeName, segments, true);
+ }
+
+ /**
+ * Checking that if the renaming of root pages is not a checkpoint,
Review comment:
"is not checkpointed" maybe, it's kinda hard to understand right now.
Anyway, is this a valid scenario?
##########
File path:
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/IndexStorage.java
##########
@@ -77,6 +77,23 @@
*/
public RootPage dropIndex(String idxName) throws IgniteCheckedException;
+ /**
+ * Renaming the root page of the index tree.
+ *
+ * @param cacheId Cache id.
+ * @param oldIdxName Old name of the index tree.
+ * @param newIdxName New name of the index tree.
+ * @param segment Segment number.
Review comment:
Same here
##########
File path:
modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/AbstractRebuildIndexTest.java
##########
@@ -295,4 +297,40 @@ protected IndexBuildStatusStorage
indexBuildStatusStorage(IgniteEx n) {
protected ConcurrentMap<String, IndexBuildStatusHolder> statuses(IgniteEx
n) {
return getFieldValue(indexBuildStatusStorage(n), "statuses");
}
+
+ /**
+ * Creation of a new index for the cache of {@link Person}.
+ * SQL: CREATE INDEX " + idxName + " ON Person(name)
+ *
+ * @param cache Cache.
+ * @param idxName Index name.
+ * @return Index creation result.
+ */
+ protected List<List<?>> createIdx(IgniteCache<Integer, Person> cache,
String idxName) {
+ String sql = "CREATE INDEX " + idxName + " ON Person(name)";
+
+ return cache.query(new SqlFieldsQuery(sql)).getAll();
+ }
+
+ /**
+ * Enable checkpoints.
+ *
+ * @param n Node.
+ * @param reason Reason for checkpoint wakeup if it would be required.
+ * @param enable Enable/disable.
+ */
+ protected Void enableCheckpoints(IgniteEx n, String reason, boolean
enable) throws Exception {
+ if (enable) {
+ dbMgr(n).enableCheckpoints(true).get(getTestTimeout());
+
+ forceCheckpoint(F.asList(n), reason);
+ }
+ else {
+ forceCheckpoint(F.asList(n), reason);
+
+ dbMgr(n).enableCheckpoints(false).get(getTestTimeout());
Review comment:
getTestTimeout() is too much, isn't it?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]