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;
}
}
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;
}
}
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;
}
}
Aggregations