Search in sources :

Example 1 with GuardedBy

use of javax.annotation.concurrent.GuardedBy in project flink by apache.

the class EmbeddedLeaderService method updateLeader.

@GuardedBy("lock")
private void updateLeader() {
    // this must be called under the lock
    assert Thread.holdsLock(lock);
    if (currentLeaderConfirmed == null && currentLeaderProposed == null) {
        // we need a new leader
        if (allLeaderContenders.isEmpty()) {
            // no new leader available, tell everyone that there is no leader currently
            for (EmbeddedLeaderRetrievalService listener : listeners) {
                notificationExecutor.execute(new NotifyOfLeaderCall(null, null, listener.listener, LOG));
            }
        } else {
            // propose a leader and ask it
            final UUID leaderSessionId = UUID.randomUUID();
            EmbeddedLeaderElectionService leaderService = allLeaderContenders.iterator().next();
            currentLeaderSessionId = leaderSessionId;
            currentLeaderProposed = leaderService;
            LOG.info("Proposing leadership to contender {} @ {}", leaderService.contender, leaderService.contender.getAddress());
            notificationExecutor.execute(new GrantLeadershipCall(leaderService.contender, leaderSessionId, LOG));
        }
    }
}
Also used : UUID(java.util.UUID) GuardedBy(javax.annotation.concurrent.GuardedBy)

Example 2 with GuardedBy

use of javax.annotation.concurrent.GuardedBy in project flink by apache.

the class MiniCluster method shutdownInternally.

@GuardedBy("lock")
private void shutdownInternally() throws Exception {
    // this should always be called under the lock
    assert Thread.holdsLock(lock);
    // collect the first exception, but continue and add all successive
    // exceptions as suppressed
    Throwable exception = null;
    // cancel all jobs and shut down the job dispatcher
    if (jobDispatcher != null) {
        try {
            jobDispatcher.shutdown();
        } catch (Exception e) {
            exception = e;
        }
        jobDispatcher = null;
    }
    if (resourceManagerRunners != null) {
        for (ResourceManagerRunner rm : resourceManagerRunners) {
            if (rm != null) {
                try {
                    rm.shutDown();
                } catch (Throwable t) {
                    exception = firstOrSuppressed(t, exception);
                }
            }
        }
        resourceManagerRunners = null;
    }
    if (taskManagerRunners != null) {
        for (TaskManagerRunner tm : taskManagerRunners) {
            if (tm != null) {
                try {
                    tm.shutDown(null);
                } catch (Throwable t) {
                    exception = firstOrSuppressed(t, exception);
                }
            }
        }
        taskManagerRunners = null;
    }
    // shut down the RpcServices
    exception = shutDownRpc(commonRpcService, exception);
    exception = shutDownRpcs(jobManagerRpcServices, exception);
    exception = shutDownRpcs(taskManagerRpcServices, exception);
    exception = shutDownRpcs(resourceManagerRpcServices, exception);
    commonRpcService = null;
    jobManagerRpcServices = null;
    taskManagerRpcServices = null;
    resourceManagerRpcServices = null;
    // shut down high-availability services
    if (haServices != null) {
        try {
            haServices.closeAndCleanupAllData();
        } catch (Exception e) {
            exception = firstOrSuppressed(e, exception);
        }
        haServices = null;
    }
    // metrics shutdown
    if (metricRegistry != null) {
        metricRegistry.shutdown();
        metricRegistry = null;
    }
    // if anything went wrong, throw the first error with all the additional suppressed exceptions
    if (exception != null) {
        ExceptionUtils.rethrowException(exception, "Error while shutting down mini cluster");
    }
}
Also used : ResourceManagerRunner(org.apache.flink.runtime.resourcemanager.ResourceManagerRunner) TaskManagerRunner(org.apache.flink.runtime.taskexecutor.TaskManagerRunner) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) GuardedBy(javax.annotation.concurrent.GuardedBy)

Example 3 with GuardedBy

use of javax.annotation.concurrent.GuardedBy in project presto by prestodb.

the class SemiTransactionalHiveMetastore method commitShared.

