Search in sources :

Example 1 with MINUTES

use of java.util.concurrent.TimeUnit.MINUTES 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 2 with MINUTES

use of java.util.concurrent.TimeUnit.MINUTES in project neo4j by neo4j.

the class ReadReplicaReplicationIT method shouldEventuallyPullTransactionDownToAllReadReplicas.

@Test
public void shouldEventuallyPullTransactionDownToAllReadReplicas() throws Exception {
    // given
    Cluster cluster = clusterRule.withNumberOfReadReplicas(0).startCluster();
    int nodesBeforeReadReplicaStarts = 1;
    cluster.coreTx((db, tx) -> {
        db.schema().constraintFor(Label.label("Foo")).assertPropertyIsUnique("foobar").create();
        tx.success();
    });
    // when
    for (int i = 0; i < 100; i++) {
        cluster.coreTx((db, tx) -> {
            createData(db, nodesBeforeReadReplicaStarts);
            tx.success();
        });
    }
    Set<Path> labelScanStoreFiles = new HashSet<>();
    cluster.coreTx((db, tx) -> gatherLabelScanStoreFiles(db, labelScanStoreFiles));
    AtomicBoolean labelScanStoreCorrectlyPlaced = new AtomicBoolean(false);
    Monitors monitors = new Monitors();
    ReadReplica rr = cluster.addReadReplicaWithIdAndMonitors(0, monitors);
    Path readReplicateStoreDir = rr.storeDir().toPath().toAbsolutePath();
    monitors.addMonitorListener((FileCopyMonitor) file -> {
        Path relativPath = readReplicateStoreDir.relativize(file.toPath().toAbsolutePath());
        relativPath = relativPath.subpath(1, relativPath.getNameCount());
        if (labelScanStoreFiles.contains(relativPath)) {
            labelScanStoreCorrectlyPlaced.set(true);
        }
    });
    rr.start();
    for (int i = 0; i < 100; i++) {
        cluster.coreTx((db, tx) -> {
            createData(db, nodesBeforeReadReplicaStarts);
            tx.success();
        });
    }
    // then
    for (final ReadReplica server : cluster.readReplicas()) {
        GraphDatabaseService readReplica = server.database();
        try (Transaction tx = readReplica.beginTx()) {
            ThrowingSupplier<Long, Exception> nodeCount = () -> count(readReplica.getAllNodes());
            assertEventually("node to appear on read replica", nodeCount, is(400L), 1, MINUTES);
            for (Node node : readReplica.getAllNodes()) {
                assertThat(node.getProperty("foobar").toString(), startsWith("baz_bat"));
            }
            tx.success();
        }
    }
    assertTrue(labelScanStoreCorrectlyPlaced.get());
}
Also used : Path(java.nio.file.Path) 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) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Node(org.neo4j.graphdb.Node) Cluster(org.neo4j.causalclustering.discovery.Cluster) 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) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ReadReplica(org.neo4j.causalclustering.discovery.ReadReplica) Transaction(org.neo4j.graphdb.Transaction) Monitors(org.neo4j.kernel.monitoring.Monitors) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

File (java.io.File)2 Map (java.util.Map)2 MINUTES (java.util.concurrent.TimeUnit.MINUTES)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Rule (org.junit.Rule)2 Test (org.junit.Test)2 Cluster (org.neo4j.causalclustering.discovery.Cluster)2 IOException (java.io.IOException)1 Boolean.parseBoolean (java.lang.Boolean.parseBoolean)1 Integer.parseInt (java.lang.Integer.parseInt)1 Long.parseLong (java.lang.Long.parseLong)1 System.getProperty (java.lang.System.getProperty)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 Clock (java.time.Clock)1 Duration.ofSeconds (java.time.Duration.ofSeconds)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1