use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.
the class StoreUpgraderInterruptionTestIT method shouldSucceedWithUpgradeAfterPreviousAttemptDiedDuringMovingFiles.
@Test
public void shouldSucceedWithUpgradeAfterPreviousAttemptDiedDuringMovingFiles() throws IOException, ConsistencyCheckIncompleteException {
File workingDirectory = directory.directory("working");
File prepareDirectory = directory.directory("prepare");
MigrationTestUtils.prepareSampleLegacyDatabase(version, fs, workingDirectory, prepareDirectory);
PageCache pageCache = pageCacheRule.getPageCache(fs);
StoreVersionCheck check = new StoreVersionCheck(pageCache);
UpgradableDatabase upgradableDatabase = new UpgradableDatabase(fs, check, new LegacyStoreVersionCheck(fs), Standard.LATEST_RECORD_FORMATS);
SilentMigrationProgressMonitor progressMonitor = new SilentMigrationProgressMonitor();
LogService logService = NullLogService.getInstance();
StoreMigrator failingStoreMigrator = new StoreMigrator(fs, pageCache, CONFIG, logService, schemaIndexProvider) {
@Override
public void moveMigratedFiles(File migrationDir, File storeDir, String versionToUpgradeFrom, String versionToMigrateTo) throws IOException {
super.moveMigratedFiles(migrationDir, storeDir, versionToUpgradeFrom, versionToMigrateTo);
throw new RuntimeException("This upgrade is failing");
}
};
assertEquals(!StandardV2_3.STORE_VERSION.equals(version), allLegacyStoreFilesHaveVersion(fs, workingDirectory, version));
try {
newUpgrader(upgradableDatabase, pageCache, progressMonitor, createIndexMigrator(), failingStoreMigrator).migrateIfNeeded(workingDirectory);
fail("Should throw exception");
} catch (RuntimeException e) {
assertEquals("This upgrade is failing", e.getMessage());
}
assertTrue(checkNeoStoreHasDefaultFormatVersion(check, workingDirectory));
assertTrue(allStoreFilesHaveNoTrailer(fs, workingDirectory));
progressMonitor = new SilentMigrationProgressMonitor();
StoreMigrator migrator = new StoreMigrator(fs, pageCache, CONFIG, logService, schemaIndexProvider);
newUpgrader(upgradableDatabase, pageCache, progressMonitor, createIndexMigrator(), migrator).migrateIfNeeded(workingDirectory);
assertTrue(checkNeoStoreHasDefaultFormatVersion(check, workingDirectory));
assertTrue(allStoreFilesHaveNoTrailer(fs, workingDirectory));
pageCache.close();
// Since consistency checker is in read only mode we need to start/stop db to generate label scan store.
startStopDatabase(workingDirectory);
assertConsistentStore(workingDirectory);
}
use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.
the class StoreUpgraderTest method shouldLeaveAllFilesUntouchedIfWrongVersionNumberFound.
@Test
public void shouldLeaveAllFilesUntouchedIfWrongVersionNumberFound() throws IOException {
Set<String> applicableVersions = versionSet(StandardV2_0.STORE_VERSION, StandardV2_1.STORE_VERSION, StandardV2_2.STORE_VERSION);
assumeTrue("Applicable only to specified version set.", applicableVersions.contains(version));
File comparisonDirectory = new File("target/" + StoreUpgraderTest.class.getSimpleName() + "shouldLeaveAllFilesUntouchedIfWrongVersionNumberFound-comparison");
changeVersionNumber(fileSystem, new File(dbDirectory, "neostore.nodestore.db"), "v0.9.5");
fileSystem.deleteRecursively(comparisonDirectory);
fileSystem.copyRecursively(dbDirectory, comparisonDirectory);
PageCache pageCache = pageCacheRule.getPageCache(fileSystem);
UpgradableDatabase upgradableDatabase = new UpgradableDatabase(fileSystem, new StoreVersionCheck(pageCache), new LegacyStoreVersionCheck(fileSystem), getRecordFormats());
try {
newUpgrader(upgradableDatabase, pageCache).migrateIfNeeded(dbDirectory);
fail("Should throw exception");
} catch (StoreUpgrader.UnexpectedUpgradingStoreVersionException e) {
// expected
}
verifyFilesHaveSameContent(fileSystem, comparisonDirectory, dbDirectory);
}
use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.
the class StoreUpgraderTest method shouldHaltUpgradeIfUpgradeConfigurationVetoesTheProcess.
@Test
public void shouldHaltUpgradeIfUpgradeConfigurationVetoesTheProcess() throws IOException {
PageCache pageCache = pageCacheRule.getPageCache(fileSystem);
Config deniedMigrationConfig = Config.embeddedDefaults(MapUtil.stringMap(GraphDatabaseSettings.allow_store_upgrade.name(), "false"));
UpgradableDatabase upgradableDatabase = new UpgradableDatabase(fileSystem, new StoreVersionCheck(pageCache), new LegacyStoreVersionCheck(fileSystem), getRecordFormats());
try {
newUpgrader(upgradableDatabase, deniedMigrationConfig, pageCache).migrateIfNeeded(dbDirectory);
fail("Should throw exception");
} catch (UpgradeNotAllowedByConfigurationException e) {
// expected
}
}
use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.
the class DatabaseStartupTest method startTheDatabaseWithWrongVersionShouldFailWithUpgradeNotAllowed.
@Test
public void startTheDatabaseWithWrongVersionShouldFailWithUpgradeNotAllowed() throws Throwable {
// given
// create a store
File storeDir = testDirectory.graphDbDir();
GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase(storeDir);
try (Transaction tx = db.beginTx()) {
db.createNode();
tx.success();
}
db.shutdown();
// mess up the version in the metadatastore
try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
PageCache pageCache = StandalonePageCacheFactory.createPageCache(fileSystem)) {
MetaDataStore.setRecord(pageCache, new File(storeDir, MetaDataStore.DEFAULT_NAME), MetaDataStore.Position.STORE_VERSION, MetaDataStore.versionStringToLong("bad"));
}
// when
try {
new TestGraphDatabaseFactory().newEmbeddedDatabase(storeDir);
fail("It should have failed.");
} catch (RuntimeException ex) {
// then
assertTrue(ex.getCause() instanceof LifecycleException);
assertTrue(ex.getCause().getCause() instanceof UpgradeNotAllowedByConfigurationException);
assertEquals("Failed to start Neo4j with an older data store version. To enable automatic upgrade, " + "please set configuration parameter \"dbms.allow_format_migration=true\"", ex.getCause().getCause().getMessage());
}
}
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));
}
Aggregations