Search in sources :

Example 11 with PageCache

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

the class SwitchToSlaveCopyThenBranchTest method newSwitchToSlaveSpy.

@SuppressWarnings("unchecked")
private SwitchToSlaveCopyThenBranch newSwitchToSlaveSpy(PageCache pageCacheMock, StoreCopyClient storeCopyClient) throws IOException {
    ClusterMembers clusterMembers = mock(ClusterMembers.class);
    ClusterMember master = mock(ClusterMember.class);
    when(master.getStoreId()).thenReturn(storeId);
    when(master.getHARole()).thenReturn(HighAvailabilityModeSwitcher.MASTER);
    when(master.hasRole(eq(HighAvailabilityModeSwitcher.MASTER))).thenReturn(true);
    when(master.getInstanceId()).thenReturn(new InstanceId(1));
    when(clusterMembers.getMembers()).thenReturn(asList(master));
    Dependencies resolver = new Dependencies();
    resolver.satisfyDependencies(requestContextFactory, clusterMembers, mock(TransactionObligationFulfiller.class), mock(OnlineBackupKernelExtension.class), mock(IndexConfigStore.class), mock(TransactionCommittingResponseUnpacker.class), mock(DataSourceManager.class), mock(StoreLockerLifecycleAdapter.class), mock(FileSystemWatcherService.class));
    NeoStoreDataSource dataSource = mock(NeoStoreDataSource.class);
    when(dataSource.getStoreId()).thenReturn(storeId);
    TransactionStats transactionCounters = mock(TransactionStats.class);
    when(transactionCounters.getNumberOfActiveTransactions()).thenReturn(0L);
    Response<HandshakeResult> response = mock(Response.class);
    when(response.response()).thenReturn(new HandshakeResult(42, 2));
    when(masterClient.handshake(anyLong(), any(StoreId.class))).thenReturn(response);
    when(masterClient.getProtocolVersion()).thenReturn(MasterClient.CURRENT);
    TransactionIdStore transactionIdStoreMock = mock(TransactionIdStore.class);
    // note that the checksum (the second member of the array) is the same as the one in the handshake mock above
    when(transactionIdStoreMock.getLastCommittedTransaction()).thenReturn(new TransactionId(42, 42, 42));
    MasterClientResolver masterClientResolver = mock(MasterClientResolver.class);
    when(masterClientResolver.instantiate(anyString(), anyInt(), anyString(), any(Monitors.class), any(StoreId.class), any(LifeSupport.class))).thenReturn(masterClient);
    return spy(new SwitchToSlaveCopyThenBranch(new File(""), NullLogService.getInstance(), configMock(), resolver, mock(HaIdGeneratorFactory.class), mock(DelegateInvocationHandler.class), mock(ClusterMemberAvailability.class), requestContextFactory, pullerFactory, masterClientResolver, mock(SwitchToSlave.Monitor.class), storeCopyClient, Suppliers.singleton(dataSource), Suppliers.singleton(transactionIdStoreMock), slave -> {
        SlaveServer server = mock(SlaveServer.class);
        InetSocketAddress inetSocketAddress = InetSocketAddress.createUnresolved("localhost", 42);
        when(server.getSocketAddress()).thenReturn(inetSocketAddress);
        return server;
    }, updatePuller, pageCacheMock, mock(Monitors.class), transactionCounters));
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) StoreId(org.neo4j.kernel.impl.store.StoreId) NeoStoreDataSource(org.neo4j.kernel.NeoStoreDataSource) MasterClientResolver(org.neo4j.kernel.ha.com.slave.MasterClientResolver) Suppliers(org.neo4j.function.Suppliers) URISyntaxException(java.net.URISyntaxException) OnlineBackupKernelExtension(org.neo4j.backup.OnlineBackupKernelExtension) DelegateInvocationHandler(org.neo4j.kernel.ha.DelegateInvocationHandler) Dependencies(org.neo4j.kernel.impl.util.Dependencies) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) NullLogProvider(org.neo4j.logging.NullLogProvider) MasterClient(org.neo4j.kernel.ha.com.slave.MasterClient) StoreIdTestFactory.newStoreIdForCurrentVersion(org.neo4j.com.StoreIdTestFactory.newStoreIdForCurrentVersion) HighAvailabilityModeSwitcher(org.neo4j.kernel.ha.cluster.modeswitch.HighAvailabilityModeSwitcher) Mockito.doThrow(org.mockito.Mockito.doThrow) TransactionObligationFulfiller(org.neo4j.com.storecopy.TransactionObligationFulfiller) Arrays.asList(java.util.Arrays.asList) Matchers.eq(org.mockito.Matchers.eq) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Matchers.anyInt(org.mockito.Matchers.anyInt) Assert.fail(org.junit.Assert.fail) URI(java.net.URI) MismatchingStoreIdException(org.neo4j.kernel.impl.store.MismatchingStoreIdException) Response(org.neo4j.com.Response) PageCache(org.neo4j.io.pagecache.PageCache) Predicate(java.util.function.Predicate) InetSocketAddress(java.net.InetSocketAddress) TransactionCommittingResponseUnpacker(org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker) UpdatePuller(org.neo4j.kernel.ha.UpdatePuller) UpdatePullerScheduler(org.neo4j.kernel.ha.UpdatePullerScheduler) Matchers.any(org.mockito.Matchers.any) Stream(java.util.stream.Stream) ClusterMemberAvailability(org.neo4j.cluster.member.ClusterMemberAvailability) Mockito.withSettings(org.mockito.Mockito.withSettings) RequestContextFactory(org.neo4j.kernel.ha.com.RequestContextFactory) SlaveUpdatePuller(org.neo4j.kernel.ha.SlaveUpdatePuller) Mockito.mock(org.mockito.Mockito.mock) BranchedDataException(org.neo4j.kernel.ha.BranchedDataException) BranchedDataPolicy(org.neo4j.kernel.ha.BranchedDataPolicy) MoveAfterCopy(org.neo4j.com.storecopy.MoveAfterCopy) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) PagedFile(org.neo4j.io.pagecache.PagedFile) Monitors(org.neo4j.kernel.monitoring.Monitors) HandshakeResult(org.neo4j.kernel.ha.com.master.HandshakeResult) JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) Mockito.spy(org.mockito.Mockito.spy) PullerFactory(org.neo4j.kernel.ha.PullerFactory) Matchers.anyString(org.mockito.Matchers.anyString) TransactionId(org.neo4j.kernel.impl.store.TransactionId) ClusterMembers(org.neo4j.kernel.ha.cluster.member.ClusterMembers) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) StoreLockerLifecycleAdapter(org.neo4j.kernel.internal.StoreLockerLifecycleAdapter) SlaveServer(org.neo4j.kernel.ha.com.slave.SlaveServer) HaIdGeneratorFactory(org.neo4j.kernel.ha.id.HaIdGeneratorFactory) CancellationRequest(org.neo4j.helpers.CancellationRequest) Matchers.anyLong(org.mockito.Matchers.anyLong) MapUtil.stringMap(org.neo4j.helpers.collection.MapUtil.stringMap) Lifecycle(org.neo4j.kernel.lifecycle.Lifecycle) Config(org.neo4j.kernel.configuration.Config) InOrder(org.mockito.InOrder) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) DataSourceManager(org.neo4j.kernel.impl.transaction.state.DataSourceManager) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) NullLogService(org.neo4j.kernel.impl.logging.NullLogService) Mockito.never(org.mockito.Mockito.never) IndexConfigStore(org.neo4j.kernel.impl.index.IndexConfigStore) Assert.assertNull(org.junit.Assert.assertNull) ClusterSettings(org.neo4j.cluster.ClusterSettings) StoreCopyClient(org.neo4j.com.storecopy.StoreCopyClient) TransactionStats(org.neo4j.kernel.impl.transaction.TransactionStats) ClusterMember(org.neo4j.kernel.ha.cluster.member.ClusterMember) FileSystemWatcherService(org.neo4j.kernel.impl.util.watcher.FileSystemWatcherService) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) HandshakeResult(org.neo4j.kernel.ha.com.master.HandshakeResult) TransactionObligationFulfiller(org.neo4j.com.storecopy.TransactionObligationFulfiller) InetSocketAddress(java.net.InetSocketAddress) OnlineBackupKernelExtension(org.neo4j.backup.OnlineBackupKernelExtension) ClusterMembers(org.neo4j.kernel.ha.cluster.member.ClusterMembers) DataSourceManager(org.neo4j.kernel.impl.transaction.state.DataSourceManager) SlaveServer(org.neo4j.kernel.ha.com.slave.SlaveServer) ClusterMember(org.neo4j.kernel.ha.cluster.member.ClusterMember) StoreId(org.neo4j.kernel.impl.store.StoreId) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) Dependencies(org.neo4j.kernel.impl.util.Dependencies) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) InstanceId(org.neo4j.cluster.InstanceId) NeoStoreDataSource(org.neo4j.kernel.NeoStoreDataSource) IndexConfigStore(org.neo4j.kernel.impl.index.IndexConfigStore) TransactionCommittingResponseUnpacker(org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker) TransactionId(org.neo4j.kernel.impl.store.TransactionId) MasterClientResolver(org.neo4j.kernel.ha.com.slave.MasterClientResolver) TransactionStats(org.neo4j.kernel.impl.transaction.TransactionStats) FileSystemWatcherService(org.neo4j.kernel.impl.util.watcher.FileSystemWatcherService) Monitors(org.neo4j.kernel.monitoring.Monitors) StoreLockerLifecycleAdapter(org.neo4j.kernel.internal.StoreLockerLifecycleAdapter) PagedFile(org.neo4j.io.pagecache.PagedFile) File(java.io.File)

