Search in sources :

Example 1 with Query

use of io.prestosql.server.protocol.Query in project hetu-core by openlookeng.

the class AutoVacuumScanner method startVacuum.

private void startVacuum(Catalog catalog, String vacuumTable, boolean isFull) {
    String catalogNameVacuumTable = catalog.getCatalogName() + "." + vacuumTable;
    if (vacuumInProgressMap.containsKey(catalogNameVacuumTable)) {
        log.debug("return Present in vacuumInProgressMap %s ", catalogNameVacuumTable);
        return;
    }
    long attempts = 0;
    QueryId queryId = dispatchManager.createQueryId();
    String slug = "x" + randomUUID().toString().toLowerCase(ENGLISH).replace("-", "");
    String vacuumQuery;
    if (isFull) {
        vacuumQuery = "vacuum table " + catalogNameVacuumTable + "  full";
    } else {
        vacuumQuery = "vacuum table " + catalogNameVacuumTable;
    }
    Session.SessionBuilder sessionBuilder = Session.builder(sessionPropertyManager).setQueryId(queryId).setIdentity(new Identity("openLooKeng", Optional.empty())).setSource("auto-vacuum");
    Session session = sessionBuilder.build();
    AutoVacuumSessionContext sessionContext = new AutoVacuumSessionContext(session);
    vacuumInProgressMap.put(catalogNameVacuumTable, System.currentTimeMillis());
    log.debug("Query.create queryId %s  catalogNameVacuumTable: %s ", queryId.toString(), catalogNameVacuumTable);
    ListenableFuture<?> lf = waitForDispatched(queryId, slug, sessionContext, vacuumQuery);
    Futures.addCallback(lf, new FutureCallback<Object>() {

        @Override
        public void onSuccess(@Nullable Object result) {
            try {
                DispatchQuery dispatchQuery = dispatchManager.getQuery(queryId);
                dispatchQuery.addStateChangeListener((state) -> {
                    Query query = getQuery(queryId, slug);
                    if ((null != query) && (!dispatchManager.getQueryInfo(queryId).getState().isDone())) {
                        query.waitForResults(attempts, Duration.valueOf("1s"), DataSize.valueOf("1MB"));
                    }
                    if (state.isDone()) {
                        log.debug("STATUS  %s QueryID %s Query %s", state.name(), queryId.toString(), vacuumQuery);
                        vacuumInProgressMap.remove(catalogNameVacuumTable);
                    }
                });
            } catch (Throwable e) {
                vacuumInProgressMap.remove(catalogNameVacuumTable);
                log.error("Filed to execute vacuum for table %s QueryID %s", catalogNameVacuumTable, queryId.toString(), e.getMessage());
            }
        }

        @Override
        public void onFailure(Throwable t) {
            vacuumInProgressMap.remove(catalogNameVacuumTable);
            log.error("Query %s request to start vacuum scan failed at queryId[%s]: %s ", vacuumQuery, queryId, t.getMessage());
        }
    }, directExecutor());
}
Also used : ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata) DispatchQuery(io.prestosql.dispatcher.DispatchQuery) Inject(com.google.inject.Inject) DataCenterStatementResource(io.prestosql.datacenter.DataCenterStatementResource) Duration(io.airlift.units.Duration) QueryManager(io.prestosql.execution.QueryManager) PreDestroy(javax.annotation.PreDestroy) Future(java.util.concurrent.Future) BoundedExecutor(io.airlift.concurrent.BoundedExecutor) Map(java.util.Map) SimpleLocalMemoryContext(io.prestosql.memory.context.SimpleLocalMemoryContext) ENGLISH(java.util.Locale.ENGLISH) PrestoException(io.prestosql.spi.PrestoException) Query(io.prestosql.server.protocol.Query) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Identity(io.prestosql.spi.security.Identity) ThreadSafe(javax.annotation.concurrent.ThreadSafe) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Executors(java.util.concurrent.Executors) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) DataSize(io.airlift.units.DataSize) List(java.util.List) SessionPropertyManager(io.prestosql.metadata.SessionPropertyManager) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) StandardErrorCode(io.prestosql.spi.StandardErrorCode) ConnectorVacuumTableInfo(io.prestosql.spi.connector.ConnectorVacuumTableInfo) AggregatedMemoryContext.newSimpleAggregatedMemoryContext(io.prestosql.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext) Connector(io.prestosql.spi.connector.Connector) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Logger(io.airlift.log.Logger) BlockEncodingSerde(io.prestosql.spi.block.BlockEncodingSerde) AtomicReference(java.util.concurrent.atomic.AtomicReference) ExchangeClient(io.prestosql.operator.ExchangeClient) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) QueryId(io.prestosql.spi.QueryId) NoSuchElementException(java.util.NoSuchElementException) DispatchManager(io.prestosql.dispatcher.DispatchManager) Nullable(javax.annotation.Nullable) ForStatementResource(io.prestosql.server.ForStatementResource) FutureCallback(com.google.common.util.concurrent.FutureCallback) Futures(com.google.common.util.concurrent.Futures) UUID.randomUUID(java.util.UUID.randomUUID) Catalog(io.prestosql.metadata.Catalog) ExchangeClientSupplier(io.prestosql.operator.ExchangeClientSupplier) CatalogManager(io.prestosql.metadata.CatalogManager) DispatchQuery(io.prestosql.dispatcher.DispatchQuery) Query(io.prestosql.server.protocol.Query) DispatchQuery(io.prestosql.dispatcher.DispatchQuery) QueryId(io.prestosql.spi.QueryId) Identity(io.prestosql.spi.security.Identity) Session(io.prestosql.Session)

Aggregations

Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors.directExecutor (com.google.common.util.concurrent.MoreExecutors.directExecutor)1 Inject (com.google.inject.Inject)1 BoundedExecutor (io.airlift.concurrent.BoundedExecutor)1 Logger (io.airlift.log.Logger)1 DataSize (io.airlift.units.DataSize)1 Duration (io.airlift.units.Duration)1 Session (io.prestosql.Session)1 DataCenterStatementResource (io.prestosql.datacenter.DataCenterStatementResource)1 DispatchManager (io.prestosql.dispatcher.DispatchManager)1 DispatchQuery (io.prestosql.dispatcher.DispatchQuery)1 QueryManager (io.prestosql.execution.QueryManager)1 AggregatedMemoryContext.newSimpleAggregatedMemoryContext (io.prestosql.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext)1 SimpleLocalMemoryContext (io.prestosql.memory.context.SimpleLocalMemoryContext)1 Catalog (io.prestosql.metadata.Catalog)1 CatalogManager (io.prestosql.metadata.CatalogManager)1 SessionPropertyManager (io.prestosql.metadata.SessionPropertyManager)1