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);
}
}
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;
}
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());
}
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");
}
}
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));
}
Aggregations