Search in sources :

Example 11 with NeoStoreDataSource

use of org.neo4j.kernel.NeoStoreDataSource in project neo4j by neo4j.

the class DefaultUdcInformationCollectorTest method shouldReportStoreSizes.

@Test
public void shouldReportStoreSizes() throws Throwable {
    DataSourceManager dataSourceManager = new DataSourceManager();
    NeoStoreDataSource dataSource = mock(NeoStoreDataSource.class);
    dataSourceManager.start();
    UdcInformationCollector collector = new DefaultUdcInformationCollector(Config.empty(), dataSourceManager, new StubIdGeneratorFactory(), mock(StartupStatistics.class), usageData);
    when(dataSource.getStoreId()).thenReturn(StoreId.DEFAULT);
    dataSourceManager.register(dataSource);
    when(dataSource.listStoreFiles(false)).thenReturn(asResourceIterator(testFiles().iterator()));
    Map<String, String> udcParams = collector.getUdcParams();
    assertThat(udcParams.get("storesize"), is("152"));
}
Also used : NeoStoreDataSource(org.neo4j.kernel.NeoStoreDataSource) DataSourceManager(org.neo4j.kernel.impl.transaction.state.DataSourceManager) StartupStatistics(org.neo4j.kernel.impl.core.StartupStatistics) Test(org.junit.Test)

Example 12 with NeoStoreDataSource

use of org.neo4j.kernel.NeoStoreDataSource in project neo4j by neo4j.

the class SwitchToSlave method switchToSlave.

/**
     * Performs a switch to the slave state. Starts the communication endpoints, switches components to the slave state
     * and ensures that the current database is appropriate for this cluster. It also broadcasts the appropriate
     * Slave Is Available event
     *
     * @param haCommunicationLife The LifeSupport instance to register the network facilities required for
     *                            communication with the rest of the cluster
     * @param me The URI this instance must bind to
     * @param masterUri The URI of the master for which this instance must become slave to
     * @param cancellationRequest A handle for gracefully aborting the switch
     * @return The URI that was broadcasted as the slave endpoint or null if the task was cancelled
     */
public URI switchToSlave(LifeSupport haCommunicationLife, URI me, URI masterUri, CancellationRequest cancellationRequest) throws Throwable {
    URI slaveUri;
    boolean success = false;
    monitor.switchToSlaveStarted();
    // Wait a short while for current transactions to stop first, just to be nice.
    // We can't wait forever since switching to our designated role is quite important.
    Clock clock = Clocks.systemClock();
    long deadline = clock.millis() + config.get(HaSettings.internal_state_switch_timeout);
    while (transactionCounters.getNumberOfActiveTransactions() > 0 && clock.millis() < deadline) {
        parkNanos(MILLISECONDS.toNanos(10));
    }
    try {
        InstanceId myId = config.get(ClusterSettings.server_id);
        userLog.info("ServerId %s, moving to slave for master %s", myId, masterUri);
        // since we are here it must already have been set from outside
        assert masterUri != null;
        idGeneratorFactory.switchToSlave();
        copyStoreFromMasterIfNeeded(masterUri, me, cancellationRequest);
        /*
             * The following check is mandatory, since the store copy can be cancelled and if it was actually
             * happening then we can't continue, as there is no store in place
             */
        if (cancellationRequest.cancellationRequested()) {
            msgLog.info("Switch to slave cancelled during store copy if no local store is present.");
            return null;
        }
        /*
             * We get here either with a fresh store from the master copy above so we need to
             * start the ds or we already had a store, so we have already started the ds. Either way,
             * make sure it's there.
             */
        NeoStoreDataSource neoDataSource = neoDataSourceSupplier.get();
        neoDataSource.afterModeSwitch();
        StoreId myStoreId = neoDataSource.getStoreId();
        boolean consistencyChecksExecutedSuccessfully = executeConsistencyChecks(transactionIdStoreSupplier.get(), masterUri, me, myStoreId, cancellationRequest);
        if (!consistencyChecksExecutedSuccessfully) {
            msgLog.info("Switch to slave cancelled due to consistency check failure.");
            return null;
        }
        if (cancellationRequest.cancellationRequested()) {
            msgLog.info("Switch to slave cancelled after consistency checks.");
            return null;
        }
        // no exception were thrown and we can proceed
        slaveUri = startHaCommunication(haCommunicationLife, neoDataSource, me, masterUri, myStoreId, cancellationRequest);
        if (slaveUri == null) {
            msgLog.info("Switch to slave unable to connect.");
            return null;
        }
        success = true;
        userLog.info("ServerId %s, successfully moved to slave for master %s", myId, masterUri);
    } finally {
        monitor.switchToSlaveCompleted(success);
    }
    return slaveUri;
}
Also used : StoreId(org.neo4j.kernel.impl.store.StoreId) InstanceId(org.neo4j.cluster.InstanceId) ClusterMembers.hasInstanceId(org.neo4j.kernel.ha.cluster.member.ClusterMembers.hasInstanceId) NeoStoreDataSource(org.neo4j.kernel.NeoStoreDataSource) Clock(java.time.Clock) URI(java.net.URI)

