javax.annotation.concurrent.GuardedBy Java Examples

The following examples show how to use javax.annotation.concurrent.GuardedBy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SqlTaskExecution.java    From presto with Apache License 2.0 6 votes vote down vote up
@GuardedBy("this")
private void mergeIntoPendingSplits(PlanNodeId planNodeId, Set<ScheduledSplit> scheduledSplits, Set<Lifespan> noMoreSplitsForLifespan, boolean noMoreSplits)
{
    checkHoldsLock();

    DriverSplitRunnerFactory partitionedDriverFactory = driverRunnerFactoriesWithSplitLifeCycle.get(planNodeId);
    PendingSplitsForPlanNode pendingSplitsForPlanNode = pendingSplitsByPlanNode.get(planNodeId);

    partitionedDriverFactory.splitsAdded(scheduledSplits.size());
    for (ScheduledSplit scheduledSplit : scheduledSplits) {
        Lifespan lifespan = scheduledSplit.getSplit().getLifespan();
        checkLifespan(partitionedDriverFactory.getPipelineExecutionStrategy(), lifespan);
        pendingSplitsForPlanNode.getLifespan(lifespan).addSplit(scheduledSplit);
        schedulingLifespanManager.addLifespanIfAbsent(lifespan);
    }
    for (Lifespan lifespanWithNoMoreSplits : noMoreSplitsForLifespan) {
        checkLifespan(partitionedDriverFactory.getPipelineExecutionStrategy(), lifespanWithNoMoreSplits);
        pendingSplitsForPlanNode.getLifespan(lifespanWithNoMoreSplits).noMoreSplits();
        schedulingLifespanManager.addLifespanIfAbsent(lifespanWithNoMoreSplits);
    }
    if (noMoreSplits) {
        pendingSplitsForPlanNode.setNoMoreSplits();
    }
}
 
Example #2
Source File: OkHttpClientStream.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@GuardedBy("lock")
private void cancel(Status reason, boolean stopDelivery, Metadata trailers) {
  if (cancelSent) {
    return;
  }
  cancelSent = true;
  if (canStart) {
    // stream is pending.
    transport.removePendingStream(OkHttpClientStream.this);
    // release holding data, so they can be GCed or returned to pool earlier.
    requestHeaders = null;
    pendingData.clear();
    canStart = false;
    transportReportStatus(reason, true, trailers != null ? trailers : new Metadata());
  } else {
    // If pendingData is null, start must have already been called, which means synStream has
    // been called as well.
    transport.finishStream(
        id(), reason, PROCESSED, stopDelivery, ErrorCode.CANCEL, trailers);
  }
}
 
Example #3
Source File: RecordEventsReadableSpan.java    From opentelemetry-java with Apache License 2.0 6 votes vote down vote up
@GuardedBy("lock")
private ReadableAttributes getImmutableAttributes() {
  if (attributes == null || attributes.isEmpty()) {
    return Attributes.empty();
  }
  // if the span has ended, then the attributes are unmodifiable,
  // so we can return them directly and save copying all the data.
  if (hasEnded) {
    return attributes;
  }
  // otherwise, make a copy of the data into an immutable container.
  Attributes.Builder builder = Attributes.newBuilder();
  for (Entry<String, AttributeValue> entry : attributes.entrySet()) {
    builder.setAttribute(entry.getKey(), entry.getValue());
  }
  return builder.build();
}
 
Example #4
Source File: EmbeddedLeaderService.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@GuardedBy("lock")
private void shutdownInternally(Exception exceptionForHandlers) {
	assert Thread.holdsLock(lock);

	if (!shutdown) {
		// clear all leader status
		currentLeaderProposed = null;
		currentLeaderConfirmed = null;
		currentLeaderSessionId = null;
		currentLeaderAddress = null;

		// fail all registered listeners
		for (EmbeddedLeaderElectionService service : allLeaderContenders) {
			service.shutdown(exceptionForHandlers);
		}
		allLeaderContenders.clear();

		// fail all registered listeners
		for (EmbeddedLeaderRetrievalService service : listeners) {
			service.shutdown(exceptionForHandlers);
		}
		listeners.clear();

		shutdown = true;
	}
}
 
