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());
}
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();
}
}
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);
}
}
}
}
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();
}
}
use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.
the class RsdrMain method main.
public static void main(String[] args) throws IOException {
try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction()) {
console.printf("Neo4j Raw Store Diagnostics Reader%n");
if (args.length != 1 || !fileSystem.isDirectory(new File(args[0]))) {
console.printf("Usage: rsdr <store directory>%n");
return;
}
File storedir = new File(args[0]);
Config config = buildConfig();
try (PageCache pageCache = createPageCache(fileSystem, config)) {
File neoStore = new File(storedir, MetaDataStore.DEFAULT_NAME);
StoreFactory factory = openStore(fileSystem, neoStore, config, pageCache);
NeoStores neoStores = factory.openAllNeoStores();
interact(fileSystem, neoStores);
}
}
}
Aggregations