Search in sources :

Example 56 with PageCache

use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.

the class SwitchToSlaveCopyThenBranch method stopServicesAndHandleBranchedStore.

void stopServicesAndHandleBranchedStore(BranchedDataPolicy branchPolicy, URI masterUri, URI me, CancellationRequest cancellationRequest) throws Throwable {
    MoveAfterCopy moveWithCopyThenBranch = (moves, fromDirectory, toDirectory) -> {
        stopServices();
        msgLog.debug("Branching store: " + storeDir);
        branchPolicy.handle(storeDir, pageCache, logService);
        msgLog.debug("Moving downloaded store from " + fromDirectory + " to " + toDirectory);
        MoveAfterCopy.moveReplaceExisting().move(moves, fromDirectory, toDirectory);
        msgLog.debug("Moved downloaded store from " + fromDirectory + " to " + toDirectory);
    };
    copyStore(masterUri, me, cancellationRequest, moveWithCopyThenBranch);
}
Also used : BranchedDataPolicy(org.neo4j.kernel.ha.BranchedDataPolicy) StoreId(org.neo4j.kernel.impl.store.StoreId) MoveAfterCopy(org.neo4j.com.storecopy.MoveAfterCopy) NeoStoreDataSource(org.neo4j.kernel.NeoStoreDataSource) MasterClientResolver(org.neo4j.kernel.ha.com.slave.MasterClientResolver) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) Monitors(org.neo4j.kernel.monitoring.Monitors) DelegateInvocationHandler(org.neo4j.kernel.ha.DelegateInvocationHandler) StoreUnableToParticipateInClusterException(org.neo4j.kernel.ha.StoreUnableToParticipateInClusterException) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) Function(java.util.function.Function) Supplier(java.util.function.Supplier) PullerFactory(org.neo4j.kernel.ha.PullerFactory) MasterClient(org.neo4j.kernel.ha.com.slave.MasterClient) SlaveServer(org.neo4j.kernel.ha.com.slave.SlaveServer) HaIdGeneratorFactory(org.neo4j.kernel.ha.id.HaIdGeneratorFactory) CancellationRequest(org.neo4j.helpers.CancellationRequest) URI(java.net.URI) MismatchingStoreIdException(org.neo4j.kernel.impl.store.MismatchingStoreIdException) BASE_TX_ID(org.neo4j.kernel.impl.transaction.log.TransactionIdStore.BASE_TX_ID) PageCache(org.neo4j.io.pagecache.PageCache) Config(org.neo4j.kernel.configuration.Config) IOException(java.io.IOException) LogService(org.neo4j.kernel.impl.logging.LogService) HaSettings(org.neo4j.kernel.ha.HaSettings) File(java.io.File) UpdatePuller(org.neo4j.kernel.ha.UpdatePuller) ForeignStoreException(org.neo4j.kernel.ha.store.ForeignStoreException) UnableToCopyStoreFromOldMasterException(org.neo4j.kernel.ha.store.UnableToCopyStoreFromOldMasterException) ClusterMemberAvailability(org.neo4j.cluster.member.ClusterMemberAvailability) KernelExtensionFactory(org.neo4j.kernel.extension.KernelExtensionFactory) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Slave(org.neo4j.kernel.ha.com.master.Slave) StoreCopyClient(org.neo4j.com.storecopy.StoreCopyClient) TransactionStats(org.neo4j.kernel.impl.transaction.TransactionStats) RequestContextFactory(org.neo4j.kernel.ha.com.RequestContextFactory) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Master(org.neo4j.kernel.ha.com.master.Master) MoveAfterCopy(org.neo4j.com.storecopy.MoveAfterCopy)

Example 57 with PageCache

use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.

the class StoreCopyClientTest method shouldDeleteTempCopyFolderOnFailures.

@Test
public void shouldDeleteTempCopyFolderOnFailures() throws Exception {
    // GIVEN
    File initialStore = testDir.directory("initialStore");
    File backupStore = testDir.directory("backupStore");
    PageCache pageCache = pageCacheRule.getPageCache(fileSystem);
    GraphDatabaseService initialDatabase = createInitialDatabase(initialStore);
    StoreCopyClient copier = new StoreCopyClient(backupStore, Config.empty(), loadKernelExtensions(), NullLogProvider.getInstance(), fileSystem, pageCache, new StoreCopyClient.Monitor.Adapter(), false);
    CancellationRequest falseCancellationRequest = () -> false;
    RuntimeException exception = new RuntimeException("Boom!");
    StoreCopyClient.StoreCopyRequester storeCopyRequest = new LocalStoreCopyRequester((GraphDatabaseAPI) initialDatabase, initialStore, fileSystem) {

        @Override
        public void done() {
            throw exception;
        }
    };
    // WHEN
    try {
        copier.copyStore(storeCopyRequest, falseCancellationRequest, MoveAfterCopy.moveReplaceExisting());
        fail("should have thrown ");
    } catch (RuntimeException ex) {
        assertEquals(exception, ex);
    }
    // THEN
    assertFalse(new File(backupStore, TEMP_COPY_DIRECTORY_NAME).exists());
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) File(java.io.File) PageCache(org.neo4j.io.pagecache.PageCache) CancellationRequest(org.neo4j.helpers.CancellationRequest) Test(org.junit.Test)

