Search in sources :

Example 26 with Cluster

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

the class CorePruningIT method shouldNotPruneUncommittedEntries.

@Test
public void shouldNotPruneUncommittedEntries() throws Exception {
    // given
    Cluster cluster = clusterRule.startCluster();
    CoreClusterMember coreGraphDatabase = null;
    int txs = 1000;
    for (int i = 0; i < txs; i++) {
        coreGraphDatabase = cluster.coreTx((db, tx) -> createData(db, 1));
    }
    // when pruning kicks in then some files are actually deleted
    int expectedNumberOfLogFilesAfterPruning = 2;
    File raftLogDir = coreGraphDatabase.raftLogDirectory();
    assertEventually("raft logs eventually pruned", () -> numberOfFiles(raftLogDir), equalTo(expectedNumberOfLogFilesAfterPruning), 5, TimeUnit.SECONDS);
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) CausalClusteringSettings.raft_log_pruning_strategy(org.neo4j.causalclustering.core.CausalClusteringSettings.raft_log_pruning_strategy) SampleData.createData(org.neo4j.causalclustering.scenarios.SampleData.createData) Rule(org.junit.Rule) CausalClusteringSettings(org.neo4j.causalclustering.core.CausalClusteringSettings) Matchers.equalTo(org.hamcrest.Matchers.equalTo) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Test(org.junit.Test) ClusterRule(org.neo4j.test.causalclustering.ClusterRule) Assert.assertEventually(org.neo4j.test.assertion.Assert.assertEventually) File(java.io.File) Cluster(org.neo4j.causalclustering.discovery.Cluster) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Cluster(org.neo4j.causalclustering.discovery.Cluster) File(java.io.File) Test(org.junit.Test)

Example 27 with Cluster

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

the class ClusterSeedingIT method shouldSeedNewMemberFromEmptyIdleCluster.

@Test
public void shouldSeedNewMemberFromEmptyIdleCluster() throws Throwable {
    // given
    cluster = new Cluster(testDir.directory("cluster-b"), 3, 0, new SharedDiscoveryService(), emptyMap(), backupParams(), emptyMap(), emptyMap(), Standard.LATEST_NAME);
    cluster.start();
    // when: creating a backup
    File backupDir = createBackup(cluster.getCoreMemberById(0).database(), "the-backup");
    // and: seeding new member with said backup
    CoreClusterMember newMember = cluster.addCoreMemberWithId(3);
    fsa.copyRecursively(backupDir, newMember.storeDir());
    newMember.start();
    // then
    dataMatchesEventually(DbRepresentation.of(newMember.database()), cluster.coreMembers());
}
Also used : CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Cluster(org.neo4j.causalclustering.discovery.Cluster) SharedDiscoveryService(org.neo4j.causalclustering.discovery.SharedDiscoveryService) File(java.io.File) Test(org.junit.Test)

Example 28 with Cluster

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

the class BackupStoreCopyInteractionStressTesting method shouldBehaveCorrectlyUnderStress.

