use of org.apache.ignite.internal.table.InternalTable in project ignite-3 by apache.
the class SqlSchemaManagerTest method testTableEventIsProcessedRequiredVersionIsLess.
@Test
public void testTableEventIsProcessedRequiredVersionIsLess() {
when(table.schemaView()).thenReturn(schemaRegistry);
when(table.name()).thenReturn("TEST_SCHEMA.T");
InternalTable mock = mock(InternalTable.class);
when(mock.tableId()).thenReturn(tableId);
when(table.internalTable()).thenReturn(mock);
when(schemaRegistry.schema()).thenReturn(schemaDescriptor);
when(schemaRegistry.lastSchemaVersion()).thenReturn(schemaDescriptor.version());
schemaManager.onTableCreated("TEST_SCHEMA", table, testRevisionRegister.actualToken() + 1);
testRevisionRegister.moveForward();
IgniteTable actTable = schemaManager.tableById(tableId, tableVer - 1);
assertEquals(tableId, actTable.id());
Mockito.verifyNoMoreInteractions(tableManager);
}
use of org.apache.ignite.internal.table.InternalTable in project ignite-3 by apache.
the class SqlSchemaManagerTest method testOnTableDroppedHandler.
@Test
public void testOnTableDroppedHandler() {
when(table.schemaView()).thenReturn(schemaRegistry);
when(table.name()).thenReturn("TEST_SCHEMA.T");
InternalTable mock = mock(InternalTable.class);
when(mock.tableId()).thenReturn(tableId);
when(table.internalTable()).thenReturn(mock);
when(schemaRegistry.schema()).thenReturn(schemaDescriptor);
when(schemaRegistry.lastSchemaVersion()).thenReturn(schemaDescriptor.version());
schemaManager.onTableCreated("TEST_SCHEMA", table, testRevisionRegister.actualToken() + 1);
testRevisionRegister.moveForward();
Table schemaTable = schemaManager.schema("TEST_SCHEMA").getTable("T");
assertNotNull(schemaTable);
IgniteTableImpl igniteTable = assertInstanceOf(IgniteTableImpl.class, schemaTable);
assertEquals(tableId, igniteTable.table().tableId());
schemaManager.onTableDropped("TEST_SCHEMA", table.name(), testRevisionRegister.actualToken() + 1);
testRevisionRegister.moveForward();
assertNull(schemaManager.schema("TEST_SCHEMA").getTable("T"));
}
use of org.apache.ignite.internal.table.InternalTable 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.internal.table.InternalTable in project ignite-3 by apache.
the class SqlSchemaManagerTest method testTableEventIsNotProcessed.
@Test
public void testTableEventIsNotProcessed() throws NodeStoppingException {
when(tableManager.table(eq(tableId))).thenReturn(table);
when(table.schemaView()).thenReturn(schemaRegistry);
InternalTable mock = mock(InternalTable.class);
when(mock.tableId()).thenReturn(tableId);
when(table.internalTable()).thenReturn(mock);
when(schemaRegistry.schema()).thenReturn(schemaDescriptor);
when(schemaRegistry.lastSchemaVersion()).thenReturn(schemaDescriptor.version());
IgniteTable actTable = schemaManager.tableById(tableId, tableVer);
assertEquals(tableId, actTable.id());
Mockito.verify(tableManager).table(eq(tableId));
Mockito.verifyNoMoreInteractions(tableManager);
}
use of org.apache.ignite.internal.table.InternalTable in project ignite-3 by apache.
the class SqlSchemaManagerTest method testTableEventIsProcessedRequiredVersionIsGreater.
@Test
public void testTableEventIsProcessedRequiredVersionIsGreater() throws NodeStoppingException {
when(table.schemaView()).thenReturn(schemaRegistry);
when(table.name()).thenReturn("TEST_SCHEMA.T");
InternalTable mock = mock(InternalTable.class);
when(mock.tableId()).thenReturn(tableId);
when(table.internalTable()).thenReturn(mock);
when(schemaRegistry.schema()).thenReturn(schemaDescriptor);
when(schemaRegistry.lastSchemaVersion()).thenReturn(tableVer - 1);
schemaManager.onTableCreated("TEST_SCHEMA", table, testRevisionRegister.actualToken() + 1);
testRevisionRegister.moveForward();
when(tableManager.table(eq(tableId))).thenReturn(table);
when(schemaRegistry.lastSchemaVersion()).thenReturn(tableVer);
IgniteTable actTable = schemaManager.tableById(tableId, tableVer);
assertEquals(tableId, actTable.id());
IgniteInternalException ex = assertThrows(IgniteInternalException.class, () -> schemaManager.tableById(tableId, tableVer + 1));
assertThat(ex.getMessage(), containsString("Table version not found"));
Mockito.verify(tableManager, times(2)).table(eq(tableId));
Mockito.verifyNoMoreInteractions(tableManager);
}
Aggregations