Example #5
Source File: ClusterMemoryManager.java    From presto with Apache License 2.0 6 votes vote down vote up
@GuardedBy("this")
private boolean isLastKilledQueryGone()
{
    if (lastKilledQuery == null) {
        return true;
    }

    // If the lastKilledQuery is marked as leaked by the ClusterMemoryLeakDetector we consider the lastKilledQuery as gone,
    // so that the ClusterMemoryManager can continue to make progress even if there are leaks.
    // Even if the weak references to the leaked queries are GCed in the ClusterMemoryLeakDetector, it will mark the same queries
    // as leaked in its next run, and eventually the ClusterMemoryManager will make progress.
    if (memoryLeakDetector.wasQueryPossiblyLeaked(lastKilledQuery)) {
        lastKilledQuery = null;
        return true;
    }

    // pools fields is updated based on nodes field.
    // Therefore, if the query is gone from pools field, it should also be gone from nodes field.
    // However, since nodes can updated asynchronously, it has the potential of coming back after being gone.
    // Therefore, even if the query appears to be gone here, it might be back when one inspects nodes later.
    return !pools.get(GENERAL_POOL)
            .getQueryMemoryReservations()
            .containsKey(lastKilledQuery);
}
 
Example #6
Source File: SemiTransactionalHiveMetastore.java    From presto with Apache License 2.0 6 votes vote down vote up
/**
 * 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 DROP:
            throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
        case ALTER:
        case INSERT_EXISTING:
            return TableSource.PRE_EXISTING_TABLE;
        default:
            throw new IllegalStateException("Unknown action type");
    }
}
 
Example #7
Source File: OkHttpClientTransport.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@GuardedBy("lock")
private void maybeClearInUse(OkHttpClientStream stream) {
  if (hasStream) {
    if (pendingStreams.isEmpty() && streams.isEmpty()) {
      hasStream = false;
      if (keepAliveManager != null) {
        // We don't have any active streams. No need to do keepalives any more.
        // Again, we have to call this inside the lock to avoid the race between onTransportIdle
        // and onTransportActive.
        keepAliveManager.onTransportIdle();
      }
    }
  }
  if (stream.shouldBeCountedForInUse()) {
    inUseState.updateObjectInUse(stream, false);
  }
}
 
Example #8
Source File: RecordEventsReadableSpan.java    From opentelemetry-java with Apache License 2.0 6 votes vote down vote up
@GuardedBy("lock")
private List<Event> getImmutableTimedEvents() {
  if (events.isEmpty()) {
    return Collections.emptyList();
  }

  List<Event> results = new ArrayList<>(events.size());
  for (TimedEvent event : events) {
    if (event instanceof RawTimedEventWithEvent) {
      // make sure to copy the data if the event is wrapping another one,
      // so we don't hold on the caller's memory
      results.add(
          TimedEvent.create(
              event.getEpochNanos(),
              event.getName(),
              event.getAttributes(),
              event.getTotalAttributeCount()));
    } else {
      results.add(event);
    }
  }
  return Collections.unmodifiableList(results);
}
 
Example #9
Source File: QueryContext.java    From presto with Apache License 2.0 6 votes vote down vote up
@GuardedBy("this")
private String getAdditionalFailureInfo(long allocated, long delta)
{
    Map<String, Long> queryAllocations = memoryPool.getTaggedMemoryAllocations().get(queryId);

    String additionalInfo = format("Allocated: %s, Delta: %s", succinctBytes(allocated), succinctBytes(delta));

    // It's possible that a query tries allocating more than the available memory
    // failing immediately before any allocation of that query is tagged
    if (queryAllocations == null) {
        return additionalInfo;
    }

    String topConsumers = queryAllocations.entrySet().stream()
            .sorted(comparingByValue(Comparator.reverseOrder()))
            .limit(3)
            .filter(e -> e.getValue() >= 0)
            .collect(toImmutableMap(Entry::getKey, e -> succinctBytes(e.getValue())))
            .toString();

    return format("%s, Top Consumers: %s", additionalInfo, topConsumers);
}
 
Example #10
Source File: EmbeddedLeaderService.java    From flink with Apache License 2.0 6 votes vote down vote up
@GuardedBy("lock")
private void shutdownInternally(Exception exceptionForHandlers) {
	assert Thread.holdsLock(lock);

	if (!shutdown) {
		// clear all leader status
		currentLeaderProposed = null;
		currentLeaderConfirmed = null;
		currentLeaderSessionId = null;
		currentLeaderAddress = null;

		// fail all registered listeners
		for (EmbeddedLeaderElectionService service : allLeaderContenders) {
			service.shutdown(exceptionForHandlers);
		}
		allLeaderContenders.clear();

		// fail all registered listeners
		for (EmbeddedLeaderRetrievalService service : listeners) {
			service.shutdown(exceptionForHandlers);
		}
		listeners.clear();

		shutdown = true;
	}
}
 
Example #11
Source File: OkHttpClientTransport.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@GuardedBy("lock")
private void startStream(OkHttpClientStream stream) {
  Preconditions.checkState(
      stream.id() == OkHttpClientStream.ABSENT_ID, "StreamId already assigned");
  streams.put(nextStreamId, stream);
  setInUse(stream);
  stream.transportState().start(nextStreamId);
  // For unary and server streaming, there will be a data frame soon, no need to flush the header.
  if ((stream.getType() != MethodType.UNARY && stream.getType() != MethodType.SERVER_STREAMING)
      || stream.useGet()) {
    frameWriter.flush();
  }
  if (nextStreamId >= Integer.MAX_VALUE - 2) {
    // Make sure nextStreamId greater than all used id, so that mayHaveCreatedStream() performs
    // correctly.
    nextStreamId = Integer.MAX_VALUE;
    startGoAway(Integer.MAX_VALUE, ErrorCode.NO_ERROR,
        Status.UNAVAILABLE.withDescription("Stream ids exhausted"));
  } else {
    nextStreamId += 2;
  }
}
 
Example #12
Source File: Driver.java    From presto with Apache License 2.0 6 votes vote down vote up
@GuardedBy("exclusiveLock")
private void handleMemoryRevoke()
{
    for (int i = 0; i < activeOperators.size() && !driverContext.isDone(); i++) {
        Operator operator = activeOperators.get(i);

        if (revokingOperators.containsKey(operator)) {
            checkOperatorFinishedRevoking(operator);
        }
        else if (operator.getOperatorContext().isMemoryRevokingRequested()) {
            ListenableFuture<?> future = operator.startMemoryRevoke();
            revokingOperators.put(operator, future);
            checkOperatorFinishedRevoking(operator);
        }
    }
}
 
Example #13
Source File: MonotonicTTLTimeProvider.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@GuardedBy("lock")
static long freeze() {
	synchronized (lock) {
		if (!timeIsFrozen || lastReturnedProcessingTime == Long.MIN_VALUE) {
			timeIsFrozen = true;
			return getCurrentTimestamp();
		} else {
			return lastReturnedProcessingTime;
		}
	}
}
 
Example #14
Source File: MultilevelSplitQueue.java    From presto with Apache License 2.0 5 votes vote down vote up
/**
 * Presto attempts to give each level a target amount of scheduled time, which is configurable
 * using levelTimeMultiplier.
 * <p>
 * This function selects the level that has the the lowest ratio of actual to the target time
 * with the objective of minimizing deviation from the target scheduled time. From this level,
 * we pick the split with the lowest priority.
 */
