Search in sources :

Example 6 with WriteOperationsNotAllowedException

use of org.neo4j.graphdb.security.WriteOperationsNotAllowedException in project neo4j by neo4j.

the class ReadOnlySlaveTest method givenClusterWithReadOnlySlaveWhenWriteTxOnSlaveThenCommitFails.

@Test
public void givenClusterWithReadOnlySlaveWhenWriteTxOnSlaveThenCommitFails() throws Throwable {
    // When
    ManagedCluster cluster = clusterRule.startCluster();
    HighlyAvailableGraphDatabase readOnlySlave = cluster.getMemberByServerId(new InstanceId(2));
    try (Transaction tx = readOnlySlave.beginTx()) {
        readOnlySlave.createNode();
        tx.success();
        fail("Should have thrown exception");
    } catch (WriteOperationsNotAllowedException ex) {
    // Then
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) InstanceId(org.neo4j.cluster.InstanceId) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) Test(org.junit.Test)

Example 7 with WriteOperationsNotAllowedException

use of org.neo4j.graphdb.security.WriteOperationsNotAllowedException in project neo4j by neo4j.

the class ReadOnlySlaveTest method givenClusterWithReadOnlySlaveWhenAddNewRelTypeOnSlaveThenThrowException.

@Test
public void givenClusterWithReadOnlySlaveWhenAddNewRelTypeOnSlaveThenThrowException() throws Throwable {
    // Given
    ManagedCluster cluster = clusterRule.startCluster();
    Node node;
    Node node2;
    HighlyAvailableGraphDatabase master = cluster.getMaster();
    try (Transaction tx = master.beginTx()) {
        node = master.createNode();
        node2 = master.createNode();
        tx.success();
    }
    // When
    HighlyAvailableGraphDatabase readOnlySlave = cluster.getMemberByServerId(new InstanceId(2));
    try (Transaction tx = readOnlySlave.beginTx()) {
        Node slaveNode = readOnlySlave.getNodeById(node.getId());
        Node slaveNode2 = readOnlySlave.getNodeById(node2.getId());
        // Then
        slaveNode.createRelationshipTo(slaveNode2, RelationshipType.withName("KNOWS"));
        tx.success();
        fail("Should have thrown exception");
    } catch (WriteOperationsNotAllowedException ex) {
    // Ok!
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) InstanceId(org.neo4j.cluster.InstanceId) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) Node(org.neo4j.graphdb.Node) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) Test(org.junit.Test)

Example 8 with WriteOperationsNotAllowedException

use of org.neo4j.graphdb.security.WriteOperationsNotAllowedException in project neo4j by neo4j.

the class TransactionHandle method executeStatements.

private void executeStatements(StatementDeserializer statements, ExecutionResultSerializer output, List<Neo4jError> errors, HttpServletRequest request) {
    try {
        boolean hasPrevious = false;
        while (statements.hasNext()) {
            Statement statement = statements.next();
            try {
                boolean hasPeriodicCommit = engine.isPeriodicCommit(statement.statement());
                if ((statements.hasNext() || hasPrevious) && hasPeriodicCommit) {
                    throw new QueryExecutionKernelException(new InvalidSemanticsException("Cannot execute another statement after executing " + "PERIODIC COMMIT statement in the same transaction"));
                }
                if (!hasPrevious && hasPeriodicCommit) {
                    context.closeTransactionForPeriodicCommit();
                }
                hasPrevious = true;
                TransactionalContext tc = txManagerFacade.create(request, queryService, type, securityContext, statement.statement(), statement.parameters());
                Result result = safelyExecute(statement, hasPeriodicCommit, tc);
                output.statementResult(result, statement.includeStats(), statement.resultDataContents());
                output.notifications(result.getNotifications());
            } catch (KernelException | CypherException | AuthorizationViolationException | WriteOperationsNotAllowedException e) {
                errors.add(new Neo4jError(e.status(), e));
                break;
            } catch (DeadlockDetectedException e) {
                errors.add(new Neo4jError(Status.Transaction.DeadlockDetected, e));
            } catch (IOException e) {
                errors.add(new Neo4jError(Status.Network.CommunicationError, e));
                break;
            } catch (Exception e) {
                Throwable cause = e.getCause();
                if (cause instanceof Status.HasStatus) {
                    errors.add(new Neo4jError(((Status.HasStatus) cause).status(), cause));
                } else {
                    errors.add(new Neo4jError(Status.Statement.ExecutionFailed, e));
                }
                break;
            }
        }
        addToCollection(statements.errors(), errors);
    } catch (Throwable e) {
        errors.add(new Neo4jError(Status.General.UnknownError, e));
    }
}
Also used : InvalidSemanticsException(org.neo4j.cypher.InvalidSemanticsException) Status(org.neo4j.kernel.api.exceptions.Status) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException) IOException(java.io.IOException) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) CypherException(org.neo4j.cypher.CypherException) DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException) IOException(java.io.IOException) KernelException(org.neo4j.kernel.api.exceptions.KernelException) InvalidSemanticsException(org.neo4j.cypher.InvalidSemanticsException) AuthorizationViolationException(org.neo4j.graphdb.security.AuthorizationViolationException) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) Result(org.neo4j.graphdb.Result) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) Neo4jError(org.neo4j.server.rest.transactional.error.Neo4jError) TransactionalContext(org.neo4j.kernel.impl.query.TransactionalContext) CypherException(org.neo4j.cypher.CypherException) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) KernelException(org.neo4j.kernel.api.exceptions.KernelException) AuthorizationViolationException(org.neo4j.graphdb.security.AuthorizationViolationException)

