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"));
}
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;
}
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;
}
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();
}
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());
}
Aggregations