Search in sources :

Example 1 with Table

use of org.apache.ignite.table.Table in project ignite-3 by apache.

the class ItBaselineChangesTest method testBaselineExtending.

/**
 * Check dynamic table creation.
 */
@Test
void testBaselineExtending(TestInfo testInfo) {
    initClusterNodes.forEach((nodeName, configStr) -> clusterNodes.add(IgnitionManager.start(nodeName, configStr, workDir.resolve(nodeName))));
    assertEquals(3, clusterNodes.size());
    // Create table on node 0.
    TableDefinition schTbl1 = SchemaBuilders.tableBuilder("PUBLIC", "tbl1").columns(SchemaBuilders.column("key", ColumnType.INT64).build(), SchemaBuilders.column("val", ColumnType.INT32).asNullable(true).build()).withPrimaryKey("key").build();
    clusterNodes.get(0).tables().createTable(schTbl1.canonicalName(), tblCh -> SchemaConfigurationConverter.convert(schTbl1, tblCh).changeReplicas(5).changePartitions(1));
    // Put data on node 1.
    Table tbl1 = clusterNodes.get(1).tables().table(schTbl1.canonicalName());
    RecordView<Tuple> recView1 = tbl1.recordView();
    recView1.insert(null, Tuple.create().set("key", 1L).set("val", 111));
    var metaStoreNode = clusterNodes.get(0);
    var node3Name = testNodeName(testInfo, nodePort(3));
    var node4Name = testNodeName(testInfo, nodePort(4));
    // Start 2 new nodes after
    var node3 = IgnitionManager.start(node3Name, buildConfig(metaStoreNode.name(), 3), workDir.resolve(node3Name));
    clusterNodes.add(node3);
    var node4 = IgnitionManager.start(node4Name, buildConfig(metaStoreNode.name(), 4), workDir.resolve(node4Name));
    clusterNodes.add(node4);
    // Update baseline to nodes 1,4,5
    metaStoreNode.setBaseline(Set.of(metaStoreNode.name(), node3Name, node4Name));
    IgnitionManager.stop(clusterNodes.get(1).name());
    IgnitionManager.stop(clusterNodes.get(2).name());
    Table tbl4 = node4.tables().table(schTbl1.canonicalName());
    final Tuple keyTuple1 = Tuple.create().set("key", 1L);
    assertEquals(1, (Long) tbl4.recordView().get(null, keyTuple1).value("key"));
}
Also used : Table(org.apache.ignite.table.Table) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 2 with Table

use of org.apache.ignite.table.Table in project ignite-3 by apache.

the class ItDataSchemaSyncTest method test.