Example 12 with PageCache

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

the class SwitchToSlaveCopyThenBranchTest method shouldNotBranchStoreUnlessWeHaveCopiedDownAReplacement.

@Test
public void shouldNotBranchStoreUnlessWeHaveCopiedDownAReplacement() throws Throwable {
    // Given
    StoreCopyClient storeCopyClient = mock(StoreCopyClient.class);
    doAnswer(invocation -> {
        MoveAfterCopy moveAfterCopy = invocation.getArgumentAt(2, MoveAfterCopy.class);
        moveAfterCopy.move(Stream.empty(), new File(""), new File(""));
        return null;
    }).when(storeCopyClient).copyStore(any(StoreCopyClient.StoreCopyRequester.class), any(CancellationRequest.class), any(MoveAfterCopy.class));
    PageCache pageCacheMock = mock(PageCache.class);
    PagedFile pagedFileMock = mock(PagedFile.class);
    when(pagedFileMock.getLastPageId()).thenReturn(1L);
    when(pageCacheMock.map(any(File.class), anyInt())).thenReturn(pagedFileMock);
    SwitchToSlaveCopyThenBranch switchToSlave = newSwitchToSlaveSpy(pageCacheMock, storeCopyClient);
    URI masterUri = new URI("cluster://localhost?serverId=1");
    URI me = new URI("cluster://localhost?serverId=2");
    CancellationRequest cancellationRequest = CancellationRequest.NEVER_CANCELLED;
    MasterClient masterClient = mock(MasterClient.class);
    when(masterClient.handshake(anyLong(), any(StoreId.class))).thenThrow(new BranchedDataException(""));
    TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
    when(transactionIdStore.getLastCommittedTransaction()).thenReturn(new TransactionId(42, 42, 42));
    when(transactionIdStore.getLastCommittedTransactionId()).thenReturn(TransactionIdStore.BASE_TX_ID);
    // When
    BranchedDataPolicy branchPolicy = mock(BranchedDataPolicy.class);
    switchToSlave.stopServicesAndHandleBranchedStore(branchPolicy, masterUri, me, cancellationRequest);
    // Then
    InOrder inOrder = Mockito.inOrder(storeCopyClient, branchPolicy);
    inOrder.verify(storeCopyClient).copyStore(any(StoreCopyClient.StoreCopyRequester.class), any(CancellationRequest.class), any(MoveAfterCopy.class));
    inOrder.verify(branchPolicy).handle(new File(""), pageCacheMock, NullLogService.getInstance());
}
Also used : PagedFile(org.neo4j.io.pagecache.PagedFile) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) InOrder(org.mockito.InOrder) MasterClient(org.neo4j.kernel.ha.com.slave.MasterClient) URI(java.net.URI) TransactionId(org.neo4j.kernel.impl.store.TransactionId) StoreId(org.neo4j.kernel.impl.store.StoreId) StoreCopyClient(org.neo4j.com.storecopy.StoreCopyClient) BranchedDataPolicy(org.neo4j.kernel.ha.BranchedDataPolicy) PagedFile(org.neo4j.io.pagecache.PagedFile) File(java.io.File) BranchedDataException(org.neo4j.kernel.ha.BranchedDataException) MoveAfterCopy(org.neo4j.com.storecopy.MoveAfterCopy) CancellationRequest(org.neo4j.helpers.CancellationRequest) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 13 with PageCache

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

