Search in sources :

Example 51 with TransactionFailureException

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();
        }
    }
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException)

Example 52 with TransactionFailureException

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;
    }
}
Also used : TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) Config(org.neo4j.configuration.Config) LogConfig(org.neo4j.logging.log4j.LogConfig) Log4jLogProvider(org.neo4j.logging.log4j.Log4jLogProvider) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException)

Example 53 with TransactionFailureException

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());
}
Also used : DatabaseContext(org.neo4j.dbms.database.DatabaseContext) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) DatabaseAvailability(org.neo4j.kernel.availability.DatabaseAvailability) DependencyResolver(org.neo4j.common.DependencyResolver) Test(org.junit.jupiter.api.Test)

Example 54 with TransactionFailureException

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);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) NotFoundException(org.neo4j.graphdb.NotFoundException) EntityNotFoundException(org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException) TokenCapacityExceededKernelException(org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException) EntityNotFoundException(org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException) IllegalTokenNameException(org.neo4j.internal.kernel.api.exceptions.schema.IllegalTokenNameException) PropertyKeyIdNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) TokenCapacityExceededKernelException(org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException) LabelNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.LabelNotFoundKernelException) KernelException(org.neo4j.exceptions.KernelException)

Example 55 with TransactionFailureException

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);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) ConstraintValidationException(org.neo4j.internal.kernel.api.exceptions.schema.ConstraintValidationException) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) NotFoundException(org.neo4j.graphdb.NotFoundException) EntityNotFoundException(org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException) TokenCapacityExceededKernelException(org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException) EntityNotFoundException(org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException) IllegalTokenNameException(org.neo4j.internal.kernel.api.exceptions.schema.IllegalTokenNameException) PropertyKeyIdNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) TokenCapacityExceededKernelException(org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException) LabelNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.LabelNotFoundKernelException) KernelException(org.neo4j.exceptions.KernelException)

Aggregations

TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)57 Transaction (org.neo4j.graphdb.Transaction)17 NotFoundException (org.neo4j.graphdb.NotFoundException)9 Node (org.neo4j.graphdb.Node)8 Test (org.junit.Test)7 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)7 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)7 LinkedList (java.util.LinkedList)6 SystemException (javax.transaction.SystemException)6 XAException (javax.transaction.xa.XAException)6 XAResource (javax.transaction.xa.XAResource)6 KernelException (org.neo4j.exceptions.KernelException)6 EntityNotFoundException (org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException)6 InvalidTransactionTypeKernelException (org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException)6 PropertyKeyIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)6 IllegalTokenNameException (org.neo4j.internal.kernel.api.exceptions.schema.IllegalTokenNameException)6 TokenCapacityExceededKernelException (org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException)6 XaDataSource (org.neo4j.kernel.impl.transaction.xaframework.XaDataSource)6 XaResource (org.neo4j.kernel.impl.transaction.xaframework.XaResource)6 IOException (java.io.IOException)5