Search in sources :

Example 6 with GuardedBy

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());
}
Also used : ReplSetHeartbeatReply(com.torodb.mongodb.commands.signatures.internal.ReplSetHeartbeatReply) Instant(java.time.Instant) Duration(java.time.Duration) GuardedBy(javax.annotation.concurrent.GuardedBy)

Example 7 with GuardedBy

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);
    }
}
Also used : SocketAddress(java.net.SocketAddress) GuardedBy(javax.annotation.concurrent.GuardedBy)

Example 8 with GuardedBy

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;
}
Also used : Condition(java.util.concurrent.locks.Condition) GuardedBy(javax.annotation.concurrent.GuardedBy)

Example 9 with GuardedBy

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);
            }
        }
    }
}
Also used : MasterBlockInfo(alluxio.master.block.meta.MasterBlockInfo) GuardedBy(javax.annotation.concurrent.GuardedBy)

Example 10 with GuardedBy

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);
            }
        }
    }
}
Also used : MasterBlockInfo(alluxio.master.block.meta.MasterBlockInfo) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) 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