Example 13 with NeoStoreDataSource

use of org.neo4j.kernel.NeoStoreDataSource in project neo4j by neo4j.

the class TestBranchedData method gatherLuceneFiles.

private Collection<File> gatherLuceneFiles(HighlyAvailableGraphDatabase db, String indexName) throws IOException {
    Collection<File> result = new ArrayList<>();
    NeoStoreDataSource ds = db.getDependencyResolver().resolveDependency(NeoStoreDataSource.class);
    try (ResourceIterator<StoreFileMetadata> files = ds.listStoreFiles(false)) {
        while (files.hasNext()) {
            File file = files.next().file();
            if (file.getPath().contains(indexName)) {
                result.add(file);
            }
        }
    }
    return result;
}
Also used : NeoStoreDataSource(org.neo4j.kernel.NeoStoreDataSource) ArrayList(java.util.ArrayList) StoreFileMetadata(org.neo4j.storageengine.api.StoreFileMetadata) File(java.io.File)

Example 14 with NeoStoreDataSource

use of org.neo4j.kernel.NeoStoreDataSource in project neo4j by neo4j.

the class DataSourceManagerTest method shouldSupportMultipleStartStopCycles.

@Test
public void shouldSupportMultipleStartStopCycles() throws Throwable {
    // given
    DataSourceManager manager = new DataSourceManager();
    NeoStoreDataSource dataSource = mock(NeoStoreDataSource.class);
    manager.register(dataSource);
    manager.init();
    // when
    manager.start();
    manager.stop();
    manager.start();
    // then
    verify(dataSource, times(2)).start();
}
Also used : NeoStoreDataSource(org.neo4j.kernel.NeoStoreDataSource) Test(org.junit.Test)

Example 15 with NeoStoreDataSource

use of org.neo4j.kernel.NeoStoreDataSource in project neo4j by neo4j.

the class DependencyResolverSupplierTest method shouldReturnNullIfDataSourceHasBeenUnregistered.

@Test
public void shouldReturnNullIfDataSourceHasBeenUnregistered() throws Exception {
    // given
    DataSourceManager dataSourceManager = new DataSourceManager();
    DependencyResolverSupplier supplier = new DependencyResolverSupplier(dataSourceManager);
    NeoStoreDataSource neoStoreDataSource = mock(NeoStoreDataSource.class);
    DependencyResolver dependencyResolver = mock(DependencyResolver.class);
    when(neoStoreDataSource.getDependencyResolver()).thenReturn(dependencyResolver);
    dataSourceManager.register(neoStoreDataSource);
    // when
    dataSourceManager.unregister(neoStoreDataSource);
    // then
    assertEquals(null, supplier.get());
}
Also used : NeoStoreDataSource(org.neo4j.kernel.NeoStoreDataSource) DependencyResolverSupplier(org.neo4j.kernel.impl.transaction.state.DataSourceManager.DependencyResolverSupplier) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Test(org.junit.Test)

Aggregations

NeoStoreDataSource (org.neo4j.kernel.NeoStoreDataSource)16 Test (org.junit.Test)9 Monitors (org.neo4j.kernel.monitoring.Monitors)5 File (java.io.File)4 URI (java.net.URI)4 InstanceId (org.neo4j.cluster.InstanceId)4 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)4 PageCache (org.neo4j.io.pagecache.PageCache)4 StoreId (org.neo4j.kernel.impl.store.StoreId)4 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)4 IOException (java.io.IOException)3 InetSocketAddress (java.net.InetSocketAddress)3 ClusterMemberAvailability (org.neo4j.cluster.member.ClusterMemberAvailability)3 DataSourceManager (org.neo4j.kernel.impl.transaction.state.DataSourceManager)3 URISyntaxException (java.net.URISyntaxException)2 TimeUnit (java.util.concurrent.TimeUnit)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 DependencyResolver (org.neo4j.graphdb.DependencyResolver)2 PagedFile (org.neo4j.io.pagecache.PagedFile)2 AvailabilityGuard (org.neo4j.kernel.AvailabilityGuard)2