use of org.neo4j.graphdb.TransactionFailureException in project neo4j by neo4j.
the class ServerBootstrapper method start.
@Override
@SafeVarargs
public final int start(File homeDir, Optional<File> configFile, Pair<String, String>... configOverrides) {
addShutdownHook();
try {
Config config = createConfig(homeDir, configFile, configOverrides);
LogProvider userLogProvider = setupLogging(config);
dependencies = dependencies.userLogProvider(userLogProvider);
log = userLogProvider.getLog(getClass());
config.setLogger(log);
serverAddress = config.httpConnectors().stream().filter(c -> Encryption.NONE.equals(c.encryptionLevel())).findFirst().map((connector) -> config.get(connector.listen_address).toString()).orElse(serverAddress);
checkCompatibility();
server = createNeoServer(config, dependencies, userLogProvider);
server.start();
return OK;
} catch (ServerStartupException e) {
e.describeTo(log);
return WEB_SERVER_STARTUP_ERROR_CODE;
} catch (TransactionFailureException tfe) {
String locationMsg = (server == null) ? "" : " Another process may be using database location " + server.getDatabase().getLocation();
log.error(format("Failed to start Neo4j on %s.", serverAddress) + locationMsg, tfe);
return GRAPH_DATABASE_STARTUP_ERROR_CODE;
} catch (Exception e) {
log.error(format("Failed to start Neo4j on %s.", serverAddress), e);
return WEB_SERVER_STARTUP_ERROR_CODE;
}
}
use of org.neo4j.graphdb.TransactionFailureException in project neo4j by neo4j.
the class LifecycleManagingDatabaseTest method mustIgnoreExceptionsFromPreLoadingCypherQuery.
@Test
public void mustIgnoreExceptionsFromPreLoadingCypherQuery() throws Throwable {
// Given a lifecycled database that'll try to warm up Cypher when it starts
final GraphDatabaseFacade mockDb = mock(GraphDatabaseFacade.class);
Config config = Config.empty();
GraphDatabaseFacadeFactory.Dependencies deps = GraphDatabaseDependencies.newDependencies().userLogProvider(NullLogProvider.getInstance());
LifecycleManagingDatabase.GraphFactory factory = (conf, dependencies) -> mockDb;
LifecycleManagingDatabase db = new LifecycleManagingDatabase(config, factory, deps) {
@Override
protected boolean isInTestMode() {
return false;
}
};
// When the execution of the query fails (for instance when this is a slave that just joined a cluster and is
// working on catching up to the master)
when(mockDb.execute(LifecycleManagingDatabase.CYPHER_WARMUP_QUERY)).thenThrow(new TransactionFailureException("Boo"));
// Then the database should still start up as normal, without bubbling the exception up
db.init();
db.start();
assertTrue("the database should be running", db.isRunning());
db.stop();
db.shutdown();
}
use of org.neo4j.graphdb.TransactionFailureException in project neo4j by neo4j.
the class DatabaseRecoveryIT method recoveryShouldFixPartiallyAppliedSchemaIndexUpdates.
@Test
void recoveryShouldFixPartiallyAppliedSchemaIndexUpdates() {
Label label = Label.label("Foo");
String property = "Bar";
// cause failure during 'relationship.delete()' command application
ClassGuardedAdversary adversary = new ClassGuardedAdversary(new CountingAdversary(1, true), Command.RelationshipCommand.class);
adversary.disable();
Path storeDir = directory.homePath();
DatabaseManagementService managementService = AdversarialPageCacheGraphDatabaseFactory.create(storeDir, fileSystem, adversary).build();
GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
try {
try (Transaction tx = db.beginTx()) {
tx.schema().constraintFor(label).assertPropertyIsUnique(property).create();
tx.commit();
}
long relationshipId = createRelationship(db);
TransactionFailureException txFailure = null;
try (Transaction tx = db.beginTx()) {
Node node = tx.createNode(label);
node.setProperty(property, "B");
// this should fail because of the adversary
tx.getRelationshipById(relationshipId).delete();
adversary.enable();
tx.commit();
} catch (TransactionFailureException e) {
txFailure = e;
}
assertNotNull(txFailure);
adversary.disable();
// heal the db so it is possible to inspect the data
healthOf(db).healed();
// now we can observe partially committed state: node is in the index and relationship still present
try (Transaction tx = db.beginTx()) {
assertNotNull(findNode(label, property, "B", tx));
assertNotNull(tx.getRelationshipById(relationshipId));
tx.commit();
}
// panic the db again to force recovery on the next startup
healthOf(db).panic(txFailure.getCause());
// restart the database, now with regular page cache
managementService.shutdown();
db = startDatabase(storeDir);
// now we observe correct state: node is in the index and relationship is removed
try (Transaction tx = db.beginTx()) {
assertNotNull(findNode(label, property, "B", tx));
assertRelationshipNotExist(tx, relationshipId);
tx.commit();
}
} finally {
managementService.shutdown();
}
}
use of org.neo4j.graphdb.TransactionFailureException in project graphdb by neo4j-attic.
the class LockReleaser method releaseCows.
void releaseCows(Transaction cowTxId, int param) {
PrimitiveElement element = cowMap.remove(cowTxId);
if (element == null) {
return;
}
ArrayMap<Long, CowNodeElement> cowNodeElements = element.nodes;
Set<Entry<Long, CowNodeElement>> nodeEntrySet = cowNodeElements.entrySet();
for (Entry<Long, CowNodeElement> entry : nodeEntrySet) {
NodeImpl node = nodeManager.getNodeIfCached(entry.getKey());
if (node != null) {
CowNodeElement nodeElement = entry.getValue();
if (param == Status.STATUS_COMMITTED) {
node.commitRelationshipMaps(nodeElement.relationshipAddMap, nodeElement.relationshipRemoveMap);
node.commitPropertyMaps(nodeElement.propertyAddMap, nodeElement.propertyRemoveMap);
} else if (param != Status.STATUS_ROLLEDBACK) {
throw new TransactionFailureException("Unknown transaction status: " + param);
}
}
}
ArrayMap<Long, CowRelElement> cowRelElements = element.relationships;
Set<Entry<Long, CowRelElement>> relEntrySet = cowRelElements.entrySet();
for (Entry<Long, CowRelElement> entry : relEntrySet) {
RelationshipImpl rel = nodeManager.getRelIfCached(entry.getKey());
if (rel != null) {
CowRelElement relElement = entry.getValue();
if (param == Status.STATUS_COMMITTED) {
rel.commitPropertyMaps(relElement.propertyAddMap, relElement.propertyRemoveMap);
} else if (param != Status.STATUS_ROLLEDBACK) {
throw new TransactionFailureException("Unknown transaction status: " + param);
}
}
}
cowMap.remove(cowTxId);
}
use of org.neo4j.graphdb.TransactionFailureException in project graphdb by neo4j-attic.
the class LockReleaser method addLockToTransaction.
/**
* Invoking this method with no transaction running will cause the lock to
* be released right away.
*
* @param resource
* the resource on which the lock is taken
* @param type
* type of lock (READ or WRITE)
* @throws NotInTransactionException
*/
public void addLockToTransaction(Object resource, LockType type) throws NotInTransactionException {
Transaction tx = getTransaction();
List<LockElement> lockElements = lockMap.get(tx);
if (lockElements != null) {
lockElements.add(new LockElement(resource, type));
} else {
if (tx == null) {
// no transaction we release lock right away
if (type == LockType.WRITE) {
lockManager.releaseWriteLock(resource, null);
} else if (type == LockType.READ) {
lockManager.releaseReadLock(resource, null);
}
return;
}
lockElements = new ArrayList<LockElement>();
lockMap.put(tx, lockElements);
lockElements.add(new LockElement(resource, type));
// tx was read only
try {
tx.registerSynchronization(new ReadOnlyTxReleaser(tx));
} catch (Exception e) {
throw new TransactionFailureException("Failed to register lock release synchronization hook", e);
}
}
}
Aggregations