@GuardedBy("lock")
private PrioritizedSplitRunner pollSplit()
{
    long targetScheduledTime = getLevel0TargetTime();
    double worstRatio = 1;
    int selectedLevel = -1;
    for (int level = 0; level < LEVEL_THRESHOLD_SECONDS.length; level++) {
        if (!levelWaitingSplits.get(level).isEmpty()) {
            long levelTime = levelScheduledTime[level].get();
            double ratio = levelTime == 0 ? 0 : targetScheduledTime / (1.0 * levelTime);
            if (selectedLevel == -1 || ratio > worstRatio) {
                worstRatio = ratio;
                selectedLevel = level;
            }
        }

        targetScheduledTime /= levelTimeMultiplier;
    }

    if (selectedLevel == -1) {
        return null;
    }

    PrioritizedSplitRunner result = levelWaitingSplits.get(selectedLevel).poll();
    checkState(result != null, "pollSplit cannot return null");

    return result;
}
 
Example #15
Source File: EmbeddedHaServices.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@GuardedBy("lock")
private EmbeddedLeaderService getOrCreateJobManagerService(JobID jobID) {
	EmbeddedLeaderService service = jobManagerLeaderServices.get(jobID);
	if (service == null) {
		service = createEmbeddedLeaderService(executor);
		jobManagerLeaderServices.put(jobID, service);
	}
	return service;
}
 
