use of io.crate.metadata.RelationName in project crate by crate.
the class SwapRelationsOperation method applyRenameActions.
private UpdatedState applyRenameActions(ClusterState state, SwapRelationsRequest swapRelationsRequest) {
HashSet<String> newIndexNames = new HashSet<>();
Metadata metadata = state.getMetadata();
Metadata.Builder updatedMetadata = Metadata.builder(state.getMetadata());
RoutingTable.Builder routingBuilder = RoutingTable.builder(state.routingTable());
ClusterBlocks.Builder blocksBuilder = ClusterBlocks.builder().blocks(state.blocks());
// Remove all involved indices first so that rename operations are independent of each other
for (RelationNameSwap swapAction : swapRelationsRequest.swapActions()) {
removeOccurrences(state, blocksBuilder, routingBuilder, updatedMetadata, swapAction.source());
removeOccurrences(state, blocksBuilder, routingBuilder, updatedMetadata, swapAction.target());
}
for (RelationNameSwap relationNameSwap : swapRelationsRequest.swapActions()) {
RelationName source = relationNameSwap.source();
RelationName target = relationNameSwap.target();
addSourceIndicesRenamedToTargetName(state, metadata, updatedMetadata, blocksBuilder, routingBuilder, source, target, newIndexNames::add);
addSourceIndicesRenamedToTargetName(state, metadata, updatedMetadata, blocksBuilder, routingBuilder, target, source, newIndexNames::add);
}
ClusterState stateAfterSwap = ClusterState.builder(state).metadata(updatedMetadata).routingTable(routingBuilder.build()).blocks(blocksBuilder).build();
ClusterState reroutedState = allocationService.reroute(applyClusterStateModifiers(stateAfterSwap, swapRelationsRequest.swapActions()), "indices name switch");
return new UpdatedState(reroutedState, newIndexNames);
}
use of io.crate.metadata.RelationName in project crate by crate.
the class SwapTablePlan method executeOrFail.
@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) {
boolean dropSource = Objects.requireNonNull(DataTypes.BOOLEAN.sanitizeValue(SymbolEvaluator.evaluate(plannerContext.transactionContext(), dependencies.nodeContext(), swapTable.dropSource(), params, subQueryResults)), SwapTableAnalyzer.DROP_SOURCE + " option must be true or false, not null");
RelationName source = swapTable.source().ident();
SwapRelationsRequest request = new SwapRelationsRequest(Collections.singletonList(new RelationNameSwap(source, swapTable.target().ident())), dropSource ? Collections.singletonList(source) : emptyList());
OneRowActionListener<AcknowledgedResponse> listener = new OneRowActionListener<>(consumer, r -> r.isAcknowledged() ? new Row1(1L) : new Row1(0L));
dependencies.swapRelationsAction().execute(request, listener);
}
use of io.crate.metadata.RelationName in project crate by crate.
the class CreateBlobTablePlan method executeOrFail.
@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) throws Exception {
RelationName relationName = analyzedBlobTable.relationName();
Settings settings = buildSettings(analyzedBlobTable.createBlobTable(), plannerContext.transactionContext(), dependencies.nodeContext(), params, subQueryResults, numberOfShards);
CreateIndexRequest createIndexRequest = new CreateIndexRequest(fullIndexName(relationName.name()), settings);
OneRowActionListener<CreateIndexResponse> listener = new OneRowActionListener<>(consumer, r -> new Row1(1L));
dependencies.createIndexAction().execute(createIndexRequest, listener);
}
use of io.crate.metadata.RelationName in project crate by crate.
the class RoutingBuilder method buildReaderAllocations.
ReaderAllocations buildReaderAllocations() {
Map<RelationName, Collection<String>> indicesByTable = new HashMap<>();
IndexBaseBuilder indexBaseBuilder = new IndexBaseBuilder();
Map<String, Map<Integer, String>> shardNodes = new HashMap<>();
Map<RelationName, List<Routing>> routingListByTable = routingListByTableStack.removeLast();
assert routingListByTable != null : "Call to `buildReaderAllocations` without prior `newAllocations` call";
for (var tableRouting : routingListByTable.entrySet()) {
RelationName table = tableRouting.getKey();
List<Routing> routingList = tableRouting.getValue();
for (Routing routing : routingList) {
allocateRoutingNodes(shardNodes, routing.locations());
for (Map.Entry<String, Map<String, IntIndexedContainer>> entry : routing.locations().entrySet()) {
Map<String, IntIndexedContainer> shardsByIndex = entry.getValue();
Collection<String> indices = indicesByTable.computeIfAbsent(table, ignored -> new ArrayList<>());
indices.addAll(shardsByIndex.keySet());
for (Map.Entry<String, IntIndexedContainer> shardsByIndexEntry : shardsByIndex.entrySet()) {
indexBaseBuilder.allocate(shardsByIndexEntry.getKey(), shardsByIndexEntry.getValue());
}
}
}
}
return new ReaderAllocations(indexBaseBuilder.build(), shardNodes, indicesByTable);
}
use of io.crate.metadata.RelationName in project crate by crate.
the class AlterTableRerouteAnalyzer method analyze.
public AnalyzedStatement analyze(AlterTableReroute<Expression> alterTableReroute, ParamTypeHints paramTypeHints, CoordinatorTxnCtx transactionContext) {
// safe to expect a `ShardedTable` since getTableInfo with
// Operation.ALTER_REROUTE raises a appropriate error for sys tables
ShardedTable tableInfo;
RelationName relationName;
if (alterTableReroute.blob()) {
relationName = fromBlobTable(alterTableReroute.table());
} else {
relationName = schemas.resolveRelation(alterTableReroute.table().getName(), transactionContext.sessionContext().searchPath());
}
tableInfo = schemas.getTableInfo(relationName, Operation.ALTER_REROUTE);
return alterTableReroute.rerouteOption().accept(rerouteOptionVisitor, new Context(tableInfo, alterTableReroute.table().partitionProperties(), transactionContext, nodeCtx, paramTypeHints));
}
Aggregations