Search in sources :

Example 21 with ComException

use of org.neo4j.com.ComException in project graphdb by neo4j-attic.

the class SlaveLockManager method getReadLock.

@Override
public void getReadLock(Object resource) throws DeadlockDetectedException, IllegalResourceException {
    try {
        Node node = resource instanceof Node ? (Node) resource : null;
        Relationship relationship = resource instanceof Relationship ? (Relationship) resource : null;
        if (node == null && relationship == null) {
            // This is a "fake" resource, only grab the lock locally
            super.getReadLock(resource);
            return;
        }
        //            if ( hasAlreadyGotLock() )
        //            {
        //                return;
        //            }
        LockResult result = null;
        do {
            int eventIdentifier = getLocalTxId();
            result = node != null ? receiver.receive(broker.getMaster().first().acquireNodeReadLock(receiver.getSlaveContext(eventIdentifier), node.getId())) : receiver.receive(broker.getMaster().first().acquireRelationshipReadLock(receiver.getSlaveContext(eventIdentifier), relationship.getId()));
            switch(result.getStatus()) {
                case OK_LOCKED:
                    super.getReadLock(resource);
                    return;
                case DEAD_LOCKED:
                    throw new DeadlockDetectedException(result.getDeadlockMessage());
            }
        } while (result.getStatus() == LockStatus.NOT_LOCKED);
    } catch (ZooKeeperException e) {
        receiver.newMaster(null, e);
        throw e;
    } catch (ComException e) {
        receiver.newMaster(null, e);
        throw e;
    }
}
Also used : ZooKeeperException(org.neo4j.kernel.ha.zookeeper.ZooKeeperException) ComException(org.neo4j.com.ComException) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException)

Example 22 with ComException

use of org.neo4j.com.ComException in project graphdb by neo4j-attic.

the class HaBackupProvider method resolve.

@Override
public URI resolve(URI address) {
    String master = null;
    try {
        System.out.println("Asking ZooKeeper service at '" + address + "' for master");
        master = getMasterServerInCluster(address.getSchemeSpecificPart().substring(// skip the "//" part
        2));
        System.out.println("Found master '" + master + "' in cluster");
    } catch (ComException e) {
        throw e;
    } catch (RuntimeException e) {
        if (e.getCause() instanceof KeeperException) {
            KeeperException zkException = (KeeperException) e.getCause();
            System.out.println("Couldn't connect to '" + address + "', " + zkException.getMessage());
        }
        throw e;
    }
    URI toReturn = null;
    try {
        toReturn = new URI(master);
    } catch (URISyntaxException e) {
    // no way
    }
    return toReturn;
}
Also used : ComException(org.neo4j.com.ComException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) KeeperException(org.apache.zookeeper.KeeperException)

Example 23 with ComException

use of org.neo4j.com.ComException in project neo4j by neo4j.

the class SlaveUpdatePuller method doPullUpdates.

private void doPullUpdates() {
    try {
        RequestContext context = requestContextFactory.newRequestContext();
        try (Response<Void> ignored = master.pullUpdates(context)) {
            // Updates would be applied as part of response processing
            monitor.pulledUpdates(context.lastAppliedTransaction());
        }
        invalidEpochCappedLogger.reset();
        comExceptionCappedLogger.reset();
    } catch (InvalidEpochException e) {
        invalidEpochHandler.handle();
        invalidEpochCappedLogger.warn("Pull updates by " + this + " failed at the epoch check", e);
    } catch (ComException e) {
        invalidEpochCappedLogger.warn("Pull updates by " + this + " failed due to network error.", e);
    } catch (Throwable e) {
        logger.error("Pull updates by " + this + " failed", e);
    }
    lastUpdateTime.setLastUpdateTime(currentTimeMillis());
}
Also used : ComException(org.neo4j.com.ComException) InvalidEpochException(org.neo4j.kernel.ha.com.master.InvalidEpochException) RequestContext(org.neo4j.com.RequestContext)

Aggregations

ComException (org.neo4j.com.ComException)23 Test (org.junit.Test)12 RequestContext (org.neo4j.com.RequestContext)9 ZooKeeperException (org.neo4j.kernel.ha.zookeeper.ZooKeeperException)3 IOException (java.io.IOException)2 URI (java.net.URI)2 Node (org.neo4j.graphdb.Node)2 Relationship (org.neo4j.graphdb.Relationship)2 MismatchingStoreIdException (org.neo4j.kernel.impl.store.MismatchingStoreIdException)2 URISyntaxException (java.net.URISyntaxException)1 ReadableByteChannel (java.nio.channels.ReadableByteChannel)1 Callable (java.util.concurrent.Callable)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 Future (java.util.concurrent.Future)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1