Example #16
Source File: EmbeddedLeaderService.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@GuardedBy("lock")
private CompletableFuture<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
			return notifyAllListeners(null, null);
		}
		else {
			// propose a leader and ask it
			final UUID leaderSessionId = UUID.randomUUID();
			EmbeddedLeaderElectionService leaderService = allLeaderContenders.iterator().next();

			currentLeaderSessionId = leaderSessionId;
			currentLeaderProposed = leaderService;
			currentLeaderProposed.isLeader = true;

			LOG.info("Proposing leadership to contender {} @ {}",
					leaderService.contender, leaderService.contender.getAddress());

			return execute(new GrantLeadershipCall(leaderService.contender, leaderSessionId, LOG));
		}
	} else {
		return CompletableFuture.completedFuture(null);
	}
}
 
Example #17
Source File: AkkaRpcService.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@GuardedBy("lock")
@Nonnull
private CompletableFuture<Void> terminateAkkaRpcActors() {
	final Collection<CompletableFuture<Void>> akkaRpcActorTerminationFutures = new ArrayList<>(actors.size());

	for (Map.Entry<ActorRef, RpcEndpoint> actorRefRpcEndpointEntry : actors.entrySet()) {
		akkaRpcActorTerminationFutures.add(terminateAkkaRpcActor(actorRefRpcEndpointEntry.getKey(), actorRefRpcEndpointEntry.getValue()));
	}
	actors.clear();

	return FutureUtils.waitForAll(akkaRpcActorTerminationFutures);
}
 
Example #18
Source File: MiniCluster.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@GuardedBy("lock")
private Collection<? extends CompletableFuture<Void>> terminateTaskExecutors() {
	final Collection<CompletableFuture<Void>> terminationFutures = new ArrayList<>(taskManagers.size());
	for (int i = 0; i < taskManagers.size(); i++) {
		terminationFutures.add(terminateTaskExecutor(i));
	}

	return terminationFutures;
}
 
Example #19
Source File: MonotonicTTLTimeProvider.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
@GuardedBy("lock")
public long currentTimestamp() {
	synchronized (lock) {
		if (timeIsFrozen && lastReturnedProcessingTime != Long.MIN_VALUE) {
			return lastReturnedProcessingTime;
		}
		return getCurrentTimestamp();
	}
}
 
Example #20
Source File: LimitedConnectionsFileSystem.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@GuardedBy("lock")
private boolean closeInactiveStream(HashSet<? extends StreamWithTimeout> streams, long nowNanos) {
	for (StreamWithTimeout stream : streams) {
		try {
			final StreamProgressTracker tracker = stream.getProgressTracker();

			// If the stream is closed already, it will be removed anyways, so we
			// do not classify it as inactive. We also skip the check if another check happened too recently.
			if (stream.isClosed() || nowNanos < tracker.getLastCheckTimestampNanos() + streamInactivityTimeoutNanos) {
				// interval since last check not yet over
				return false;
			}
			else if (!tracker.checkNewBytesAndMark(nowNanos)) {
				stream.closeDueToTimeout();
				return true;
			}
		}
		catch (StreamTimeoutException ignored) {
			// may happen due to races
		}
		catch (IOException e) {
			// only log on debug level here, to avoid log spamming
			LOG.debug("Could not check for stream progress to determine inactivity", e);
		}
	}

	return false;
}
 
