Search in sources :

Example 16 with RelationName

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);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterBlocks(org.elasticsearch.cluster.block.ClusterBlocks) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) IndexTemplateMetadata(org.elasticsearch.cluster.metadata.IndexTemplateMetadata) Metadata(org.elasticsearch.cluster.metadata.Metadata) AliasMetadata(org.elasticsearch.cluster.metadata.AliasMetadata) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) RelationName(io.crate.metadata.RelationName) HashSet(java.util.HashSet)

Example 17 with RelationName

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);
}
Also used : RelationNameSwap(io.crate.execution.ddl.RelationNameSwap) Row1(io.crate.data.Row1) OneRowActionListener(io.crate.execution.support.OneRowActionListener) SwapRelationsRequest(io.crate.execution.ddl.SwapRelationsRequest) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) RelationName(io.crate.metadata.RelationName)

Example 18 with RelationName

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);
}
Also used : Row1(io.crate.data.Row1) OneRowActionListener(io.crate.execution.support.OneRowActionListener) RelationName(io.crate.metadata.RelationName) CreateIndexRequest(org.elasticsearch.action.admin.indices.create.CreateIndexRequest) CreateIndexResponse(org.elasticsearch.action.admin.indices.create.CreateIndexResponse) Settings(org.elasticsearch.common.settings.Settings)

Example 19 with RelationName

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);
}
Also used : HashMap(java.util.HashMap) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) Routing(io.crate.metadata.Routing) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) IndexBaseBuilder(io.crate.planner.fetch.IndexBaseBuilder) RelationName(io.crate.metadata.RelationName) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 20 with RelationName

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));
}
Also used : NodeContext(io.crate.metadata.NodeContext) ExpressionAnalysisContext(io.crate.analyze.expressions.ExpressionAnalysisContext) RelationName(io.crate.metadata.RelationName) ShardedTable(io.crate.metadata.table.ShardedTable)

Aggregations

RelationName (io.crate.metadata.RelationName)180 Test (org.junit.Test)100 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)55 PartitionName (io.crate.metadata.PartitionName)47 Symbol (io.crate.expression.symbol.Symbol)42 Reference (io.crate.metadata.Reference)37 ColumnIdent (io.crate.metadata.ColumnIdent)31 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)21 ReferenceIdent (io.crate.metadata.ReferenceIdent)21 DocTableInfo (io.crate.metadata.doc.DocTableInfo)21 Map (java.util.Map)20 HashMap (java.util.HashMap)19 SqlExpressions (io.crate.testing.SqlExpressions)18 ArrayList (java.util.ArrayList)18 List (java.util.List)17 Before (org.junit.Before)17 DocTableRelation (io.crate.analyze.relations.DocTableRelation)13 SQLExecutor (io.crate.testing.SQLExecutor)11 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)10 IndexTemplateMetadata (org.elasticsearch.cluster.metadata.IndexTemplateMetadata)10