@GuardedBy("this")
private void commitShared() {
    checkHoldsLock();
    Committer committer = new Committer();
    try {
        for (Map.Entry<SchemaTableName, Action<TableAndMore>> entry : tableActions.entrySet()) {
            SchemaTableName schemaTableName = entry.getKey();
            Action<TableAndMore> action = entry.getValue();
            switch(action.getType()) {
                case DROP:
                    committer.prepareDropTable(schemaTableName);
                    break;
                case ALTER:
                    committer.prepareAlterTable();
                    break;
                case ADD:
                    committer.prepareAddTable(action.getUser(), action.getData());
                    break;
                case INSERT_EXISTING:
                    committer.prepareInsertExistingTable(action.getUser(), action.getData());
                    break;
                default:
                    throw new IllegalStateException("Unknown action type");
            }
        }
        for (Map.Entry<SchemaTableName, Map<List<String>, Action<PartitionAndMore>>> tableEntry : partitionActions.entrySet()) {
            SchemaTableName schemaTableName = tableEntry.getKey();
            for (Map.Entry<List<String>, Action<PartitionAndMore>> partitionEntry : tableEntry.getValue().entrySet()) {
                List<String> partitionValues = partitionEntry.getKey();
                Action<PartitionAndMore> action = partitionEntry.getValue();
                switch(action.getType()) {
                    case DROP:
                        committer.prepareDropPartition(schemaTableName, partitionValues);
                        break;
                    case ALTER:
                        committer.prepareAlterPartition(action.getQueryId(), action.getUser(), action.getData());
                        break;
                    case ADD:
                        committer.prepareAddPartition(action.getUser(), action.getData());
                        break;
                    case INSERT_EXISTING:
                        committer.prepareInsertExistingPartition(action.getUser(), action.getData());
                        break;
                    default:
                        throw new IllegalStateException("Unknown action type");
                }
            }
        }
        // Wait for all renames submitted for "INSERT_EXISTING" action to finish
        committer.waitForAsyncRenames();
        // At this point, all file system operations, whether asynchronously issued or not, have completed successfully.
        // We are moving on to metastore operations now.
        committer.executeAddTableOperations();
        committer.executeAlterPartitionOperations();
        committer.executeAddPartitionOperations();
    } catch (Throwable t) {
        committer.cancelUnstartedAsyncRenames();
        committer.undoAddPartitionOperations();
        committer.undoAddTableOperations();
        committer.waitForAsyncRenamesSuppressThrowables();
        // fileRenameFutures must all come back before any file system cleanups are carried out.
        // Otherwise, files that should be deleted may be created after cleanup is done.
        committer.executeCleanupTasksForAbort(committer.extractFilePrefixes(declaredIntentionsToWrite));
        committer.executeRenameTasksForAbort();
        // Partition directory must be put back before relevant metastore operation can be undone
        committer.undoAlterPartitionOperations();
        rollbackShared();
        throw t;
    }
    try {
        // After this line, operations are no longer reversible.
        // The next section will deal with "dropping table/partition". Commit may still fail in
        // this section. Even if commit fails, cleanups, instead of rollbacks, will be executed.
        committer.executeIrreversibleMetastoreOperations();
    // If control flow reached this point, this commit is considered successful no matter
    // what happens later. The only kind of operations that haven't been carried out yet
    // are cleanups.
    // The program control flow will go to finally next. And cleanup will run because
    // moveForwardInFinally has been set to false.
    } finally {
        // In this method, all operations are best-effort clean up operations.
        // If any operation fails, the error will be logged and ignored.
        // Additionally, other clean up operations should still be attempted.
        // Execute deletion tasks
        committer.executeDeletionTasksForFinish();
        // Clean up empty staging directories (that may recursively contain empty directories)
        committer.deleteEmptyStagingDirectories(declaredIntentionsToWrite);
    }
}
Also used : SchemaTableName(com.facebook.presto.spi.SchemaTableName) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) GuardedBy(javax.annotation.concurrent.GuardedBy)

Example 4 with GuardedBy

use of javax.annotation.concurrent.GuardedBy in project presto by prestodb.

the class SemiTransactionalHiveMetastore method getTableSource.

/**
     * This method can only be called when the table is known to exist
     */
@GuardedBy("this")
private TableSource getTableSource(String databaseName, String tableName) {
    checkHoldsLock();
    checkReadable();
    Action<TableAndMore> tableAction = tableActions.get(new SchemaTableName(databaseName, tableName));
    if (tableAction == null) {
        return TableSource.PRE_EXISTING_TABLE;
    }
    switch(tableAction.getType()) {
        case ADD:
            return TableSource.CREATED_IN_THIS_TRANSACTION;
        case ALTER:
            throw new IllegalStateException("Tables are never altered in the current implementation");
        case DROP:
            throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
        case INSERT_EXISTING:
            return TableSource.PRE_EXISTING_TABLE;
        default:
            throw new IllegalStateException("Unknown action type");
    }
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) SchemaTableName(com.facebook.presto.spi.SchemaTableName) GuardedBy(javax.annotation.concurrent.GuardedBy)