Example 58 with PageCache

use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.

the class StoreCopyClientTest method shouldResetNeoStoreLastTransactionOffsetForNonForensicCopy.

@Test
public void shouldResetNeoStoreLastTransactionOffsetForNonForensicCopy() throws Exception {
    // GIVEN
    File initialStore = testDir.directory("initialStore");
    File backupStore = testDir.directory("backupStore");
    PageCache pageCache = pageCacheRule.getPageCache(fileSystem);
    createInitialDatabase(initialStore);
    long originalTransactionOffset = MetaDataStore.getRecord(pageCache, new File(initialStore, MetaDataStore.DEFAULT_NAME), MetaDataStore.Position.LAST_CLOSED_TRANSACTION_LOG_BYTE_OFFSET);
    GraphDatabaseService initialDatabase = startDatabase(initialStore);
    StoreCopyClient copier = new StoreCopyClient(backupStore, Config.empty(), loadKernelExtensions(), NullLogProvider.getInstance(), fileSystem, pageCache, new StoreCopyClient.Monitor.Adapter(), false);
    CancellationRequest falseCancellationRequest = () -> false;
    StoreCopyClient.StoreCopyRequester storeCopyRequest = new LocalStoreCopyRequester((GraphDatabaseAPI) initialDatabase, initialStore, fileSystem);
    // WHEN
    copier.copyStore(storeCopyRequest, falseCancellationRequest, MoveAfterCopy.moveReplaceExisting());
    // THEN
    long updatedTransactionOffset = MetaDataStore.getRecord(pageCache, new File(backupStore, MetaDataStore.DEFAULT_NAME), MetaDataStore.Position.LAST_CLOSED_TRANSACTION_LOG_BYTE_OFFSET);
    assertNotEquals(originalTransactionOffset, updatedTransactionOffset);
    assertEquals(LogHeader.LOG_HEADER_SIZE, updatedTransactionOffset);
    assertFalse(new File(backupStore, TEMP_COPY_DIRECTORY_NAME).exists());
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) File(java.io.File) PageCache(org.neo4j.io.pagecache.PageCache) CancellationRequest(org.neo4j.helpers.CancellationRequest) Test(org.junit.Test)

Example 59 with PageCache

use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.

the class ToFileStoreWriterTest method shouldLetPageCacheHandleRecordStoresAndNativeLabelScanStoreFiles.

@Test
public void shouldLetPageCacheHandleRecordStoresAndNativeLabelScanStoreFiles() throws Exception {
    // GIVEN
    List<FileMoveAction> actions = new ArrayList<>();
    PageCache pageCache = spy(pageCacheRule.getPageCache(fs));
    ToFileStoreWriter writer = new ToFileStoreWriter(directory.absolutePath(), fs, new StoreCopyClient.Monitor.Adapter(), pageCache, actions);
    ByteBuffer tempBuffer = ByteBuffer.allocate(128);
    // WHEN
    for (StoreType type : StoreType.values()) {
        if (type.isRecordStore()) {
            String fileName = type.getStoreFile().fileName(STORE);
            writeAndVerifyWrittenThroughPageCache(pageCache, writer, tempBuffer, fileName);
        }
    }
    writeAndVerifyWrittenThroughPageCache(pageCache, writer, tempBuffer, NativeLabelScanStore.FILE_NAME);
}
Also used : StoreType(org.neo4j.kernel.impl.store.StoreType) ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 60 with PageCache

use of org.neo4j.io.pagecache.PageCache 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)

Aggregations

PageCache (org.neo4j.io.pagecache.PageCache)134 Test (org.junit.Test)90 File (java.io.File)74 Config (org.neo4j.kernel.configuration.Config)39 IOException (java.io.IOException)32 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)31 StoreVersionCheck (org.neo4j.kernel.impl.storemigration.StoreVersionCheck)19 LegacyStoreVersionCheck (org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck)17 UpgradableDatabase (org.neo4j.kernel.impl.storemigration.UpgradableDatabase)16 PagedFile (org.neo4j.io.pagecache.PagedFile)15 LogService (org.neo4j.kernel.impl.logging.LogService)13 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)12 NullLogService (org.neo4j.kernel.impl.logging.NullLogService)12 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)12 NeoStores (org.neo4j.kernel.impl.store.NeoStores)11 RecordFormatSelector.selectForConfig (org.neo4j.kernel.impl.store.format.RecordFormatSelector.selectForConfig)11 RecordFormatSelector.selectForStoreOrConfig (org.neo4j.kernel.impl.store.format.RecordFormatSelector.selectForStoreOrConfig)11 Before (org.junit.Before)10 TransactionId (org.neo4j.kernel.impl.store.TransactionId)10 StoreCopyClient (org.neo4j.com.storecopy.StoreCopyClient)9