Example 9 with WriteOperationsNotAllowedException

use of org.neo4j.graphdb.security.WriteOperationsNotAllowedException in project neo4j by neo4j.

the class ReadReplicaReplicationIT method shouldNotBeAbleToWriteToReadReplica.

@Test
public void shouldNotBeAbleToWriteToReadReplica() throws Exception {
    // given
    Cluster cluster = clusterRule.startCluster();
    ReadReplicaGraphDatabase readReplica = cluster.findAnyReadReplica().database();
    // when
    try (Transaction tx = readReplica.beginTx()) {
        Node node = readReplica.createNode();
        node.setProperty("foobar", "baz_bat");
        node.addLabel(Label.label("Foo"));
        tx.success();
        fail("should have thrown");
    } catch (WriteOperationsNotAllowedException e) {
    // then all good
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Cluster(org.neo4j.causalclustering.discovery.Cluster) ReadReplicaGraphDatabase(org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) Test(org.junit.Test)

Example 10 with WriteOperationsNotAllowedException

use of org.neo4j.graphdb.security.WriteOperationsNotAllowedException in project neo4j by neo4j.

the class RestartIT method restartWhileDoingTransactions.

@Test
public void restartWhileDoingTransactions() throws Exception {
    // given
    Cluster cluster = clusterRule.startCluster();
    // when
    final GraphDatabaseService coreDB = cluster.getCoreMemberById(0).database();
    ExecutorService executor = Executors.newCachedThreadPool();
    final AtomicBoolean done = new AtomicBoolean(false);
    executor.execute(() -> {
        while (!done.get()) {
            try (Transaction tx = coreDB.beginTx()) {
                Node node = coreDB.createNode(label("boo"));
                node.setProperty("foobar", "baz_bat");
                tx.success();
            } catch (AcquireLockTimeoutException | WriteOperationsNotAllowedException e) {
            // expected sometimes
            }
        }
    });
    Thread.sleep(500);
    cluster.removeCoreMemberWithMemberId(1);
    cluster.addCoreMemberWithId(1).start();
    Thread.sleep(500);
    // then
    done.set(true);
    executor.shutdown();
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AcquireLockTimeoutException(org.neo4j.storageengine.api.lock.AcquireLockTimeoutException) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) ExecutorService(java.util.concurrent.ExecutorService) Cluster(org.neo4j.causalclustering.discovery.Cluster) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) Test(org.junit.Test)

Aggregations

WriteOperationsNotAllowedException (org.neo4j.graphdb.security.WriteOperationsNotAllowedException)12 Test (org.junit.Test)11 Transaction (org.neo4j.graphdb.Transaction)10 Node (org.neo4j.graphdb.Node)5 InstanceId (org.neo4j.cluster.InstanceId)4 HighlyAvailableGraphDatabase (org.neo4j.kernel.ha.HighlyAvailableGraphDatabase)4 ManagedCluster (org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster)4 CoreGraphDatabase (org.neo4j.causalclustering.core.CoreGraphDatabase)3 Cluster (org.neo4j.causalclustering.discovery.Cluster)3 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)2 IOException (java.io.IOException)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)1 ReadReplicaGraphDatabase (org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase)1 CypherException (org.neo4j.cypher.CypherException)1 InvalidSemanticsException (org.neo4j.cypher.InvalidSemanticsException)1 Result (org.neo4j.graphdb.Result)1 UncloseableDelegatingFileSystemAbstraction (org.neo4j.graphdb.mockfs.UncloseableDelegatingFileSystemAbstraction)1 AuthorizationViolationException (org.neo4j.graphdb.security.AuthorizationViolationException)1