You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2021/11/11 18:01:41 UTC

[GitHub] [ignite-3] kgusakov commented on a change in pull request #344: IGNITE-15492 Check schema availability on local node

kgusakov commented on a change in pull request #344:
URL: https://github.com/apache/ignite-3/pull/344#discussion_r745962067



##########
File path: modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/StopCalciteModuleTest.java
##########
@@ -110,9 +111,9 @@ public void before(TestInfo testInfo) {
                 new Column[]{new Column("ID", NativeTypes.INT32, false)},
                 new Column[]{new Column("VAL", NativeTypes.INT32, false)}
         );
-        
-        schemaReg = new SchemaRegistryImpl(0, (v) -> schemaDesc);
-        
+    
+        schemaReg = new SchemaRegistryImpl(0, (v) -> schemaDesc, () -> INITIAL_SCHEMA_VERSION);

Review comment:
       We have `SchemaRegistryImpl.INITIAL_SCHEMA_VERSION = -1` and `TableManager.INITIAL_SCHEMA_VERSION = 1` - is it ok?

##########
File path: modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItDataSchemaSyncTest.java
##########
@@ -0,0 +1,263 @@
+/*
+ * 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.runner.app;
+
+import static org.apache.ignite.internal.schema.configuration.SchemaConfigurationConverter.convert;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import com.google.common.collect.Lists;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.table.TableImpl;
+import org.apache.ignite.internal.test.WatchListenerInhibitor;
+import org.apache.ignite.internal.testframework.IgniteAbstractTest;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.schema.SchemaBuilders;
+import org.apache.ignite.schema.definition.ColumnType;
+import org.apache.ignite.schema.definition.TableDefinition;
+import org.apache.ignite.table.Table;
+import org.apache.ignite.table.Tuple;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * There is a test of table schema synchronization.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+public class ItDataSchemaSyncTest extends IgniteAbstractTest {
+    /**
+     * Schema name.
+     */
+    public static final String SCHEMA = "PUBLIC";
+
+    /**
+     * Short table name.
+     */
+    public static final String SHORT_TABLE_NAME = "tbl1";
+
+    /**
+     * Table name.
+     */
+    public static final String TABLE_NAME = SCHEMA + "." + SHORT_TABLE_NAME;
+
+    /**
+     * Nodes bootstrap configuration.
+     */
+    private static final Map<String, String> nodesBootstrapCfg = new LinkedHashMap<>() {
+        {
+            put("node0", "{\n"
+                    + "  \"node\": {\n"
+                    + "    \"metastorageNodes\":[ \"node0\" ]\n"
+                    + "  },\n"
+                    + "  \"network\": {\n"
+                    + "    \"port\":3344,\n"
+                    + "    \"nodeFinder\": {\n"
+                    + "      \"netClusterNodes\":[ \"localhost:3344\", \"localhost:3345\", \"localhost:3346\" ]\n"
+                    + "    }\n"
+                    + "  }\n"
+                    + "}");
+        
+            put("node1", "{\n"
+                    + "  \"node\": {\n"
+                    + "    \"metastorageNodes\":[ \"node0\" ]\n"
+                    + "  },\n"
+                    + "  \"network\": {\n"
+                    + "    \"port\":3345,\n"
+                    + "    \"nodeFinder\": {\n"
+                    + "      \"netClusterNodes\":[ \"localhost:3344\", \"localhost:3345\", \"localhost:3346\" ]\n"
+                    + "    }\n"
+                    + "  }\n"
+                    + "}");
+        
+            put("node2", "{\n"
+                    + "  \"node\": {\n"
+                    + "    \"metastorageNodes\":[ \"node0\" ]\n"
+                    + "  },\n"
+                    + "  \"network\": {\n"
+                    + "    \"port\":3346,\n"
+                    + "    \"nodeFinder\": {\n"
+                    + "      \"netClusterNodes\":[ \"localhost:3344\", \"localhost:3345\", \"localhost:3346\" ]\n"
+                    + "    }\n"
+                    + "  }\n"
+                    + "}");
+        }
+    };
+
+    /**
+     * Cluster nodes.
+     */
+    private final List<Ignite> clusterNodes = new ArrayList<>();
+
+    /**
+     * Starts a cluster before every test started.
+     */
+    @BeforeEach
+    void beforeEach() throws Exception {
+        nodesBootstrapCfg.forEach((nodeName, configStr) ->
+                clusterNodes.add(IgnitionManager.start(nodeName, configStr, workDir.resolve(nodeName)))
+        );
+    }
+
+    /**
+     * Stops a cluster after every test finished.
+     */
+    @AfterEach
+    void afterEach() throws Exception {
+        IgniteUtils.closeAll(Lists.reverse(clusterNodes));
+    }
+
+    /**
+     * The test executes various operation over the lagging node.
+     * The operations can be executed only the node overtakes a distributed cluster state.
+     */
+    @Test
+    public void test() throws Exception {
+        Ignite ignite0 = clusterNodes.get(0);
+        final IgniteImpl ignite1 = (IgniteImpl) clusterNodes.get(1);
+    
+        createTable(ignite0, SCHEMA, SHORT_TABLE_NAME);
+    
+        TableImpl table = (TableImpl) ignite0.tables().table(TABLE_NAME);
+    
+        assertEquals(1, table.schemaView().schema().version());
+    
+        for (int i = 0; i < 10; i++) {
+            table.recordView().insert(Tuple.create()
+                    .set("key", Long.valueOf(i))
+                    .set("valInt", i)
+                    .set("valStr", "str_" + i)
+            );
+        }
+
+        WatchListenerInhibitor listenerInhibitor = WatchListenerInhibitor.metastorageEventsInhibitor(ignite1);
+
+        listenerInhibitor.startInhibit();
+    
+        ignite0.tables().alterTable(TABLE_NAME,
+                tblChanger -> tblChanger.changeColumns(cols -> {
+                    int colIdx = tblChanger.columns().namedListKeys().stream()
+                            .mapToInt(Integer::parseInt).max().getAsInt() + 1;
+                
+                    cols.create(String.valueOf(colIdx),
+                            colChg -> convert(SchemaBuilders.column("valStr2", ColumnType.string())
+                                    .withDefaultValueExpression("default").build(), colChg));
+                })
+        );
+
+        for (Ignite node : clusterNodes) {
+            if (node == ignite1) {
+                continue;
+            }
+
+            TableImpl tableOnNode = (TableImpl) node.tables().table(TABLE_NAME);
+
+            IgniteTestUtils.waitForCondition(() -> tableOnNode.schemaView().lastSchemaVersion() == 2, 10_000);
+        }
+
+        TableImpl table1 = (TableImpl) ignite1.tables().table(TABLE_NAME);
+
+        for (int i = 10; i < 20; i++) {
+            table.recordView().insert(Tuple.create()
+                    .set("key", Long.valueOf(i))
+                    .set("valInt", i)
+                    .set("valStr", "str_" + i)
+                    .set("valStr2", "str2_" + i)
+            );
+        }
+
+        final CompletableFuture insertFut = IgniteTestUtils.runAsync(() ->
+                table1.recordView().insert(Tuple.create()
+                        .set("key", Long.valueOf(0))
+                        .set("valInt", 0)
+                        .set("valStr", "str_" + 0)
+                        .set("valStr2", "str2_" + 0)
+            ));
+    
+        final CompletableFuture getFut = IgniteTestUtils.runAsync(() -> {
+            table1.recordView().get(Tuple.create().set("key", Long.valueOf(10)));
+        });
+    
+        final CompletableFuture checkDefaultFut = IgniteTestUtils.runAsync(() -> {
+            assertEquals("default",
+                    table1.recordView().get(Tuple.create().set("key", Long.valueOf(0)))
+                            .value("valStr2"));
+        });
+
+        assertEquals(1, table1.schemaView().lastSchemaVersion());
+
+        Thread.sleep(10_000);

Review comment:
       Why do we need it? It will slow down the whole test pipeline to 10 seconds...

##########
File path: modules/runner/src/integrationTest/java/org/apache/ignite/internal/test/WatchListenerInhibitor.java
##########
@@ -0,0 +1,149 @@
+/*
+ * 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.test;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.Mockito.doAnswer;
+
+import java.util.ArrayList;
+import java.util.Optional;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.apache.ignite.internal.metastorage.client.WatchEvent;
+import org.apache.ignite.internal.metastorage.client.WatchListener;
+import org.apache.ignite.internal.metastorage.watch.AggregatedWatch;
+import org.apache.ignite.internal.metastorage.watch.WatchAggregator;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.junit.platform.commons.util.ReflectionUtils;
+import org.mockito.Mockito;
+
+/**
+ * Listener which wraps another one to inhibit events.
+ */
+public class WatchListenerInhibitor implements WatchListener {
+    /** Inhibited events. */
+    private final ArrayList<WatchEvent> inhibitEvents = new ArrayList<>();
+
+    /** Inhibit flag. */
+    private boolean inhibit = false;
+
+    /** Wrapped listener. */
+    private WatchListener realListener;
+
+    /**
+     * Creates the specific listener which can inhibit events for real metastorage listener.
+     *
+     * @param ignite Ignite.
+     * @return Listener inhibitor.
+     * @throws Exception If something wrong when creating the listener inhibitor.
+     */
+    public static WatchListenerInhibitor metastorageEventsInhibitor(Ignite ignite)
+            throws Exception {
+        //TODO: IGNITE-15723 After a component factory will be implemented, need to got rid of reflection here.
+        MetaStorageManager metaMngr = (MetaStorageManager) ReflectionUtils.tryToReadFieldValue(
+                IgniteImpl.class,
+                "metaStorageMgr",
+                (IgniteImpl) ignite
+        ).get();
+    
+        assertNotNull(metaMngr);
+    
+        WatchAggregator aggregator = (WatchAggregator) ReflectionUtils.tryToReadFieldValue(

Review comment:
       Have we any plans and jira issues to remove this dirty reflection/mocking-based approach? 

##########
File path: modules/schema/src/main/java/org/apache/ignite/internal/schema/SchemaRegistry.java
##########
@@ -50,6 +51,13 @@
      * @throws SchemaRegistryException If no schema found for given version.
      */
     @NotNull SchemaDescriptor schema(int ver) throws SchemaRegistryException;
+    
+    /**
+     * Gets schema descriptor for the latest version in cluster.
+     *
+     * @return Schema descriptor if initialized, {@code null} otherwise.
+     */
+    SchemaDescriptor waitLatesSchema();

Review comment:
       waitLatestSchema - typo?




-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org