Search in sources :

Example 6 with Cluster

use of org.neo4j.causalclustering.discovery.Cluster in project neo4j by neo4j.

the class ReadReplicaReplicationIT method shouldShutdownRatherThanPullUpdatesFromCoreMemberWithDifferentStoreIdIfLocalStoreIsNonEmpty.

@Test
public void shouldShutdownRatherThanPullUpdatesFromCoreMemberWithDifferentStoreIdIfLocalStoreIsNonEmpty() throws Exception {
    Cluster cluster = clusterRule.withNumberOfReadReplicas(0).startCluster();
    cluster.coreTx(createSomeData);
    cluster.awaitCoreMemberWithRole(Role.FOLLOWER, 2, TimeUnit.SECONDS);
    // Get a read replica and make sure that it is operational
    ReadReplica readReplica = cluster.addReadReplicaWithId(4);
    readReplica.start();
    readReplica.database().beginTx().close();
    // Change the store id, so it should fail to join the cluster again
    changeStoreId(readReplica);
    readReplica.shutdown();
    try {
        readReplica.start();
        fail("Should have failed to start");
    } catch (RuntimeException required) {
        // Lifecycle should throw exception, server should not start.
        assertThat(required.getCause(), instanceOf(LifecycleException.class));
        assertThat(required.getCause().getCause(), instanceOf(Exception.class));
        assertThat(required.getCause().getCause().getMessage(), containsString("This read replica cannot join the cluster. " + "The local database is not empty and has a mismatching storeId:"));
    }
}
Also used : ReadReplica(org.neo4j.causalclustering.discovery.ReadReplica) Cluster(org.neo4j.causalclustering.discovery.Cluster) Test(org.junit.Test)

Example 7 with Cluster

use of org.neo4j.causalclustering.discovery.Cluster in project neo4j by neo4j.

the class ReadReplicaReplicationIT method allServersBecomeAvailable.

@Test
public void allServersBecomeAvailable() throws Exception {
    // given
    Cluster cluster = clusterRule.startCluster();
    // then
    for (final ReadReplica readReplica : cluster.readReplicas()) {
        ThrowingSupplier<Boolean, Exception> availability = () -> readReplica.database().isAvailable(0);
        assertEventually("read replica becomes available", availability, is(true), 10, SECONDS);
    }
}
Also used : ReadReplica(org.neo4j.causalclustering.discovery.ReadReplica) Cluster(org.neo4j.causalclustering.discovery.Cluster) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) UnsatisfiedDependencyException(org.neo4j.kernel.impl.util.UnsatisfiedDependencyException) LifecycleException(org.neo4j.kernel.lifecycle.LifecycleException) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) IOException(java.io.IOException) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) Test(org.junit.Test)

Example 8 with Cluster

use of org.neo4j.causalclustering.discovery.Cluster in project neo4j by neo4j.

the class ReadReplicaReplicationIT method shouldBeAbleToPullTxAfterHavingDownloadedANewStoreAfterPruning.

