Search in sources :

Example 1 with TableConfiguration

use of org.apache.ignite.configuration.schemas.table.TableConfiguration in project ignite-3 by apache.

the class TableManager method createTableLocally.

/**
 * Creates local structures for a table.
 *
 * @param causalityToken Causality token.
 * @param name  Table name.
 * @param tblId Table id.
 * @param assignment Affinity assignment.
 */
private void createTableLocally(long causalityToken, String name, UUID tblId, List<List<ClusterNode>> assignment, SchemaDescriptor schemaDesc) {
    int partitions = assignment.size();
    var partitionsGroupsFutures = new ArrayList<CompletableFuture<RaftGroupService>>();
    Path storageDir = partitionsStoreDir.resolve(name);
    try {
        Files.createDirectories(storageDir);
    } catch (IOException e) {
        throw new IgniteInternalException("Failed to create partitions store directory for " + name + ": " + e.getMessage(), e);
    }
    TableConfiguration tableCfg = tablesCfg.tables().get(name);
    DataRegion dataRegion = dataRegions.computeIfAbsent(tableCfg.dataRegion().value(), dataRegionName -> {
        DataRegion newDataRegion = engine.createDataRegion(dataStorageCfg.regions().get(dataRegionName));
        try {
            newDataRegion.start();
        } catch (Exception e) {
            try {
                newDataRegion.stop();
            } catch (Exception stopException) {
                e.addSuppressed(stopException);
            }
            throw e;
        }
        return newDataRegion;
    });
    TableStorage tableStorage = engine.createTable(storageDir, tableCfg, dataRegion);
    tableStorage.start();
    for (int p = 0; p < partitions; p++) {
        int partId = p;
        try {
            partitionsGroupsFutures.add(raftMgr.prepareRaftGroup(raftGroupName(tblId, p), assignment.get(p), () -> new PartitionListener(tblId, new VersionedRowStore(tableStorage.getOrCreatePartition(partId), txManager))));
        } catch (NodeStoppingException e) {
            throw new AssertionError("Loza was stopped before Table manager", e);
        }
    }
    CompletableFuture.allOf(partitionsGroupsFutures.toArray(CompletableFuture[]::new)).thenRun(() -> {
        try {
            Int2ObjectOpenHashMap<RaftGroupService> partitionMap = new Int2ObjectOpenHashMap<>(partitions);
            for (int p = 0; p < partitions; p++) {
                CompletableFuture<RaftGroupService> future = partitionsGroupsFutures.get(p);
                assert future.isDone();
                RaftGroupService service = future.join();
                partitionMap.put(p, service);
            }
            InternalTableImpl internalTable = new InternalTableImpl(name, tblId, partitionMap, partitions, netAddrResolver, txManager, tableStorage);
            var schemaRegistry = new SchemaRegistryImpl(v -> {
                if (!busyLock.enterBusy()) {
                    throw new IgniteException(new NodeStoppingException());
                }
                try {
                    return tableSchema(tblId, v);
                } finally {
                    busyLock.leaveBusy();
                }
            }, () -> {
                if (!busyLock.enterBusy()) {
                    throw new IgniteException(new NodeStoppingException());
                }
                try {
                    return latestSchemaVersion(tblId);
                } finally {
                    busyLock.leaveBusy();
                }
            });
            schemaRegistry.onSchemaRegistered(schemaDesc);
            var table = new TableImpl(internalTable, schemaRegistry);
            tablesVv.update(causalityToken, previous -> {
                var val = previous == null ? new HashMap() : new HashMap<>(previous);
                val.put(name, table);
                return val;
            }, th -> {
                throw new IgniteInternalException(IgniteStringFormatter.format("Cannot create a table [name={}, id={}]", name, tblId), th);
            });
            tablesByIdVv.update(causalityToken, previous -> {
                var val = previous == null ? new HashMap() : new HashMap<>(previous);
                val.put(tblId, table);
                return val;
            }, th -> {
                throw new IgniteInternalException(IgniteStringFormatter.format("Cannot create a table [name={}, id={}]", name, tblId), th);
            });
            completeApiCreateFuture(table);
            fireEvent(TableEvent.CREATE, new TableEventParameters(causalityToken, table), null);
        } catch (Exception e) {
            fireEvent(TableEvent.CREATE, new TableEventParameters(causalityToken, tblId, name), e);
        }
    }).join();
}
Also used : TableStorage(org.apache.ignite.internal.storage.engine.TableStorage) IgniteTablesInternal(org.apache.ignite.internal.table.IgniteTablesInternal) ExtendedTableConfiguration(org.apache.ignite.internal.configuration.schema.ExtendedTableConfiguration) TableAlreadyExistsException(org.apache.ignite.lang.TableAlreadyExistsException) ConfigurationUtil.directProxy(org.apache.ignite.internal.configuration.util.ConfigurationUtil.directProxy) ConfigurationUtil.getByInternalId(org.apache.ignite.internal.configuration.util.ConfigurationUtil.getByInternalId) ExtendedTableChange(org.apache.ignite.internal.configuration.schema.ExtendedTableChange) IgniteLogger(org.apache.ignite.lang.IgniteLogger) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) Map(java.util.Map) DataRegion(org.apache.ignite.internal.storage.engine.DataRegion) TableNotFoundException(org.apache.ignite.lang.TableNotFoundException) Path(java.nio.file.Path) SchemaUtils(org.apache.ignite.internal.schema.SchemaUtils) ExtendedTableView(org.apache.ignite.internal.configuration.schema.ExtendedTableView) IgniteComponent(org.apache.ignite.internal.manager.IgniteComponent) SchemaConfiguration(org.apache.ignite.internal.configuration.schema.SchemaConfiguration) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) InternalTableImpl(org.apache.ignite.internal.table.distributed.storage.InternalTableImpl) DataStorageConfiguration(org.apache.ignite.configuration.schemas.store.DataStorageConfiguration) TablesConfiguration(org.apache.ignite.configuration.schemas.table.TablesConfiguration) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) DEFAULT_DATA_REGION_NAME(org.apache.ignite.configuration.schemas.store.DataStorageConfigurationSchema.DEFAULT_DATA_REGION_NAME) CompletionException(java.util.concurrent.CompletionException) Producer(org.apache.ignite.internal.manager.Producer) StorageEngine(org.apache.ignite.internal.storage.engine.StorageEngine) UUID(java.util.UUID) ConfigurationChangeException(org.apache.ignite.configuration.ConfigurationChangeException) Collectors(java.util.stream.Collectors) TxManager(org.apache.ignite.internal.tx.TxManager) TableView(org.apache.ignite.configuration.schemas.table.TableView) ClusterNode(org.apache.ignite.network.ClusterNode) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) IgniteStringFormatter(org.apache.ignite.lang.IgniteStringFormatter) NotNull(org.jetbrains.annotations.NotNull) InternalTable(org.apache.ignite.internal.table.InternalTable) IgniteException(org.apache.ignite.lang.IgniteException) Loza(org.apache.ignite.internal.raft.Loza) SchemaRegistryImpl(org.apache.ignite.internal.schema.registry.SchemaRegistryImpl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TableConfiguration(org.apache.ignite.configuration.schemas.table.TableConfiguration) ByteUtils(org.apache.ignite.internal.util.ByteUtils) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) SchemaSerializerImpl(org.apache.ignite.internal.schema.marshaller.schema.SchemaSerializerImpl) Function(java.util.function.Function) Supplier(java.util.function.Supplier) SchemaView(org.apache.ignite.internal.configuration.schema.SchemaView) VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TableImpl(org.apache.ignite.internal.table.TableImpl) IgniteSpinBusyLock(org.apache.ignite.internal.util.IgniteSpinBusyLock) IgniteTables(org.apache.ignite.table.manager.IgniteTables) NoSuchElementException(java.util.NoSuchElementException) VersionedValue(org.apache.ignite.internal.causality.VersionedValue) TopologyService(org.apache.ignite.network.TopologyService) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) TableEventParameters(org.apache.ignite.internal.table.event.TableEventParameters) Files(java.nio.file.Files) NamedListView(org.apache.ignite.configuration.NamedListView) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) IgniteObjectName(org.apache.ignite.internal.util.IgniteObjectName) IOException(java.io.IOException) Ignite(org.apache.ignite.Ignite) BaselineManager(org.apache.ignite.internal.baseline.BaselineManager) TableStorage(org.apache.ignite.internal.storage.engine.TableStorage) ConfigurationNamedListListener(org.apache.ignite.configuration.notifications.ConfigurationNamedListListener) NetworkAddress(org.apache.ignite.network.NetworkAddress) Consumer(java.util.function.Consumer) ConfigurationNotificationEvent(org.apache.ignite.configuration.notifications.ConfigurationNotificationEvent) TableEvent(org.apache.ignite.internal.table.event.TableEvent) AffinityUtils(org.apache.ignite.internal.affinity.AffinityUtils) EventListener(org.apache.ignite.internal.manager.EventListener) PartitionListener(org.apache.ignite.internal.table.distributed.raft.PartitionListener) Table(org.apache.ignite.table.Table) ConfigurationValidationException(org.apache.ignite.configuration.validation.ConfigurationValidationException) RocksDbStorageEngine(org.apache.ignite.internal.storage.rocksdb.RocksDbStorageEngine) TableChange(org.apache.ignite.configuration.schemas.table.TableChange) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) InternalTableImpl(org.apache.ignite.internal.table.distributed.storage.InternalTableImpl) TableImpl(org.apache.ignite.internal.table.TableImpl) CompletableFuture(java.util.concurrent.CompletableFuture) IgniteException(org.apache.ignite.lang.IgniteException) ExtendedTableConfiguration(org.apache.ignite.internal.configuration.schema.ExtendedTableConfiguration) TableConfiguration(org.apache.ignite.configuration.schemas.table.TableConfiguration) Path(java.nio.file.Path) VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) IOException(java.io.IOException) SchemaRegistryImpl(org.apache.ignite.internal.schema.registry.SchemaRegistryImpl) TableAlreadyExistsException(org.apache.ignite.lang.TableAlreadyExistsException) TableNotFoundException(org.apache.ignite.lang.TableNotFoundException) CompletionException(java.util.concurrent.CompletionException) ConfigurationChangeException(org.apache.ignite.configuration.ConfigurationChangeException) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) IgniteException(org.apache.ignite.lang.IgniteException) NoSuchElementException(java.util.NoSuchElementException) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) IOException(java.io.IOException) ConfigurationValidationException(org.apache.ignite.configuration.validation.ConfigurationValidationException) PartitionListener(org.apache.ignite.internal.table.distributed.raft.PartitionListener) TableEventParameters(org.apache.ignite.internal.table.event.TableEventParameters) InternalTableImpl(org.apache.ignite.internal.table.distributed.storage.InternalTableImpl) DataRegion(org.apache.ignite.internal.storage.engine.DataRegion)