/**
 * 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(null, Tuple.create().set("key", (long) i).set("valInt", i).set("valStr", "str_" + i));
    }
    WatchListenerInhibitor listenerInhibitor = WatchListenerInhibitor.metastorageEventsInhibitor(ignite1);
    listenerInhibitor.startInhibit();
    ColumnDefinition columnDefinition = SchemaBuilders.column("valStr2", ColumnType.string()).withDefaultValueExpression("default").build();
    ignite0.tables().alterTable(TABLE_NAME, tblChanger -> tblChanger.changeColumns(cols -> cols.create(columnDefinition.name(), colChg -> convert(columnDefinition, 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(null, Tuple.create().set("key", (long) i).set("valInt", i).set("valStr", "str_" + i).set("valStr2", "str2_" + i));
    }
    final CompletableFuture insertFut = IgniteTestUtils.runAsync(() -> table1.recordView().insert(null, Tuple.create().set("key", 0L).set("valInt", 0).set("valStr", "str_" + 0).set("valStr2", "str2_" + 0)));
    final CompletableFuture getFut = IgniteTestUtils.runAsync(() -> {
        table1.recordView().get(null, Tuple.create().set("key", 10L));
    });
    final CompletableFuture checkDefaultFut = IgniteTestUtils.runAsync(() -> {
        assertEquals("default", table1.recordView().get(null, Tuple.create().set("key", 0L)).value("valStr2"));
    });
    assertEquals(1, table1.schemaView().lastSchemaVersion());
    assertFalse(getFut.isDone());
    assertFalse(insertFut.isDone());
    assertFalse(checkDefaultFut.isDone());
    listenerInhibitor.stopInhibit();
    getFut.get(10, TimeUnit.SECONDS);
    insertFut.get(10, TimeUnit.SECONDS);
    checkDefaultFut.get(10, TimeUnit.SECONDS);
    for (Ignite node : clusterNodes) {
        Table tableOnNode = node.tables().table(TABLE_NAME);
        for (int i = 0; i < 20; i++) {
            Tuple row = tableOnNode.recordView().get(null, Tuple.create().set("key", (long) i));
            assertNotNull(row);
            assertEquals(i, row.intValue("valInt"));
            assertEquals("str_" + i, row.value("valStr"));
            assertEquals(i < 10 ? "default" : ("str2_" + i), row.value("valStr2"));
        }
    }
}
Also used : IgniteImpl(org.apache.ignite.internal.app.IgniteImpl) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) BeforeEach(org.junit.jupiter.api.BeforeEach) SchemaConfigurationConverter.convert(org.apache.ignite.internal.schema.configuration.SchemaConfigurationConverter.convert) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) WatchListenerInhibitor(org.apache.ignite.internal.test.WatchListenerInhibitor) Lists(com.google.common.collect.Lists) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) TableImpl(org.apache.ignite.internal.table.TableImpl) Map(java.util.Map) IgniteUtils(org.apache.ignite.internal.util.IgniteUtils) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) ColumnDefinition(org.apache.ignite.schema.definition.ColumnDefinition) Ignite(org.apache.ignite.Ignite) ColumnType(org.apache.ignite.schema.definition.ColumnType) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) IgnitionManager(org.apache.ignite.IgnitionManager) IgniteTestUtils(org.apache.ignite.internal.testframework.IgniteTestUtils) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest) SchemaBuilders(org.apache.ignite.schema.SchemaBuilders) WorkDirectoryExtension(org.apache.ignite.internal.testframework.WorkDirectoryExtension) Table(org.apache.ignite.table.Table) Tuple(org.apache.ignite.table.Tuple) CompletableFuture(java.util.concurrent.CompletableFuture) Table(org.apache.ignite.table.Table) IgniteImpl(org.apache.ignite.internal.app.IgniteImpl) TableImpl(org.apache.ignite.internal.table.TableImpl) Ignite(org.apache.ignite.Ignite) WatchListenerInhibitor(org.apache.ignite.internal.test.WatchListenerInhibitor) Tuple(org.apache.ignite.table.Tuple) ColumnDefinition(org.apache.ignite.schema.definition.ColumnDefinition) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest)

Example 3 with Table

use of org.apache.ignite.table.Table in project ignite-3 by apache.

the class ItDynamicTableCreationTest method testDynamicTableCreation.

/**
 * Check dynamic table creation.
 */
