Search in sources :

Example 11 with GuardedBy

use of javax.annotation.concurrent.GuardedBy in project druid by druid-io.

the class QuotableWhiteSpaceSplitter method saveRunningTasks.

// Save running tasks to a file, so they can potentially be restored on next startup. Suppresses exceptions that
// occur while saving.
@GuardedBy("tasks")
private void saveRunningTasks() {
    final File restoreFile = getRestoreFile();
    final List<String> theTasks = Lists.newArrayList();
    for (ForkingTaskRunnerWorkItem forkingTaskRunnerWorkItem : tasks.values()) {
        theTasks.add(forkingTaskRunnerWorkItem.getTaskId());
    }
    try {
        Files.createParentDirs(restoreFile);
        jsonMapper.writeValue(restoreFile, new TaskRestoreInfo(theTasks));
    } catch (Exception e) {
        log.warn(e, "Failed to save tasks to restore file[%s]. Skipping this save.", restoreFile);
    }
}
Also used : File(java.io.File) IOException(java.io.IOException) GuardedBy(javax.annotation.concurrent.GuardedBy)

Example 12 with GuardedBy

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

the class Driver method processNewSources.

@GuardedBy("exclusiveLock")
private void processNewSources() {
    checkLockHeld("Lock must be held to call processNewSources");
    // only update if the driver is still alive
    if (state.get() != State.ALIVE) {
        return;
    }
    TaskSource source = newTaskSource.getAndSet(null);
    if (source == null) {
        return;
    }
    // merge the current source and the specified source
    TaskSource newSource = currentTaskSource.update(source);
    // if source contains no new data, just return
    if (newSource == currentTaskSource) {
        return;
    }
    // determine new splits to add
    Set<ScheduledSplit> newSplits = Sets.difference(newSource.getSplits(), currentTaskSource.getSplits());
    // add new splits
    SourceOperator sourceOperator = this.sourceOperator.orElseThrow(VerifyException::new);
    for (ScheduledSplit newSplit : newSplits) {
        Split split = newSplit.getSplit();
        Supplier<Optional<UpdatablePageSource>> pageSource = sourceOperator.addSplit(split);
        deleteOperator.ifPresent(deleteOperator -> deleteOperator.setPageSource(pageSource));
    }
    // set no more splits
    if (newSource.isNoMoreSplits()) {
        sourceOperator.noMoreSplits();
    }
    currentTaskSource = newSource;
}
Also used : ScheduledSplit(com.facebook.presto.ScheduledSplit) Optional(java.util.Optional) VerifyException(com.google.common.base.VerifyException) ScheduledSplit(com.facebook.presto.ScheduledSplit) Split(com.facebook.presto.metadata.Split) TaskSource(com.facebook.presto.TaskSource) GuardedBy(javax.annotation.concurrent.GuardedBy)

Example 13 with GuardedBy

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

the class SemiTransactionalHiveMetastore method doGetPartitionNames.