@Test
public void shouldBeAbleToPullTxAfterHavingDownloadedANewStoreAfterPruning() throws Exception {
    // given
    Map<String, String> params = stringMap(GraphDatabaseSettings.keep_logical_logs.name(), "keep_none", GraphDatabaseSettings.logical_log_rotation_threshold.name(), "1M", GraphDatabaseSettings.check_point_interval_time.name(), "100ms");
    Cluster cluster = clusterRule.withSharedCoreParams(params).startCluster();
    cluster.coreTx((db, tx) -> {
        createData(db, 10);
        tx.success();
    });
    awaitEx(() -> readReplicasUpToDateAsTheLeader(cluster.awaitLeader(), cluster.readReplicas()), 1, TimeUnit.MINUTES);
    ReadReplica readReplica = cluster.getReadReplicaById(0);
    long highestReadReplicaLogVersion = physicalLogFiles(readReplica).getHighestLogVersion();
    readReplica.shutdown();
    CoreClusterMember core;
    do {
        core = cluster.coreTx((db, tx) -> {
            createData(db, 1_000);
            tx.success();
        });
    } while (physicalLogFiles(core).getLowestLogVersion() <= highestReadReplicaLogVersion);
    readReplica.start();
    awaitEx(() -> readReplicasUpToDateAsTheLeader(cluster.awaitLeader(), cluster.readReplicas()), 1, TimeUnit.MINUTES);
    // when
    cluster.coreTx((db, tx) -> {
        createData(db, 10);
        tx.success();
    });
    // then
    assertEventually("The read replica has the same data as the core members", () -> DbRepresentation.of(readReplica.database()), equalTo(DbRepresentation.of(cluster.awaitLeader().database())), 10, TimeUnit.SECONDS);
}
Also used : ResourceIterator(org.neo4j.graphdb.ResourceIterator) AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) Log(org.neo4j.logging.Log) CausalClusteringSettings(org.neo4j.causalclustering.core.CausalClusteringSettings) ReadReplicaGraphDatabase(org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase) CoreMatchers.startsWith(org.hamcrest.CoreMatchers.startsWith) ThrowingSupplier(org.neo4j.function.ThrowingSupplier) HighLimit(org.neo4j.kernel.impl.store.format.highlimit.HighLimit) Map(java.util.Map) Is.is(org.hamcrest.core.Is.is) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Assert.fail(org.junit.Assert.fail) Transaction(org.neo4j.graphdb.Transaction) Path(java.nio.file.Path) Collectors.toSet(java.util.stream.Collectors.toSet) Standard(org.neo4j.kernel.impl.store.format.standard.Standard) PageCache(org.neo4j.io.pagecache.PageCache) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Collection(java.util.Collection) Set(java.util.Set) BinaryOperator(java.util.function.BinaryOperator) UnsatisfiedDependencyException(org.neo4j.kernel.impl.util.UnsatisfiedDependencyException) Cluster(org.neo4j.causalclustering.discovery.Cluster) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) CoreGraphDatabase(org.neo4j.causalclustering.core.CoreGraphDatabase) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) TransactionIdTracker(org.neo4j.kernel.api.txtracking.TransactionIdTracker) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Predicates.awaitEx(org.neo4j.function.Predicates.awaitEx) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) GraphDatabaseSettings(org.neo4j.graphdb.factory.GraphDatabaseSettings) SortedMap(java.util.SortedMap) Mockito.mock(org.mockito.Mockito.mock) Role(org.neo4j.causalclustering.core.consensus.roles.Role) ClusterMember(org.neo4j.causalclustering.discovery.ClusterMember) Label(org.neo4j.graphdb.Label) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) Iterables.count(org.neo4j.helpers.collection.Iterables.count) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Monitors(org.neo4j.kernel.monitoring.Monitors) MINUTES(java.util.concurrent.TimeUnit.MINUTES) ClusterRule(org.neo4j.test.causalclustering.ClusterRule) LabelScanStore(org.neo4j.kernel.api.labelscan.LabelScanStore) Duration.ofSeconds(java.time.Duration.ofSeconds) Function(java.util.function.Function) Node(org.neo4j.graphdb.Node) HashSet(java.util.HashSet) CatchupPollingProcess(org.neo4j.causalclustering.catchup.tx.CatchupPollingProcess) LifecycleException(org.neo4j.kernel.lifecycle.LifecycleException) HazelcastDiscoveryServiceFactory(org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TIME(org.neo4j.kernel.impl.store.MetaDataStore.Position.TIME) BiConsumer(java.util.function.BiConsumer) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) MapUtil.stringMap(org.neo4j.helpers.collection.MapUtil.stringMap) FileNames(org.neo4j.causalclustering.core.consensus.log.segmented.FileNames) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) FileCopyMonitor(org.neo4j.causalclustering.catchup.tx.FileCopyMonitor) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Assert.assertEventually(org.neo4j.test.assertion.Assert.assertEventually) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) SampleData.createData(org.neo4j.causalclustering.scenarios.SampleData.createData) Rule(org.junit.Rule) Paths(java.nio.file.Paths) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) DbRepresentation(org.neo4j.test.DbRepresentation) Clock(java.time.Clock) ReadReplica(org.neo4j.causalclustering.discovery.ReadReplica) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Assert.assertEquals(org.junit.Assert.assertEquals) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) ReadReplica(org.neo4j.causalclustering.discovery.ReadReplica) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Cluster(org.neo4j.causalclustering.discovery.Cluster) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 9 with Cluster

use of org.neo4j.causalclustering.discovery.Cluster 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 10 with Cluster

use of org.neo4j.causalclustering.discovery.Cluster in project neo4j by neo4j.

the class RecoveryIT method singleServerWithinClusterShouldBeConsistentAfterRestart.

@Test
public void singleServerWithinClusterShouldBeConsistentAfterRestart() throws Exception {
    // given
    Cluster cluster = clusterRule.startCluster();
    int clusterSize = cluster.numberOfCoreMembersReportedByTopology();
    fireSomeLoadAtTheCluster(cluster);
    Set<File> storeDirs = cluster.coreMembers().stream().map(CoreClusterMember::storeDir).collect(toSet());
    // when
    for (int i = 0; i < clusterSize; i++) {
        cluster.removeCoreMemberWithMemberId(i);
        fireSomeLoadAtTheCluster(cluster);
        cluster.addCoreMemberWithId(i).start();
    }
    // then
    assertEventually("All cores have the same data", () -> cluster.coreMembers().stream().map(this::dbRepresentation).collect(toSet()).size(), equalTo(1), 10, TimeUnit.SECONDS);
    cluster.shutdown();
    storeDirs.forEach(this::assertConsistent);
}
Also used : Cluster(org.neo4j.causalclustering.discovery.Cluster) File(java.io.File) Test(org.junit.Test)

Aggregations

Cluster (org.neo4j.causalclustering.discovery.Cluster)52 Test (org.junit.Test)51 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)21 File (java.io.File)14 HazelcastDiscoveryServiceFactory (org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory)13 ReadReplica (org.neo4j.causalclustering.discovery.ReadReplica)13 Node (org.neo4j.graphdb.Node)12 Rule (org.junit.Rule)11 WriteOperationsNotAllowedException (org.neo4j.graphdb.security.WriteOperationsNotAllowedException)11 IOException (java.io.IOException)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 Transaction (org.neo4j.graphdb.Transaction)10 TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)10 ClusterRule (org.neo4j.test.causalclustering.ClusterRule)10 CoreGraphDatabase (org.neo4j.causalclustering.core.CoreGraphDatabase)9 Map (java.util.Map)8 TimeUnit (java.util.concurrent.TimeUnit)8 ReadReplicaGraphDatabase (org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase)8 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)8 UnsatisfiedDependencyException (org.neo4j.kernel.impl.util.UnsatisfiedDependencyException)8