Search in sources :

Example 1 with ReadReplicaGraphDatabase

use of org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase in project neo4j by neo4j.

the class ReadReplicaReplicationIT method transactionsShouldNotAppearOnTheReadReplicaWhilePollingIsPaused.

@Test
public void transactionsShouldNotAppearOnTheReadReplicaWhilePollingIsPaused() throws Throwable {
    // given
    Cluster cluster = clusterRule.startCluster();
    ReadReplicaGraphDatabase readReplicaGraphDatabase = cluster.findAnyReadReplica().database();
    CatchupPollingProcess pollingClient = readReplicaGraphDatabase.getDependencyResolver().resolveDependency(CatchupPollingProcess.class);
    pollingClient.stop();
    cluster.coreTx((coreGraphDatabase, transaction) -> {
        coreGraphDatabase.createNode();
        transaction.success();
    });
    CoreGraphDatabase leaderDatabase = cluster.awaitLeader().database();
    long transactionVisibleOnLeader = transactionIdTracker(leaderDatabase).newestEncounteredTxId();
    // when the poller is paused, transaction doesn't make it to the read replica
    try {
        transactionIdTracker(readReplicaGraphDatabase).awaitUpToDate(transactionVisibleOnLeader, ofSeconds(3));
        fail("should have thrown exception");
    } catch (TransactionFailureException e) {
    // expected timeout
    }
    // when the poller is resumed, it does make it to the read replica
    pollingClient.start();
    transactionIdTracker(readReplicaGraphDatabase).awaitUpToDate(transactionVisibleOnLeader, ofSeconds(3));
}
Also used : TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) CatchupPollingProcess(org.neo4j.causalclustering.catchup.tx.CatchupPollingProcess) Cluster(org.neo4j.causalclustering.discovery.Cluster) ReadReplicaGraphDatabase(org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase) CoreGraphDatabase(org.neo4j.causalclustering.core.CoreGraphDatabase) Test(org.junit.Test)

Example 2 with ReadReplicaGraphDatabase

use of org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase in project neo4j by neo4j.

the class ReadReplicaStoreCopyIT method shouldNotBePossibleToStartTransactionsWhenReadReplicaCopiesStore.

@Test(timeout = 120_000)
public void shouldNotBePossibleToStartTransactionsWhenReadReplicaCopiesStore() throws Throwable {
    Cluster cluster = clusterRule.startCluster();
    ReadReplica readReplica = cluster.findAnyReadReplica();
    readReplica.txPollingClient().stop();
    writeSomeDataAndForceLogRotations(cluster);
    Semaphore storeCopyBlockingSemaphore = addStoreCopyBlockingMonitor(readReplica);
    try {
        readReplica.txPollingClient().start();
        waitForStoreCopyToStartAndBlock(storeCopyBlockingSemaphore);
        ReadReplicaGraphDatabase replicaGraphDatabase = readReplica.database();
        try {
            replicaGraphDatabase.beginTx();
            fail("Exception expected");
        } catch (Exception e) {
            assertThat(e, instanceOf(TransactionFailureException.class));
            assertThat(e.getMessage(), containsString("Database is stopped to copy store"));
        }
    } finally {
        // release all waiters of the semaphore
        storeCopyBlockingSemaphore.release(Integer.MAX_VALUE);
    }
}
Also used : ReadReplica(org.neo4j.causalclustering.discovery.ReadReplica) Cluster(org.neo4j.causalclustering.discovery.Cluster) Semaphore(java.util.concurrent.Semaphore) ReadReplicaGraphDatabase(org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Test(org.junit.Test)

Example 3 with ReadReplicaGraphDatabase

use of org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase in project neo4j by neo4j.

the class CausalClusteringProceduresIT method readReplicaProceduresShouldBeAvailable.

@Test
public void readReplicaProceduresShouldBeAvailable() throws Exception {
    // given
    String[] readReplicaProcs = new String[] { // Server role
    "dbms.cluster.role", // Kernel built procedures
    "dbms.procedures", // Built in procedure from enterprise
    "dbms.listQueries" };
    // when
    for (String procedure : readReplicaProcs) {
        Optional<ReadReplica> firstReadReplica = cluster.readReplicas().stream().findFirst();
        assert firstReadReplica.isPresent();
        ReadReplicaGraphDatabase database = firstReadReplica.get().database();
        InternalTransaction tx = database.beginTransaction(KernelTransaction.Type.explicit, AUTH_DISABLED);
        Result readReplicaResult = database.execute("CALL " + procedure + "()");
        // then
        assertTrue("read replica with procedure " + procedure, readReplicaResult.hasNext());
        readReplicaResult.close();
        tx.close();
    }
}
Also used : ReadReplica(org.neo4j.causalclustering.discovery.ReadReplica) ReadReplicaGraphDatabase(org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Result(org.neo4j.graphdb.Result) Test(org.junit.Test)

Example 4 with ReadReplicaGraphDatabase

use of org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase in project neo4j by neo4j.

the class BackupReadReplicaIT method makeSureBackupCanBePerformed.

@Test
public void makeSureBackupCanBePerformed() throws Throwable {
    // Run backup
    CoreGraphDatabase leader = createSomeData(cluster);
    ReadReplicaGraphDatabase readReplica = cluster.findAnyReadReplica().database();
    awaitEx(() -> readReplicasUpToDateAsTheLeader(leader, readReplica), 1, TimeUnit.MINUTES);
    DbRepresentation beforeChange = DbRepresentation.of(readReplica);
    String backupAddress = this.backupAddress(readReplica);
    String[] args = backupArguments(backupAddress, backupPath, "readreplica");
    assertEquals(0, runBackupToolFromOtherJvmToGetExitCode(clusterRule.clusterDirectory(), args));
    // Add some new data
    DbRepresentation afterChange = DbRepresentation.of(createSomeData(cluster));
    // Verify that backed up database can be started and compare representation
    DbRepresentation backupRepresentation = DbRepresentation.of(new File(backupPath, "readreplica"), getConfig());
    assertEquals(beforeChange, backupRepresentation);
    assertNotEquals(backupRepresentation, afterChange);
}
Also used : ReadReplicaGraphDatabase(org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase) CoreGraphDatabase(org.neo4j.causalclustering.core.CoreGraphDatabase) File(java.io.File) DbRepresentation(org.neo4j.test.DbRepresentation) Test(org.junit.Test)

Example 5 with ReadReplicaGraphDatabase

use of org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase 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)

Aggregations

Test (org.junit.Test)5 ReadReplicaGraphDatabase (org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase)5 Cluster (org.neo4j.causalclustering.discovery.Cluster)3 CoreGraphDatabase (org.neo4j.causalclustering.core.CoreGraphDatabase)2 ReadReplica (org.neo4j.causalclustering.discovery.ReadReplica)2 File (java.io.File)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 Semaphore (java.util.concurrent.Semaphore)1 CatchupPollingProcess (org.neo4j.causalclustering.catchup.tx.CatchupPollingProcess)1 Node (org.neo4j.graphdb.Node)1 Result (org.neo4j.graphdb.Result)1 Transaction (org.neo4j.graphdb.Transaction)1 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)1 WriteOperationsNotAllowedException (org.neo4j.graphdb.security.WriteOperationsNotAllowedException)1 TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)1 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)1 DbRepresentation (org.neo4j.test.DbRepresentation)1