Example 5 with GuardedBy

use of javax.annotation.concurrent.GuardedBy in project presto by prestodb.

the class Driver method processInternal.

@GuardedBy("exclusiveLock")
private ListenableFuture<?> processInternal() {
    checkLockHeld("Lock must be held to call processInternal");
    try {
        processNewSources();
        // special handling for drivers with a single operator
        if (operators.size() == 1) {
            if (driverContext.isDone()) {
                return NOT_BLOCKED;
            }
            // check if operator is blocked
            Operator current = operators.get(0);
            ListenableFuture<?> blocked = isBlocked(current);
            if (!blocked.isDone()) {
                current.getOperatorContext().recordBlocked(blocked);
                return blocked;
            }
            // there is only one operator so just finish it
            current.getOperatorContext().startIntervalTimer();
            current.finish();
            current.getOperatorContext().recordFinish();
            return NOT_BLOCKED;
        }
        boolean movedPage = false;
        for (int i = 0; i < operators.size() - 1 && !driverContext.isDone(); i++) {
            Operator current = operators.get(i);
            Operator next = operators.get(i + 1);
            // skip blocked operators
            if (!isBlocked(current).isDone()) {
                continue;
            }
            if (!isBlocked(next).isDone()) {
                continue;
            }
            // if the current operator is not finished and next operator needs input...
            if (!current.isFinished() && next.needsInput()) {
                // get an output page from current operator
                current.getOperatorContext().startIntervalTimer();
                Page page = current.getOutput();
                current.getOperatorContext().recordGetOutput(page);
                // if we got an output page, add it to the next operator
                if (page != null && page.getPositionCount() != 0) {
                    next.getOperatorContext().startIntervalTimer();
                    next.addInput(page);
                    next.getOperatorContext().recordAddInput(page);
                    movedPage = true;
                }
                if (current instanceof SourceOperator) {
                    movedPage = true;
                }
            }
            // if current operator is finished...
            if (current.isFinished()) {
                // let next operator know there will be no more data
                next.getOperatorContext().startIntervalTimer();
                next.finish();
                next.getOperatorContext().recordFinish();
            }
        }
        // if we did not move any pages, check if we are blocked
        if (!movedPage) {
            List<Operator> blockedOperators = new ArrayList<>();
            List<ListenableFuture<?>> blockedFutures = new ArrayList<>();
            for (Operator operator : operators) {
                ListenableFuture<?> blocked = isBlocked(operator);
                if (!blocked.isDone()) {
                    blockedOperators.add(operator);
                    blockedFutures.add(blocked);
                }
            }
            if (!blockedFutures.isEmpty()) {
                // unblock when the first future is complete
                ListenableFuture<?> blocked = firstFinishedFuture(blockedFutures);
                // driver records serial blocked time
                driverContext.recordBlocked(blocked);
                // until one of the operators can continue
                for (Operator operator : blockedOperators) {
                    operator.getOperatorContext().recordBlocked(blocked);
                }
                return blocked;
            }
        }
        return NOT_BLOCKED;
    } catch (Throwable t) {
        driverContext.failed(t);
        throw t;
    }
}
Also used : ArrayList(java.util.ArrayList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Page(com.facebook.presto.spi.Page) GuardedBy(javax.annotation.concurrent.GuardedBy)

Aggregations

GuardedBy (javax.annotation.concurrent.GuardedBy)16 ArrayList (java.util.ArrayList)6 SchemaTableName (com.facebook.presto.spi.SchemaTableName)4 List (java.util.List)4 MasterBlockInfo (alluxio.master.block.meta.MasterBlockInfo)3 ImmutableList (com.google.common.collect.ImmutableList)3 PrestoException (com.facebook.presto.spi.PrestoException)2 Instant (java.time.Instant)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Optional (java.util.Optional)2 MasterBlockLocation (alluxio.master.block.meta.MasterBlockLocation)1 MasterWorkerInfo (alluxio.master.block.meta.MasterWorkerInfo)1 BlockInfo (alluxio.wire.BlockInfo)1 BlockLocation (alluxio.wire.BlockLocation)1 ErroneousRemoteCommandResponse (com.eightkdata.mongowp.client.core.MongoConnection.ErroneousRemoteCommandResponse)1 RemoteCommandResponse (com.eightkdata.mongowp.client.core.MongoConnection.RemoteCommandResponse)1 ScheduledSplit (com.facebook.presto.ScheduledSplit)1 TaskSource (com.facebook.presto.TaskSource)1 Split (com.facebook.presto.metadata.Split)1