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();
}
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\"")));
}
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\"")));
}
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());
}
Aggregations