use of org.apache.ignite.internal.manager.EventListener in project ignite-3 by apache.
the class TableManager method tableSchema.
/**
* Return table schema of certain version from history.
*
* @param tblId Table id.
* @param schemaVer Schema version.
* @return Schema descriptor.
*/
private SchemaDescriptor tableSchema(UUID tblId, int schemaVer) {
Map<UUID, TableImpl> tablesById = tablesByIdVv.latest();
TableImpl table = tablesById == null ? null : tablesById.get(tblId);
assert table != null : "Table is undefined [tblId=" + tblId + ']';
ExtendedTableConfiguration tblCfg = ((ExtendedTableConfiguration) tablesCfg.tables().get(table.name()));
if (schemaVer <= table.schemaView().lastSchemaVersion()) {
return getSchemaDescriptorLocally(schemaVer, tblCfg);
}
CompletableFuture<SchemaDescriptor> fut = new CompletableFuture<>();
var clo = new EventListener<TableEventParameters>() {
@Override
public boolean notify(@NotNull TableEventParameters parameters, @Nullable Throwable exception) {
if (tblId.equals(parameters.tableId()) && schemaVer <= parameters.table().schemaView().lastSchemaVersion()) {
fut.complete(getSchemaDescriptorLocally(schemaVer, tblCfg));
return true;
}
return false;
}
@Override
public void remove(@NotNull Throwable exception) {
fut.completeExceptionally(exception);
}
};
listen(TableEvent.ALTER, clo);
if (schemaVer <= table.schemaView().lastSchemaVersion()) {
fut.complete(getSchemaDescriptorLocally(schemaVer, tblCfg));
}
if (!isSchemaExists(tblId, schemaVer) && fut.complete(null)) {
removeListener(TableEvent.ALTER, clo);
}
return fut.join();
}
use of org.apache.ignite.internal.manager.EventListener in project ignite-3 by apache.
the class StopCalciteModuleTest method before.
/**
* Before.
* TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*/
@BeforeEach
public void before(TestInfo testInfo) {
when(clusterSrvc.messagingService()).thenReturn(msgSrvc);
when(clusterSrvc.topologyService()).thenReturn(topologySrvc);
when(clusterSrvc.localConfiguration()).thenReturn(localCfg);
ClusterNode node = new ClusterNode("mock-node-id", NODE_NAME, null);
when(topologySrvc.localMember()).thenReturn(node);
when(topologySrvc.allMembers()).thenReturn(Collections.singleton(node));
SchemaDescriptor schemaDesc = new SchemaDescriptor(1, new Column[] { new Column(0, "ID", NativeTypes.INT32, false) }, new Column[] { new Column(1, "VAL", NativeTypes.INT32, false) });
schemaReg = new SchemaRegistryImpl(1, (v) -> schemaDesc, () -> INITIAL_SCHEMA_VERSION);
when(tbl.name()).thenReturn("PUBLIC.TEST");
// Mock create table (notify on register listener).
doAnswer(invocation -> {
EventListener<TableEventParameters> clo = (EventListener<TableEventParameters>) invocation.getArguments()[1];
clo.notify(new TableEventParameters(0, UUID.randomUUID(), "TEST", new TableImpl(tbl, schemaReg)), null);
return null;
}).when(tableManager).listen(eq(TableEvent.CREATE), any());
RowAssembler asm = new RowAssembler(schemaReg.schema(), 0, 0, 0, 0);
asm.appendInt(0);
asm.appendInt(0);
BinaryRow binaryRow = asm.build();
// Mock table scan
doAnswer(invocation -> {
int part = (int) invocation.getArguments()[0];
return (Flow.Publisher<BinaryRow>) s -> {
s.onSubscribe(new Flow.Subscription() {
@Override
public void request(long n) {
}
@Override
public void cancel() {
}
});
if (part == 0) {
for (int i = 0; i < ROWS; ++i) {
s.onNext(binaryRow);
}
}
s.onComplete();
};
}).when(tbl).scan(anyInt(), any());
LOG.info(">>>> Starting test {}", testInfo.getTestMethod().orElseThrow().getName());
}
Aggregations