@Test
void testDynamicTableCreation() {
    startGrid();
    // Create table on node 0.
    TableDefinition scmTbl1 = SchemaBuilders.tableBuilder("PUBLIC", "tbl1").columns(SchemaBuilders.column("key", ColumnType.UUID).build(), SchemaBuilders.column("affKey", ColumnType.INT64).build(), SchemaBuilders.column("valStr", ColumnType.string()).asNullable(true).build(), SchemaBuilders.column("valInt", ColumnType.INT32).asNullable(true).build(), SchemaBuilders.column("valNull", ColumnType.INT16).asNullable(true).build()).withPrimaryKey(SchemaBuilders.primaryKey().withColumns("key", "affKey").withColocationColumns("affKey").build()).build();
    clusterNodes.get(0).tables().createTable(scmTbl1.canonicalName(), tblCh -> SchemaConfigurationConverter.convert(scmTbl1, tblCh).changeReplicas(1).changePartitions(10));
    final UUID uuid = UUID.randomUUID();
    final UUID uuid2 = UUID.randomUUID();
    // Put data on node 1.
    Table tbl1 = clusterNodes.get(1).tables().table(scmTbl1.canonicalName());
    RecordView<Tuple> recView1 = tbl1.recordView();
    KeyValueView<Tuple, Tuple> kvView1 = tbl1.keyValueView();
    recView1.insert(null, Tuple.create().set("key", uuid).set("affKey", 42L).set("valStr", "String value").set("valInt", 73).set("valNull", null));
    kvView1.put(null, Tuple.create().set("key", uuid2).set("affKey", 4242L), Tuple.create().set("valStr", "String value 2").set("valInt", 7373).set("valNull", null));
    // Get data on node 2.
    Table tbl2 = clusterNodes.get(2).tables().table(scmTbl1.canonicalName());
    final RecordView<Tuple> recView2 = tbl2.recordView();
    KeyValueView<Tuple, Tuple> kvView2 = tbl2.keyValueView();
    final Tuple keyTuple1 = Tuple.create().set("key", uuid).set("affKey", 42L);
    final Tuple keyTuple2 = Tuple.create().set("key", uuid2).set("affKey", 4242L);
    // KV view must NOT return key columns in value.
    assertThrows(IllegalArgumentException.class, () -> kvView2.get(null, keyTuple1).value("key"));
    assertThrows(IllegalArgumentException.class, () -> kvView2.get(null, keyTuple1).value("affKey"));
    assertThrows(IllegalArgumentException.class, () -> kvView2.get(null, keyTuple2).value("key"));
    assertThrows(IllegalArgumentException.class, () -> kvView2.get(null, keyTuple2).value("affKey"));
    // Record binary view MUST return key columns in value.
    assertEquals(uuid, recView2.get(null, keyTuple1).value("key"));
    assertEquals(42L, (Long) recView2.get(null, keyTuple1).value("affKey"));
    assertEquals(uuid2, recView2.get(null, keyTuple2).value("key"));
    assertEquals(4242L, (Long) recView2.get(null, keyTuple2).value("affKey"));
    assertEquals("String value", recView2.get(null, keyTuple1).value("valStr"));
    assertEquals(73, (Integer) recView2.get(null, keyTuple1).value("valInt"));
    assertNull(recView2.get(null, keyTuple1).value("valNull"));
    assertEquals("String value 2", recView2.get(null, keyTuple2).value("valStr"));
    assertEquals(7373, (Integer) recView2.get(null, keyTuple2).value("valInt"));
    assertNull(recView2.get(null, keyTuple2).value("valNull"));
    assertEquals("String value", kvView2.get(null, keyTuple1).value("valStr"));
    assertEquals(73, (Integer) kvView2.get(null, keyTuple1).value("valInt"));
    assertNull(kvView2.get(null, keyTuple1).value("valNull"));
    assertEquals("String value 2", kvView2.get(null, keyTuple2).value("valStr"));
    assertEquals(7373, (Integer) kvView2.get(null, keyTuple2).value("valInt"));
    assertNull(kvView2.get(null, keyTuple2).value("valNull"));
}
Also used : Table(org.apache.ignite.table.Table) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) UUID(java.util.UUID) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 4 with Table

use of org.apache.ignite.table.Table in project ignite-3 by apache.

the class ItDynamicTableCreationTest method testDynamicSimpleTableCreation.

/**
 * Check dynamic table creation.
 */
@Test
void testDynamicSimpleTableCreation() {
    startGrid();
    // Create table on node 0.
    TableDefinition schTbl1 = SchemaBuilders.tableBuilder("PUBLIC", "tbl1").columns(SchemaBuilders.column("key", ColumnType.INT64).build(), SchemaBuilders.column("val", ColumnType.INT32).asNullable(true).build()).withPrimaryKey("key").build();
    clusterNodes.get(0).tables().createTable(schTbl1.canonicalName(), tblCh -> SchemaConfigurationConverter.convert(schTbl1, tblCh).changeReplicas(1).changePartitions(10));
    // Put data on node 1.
    Table tbl1 = clusterNodes.get(1).tables().table(schTbl1.canonicalName());
    RecordView<Tuple> recView1 = tbl1.recordView();
    KeyValueView<Tuple, Tuple> kvView1 = tbl1.keyValueView();
    recView1.insert(null, Tuple.create().set("key", 1L).set("val", 111));
    kvView1.put(null, Tuple.create().set("key", 2L), Tuple.create().set("val", 222));
    // Get data on node 2.
    Table tbl2 = clusterNodes.get(2).tables().table(schTbl1.canonicalName());
    RecordView<Tuple> recView2 = tbl2.recordView();
    KeyValueView<Tuple, Tuple> kvView2 = tbl2.keyValueView();
    final Tuple keyTuple1 = Tuple.create().set("key", 1L);
    final Tuple keyTuple2 = Tuple.create().set("key", 2L);
    assertThrows(IllegalArgumentException.class, () -> kvView2.get(null, keyTuple1).value("key"));
    assertThrows(IllegalArgumentException.class, () -> kvView2.get(null, keyTuple2).value("key"));
    assertEquals(1, (Long) recView2.get(null, keyTuple1).value("key"));
    assertEquals(2, (Long) recView2.get(null, keyTuple2).value("key"));
    assertEquals(111, (Integer) recView2.get(null, keyTuple1).value("val"));
    assertEquals(111, (Integer) kvView2.get(null, keyTuple1).value("val"));
    assertEquals(222, (Integer) recView2.get(null, keyTuple2).value("val"));
    assertEquals(222, (Integer) kvView2.get(null, keyTuple2).value("val"));
    assertThrows(IllegalArgumentException.class, () -> kvView1.get(null, keyTuple1).value("key"));
    assertThrows(IllegalArgumentException.class, () -> kvView1.get(null, keyTuple2).value("key"));
}
Also used : Table(org.apache.ignite.table.Table) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 5 with Table