@GuardedBy("this")
private Optional<List<String>> doGetPartitionNames(String databaseName, String tableName, Optional<List<String>> parts) {
    checkHoldsLock();
    checkReadable();
    Optional<Table> table = getTable(databaseName, tableName);
    if (!table.isPresent()) {
        return Optional.empty();
    }
    List<String> partitionNames;
    TableSource tableSource = getTableSource(databaseName, tableName);
    switch(tableSource) {
        case CREATED_IN_THIS_TRANSACTION:
            partitionNames = ImmutableList.of();
            break;
        case PRE_EXISTING_TABLE:
            {
                Optional<List<String>> partitionNameResult;
                if (parts.isPresent()) {
                    partitionNameResult = delegate.getPartitionNamesByParts(databaseName, tableName, parts.get());
                } else {
                    partitionNameResult = delegate.getPartitionNames(databaseName, tableName);
                }
                if (!partitionNameResult.isPresent()) {
                    throw new PrestoException(TRANSACTION_CONFLICT, "Table %s.%s was dropped by another transaction");
                }
                partitionNames = partitionNameResult.get();
                break;
            }
        default:
            throw new UnsupportedOperationException("Unknown table source");
    }
    Map<List<String>, Action<PartitionAndMore>> partitionActionsOfTable = partitionActions.computeIfAbsent(new SchemaTableName(databaseName, tableName), k -> new HashMap<>());
    ImmutableList.Builder<String> resultBuilder = ImmutableList.builder();
    // alter/remove newly-altered/dropped partitions from the results from underlying metastore
    for (String partitionName : partitionNames) {
        List<String> partitionValues = toPartitionValues(partitionName);
        Action<PartitionAndMore> partitionAction = partitionActionsOfTable.get(partitionValues);
        if (partitionAction == null) {
            resultBuilder.add(partitionName);
            continue;
        }
        switch(partitionAction.getType()) {
            case ADD:
                throw new PrestoException(TRANSACTION_CONFLICT, format("Another transaction created partition %s in table %s.%s", partitionValues, databaseName, tableName));
            case DROP:
                // do nothing
                break;
            case ALTER:
            case INSERT_EXISTING:
                resultBuilder.add(partitionName);
                break;
            default:
                throw new IllegalStateException("Unknown action type");
        }
    }
    // add newly-added partitions to the results from underlying metastore
    if (!partitionActionsOfTable.isEmpty()) {
        List<String> columnNames = table.get().getPartitionColumns().stream().map(Column::getName).collect(Collectors.toList());
        for (Action<PartitionAndMore> partitionAction : partitionActionsOfTable.values()) {
            if (partitionAction.getType() == ActionType.ADD) {
                List<String> values = partitionAction.getData().getPartition().getValues();
                if (!parts.isPresent() || partitionValuesMatch(values, parts.get())) {
                    resultBuilder.add(makePartName(columnNames, values));
                }
            }
        }
    }
    return Optional.of(resultBuilder.build());
}
Also used : Optional(java.util.Optional) ImmutableList(com.google.common.collect.ImmutableList) PrestoException(com.facebook.presto.spi.PrestoException) SchemaTableName(com.facebook.presto.spi.SchemaTableName) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) GuardedBy(javax.annotation.concurrent.GuardedBy)

Example 14 with GuardedBy

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

the class SemiTransactionalHiveMetastore method checkNoPartitionAction.

@GuardedBy("this")
private void checkNoPartitionAction(String databaseName, String tableName) {
    checkHoldsLock();
    Map<List<String>, Action<PartitionAndMore>> partitionActionsOfTable = partitionActions.get(new SchemaTableName(databaseName, tableName));
    if (partitionActionsOfTable != null && !partitionActionsOfTable.isEmpty()) {
        throw new PrestoException(NOT_SUPPORTED, "Cannot make schema changes to a table/view with modified partitions in the same transaction");
    }
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) PrestoException(com.facebook.presto.spi.PrestoException) SchemaTableName(com.facebook.presto.spi.SchemaTableName) GuardedBy(javax.annotation.concurrent.GuardedBy)

Example 15 with GuardedBy

use of javax.annotation.concurrent.GuardedBy in project torodb by torodb.

the class TopologyHeartbeatHandler method doHeartbeat.

@GuardedBy("executor")
private void doHeartbeat(final TopologyCoordinator coord, final HostAndPort target) {
    if (stopped) {
        LOGGER.trace("Ignoring heartbeat to {} because the handler has " + "been stopped", target);
        return;
    }
    Instant start = clock.instant();
    RemoteCommandRequest<ReplSetHeartbeatArgument> request = coord.prepareHeartbeatRequest(start, replSetName, target);
    CompletableFuture<RemoteCommandResponse<ReplSetHeartbeatReply>> hbHandle = networkHandler.sendHeartbeat(request).exceptionally(t -> onNetworkError(t, target, start));
    executor.onCurrentVersion().andThenAcceptAsync(hbHandle, (coord2, response) -> handleHeartbeatResponse(coord2, target, request.getCmdObj(), response));
}
Also used : Instant(java.time.Instant) RemoteCommandResponse(com.eightkdata.mongowp.client.core.MongoConnection.RemoteCommandResponse) ErroneousRemoteCommandResponse(com.eightkdata.mongowp.client.core.MongoConnection.ErroneousRemoteCommandResponse) ReplSetHeartbeatArgument(com.torodb.mongodb.commands.signatures.internal.ReplSetHeartbeatCommand.ReplSetHeartbeatArgument) 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