Example 2 with TableConfiguration

use of org.apache.ignite.configuration.schemas.table.TableConfiguration in project ignite-3 by apache.

the class TableValidatorImplTest method testMisalignedColumnNamedListKeys.

/**
 * Tests that column names and column keys inside a Named List must be equal.
 */
@Test
void testMisalignedColumnNamedListKeys(@InjectConfiguration(polymorphicExtensions = RocksDbDataRegionConfigurationSchema.class) DataStorageConfiguration dbCfg) {
    NamedListView<TableView> oldValue = tablesCfg.tables().value();
    TableConfiguration tableCfg = tablesCfg.tables().get("table");
    CompletableFuture<Void> tableChangeFuture = tableCfg.columns().change(columnsChange -> columnsChange.create("ololo", columnChange -> columnChange.changeName("not ololo").changeType(columnTypeChange -> columnTypeChange.changeType("STRING")).changeNullable(true)));
    assertThat(tableChangeFuture, willBe(nullValue(Void.class)));
    ValidationContext<NamedListView<TableView>> ctx = mockContext(oldValue, dbCfg.value());
    ArgumentCaptor<ValidationIssue> issuesCaptor = validate(ctx);
    assertThat(issuesCaptor.getAllValues(), hasSize(1));
    assertThat(issuesCaptor.getValue().message(), is(equalTo("Column name \"not ololo\" does not match its Named List key: \"ololo\"")));
}
Also used : HashIndexConfigurationSchema(org.apache.ignite.configuration.schemas.table.HashIndexConfigurationSchema) PageMemoryDataRegionConfigurationSchema(org.apache.ignite.configuration.schemas.store.PageMemoryDataRegionConfigurationSchema) TableConfiguration(org.apache.ignite.configuration.schemas.table.TableConfiguration) CompletableFuture(java.util.concurrent.CompletableFuture) PartialIndexConfigurationSchema(org.apache.ignite.configuration.schemas.table.PartialIndexConfigurationSchema) SortedIndexConfigurationSchema(org.apache.ignite.configuration.schemas.table.SortedIndexConfigurationSchema) InjectConfiguration(org.apache.ignite.internal.configuration.testframework.InjectConfiguration) ArgumentCaptor(org.mockito.ArgumentCaptor) UnsafeMemoryAllocatorConfigurationSchema(org.apache.ignite.configuration.schemas.store.UnsafeMemoryAllocatorConfigurationSchema) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ConfigurationExtension(org.apache.ignite.internal.configuration.testframework.ConfigurationExtension) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Matchers.hasSize(org.hamcrest.Matchers.hasSize) RocksDbDataRegionConfigurationSchema(org.apache.ignite.configuration.schemas.store.RocksDbDataRegionConfigurationSchema) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DataStorageView(org.apache.ignite.configuration.schemas.store.DataStorageView) Matchers.empty(org.hamcrest.Matchers.empty) ValidationContext(org.apache.ignite.configuration.validation.ValidationContext) NamedListView(org.apache.ignite.configuration.NamedListView) DataStorageConfiguration(org.apache.ignite.configuration.schemas.store.DataStorageConfiguration) TablesConfiguration(org.apache.ignite.configuration.schemas.table.TablesConfiguration) CompletableFutureMatcher.willBe(org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willBe) Mockito.doNothing(org.mockito.Mockito.doNothing) Mockito.when(org.mockito.Mockito.when) TableView(org.apache.ignite.configuration.schemas.table.TableView) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) Nullable(org.jetbrains.annotations.Nullable) ValidationIssue(org.apache.ignite.configuration.validation.ValidationIssue) Matchers.equalTo(org.hamcrest.Matchers.equalTo) HashIndexChange(org.apache.ignite.configuration.schemas.table.HashIndexChange) Matchers.is(org.hamcrest.Matchers.is) Mockito.mock(org.mockito.Mockito.mock) NamedListView(org.apache.ignite.configuration.NamedListView) ValidationIssue(org.apache.ignite.configuration.validation.ValidationIssue) TableConfiguration(org.apache.ignite.configuration.schemas.table.TableConfiguration) TableView(org.apache.ignite.configuration.schemas.table.TableView) Test(org.junit.jupiter.api.Test)

