Search in sources :

Example 1 with DropTableRequest

use of io.crate.execution.ddl.tables.DropTableRequest in project crate by crate.

the class DropTablePlan method executeOrFail.

@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) {
    TableInfo table = dropTable.table();
    DropTableRequest request;
    if (table == null) {
        if (dropTable.maybeCorrupt()) {
            // setting isPartitioned=true should be safe.
            // It will delete a template if it exists, and if there is no template it shouldn't do any harm
            request = new DropTableRequest(dropTable.tableName(), true);
        } else {
            // no-op, table is already gone
            assert dropTable.dropIfExists() : "If table is null, IF EXISTS flag must have been present";
            consumer.accept(InMemoryBatchIterator.of(ROW_ZERO, SENTINEL), null);
            return;
        }
    } else {
        boolean isPartitioned = table instanceof DocTableInfo && ((DocTableInfo) table).isPartitioned();
        request = new DropTableRequest(table.ident(), isPartitioned);
    }
    dependencies.transportDropTableAction().execute(request, new ActionListener<>() {

        @Override
        public void onResponse(AcknowledgedResponse response) {
            if (!response.isAcknowledged() && LOGGER.isWarnEnabled()) {
                if (LOGGER.isWarnEnabled()) {
                    LOGGER.warn("Dropping table {} was not acknowledged. This could lead to inconsistent state.", dropTable.tableName());
                }
            }
            consumer.accept(InMemoryBatchIterator.of(ROW_ONE, SENTINEL), null);
        }

        @Override
        public void onFailure(Exception e) {
            if (dropTable.dropIfExists() && e instanceof IndexNotFoundException) {
                consumer.accept(InMemoryBatchIterator.of(ROW_ZERO, SENTINEL), null);
            } else {
                consumer.accept(null, e);
            }
        }
    });
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo) DropTableRequest(io.crate.execution.ddl.tables.DropTableRequest) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException)

Aggregations

DropTableRequest (io.crate.execution.ddl.tables.DropTableRequest)1 DocTableInfo (io.crate.metadata.doc.DocTableInfo)1 TableInfo (io.crate.metadata.table.TableInfo)1 AcknowledgedResponse (org.elasticsearch.action.support.master.AcknowledgedResponse)1 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)1