@Test
public void shouldBehaveCorrectlyUnderStress() throws Exception {
    int numberOfCores = parseInt(fromEnv("BACKUP_STORE_COPY_INTERACTION_STRESS_NUMBER_OF_CORES", DEFAULT_NUMBER_OF_CORES));
    int numberOfEdges = parseInt(fromEnv("BACKUP_STORE_COPY_INTERACTION_STRESS_NUMBER_OF_EDGES", DEFAULT_NUMBER_OF_EDGES));
    long durationInMinutes = parseLong(fromEnv("BACKUP_STORE_COPY_INTERACTION_STRESS_DURATION", DEFAULT_DURATION_IN_MINUTES));
    String workingDirectory = fromEnv("BACKUP_STORE_COPY_INTERACTION_STRESS_WORKING_DIRECTORY", DEFAULT_WORKING_DIR);
    int baseCoreBackupPort = parseInt(fromEnv("BACKUP_STORE_COPY_INTERACTION_STRESS_BASE_CORE_BACKUP_PORT", DEFAULT_BASE_CORE_BACKUP_PORT));
    int baseEdgeBackupPort = parseInt(fromEnv("BACKUP_STORE_COPY_INTERACTION_STRESS_BASE_EDGE_BACKUP_PORT", DEFAULT_BASE_EDGE_BACKUP_PORT));
    boolean enableIndexes = parseBoolean(fromEnv("BACKUP_STORE_COPY_INTERACTION_STRESS_ENABLE_INDEXES", DEFAULT_ENABLE_INDEXES));
    String txPrune = fromEnv("BACKUP_STORE_COPY_INTERACTION_STRESS_TX_PRUNE", DEFAULT_TX_PRUNE);
    File clusterDirectory = ensureExistsAndEmpty(new File(workingDirectory, "cluster"));
    File backupDirectory = ensureExistsAndEmpty(new File(workingDirectory, "backups"));
    BiFunction<Boolean, Integer, SocketAddress> backupAddress = (isCore, id) -> new AdvertisedSocketAddress("localhost", (isCore ? baseCoreBackupPort : baseEdgeBackupPort) + id);
    Map<String, String> coreParams = enableRaftMessageLogging(configureRaftLogRotationAndPruning(configureTxLogRotationAndPruning(new HashMap<>(), txPrune)));
    Map<String, String> readReplicaParams = configureTxLogRotationAndPruning(new HashMap<>(), txPrune);
    Map<String, IntFunction<String>> instanceCoreParams = configureBackup(new HashMap<>(), id -> backupAddress.apply(true, id));
    Map<String, IntFunction<String>> instanceReadReplicaParams = configureBackup(new HashMap<>(), id -> backupAddress.apply(false, id));
    HazelcastDiscoveryServiceFactory discoveryServiceFactory = new HazelcastDiscoveryServiceFactory();
    Cluster cluster = new Cluster(clusterDirectory, numberOfCores, numberOfEdges, discoveryServiceFactory, coreParams, instanceCoreParams, readReplicaParams, instanceReadReplicaParams, Standard.LATEST_NAME);
    AtomicBoolean stopTheWorld = new AtomicBoolean();
    BooleanSupplier notExpired = untilTimeExpired(durationInMinutes, MINUTES);
    BooleanSupplier keepGoing = () -> !stopTheWorld.get() && notExpired.getAsBoolean();
    Runnable onFailure = () -> stopTheWorld.set(true);
    ExecutorService service = Executors.newFixedThreadPool(3);
    try {
        cluster.start();
        if (enableIndexes) {
            Workload.setupIndexes(cluster);
        }
        Future<Throwable> workload = service.submit(new Workload(keepGoing, onFailure, cluster));
        Future<Throwable> startStopWorker = service.submit(new StartStopLoad(fs, pageCache, keepGoing, onFailure, cluster, numberOfCores, numberOfEdges));
        Future<Throwable> backupWorker = service.submit(new BackupLoad(keepGoing, onFailure, cluster, numberOfCores, numberOfEdges, backupDirectory, backupAddress));
        long timeout = durationInMinutes + 5;
        assertNull(Exceptions.stringify(workload.get()), workload.get(timeout, MINUTES));
        assertNull(Exceptions.stringify(startStopWorker.get()), startStopWorker.get(timeout, MINUTES));
        assertNull(Exceptions.stringify(backupWorker.get()), backupWorker.get(timeout, MINUTES));
    } finally {
        cluster.shutdown();
        service.shutdown();
    }
    // let's cleanup disk space when everything went well
    FileUtils.deleteRecursively(clusterDirectory);
    FileUtils.deleteRecursively(backupDirectory);
}
Also used : StressTestingHelper.ensureExistsAndEmpty(org.neo4j.helper.StressTestingHelper.ensureExistsAndEmpty) Suppliers.untilTimeExpired(org.neo4j.function.Suppliers.untilTimeExpired) BiFunction(java.util.function.BiFunction) Exceptions(org.neo4j.helpers.Exceptions) StressTestingHelper.fromEnv(org.neo4j.helper.StressTestingHelper.fromEnv) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) MINUTES(java.util.concurrent.TimeUnit.MINUTES) BooleanSupplier(java.util.function.BooleanSupplier) SocketAddress(org.neo4j.helpers.SocketAddress) Future(java.util.concurrent.Future) AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress) ClusterConfiguration.configureRaftLogRotationAndPruning(org.neo4j.causalclustering.stresstests.ClusterConfiguration.configureRaftLogRotationAndPruning) HazelcastDiscoveryServiceFactory(org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory) PageCacheRule(org.neo4j.test.rule.PageCacheRule) Map(java.util.Map) ClusterConfiguration.configureBackup(org.neo4j.causalclustering.stresstests.ClusterConfiguration.configureBackup) System.getProperty(java.lang.System.getProperty) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) IntFunction(java.util.function.IntFunction) Standard(org.neo4j.kernel.impl.store.format.standard.Standard) PageCache(org.neo4j.io.pagecache.PageCache) ClusterConfiguration.enableRaftMessageLogging(org.neo4j.causalclustering.stresstests.ClusterConfiguration.enableRaftMessageLogging) FileUtils(org.neo4j.io.fs.FileUtils) Test(org.junit.Test) Integer.parseInt(java.lang.Integer.parseInt) File(java.io.File) Executors(java.util.concurrent.Executors) Cluster(org.neo4j.causalclustering.discovery.Cluster) RuleChain(org.junit.rules.RuleChain) Rule(org.junit.Rule) DefaultFileSystemRule(org.neo4j.test.rule.fs.DefaultFileSystemRule) Boolean.parseBoolean(java.lang.Boolean.parseBoolean) Assert.assertNull(org.junit.Assert.assertNull) DatabaseConfiguration.configureTxLogRotationAndPruning(org.neo4j.helper.DatabaseConfiguration.configureTxLogRotationAndPruning) Long.parseLong(java.lang.Long.parseLong) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress) HazelcastDiscoveryServiceFactory(org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Boolean.parseBoolean(java.lang.Boolean.parseBoolean) SocketAddress(org.neo4j.helpers.SocketAddress) AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress) BooleanSupplier(java.util.function.BooleanSupplier) Cluster(org.neo4j.causalclustering.discovery.Cluster) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IntFunction(java.util.function.IntFunction) ExecutorService(java.util.concurrent.ExecutorService) File(java.io.File) Test(org.junit.Test)