the class SwitchToSlaveCopyThenBranchTest method shouldRestartServicesIfCopyStoreFails.

@Test
public void shouldRestartServicesIfCopyStoreFails() throws Throwable {
    when(updatePuller.tryPullUpdates()).thenReturn(true);
    PageCache pageCacheMock = mockPageCache();
    StoreCopyClient storeCopyClient = mock(StoreCopyClient.class);
    doThrow(new RuntimeException()).doNothing().when(storeCopyClient).copyStore(any(StoreCopyClient.StoreCopyRequester.class), any(CancellationRequest.class), any(MoveAfterCopy.class));
    SwitchToSlaveCopyThenBranch switchToSlave = newSwitchToSlaveSpy(pageCacheMock, storeCopyClient);
    URI localhost = getLocalhostUri();
    try {
        switchToSlave.switchToSlave(mock(LifeSupport.class), localhost, localhost, mock(CancellationRequest.class));
        fail("Should have thrown an Exception");
    } catch (RuntimeException e) {
        verify(requestContextFactory, never()).start();
        // Store should have been deleted due to failure in copy
        verify(switchToSlave).cleanStoreDir();
        // Try again, should succeed
        switchToSlave.switchToSlave(mock(LifeSupport.class), localhost, localhost, mock(CancellationRequest.class));
        verify(requestContextFactory).start();
    }
}
Also used : LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) StoreCopyClient(org.neo4j.com.storecopy.StoreCopyClient) URI(java.net.URI) PageCache(org.neo4j.io.pagecache.PageCache) CancellationRequest(org.neo4j.helpers.CancellationRequest) MoveAfterCopy(org.neo4j.com.storecopy.MoveAfterCopy) Test(org.junit.Test)

