rpuch commented on code in PR #3136:
URL: https://github.com/apache/ignite-3/pull/3136#discussion_r1475637400


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/ReplicatorUtils.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.table.distributed.replicator;
+
+import static 
org.apache.ignite.internal.catalog.descriptors.CatalogIndexStatus.BUILDING;
+
+import org.apache.ignite.internal.catalog.CatalogService;
+import org.apache.ignite.internal.catalog.descriptors.CatalogIndexDescriptor;
+import org.apache.ignite.internal.catalog.descriptors.CatalogIndexStatus;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import 
org.apache.ignite.internal.table.distributed.replication.request.ReadWriteReplicaRequest;
+import org.apache.ignite.internal.tx.TransactionIds;
+import org.jetbrains.annotations.Nullable;
+
+/** Auxiliary class. */
+class ReplicatorUtils {
+    /**
+     * Looks for the latest index with {@link CatalogIndexStatus#BUILDING} for 
the table, {@code null} if missing.
+     *
+     * <p>NOTE: It is expected that the method will be executed in the 
metastore thread so that the catalog does not change.</p>

Review Comment:
   ```suggestion
        * <p>NOTE: It is expected that the method will be executed in the 
metastore thread so that the catalog does not change concurrently.</p>
   ```



##########
modules/table/src/test/java/org/apache/ignite/internal/table/distributed/replicator/ReplicatorUtilsTest.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * 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.table.distributed.replicator;
+
+import static org.apache.ignite.internal.table.TableTestUtils.INDEX_NAME;
+import static org.apache.ignite.internal.table.TableTestUtils.TABLE_NAME;
+import static 
org.apache.ignite.internal.table.TableTestUtils.createSimpleHashIndex;
+import static 
org.apache.ignite.internal.table.TableTestUtils.createSimpleTable;
+import static org.apache.ignite.internal.table.TableTestUtils.getIndexIdStrict;
+import static org.apache.ignite.internal.table.TableTestUtils.getTableIdStrict;
+import static 
org.apache.ignite.internal.table.TableTestUtils.makeIndexAvailable;
+import static 
org.apache.ignite.internal.table.TableTestUtils.startBuildingIndex;
+import static 
org.apache.ignite.internal.table.distributed.replicator.ReplicatorUtils.beginRwTxTs;
+import static 
org.apache.ignite.internal.table.distributed.replicator.ReplicatorUtils.latestIndexDescriptorInBuildingStatus;
+import static 
org.apache.ignite.internal.table.distributed.replicator.ReplicatorUtils.rwTxActiveCatalogVersion;
+import static 
org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TransactionIds.transactionId;
+import static org.apache.ignite.internal.util.IgniteUtils.closeAll;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.UUID;
+import java.util.function.Consumer;
+import org.apache.ignite.internal.catalog.CatalogManager;
+import org.apache.ignite.internal.catalog.CatalogService;
+import org.apache.ignite.internal.catalog.CatalogTestUtils;
+import org.apache.ignite.internal.hlc.HybridClock;
+import org.apache.ignite.internal.hlc.HybridClockImpl;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import 
org.apache.ignite.internal.table.distributed.replication.request.ReadWriteReplicaRequest;
+import org.apache.ignite.internal.testframework.IgniteAbstractTest;
+import org.junit.jupiter.api.Test;
+
+/** For {@link ReplicatorUtils} testing. */
+public class ReplicatorUtilsTest extends IgniteAbstractTest {
+    private final HybridClock clock = new HybridClockImpl();
+
+    @Test
+    void testBeginRwTxTs() {
+        HybridTimestamp beginTs = clock.now();
+
+        UUID txId = transactionId(beginTs, 10);
+
+        assertEquals(beginTs, beginRwTxTs(readWriteReplicaRequest(txId)));
+    }
+
+    @Test
+    void testRwTxActiveCatalogVersion() {
+        HybridTimestamp beginTs = clock.now();
+
+        UUID txId = transactionId(beginTs, 10);
+
+        CatalogService catalogService = mock(CatalogService.class);
+
+        when(catalogService.activeCatalogVersion(anyLong())).thenReturn(666);
+
+        assertEquals(666, rwTxActiveCatalogVersion(catalogService, 
readWriteReplicaRequest(txId)));
+
+        verify(catalogService).activeCatalogVersion(eq(beginTs.longValue()));
+    }
+
+    @Test
+    void testLatestIndexDescriptorInBuildingStatus() throws Exception {
+        withCatalogManager(catalogManager -> {
+            createSimpleTable(catalogManager, TABLE_NAME);
+
+            int tableId = getTableIdStrict(catalogManager, TABLE_NAME, 
clock.nowLong());
+
+            assertNull(latestIndexDescriptorInBuildingStatus(catalogManager, 
tableId));
+
+            createSimpleHashIndex(catalogManager, TABLE_NAME, INDEX_NAME);
+            assertNull(latestIndexDescriptorInBuildingStatus(catalogManager, 
tableId));
+
+            int indexId = getIndexIdStrict(catalogManager, INDEX_NAME, 
clock.nowLong());
+
+            startBuildingIndex(catalogManager, indexId);
+            assertEquals(indexId, 
latestIndexDescriptorInBuildingStatus(catalogManager, tableId).id());
+
+            makeIndexAvailable(catalogManager, indexId);
+            assertEquals(indexId, 
latestIndexDescriptorInBuildingStatus(catalogManager, tableId).id());
+
+            createSimpleHashIndex(catalogManager, TABLE_NAME, INDEX_NAME + 
"_ONE_MORE");
+            assertEquals(indexId, 
latestIndexDescriptorInBuildingStatus(catalogManager, tableId).id());

Review Comment:
   How about also starting the build of the second index and making sure that 
`latestIndexDescriptorInBuildingStatus()` will return the second index this 
time?



##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/ReplicatorUtils.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.table.distributed.replicator;
+
+import static 
org.apache.ignite.internal.catalog.descriptors.CatalogIndexStatus.BUILDING;
+
+import org.apache.ignite.internal.catalog.CatalogService;
+import org.apache.ignite.internal.catalog.descriptors.CatalogIndexDescriptor;
+import org.apache.ignite.internal.catalog.descriptors.CatalogIndexStatus;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import 
org.apache.ignite.internal.table.distributed.replication.request.ReadWriteReplicaRequest;
+import org.apache.ignite.internal.tx.TransactionIds;
+import org.jetbrains.annotations.Nullable;
+
+/** Auxiliary class. */

Review Comment:
   Doesn't look like the best possible javadoc :)



-- 
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]

Reply via email to