Example 29 with Cluster

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

the class ClusterSeedingIT method setup.

@Before
public void setup() throws Exception {
    fsa = fileSystemRule.get();
    backupCluster = new Cluster(testDir.directory("cluster-for-backup"), 3, 0, new SharedDiscoveryService(), emptyMap(), backupParams(), emptyMap(), emptyMap(), Standard.LATEST_NAME);
    cluster = new Cluster(testDir.directory("cluster-b"), 3, 0, new SharedDiscoveryService(), emptyMap(), emptyMap(), emptyMap(), emptyMap(), Standard.LATEST_NAME);
    baseBackupDir = testDir.directory("backups");
}
Also used : Cluster(org.neo4j.causalclustering.discovery.Cluster) SharedDiscoveryService(org.neo4j.causalclustering.discovery.SharedDiscoveryService) Before(org.junit.Before)

Example 30 with Cluster

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

the class ClusterSeedingIT method shouldSeedNewMemberFromNonEmptyIdleCluster.

@Test
public void shouldSeedNewMemberFromNonEmptyIdleCluster() throws Throwable {
    // given
    cluster = new Cluster(testDir.directory("cluster-b"), 3, 0, new SharedDiscoveryService(), emptyMap(), backupParams(), emptyMap(), emptyMap(), Standard.LATEST_NAME);
    cluster.start();
    createEmptyNodes(cluster, 100);
    // when: creating a backup
    File backupDir = createBackup(cluster.getCoreMemberById(0).database(), "the-backup");
    // and: seeding new member with said backup
    CoreClusterMember newMember = cluster.addCoreMemberWithId(3);
    fsa.copyRecursively(backupDir, newMember.storeDir());
    newMember.start();
    // then
    dataMatchesEventually(DbRepresentation.of(newMember.database()), cluster.coreMembers());
}
Also used : CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Cluster(org.neo4j.causalclustering.discovery.Cluster) SharedDiscoveryService(org.neo4j.causalclustering.discovery.SharedDiscoveryService) 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