use of org.neo4j.graphdb.TransactionFailureException in project graphdb by neo4j-attic.
the class TestUpgradeStore method assertCannotStart.
private void assertCannotStart(String path, String failMessage) {
GraphDatabaseService db = null;
try {
db = new EmbeddedGraphDatabase(path);
fail(failMessage);
} catch (TransactionFailureException e) {
if (!(e.getCause() instanceof IllegalStoreVersionException)) {
throw e;
}
// Good
} finally {
if (db != null) {
db.shutdown();
}
}
}
use of org.neo4j.graphdb.TransactionFailureException in project neo4j by neo4j.
the class NeoBootstrapper method start.
@Override
public final int start(Path homeDir, Path configFile, Map<String, String> configOverrides, boolean expandCommands) {
addShutdownHook();
installSignalHandlers();
Config config = Config.newBuilder().commandExpansion(expandCommands).setDefaults(GraphDatabaseSettings.SERVER_DEFAULTS).fromFileNoThrow(configFile).setRaw(configOverrides).set(GraphDatabaseSettings.neo4j_home, homeDir.toAbsolutePath()).build();
Log4jLogProvider userLogProvider = setupLogging(config);
userLogFileStream = userLogProvider;
dependencies = dependencies.userLogProvider(userLogProvider);
log = userLogProvider.getLog(getClass());
// Log any messages written before logging was configured.
startupLog.replayInto(log);
config.setLogger(log);
if (requestedMemoryExceedsAvailable(config)) {
log.error(format("Invalid memory configuration - exceeds physical memory. Check the configured values for %s and %s", GraphDatabaseSettings.pagecache_memory.name(), BootloaderSettings.max_heap_size.name()));
return INVALID_CONFIGURATION_ERROR_CODE;
}
try {
serverAddress = HttpConnector.listen_address.toString();
log.info("Starting...");
databaseManagementService = createNeo(config, dependencies);
log.info("Started.");
return OK;
} catch (ServerStartupException e) {
e.describeTo(log);
return WEB_SERVER_STARTUP_ERROR_CODE;
} catch (TransactionFailureException tfe) {
String locationMsg = (databaseManagementService == null) ? "" : " Another process may be using databases at location: " + config.get(GraphDatabaseInternalSettings.databases_root_path);
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 DatabaseAvailabilityIT method notConfusingMessageOnDatabaseNonAvailability.
@Test
void notConfusingMessageOnDatabaseNonAvailability() {
DependencyResolver dependencyResolver = database.getDependencyResolver();
DatabaseManager<?> databaseManager = getDatabaseManager(dependencyResolver);
DatabaseContext databaseContext = databaseManager.getDatabaseContext(defaultNamedDatabaseId).get();
DatabaseAvailability databaseAvailability = databaseContext.database().getDependencyResolver().resolveDependency(DatabaseAvailability.class);
databaseAvailability.stop();
TransactionFailureException exception = assertThrows(TransactionFailureException.class, () -> database.beginTx());
assertEquals("Timeout waiting for database to become available and allow new transactions. Waited 1s. 1 reasons for blocking: Database unavailable.", exception.getMessage());
}
use of org.neo4j.graphdb.TransactionFailureException in project neo4j by neo4j.
the class NodeEntity method createRelationshipTo.
@Override
public Relationship createRelationshipTo(Node otherNode, RelationshipType type) {
if (otherNode == null) {
throw new IllegalArgumentException("Other node is null.");
}
KernelTransaction transaction = internalTransaction.kernelTransaction();
int relationshipTypeId;
try {
relationshipTypeId = transaction.tokenWrite().relationshipTypeGetOrCreateForName(type.name());
} catch (IllegalTokenNameException e) {
throw new IllegalArgumentException(e);
} catch (TokenCapacityExceededKernelException e) {
throw new ConstraintViolationException(e.getMessage(), e);
} catch (KernelException e) {
throw new TransactionFailureException("Unknown error trying to create relationship type token", e);
}
try {
long relationshipId = transaction.dataWrite().relationshipCreate(nodeId, relationshipTypeId, otherNode.getId());
return internalTransaction.newRelationshipEntity(relationshipId, nodeId, relationshipTypeId, otherNode.getId());
} catch (EntityNotFoundException e) {
throw new NotFoundException("Node[" + e.entityId() + "] is deleted and cannot be used to create a relationship");
} catch (InvalidTransactionTypeKernelException e) {
throw new ConstraintViolationException(e.getMessage(), e);
}
}
use of org.neo4j.graphdb.TransactionFailureException in project neo4j by neo4j.
the class NodeEntity method addLabel.
@Override
public void addLabel(Label label) {
KernelTransaction transaction = internalTransaction.kernelTransaction();
int labelId;
try {
labelId = transaction.tokenWrite().labelGetOrCreateForName(label.name());
} catch (IllegalTokenNameException e) {
throw new ConstraintViolationException(format("Invalid label name '%s'.", label.name()), e);
} catch (TokenCapacityExceededKernelException e) {
throw new ConstraintViolationException(e.getMessage(), e);
} catch (KernelException e) {
throw new TransactionFailureException("Unknown error trying to create label token", e);
}
try {
transaction.dataWrite().nodeAddLabel(getId(), labelId);
} catch (ConstraintValidationException e) {
throw new ConstraintViolationException(e.getUserMessage(transaction.tokenRead()), e);
} catch (EntityNotFoundException e) {
throw new NotFoundException("No node with id " + getId() + " found.", e);
} catch (KernelException e) {
throw new ConstraintViolationException(e.getMessage(), e);
}
}
Aggregations