Example 14 with PageCache

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

the class DumpStoreChain method dump.

void dump(File storeDir) throws IOException {
    try (DefaultFileSystemAbstraction fs = new DefaultFileSystemAbstraction();
        PageCache pageCache = createPageCache(fs)) {
        DefaultIdGeneratorFactory idGeneratorFactory = new DefaultIdGeneratorFactory(fs);
        Config config = Config.defaults();
        StoreFactory storeFactory = new StoreFactory(storeDir, config, idGeneratorFactory, pageCache, fs, logProvider());
        try (NeoStores neoStores = storeFactory.openNeoStores(getStoreTypes())) {
            RecordStore<RECORD> store = store(neoStores);
            RECORD record = store.newRecord();
            for (long next = first; next != -1; ) {
                store.getRecord(next, record, RecordLoad.FORCE);
                System.out.println(record);
                next = next(record);
            }
        }
    }
}
Also used : DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Config(org.neo4j.kernel.configuration.Config) NeoStores(org.neo4j.kernel.impl.store.NeoStores) DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) StandalonePageCacheFactory.createPageCache(org.neo4j.io.pagecache.impl.muninn.StandalonePageCacheFactory.createPageCache) PageCache(org.neo4j.io.pagecache.PageCache)

Example 15 with PageCache

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