Example #21
Source File: SqlTaskExecution.java    From presto with Apache License 2.0 5 votes vote down vote up
@GuardedBy("this")
private PerLifespanStatus per(Lifespan lifespan)
{
    if (perLifespan.containsKey(lifespan)) {
        return perLifespan.get(lifespan);
    }
    PerLifespanStatus result = new PerLifespanStatus();
    perLifespan.put(lifespan, result);
    return result;
}
 
Example #22
Source File: MonotonicTTLTimeProvider.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@GuardedBy("lock")
private static long getCurrentTimestamp() {
	final long currentProcessingTime = System.currentTimeMillis();
	if (currentProcessingTime < lastReturnedProcessingTime) {
		return lastReturnedProcessingTime;
	}

	lastReturnedProcessingTime = currentProcessingTime;
	return lastReturnedProcessingTime;
}
 
Example #23
Source File: PipelinedSubpartition.java    From flink with Apache License 2.0 5 votes vote down vote up
@GuardedBy("buffers")
private void decreaseBuffersInBacklogUnsafe(boolean isBuffer) {
	assert Thread.holdsLock(buffers);
	if (isBuffer) {
		buffersInBacklog--;
	}
}
 
Example #24
Source File: Driver.java    From presto with Apache License 2.0 5 votes vote down vote up
@GuardedBy("exclusiveLock")
private void checkOperatorFinishedRevoking(Operator operator)
{
    ListenableFuture<?> future = revokingOperators.get(operator);
    if (future.isDone()) {
        getFutureValue(future); // propagate exception if there was some
        revokingOperators.remove(operator);
        operator.finishMemoryRevoke();
        operator.getOperatorContext().resetMemoryRevokingRequested();
    }
}
 
Example #25
Source File: QueryContext.java    From presto with Apache License 2.0 5 votes vote down vote up
@GuardedBy("this")
private void enforceUserMemoryLimit(long allocated, long delta, long maxMemory)
{
    if (allocated + delta > maxMemory) {
        throw exceededLocalUserMemoryLimit(succinctBytes(maxMemory), getAdditionalFailureInfo(allocated, delta));
    }
}
 
Example #26
Source File: DnsNameResolver.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@GuardedBy("this")
private void resolve() {
  if (resolving || shutdown) {
    return;
  }
  executor.execute(resolveRunnable);
}
 
Example #27
Source File: DelayedClientTransport.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
/**
 * Caller must call {@code syncContext.drain()} outside of lock because this method may
 * schedule tasks on syncContext.
 */
@GuardedBy("lock")
private PendingStream createPendingStream(PickSubchannelArgs args) {
  PendingStream pendingStream = new PendingStream(args);
  pendingStreams.add(pendingStream);
  if (getPendingStreamsCount() == 1) {
    syncContext.executeLater(reportTransportInUse);
  }
  return pendingStream;
}
 
Example #28
Source File: MonotonicTTLTimeProvider.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@GuardedBy("lock")
static long unfreezeTime() {
	synchronized (lock) {
		timeIsFrozen = false;
		return lastReturnedProcessingTime;
	}
}
 
Example #29
Source File: InternalSubchannel.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@GuardedBy("lock")
private void cancelReconnectTask() {
  if (reconnectTask != null) {
    reconnectTask.cancel(false);
    reconnectCanceled = true;
    reconnectTask = null;
    reconnectPolicy = null;
  }
}
 
Example #30
Source File: InternalSubchannel.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@GuardedBy("lock")
private void handleTermination() {
  channelLogger.log(ChannelLogLevel.INFO, "Terminated");
  syncContext.executeLater(new Runnable() {
      @Override
      public void run() {
        callback.onTerminated(InternalSubchannel.this);
      }
    });
}