Example 3 with TableConfiguration

use of org.apache.ignite.configuration.schemas.table.TableConfiguration in project ignite-3 by apache.

the class TableValidatorImplTest method testMisalignedIndexNamedListKeys.

/**
 * Tests that index names and index keys inside a Named List must be equal.
 */
@Test
void testMisalignedIndexNamedListKeys(@InjectConfiguration(polymorphicExtensions = RocksDbDataRegionConfigurationSchema.class) DataStorageConfiguration dbCfg) {
    NamedListView<TableView> oldValue = tablesCfg.tables().value();
    TableConfiguration tableCfg = tablesCfg.tables().get("table");
    CompletableFuture<Void> tableChangeFuture = tableCfg.indices().change(indicesChange -> indicesChange.create("ololo", indexChange -> indexChange.changeName("not ololo").convert(HashIndexChange.class).changeColNames("id")));
    assertThat(tableChangeFuture, willBe(nullValue(Void.class)));
    ValidationContext<NamedListView<TableView>> ctx = mockContext(oldValue, dbCfg.value());
    ArgumentCaptor<ValidationIssue> issuesCaptor = validate(ctx);
    assertThat(issuesCaptor.getAllValues(), hasSize(1));
    assertThat(issuesCaptor.getValue().message(), is(equalTo("Index name \"not ololo\" does not match its Named List key: \"ololo\"")));
}
Also used : HashIndexConfigurationSchema(org.apache.ignite.configuration.schemas.table.HashIndexConfigurationSchema) PageMemoryDataRegionConfigurationSchema(org.apache.ignite.configuration.schemas.store.PageMemoryDataRegionConfigurationSchema) TableConfiguration(org.apache.ignite.configuration.schemas.table.TableConfiguration) CompletableFuture(java.util.concurrent.CompletableFuture) PartialIndexConfigurationSchema(org.apache.ignite.configuration.schemas.table.PartialIndexConfigurationSchema) SortedIndexConfigurationSchema(org.apache.ignite.configuration.schemas.table.SortedIndexConfigurationSchema) InjectConfiguration(org.apache.ignite.internal.configuration.testframework.InjectConfiguration) ArgumentCaptor(org.mockito.ArgumentCaptor) UnsafeMemoryAllocatorConfigurationSchema(org.apache.ignite.configuration.schemas.store.UnsafeMemoryAllocatorConfigurationSchema) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ConfigurationExtension(org.apache.ignite.internal.configuration.testframework.ConfigurationExtension) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Matchers.hasSize(org.hamcrest.Matchers.hasSize) RocksDbDataRegionConfigurationSchema(org.apache.ignite.configuration.schemas.store.RocksDbDataRegionConfigurationSchema) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DataStorageView(org.apache.ignite.configuration.schemas.store.DataStorageView) Matchers.empty(org.hamcrest.Matchers.empty) ValidationContext(org.apache.ignite.configuration.validation.ValidationContext) NamedListView(org.apache.ignite.configuration.NamedListView) DataStorageConfiguration(org.apache.ignite.configuration.schemas.store.DataStorageConfiguration) TablesConfiguration(org.apache.ignite.configuration.schemas.table.TablesConfiguration) CompletableFutureMatcher.willBe(org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willBe) Mockito.doNothing(org.mockito.Mockito.doNothing) Mockito.when(org.mockito.Mockito.when) TableView(org.apache.ignite.configuration.schemas.table.TableView) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) Nullable(org.jetbrains.annotations.Nullable) ValidationIssue(org.apache.ignite.configuration.validation.ValidationIssue) Matchers.equalTo(org.hamcrest.Matchers.equalTo) HashIndexChange(org.apache.ignite.configuration.schemas.table.HashIndexChange) Matchers.is(org.hamcrest.Matchers.is) Mockito.mock(org.mockito.Mockito.mock) HashIndexChange(org.apache.ignite.configuration.schemas.table.HashIndexChange) NamedListView(org.apache.ignite.configuration.NamedListView) ValidationIssue(org.apache.ignite.configuration.validation.ValidationIssue) TableConfiguration(org.apache.ignite.configuration.schemas.table.TableConfiguration) TableView(org.apache.ignite.configuration.schemas.table.TableView) Test(org.junit.jupiter.api.Test)