the class StoreMigration method run.

public void run(final FileSystemAbstraction fs, final File storeDirectory, Config config, LogProvider userLogProvider) throws IOException {
    StoreLogService logService = StoreLogService.withUserLogProvider(userLogProvider).inLogsDirectory(fs, storeDirectory);
    VisibleMigrationProgressMonitor progressMonitor = new VisibleMigrationProgressMonitor(logService.getUserLog(StoreMigration.class));
    LifeSupport life = new LifeSupport();
    life.add(logService);
    // Add participants from kernel extensions...
    LegacyIndexProvider legacyIndexProvider = new LegacyIndexProvider();
    Log log = userLogProvider.getLog(StoreMigration.class);
    try (PageCache pageCache = createPageCache(fs, config)) {
        Dependencies deps = new Dependencies();
        deps.satisfyDependencies(fs, config, legacyIndexProvider, pageCache, logService);
        KernelContext kernelContext = new SimpleKernelContext(storeDirectory, DatabaseInfo.UNKNOWN, deps);
        KernelExtensions kernelExtensions = life.add(new KernelExtensions(kernelContext, GraphDatabaseDependencies.newDependencies().kernelExtensions(), deps, ignore()));
        // Add the kernel store migrator
        life.start();
        SchemaIndexProvider schemaIndexProvider = kernelExtensions.resolveDependency(SchemaIndexProvider.class, HighestSelectionStrategy.getInstance());
        LabelScanStoreProvider labelScanStoreProvider = kernelExtensions.resolveDependency(LabelScanStoreProvider.class, new NamedLabelScanStoreSelectionStrategy(config));
        long startTime = System.currentTimeMillis();
        DatabaseMigrator migrator = new DatabaseMigrator(progressMonitor, fs, config, logService, schemaIndexProvider, labelScanStoreProvider, legacyIndexProvider.getIndexProviders(), pageCache, RecordFormatSelector.selectForConfig(config, userLogProvider));
        migrator.migrate(storeDirectory);
        long duration = System.currentTimeMillis() - startTime;
        log.info(format("Migration completed in %d s%n", duration / 1000));
    } catch (Exception e) {
        throw new StoreUpgrader.UnableToUpgradeException("Failure during upgrade", e);
    } finally {
        life.shutdown();
    }
}
Also used : SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) LabelScanStoreProvider(org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider) VisibleMigrationProgressMonitor(org.neo4j.kernel.impl.storemigration.monitoring.VisibleMigrationProgressMonitor) StoreLogService(org.neo4j.kernel.impl.logging.StoreLogService) Log(org.neo4j.logging.Log) IOException(java.io.IOException) DatabaseMigrator(org.neo4j.kernel.impl.storemigration.DatabaseMigrator) KernelExtensions(org.neo4j.kernel.extension.KernelExtensions) SimpleKernelContext(org.neo4j.kernel.impl.spi.SimpleKernelContext) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) Dependencies(org.neo4j.kernel.impl.util.Dependencies) GraphDatabaseDependencies(org.neo4j.kernel.GraphDatabaseDependencies) StoreUpgrader(org.neo4j.kernel.impl.storemigration.StoreUpgrader) NamedLabelScanStoreSelectionStrategy(org.neo4j.kernel.extension.dependency.NamedLabelScanStoreSelectionStrategy) PageCache(org.neo4j.io.pagecache.PageCache) ConfigurableStandalonePageCacheFactory.createPageCache(org.neo4j.kernel.impl.pagecache.ConfigurableStandalonePageCacheFactory.createPageCache) SimpleKernelContext(org.neo4j.kernel.impl.spi.SimpleKernelContext) KernelContext(org.neo4j.kernel.impl.spi.KernelContext)

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