Search in sources :

Example 1 with ZooKeeperException

use of org.neo4j.kernel.ha.zookeeper.ZooKeeperException in project graphdb by neo4j-attic.

the class SlaveLockManager method getWriteLock.

@Override
public void getWriteLock(Object resource) throws DeadlockDetectedException, IllegalResourceException {
    // Code copied from getReadLock. Fix!
    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.getWriteLock(resource);
            return;
        }
        //          if ( hasAlreadyGotLock() )
        //          {
        //              return;
        //          }
        LockResult result = null;
        do {
            int eventIdentifier = getLocalTxId();
            result = node != null ? receiver.receive(broker.getMaster().first().acquireNodeWriteLock(receiver.getSlaveContext(eventIdentifier), node.getId())) : receiver.receive(broker.getMaster().first().acquireRelationshipWriteLock(receiver.getSlaveContext(eventIdentifier), relationship.getId()));
            switch(result.getStatus()) {
                case OK_LOCKED:
                    super.getWriteLock(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 2 with ZooKeeperException

use of org.neo4j.kernel.ha.zookeeper.ZooKeeperException in project graphdb by neo4j-attic.

the class SlaveTxIdGenerator method generate.

public long generate(final XaDataSource dataSource, final int identifier) {
    try {
        final int eventIdentifier = txManager.getEventIdentifier();
        Response<Long> response = broker.getMaster().first().commitSingleResourceTransaction(receiver.getSlaveContext(eventIdentifier), dataSource.getName(), new TxExtractor() {

            public void extract(LogBuffer buffer) {
                try {
                    dataSource.getPreparedTransaction(identifier, buffer);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            public ReadableByteChannel extract() {
                try {
                    return dataSource.getPreparedTransaction(identifier);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        return receiver.receive(response);
    } 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) LogBuffer(org.neo4j.kernel.impl.transaction.xaframework.LogBuffer) ReadableByteChannel(java.nio.channels.ReadableByteChannel) TxExtractor(org.neo4j.com.TxExtractor) IOException(java.io.IOException)

Example 3 with ZooKeeperException

use of org.neo4j.kernel.ha.zookeeper.ZooKeeperException 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)

Aggregations

ComException (org.neo4j.com.ComException)3 ZooKeeperException (org.neo4j.kernel.ha.zookeeper.ZooKeeperException)3 Node (org.neo4j.graphdb.Node)2 Relationship (org.neo4j.graphdb.Relationship)2 DeadlockDetectedException (org.neo4j.kernel.DeadlockDetectedException)2 IOException (java.io.IOException)1 ReadableByteChannel (java.nio.channels.ReadableByteChannel)1 TxExtractor (org.neo4j.com.TxExtractor)1 LogBuffer (org.neo4j.kernel.impl.transaction.xaframework.LogBuffer)1