use of javax.annotation.concurrent.GuardedBy in project torodb by torodb.
the class TopologyHeartbeatHandler method handleHeartbeatResponse.
@GuardedBy("executor")
private void handleHeartbeatResponse(TopologyCoordinator coord, HostAndPort target, ReplSetHeartbeatArgument request, RemoteCommandResponse<ReplSetHeartbeatReply> response) {
boolean isUnauthorized = (response.getErrorCode() == ErrorCode.UNAUTHORIZED) || (response.getErrorCode() == ErrorCode.AUTHENTICATION_FAILED);
Instant now = clock.instant();
Duration networkTime = Duration.ZERO;
if (response.isOk()) {
networkTime = response.getNetworkTime();
} else {
LOGGER.warn("Error in heartbeat request to {}; {}", target, response.asStatus());
if (response.getBson() != null) {
LOGGER.debug("heartbeat response: ", response.getBson());
}
if (isUnauthorized) {
networkTime = response.getNetworkTime();
}
}
HeartbeatResponseAction action = coord.processHeartbeatResponse(now, networkTime, target, response);
ReplSetHeartbeatReply hbReply = response.getCommandReply().orElse(null);
assert hbReply != null || !response.isOk() : "Recived a null hbReply when the request didn't fail";
scheduleHeartbeatToTarget(target, action.getNextHeartbeatDelay());
handleHeartbeatResponseAction(coord, action, hbReply, response.getErrorCode());
}
use of javax.annotation.concurrent.GuardedBy in project grpc-java by grpc.
the class InternalSubchannel method startNewTransport.
@GuardedBy("lock")
private void startNewTransport() {
Preconditions.checkState(reconnectTask == null, "Should have no reconnectTask scheduled");
if (nextAddressIndex == 0) {
connectingTimer.reset().start();
}
List<SocketAddress> addrs = addressGroup.getAddresses();
final SocketAddress address = addrs.get(nextAddressIndex++);
if (nextAddressIndex >= addrs.size()) {
nextAddressIndex = 0;
}
ConnectionClientTransport transport = transportFactory.newClientTransport(address, authority, userAgent);
if (log.isLoggable(Level.FINE)) {
log.log(Level.FINE, "[{0}] Created {1} for {2}", new Object[] { logId, transport.getLogId(), address });
}
pendingTransport = transport;
transports.add(transport);
Runnable runnable = transport.start(new TransportListener(transport, address));
if (runnable != null) {
channelExecutor.executeLater(runnable);
}
}
use of javax.annotation.concurrent.GuardedBy in project guava by hceylan.
the class Monitor method waitUninterruptibly.
@GuardedBy("lock")
private boolean waitUninterruptibly(Guard guard, long timeoutNanos, boolean signalBeforeWaiting) {
if (!guard.isSatisfied()) {
long startNanos = System.nanoTime();
if (signalBeforeWaiting) {
signalConditionsOfSatisfiedGuards(null);
}
boolean interruptIgnored = false;
try {
incrementWaiters(guard);
try {
final Condition condition = guard.condition;
long remainingNanos = timeoutNanos;
do {
if (remainingNanos <= 0) {
return false;
}
try {
remainingNanos = condition.awaitNanos(remainingNanos);
} catch (InterruptedException ignored) {
try {
signalConditionsOfSatisfiedGuards(guard);
} catch (Throwable throwable) {
Thread.currentThread().interrupt();
throw Throwables.propagate(throwable);
}
interruptIgnored = true;
remainingNanos = (timeoutNanos - (System.nanoTime() - startNanos));
}
} while (!guard.isSatisfied());
} finally {
decrementWaiters(guard);
}
} finally {
if (interruptIgnored) {
Thread.currentThread().interrupt();
}
}
}
return true;
}
use of javax.annotation.concurrent.GuardedBy in project alluxio by Alluxio.
the class BlockMaster method processWorkerRemovedBlocks.
/**
* Updates the worker and block metadata for blocks removed from a worker.
*
* @param workerInfo The worker metadata object
* @param removedBlockIds A list of block ids removed from the worker
*/
@GuardedBy("workerInfo")
private void processWorkerRemovedBlocks(MasterWorkerInfo workerInfo, Collection<Long> removedBlockIds) {
for (long removedBlockId : removedBlockIds) {
MasterBlockInfo block = mBlocks.get(removedBlockId);
// TODO(calvin): Investigate if this branching logic can be simplified.
if (block == null) {
// LOG.warn("Worker {} informs the removed block {}, but block metadata does not exist"
// + " on Master!", workerInfo.getId(), removedBlockId);
// TODO(pfxuan): [ALLUXIO-1804] should find a better way to handle the removed blocks.
// Ideally, the delete/free I/O flow should never reach this point. Because Master may
// update the block metadata only after receiving the acknowledgement from Workers.
workerInfo.removeBlock(removedBlockId);
// Continue to remove the remaining blocks.
continue;
}
synchronized (block) {
LOG.info("Block {} is removed on worker {}.", removedBlockId, workerInfo.getId());
workerInfo.removeBlock(block.getBlockId());
block.removeWorker(workerInfo.getId());
if (block.getNumLocations() == 0) {
mLostBlocks.add(removedBlockId);
}
}
}
}
use of javax.annotation.concurrent.GuardedBy in project alluxio by Alluxio.
the class BlockMaster method processWorkerAddedBlocks.
/**
* Updates the worker and block metadata for blocks added to a worker.
*
* @param workerInfo The worker metadata object
* @param addedBlockIds A mapping from storage tier alias to a list of block ids added
*/
@GuardedBy("workerInfo")
private void processWorkerAddedBlocks(MasterWorkerInfo workerInfo, Map<String, List<Long>> addedBlockIds) {
for (Map.Entry<String, List<Long>> entry : addedBlockIds.entrySet()) {
for (long blockId : entry.getValue()) {
MasterBlockInfo block = mBlocks.get(blockId);
if (block != null) {
synchronized (block) {
workerInfo.addBlock(blockId);
block.addWorker(workerInfo.getId(), entry.getKey());
mLostBlocks.remove(blockId);
}
} else {
LOG.warn("Failed to register workerId: {} to blockId: {}", workerInfo.getId(), blockId);
}
}
}
}
Aggregations