use of org.apache.ignite.table.Table in project ignite-3 by apache.

the class ItIgniteNodeRestartTest method nodeWithDataTest.

/**
 * Restarts the node which stores some data.
 */
@Test
@Disabled("https://issues.apache.org/jira/browse/IGNITE-16433")
public void nodeWithDataTest(TestInfo testInfo) {
    String nodeName = testNodeName(testInfo, 3344);
    Ignite ignite = IgnitionManager.start(nodeName, "{\n" + "  \"node\": {\n" + "    \"metastorageNodes\":[ " + nodeName + " ]\n" + "  },\n" + "  \"network\": {\n" + "    \"port\":3344,\n" + "    \"nodeFinder\": {\n" + "      \"netClusterNodes\":[ \"localhost:3344\" ] \n" + "    }\n" + "  }\n" + "}", workDir);
    TableDefinition scmTbl1 = SchemaBuilders.tableBuilder("PUBLIC", TABLE_NAME).columns(SchemaBuilders.column("id", ColumnType.INT32).build(), SchemaBuilders.column("name", ColumnType.string()).asNullable(true).build()).withPrimaryKey(SchemaBuilders.primaryKey().withColumns("id").build()).build();
    Table table = ignite.tables().createTable(scmTbl1.canonicalName(), tbl -> SchemaConfigurationConverter.convert(scmTbl1, tbl).changePartitions(10));
    for (int i = 0; i < 100; i++) {
        Tuple key = Tuple.create().set("id", i);
        Tuple val = Tuple.create().set("name", "name " + i);
        table.keyValueView().put(null, key, val);
    }
    IgnitionManager.stop(nodeName);
    ignite = IgnitionManager.start(nodeName, null, workDir);
    assertNotNull(ignite.tables().table(TABLE_NAME));
    for (int i = 0; i < 100; i++) {
        assertEquals("name " + i, table.keyValueView().get(null, Tuple.create().set("id", i)).stringValue("name"));
    }
    IgnitionManager.stop(nodeName);
}
Also used : Table(org.apache.ignite.table.Table) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Ignite(org.apache.ignite.Ignite) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

Table (org.apache.ignite.table.Table)65 Test (org.junit.jupiter.api.Test)51 Tuple (org.apache.ignite.table.Tuple)29 Ignite (org.apache.ignite.Ignite)15 TableDefinition (org.apache.ignite.schema.definition.TableDefinition)15 List (java.util.List)12 UUID (java.util.UUID)12 CompletableFuture (java.util.concurrent.CompletableFuture)12 IgniteAbstractTest (org.apache.ignite.internal.testframework.IgniteAbstractTest)12 ArrayList (java.util.ArrayList)11 NodeStoppingException (org.apache.ignite.lang.NodeStoppingException)11 TableImpl (org.apache.ignite.internal.table.TableImpl)10 Function (java.util.function.Function)9 Collectors (java.util.stream.Collectors)9 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)9 SchemaBuilders (org.apache.ignite.schema.SchemaBuilders)8 ColumnType (org.apache.ignite.schema.definition.ColumnType)8 NotNull (org.jetbrains.annotations.NotNull)8 Consumer (java.util.function.Consumer)7 DataStorageConfiguration (org.apache.ignite.configuration.schemas.store.DataStorageConfiguration)7