Example 4 with TableConfiguration

use of org.apache.ignite.configuration.schemas.table.TableConfiguration in project ignite-3 by apache.

the class SchemaConfigurationConverterTest method testConvertTable.

/**
 * Add/remove table and read it back.
 */
@Test
public void testConvertTable() {
    TableDefinition tbl = tblBuilder.build();
    TableConfiguration tblCfg = confRegistry.getConfiguration(TablesConfiguration.KEY).tables().get(tbl.canonicalName());
    TableDefinition tbl2 = SchemaConfigurationConverter.convert(tblCfg);
    assertEquals(tbl.canonicalName(), tbl2.canonicalName());
    assertEquals(tbl.indices().size(), tbl2.indices().size());
    assertEquals(tbl.keyColumns().size(), tbl2.keyColumns().size());
    assertEquals(tbl.colocationColumns().size(), tbl2.colocationColumns().size());
    assertEquals(tbl.columns().size(), tbl2.columns().size());
}
Also used : TableDefinition(org.apache.ignite.schema.definition.TableDefinition) TableConfiguration(org.apache.ignite.configuration.schemas.table.TableConfiguration) Test(org.junit.jupiter.api.Test)

Aggregations

TableConfiguration (org.apache.ignite.configuration.schemas.table.TableConfiguration)4 CompletableFuture (java.util.concurrent.CompletableFuture)3 NamedListView (org.apache.ignite.configuration.NamedListView)3 DataStorageConfiguration (org.apache.ignite.configuration.schemas.store.DataStorageConfiguration)3 TableView (org.apache.ignite.configuration.schemas.table.TableView)3 TablesConfiguration (org.apache.ignite.configuration.schemas.table.TablesConfiguration)3 Test (org.junit.jupiter.api.Test)3 TimeUnit (java.util.concurrent.TimeUnit)2 DataStorageView (org.apache.ignite.configuration.schemas.store.DataStorageView)2 PageMemoryDataRegionConfigurationSchema (org.apache.ignite.configuration.schemas.store.PageMemoryDataRegionConfigurationSchema)2 RocksDbDataRegionConfigurationSchema (org.apache.ignite.configuration.schemas.store.RocksDbDataRegionConfigurationSchema)2 UnsafeMemoryAllocatorConfigurationSchema (org.apache.ignite.configuration.schemas.store.UnsafeMemoryAllocatorConfigurationSchema)2 HashIndexChange (org.apache.ignite.configuration.schemas.table.HashIndexChange)2 HashIndexConfigurationSchema (org.apache.ignite.configuration.schemas.table.HashIndexConfigurationSchema)2 PartialIndexConfigurationSchema (org.apache.ignite.configuration.schemas.table.PartialIndexConfigurationSchema)2 SortedIndexConfigurationSchema (org.apache.ignite.configuration.schemas.table.SortedIndexConfigurationSchema)2 ValidationContext (org.apache.ignite.configuration.validation.ValidationContext)2 ValidationIssue (org.apache.ignite.configuration.validation.ValidationIssue)2 ConfigurationExtension (org.apache.ignite.internal.configuration.testframework.ConfigurationExtension)2 InjectConfiguration (org.apache.ignite.internal.configuration.testframework.InjectConfiguration)2