//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void recoverFirstCorruptedTransactionAfterCheckpointInLastLogFile() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void RecoverFirstCorruptedTransactionAfterCheckpointInLastLogFile() { GraphDatabaseAPI database = ( GraphDatabaseAPI )_databaseFactory.newEmbeddedDatabase(_storeDir); GenerateTransactionsAndRotate(database, 5); database.Shutdown(); File highestLogFile = _logFiles.HighestLogFile; long originalFileLength = highestLogFile.length(); AddCorruptedCommandsToLastLogFile(); long modifiedFileLength = highestLogFile.length(); assertThat(modifiedFileLength, greaterThan(originalFileLength)); database = StartDbNoRecoveryOfCorruptedLogs(); database.Shutdown(); _logProvider.rawMessageMatcher().assertContains("Fail to read transaction log version 5."); _logProvider.rawMessageMatcher().assertContains("Fail to read first transaction of log version 5."); _logProvider.rawMessageMatcher().assertContains("Recovery required from position LogPosition{logVersion=5, byteOffset=593}"); _logProvider.rawMessageMatcher().assertContains("Fail to recover all transactions. " + "Any later transactions after position LogPosition{logVersion=5, byteOffset=593} " + "are unreadable and will be truncated."); assertEquals(5, _logFiles.HighestLogVersion); ObjectLongMap <Type> logEntriesDistribution = GetLogEntriesDistribution(_logFiles); assertEquals(1, logEntriesDistribution.get(typeof(CheckPoint))); assertEquals(originalFileLength, highestLogFile.length()); }
private void GenerateInitialData() { GraphDatabaseBuilder builder = (new TestGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(_directory.databaseDir()); GraphDatabaseAPI graphDb = ( GraphDatabaseAPI )builder.SetConfig(GraphDatabaseSettings.record_format, _formatName).setConfig(GraphDatabaseSettings.label_block_size, "60").setConfig("dbms.backup.enabled", "false").newGraphDatabase(); try { GenerateInitialData(graphDb); StoreAccess stores = (new StoreAccess(graphDb.DependencyResolver.resolveDependency(typeof(RecordStorageEngine)).testAccessNeoStores())).initialize(); _schemaId = stores.SchemaStore.HighId; _nodeId = stores.NodeStore.HighId; _labelId = ( int )stores.LabelTokenStore.HighId; _nodeLabelsId = stores.NodeDynamicLabelStore.HighId; _relId = stores.RelationshipStore.HighId; _relGroupId = stores.RelationshipGroupStore.HighId; _propId = ( int )stores.PropertyStore.HighId; _stringPropId = stores.StringStore.HighId; _arrayPropId = stores.ArrayStore.HighId; _relTypeId = ( int )stores.RelationshipTypeTokenStore.HighId; _propKeyId = ( int )stores.PropertyKeyNameStore.HighId; } finally { graphDb.Shutdown(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void doNotTruncateNewerTransactionLogFileWhenFailOnError() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void DoNotTruncateNewerTransactionLogFileWhenFailOnError() { GraphDatabaseAPI database = ( GraphDatabaseAPI )_databaseFactory.newEmbeddedDatabase(_storeDir); for (int i = 0; i < 10; i++) { GenerateTransaction(database); } database.Shutdown(); RemoveLastCheckpointRecordFromLastLogFile(); AddRandomBytesToLastLogFile(this.randomPositiveBytes); _expectedException.expectCause(new RootCauseMatcher <>(typeof(UnsupportedLogVersionException))); database = ( GraphDatabaseAPI )_databaseFactory.newEmbeddedDatabase(_storeDir); database.Shutdown(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void verifyLogFilesWithCustomPathListing(String path) throws java.io.IOException private void VerifyLogFilesWithCustomPathListing(string path) { GraphDatabaseAPI graphDatabase = ( GraphDatabaseAPI )(new TestGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(TestDirectory.databaseDir("customDb")).setConfig(GraphDatabaseSettings.logical_logs_location, path).newGraphDatabase(); NeoStoreDataSource dataSource = graphDatabase.DependencyResolver.resolveDependency(typeof(NeoStoreDataSource)); LogFiles logFiles = graphDatabase.DependencyResolver.resolveDependency(typeof(LogFiles)); assertTrue(dataSource.ListStoreFiles(true).Any(metadata => metadata.LogFile && logFiles.IsLogFile(metadata.file()))); assertEquals(Paths.get(path).FileName.ToString(), logFiles.LogFilesDirectory().Name); graphDatabase.Shutdown(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void recoverNotAFirstCorruptedTransactionMultipleFilesNoCheckpoints() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void RecoverNotAFirstCorruptedTransactionMultipleFilesNoCheckpoints() { GraphDatabaseAPI database = ( GraphDatabaseAPI )_databaseFactory.newEmbeddedDatabase(_storeDir); TransactionIdStore transactionIdStore = GetTransactionIdStore(database); long lastClosedTransactionBeforeStart = transactionIdStore.LastClosedTransactionId; GenerateTransactionsAndRotate(database, 3); for (int i = 0; i < 7; i++) { GenerateTransaction(database); } long numberOfTransactions = transactionIdStore.LastClosedTransactionId - lastClosedTransactionBeforeStart; database.Shutdown(); LogFiles logFiles = BuildDefaultLogFiles(); File highestLogFile = logFiles.HighestLogFile; long originalFileLength = highestLogFile.length(); RemoveLastCheckpointRecordFromLastLogFile(); AddCorruptedCommandsToLastLogFile(); long modifiedFileLength = highestLogFile.length(); assertThat(modifiedFileLength, greaterThan(originalFileLength)); database = StartDbNoRecoveryOfCorruptedLogs(); database.Shutdown(); _logProvider.rawMessageMatcher().assertContains("Fail to read transaction log version 3."); _logProvider.rawMessageMatcher().assertContains("Recovery required from position LogPosition{logVersion=0, byteOffset=16}"); _logProvider.rawMessageMatcher().assertContains("Fail to recover all transactions."); _logProvider.rawMessageMatcher().assertContains("Any later transaction after LogPosition{logVersion=3, byteOffset=4632} are unreadable and will be truncated."); assertEquals(3, logFiles.HighestLogVersion); ObjectLongMap <Type> logEntriesDistribution = GetLogEntriesDistribution(logFiles); assertEquals(1, logEntriesDistribution.get(typeof(CheckPoint))); assertEquals(numberOfTransactions, _recoveryMonitor.NumberOfRecoveredTransactions); assertEquals(originalFileLength, highestLogFile.length()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void evenTruncateNewerTransactionLogFile() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void EvenTruncateNewerTransactionLogFile() { GraphDatabaseAPI database = ( GraphDatabaseAPI )_databaseFactory.newEmbeddedDatabase(_storeDir); TransactionIdStore transactionIdStore = GetTransactionIdStore(database); long lastClosedTransactionBeforeStart = transactionIdStore.LastClosedTransactionId; for (int i = 0; i < 10; i++) { GenerateTransaction(database); } long numberOfClosedTransactions = GetTransactionIdStore(database).LastClosedTransactionId - lastClosedTransactionBeforeStart; database.Shutdown(); RemoveLastCheckpointRecordFromLastLogFile(); AddRandomBytesToLastLogFile(this.randomBytes); database = StartDbNoRecoveryOfCorruptedLogs(); database.Shutdown(); assertEquals(numberOfClosedTransactions, _recoveryMonitor.NumberOfRecoveredTransactions); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void truncateNewerTransactionLogFileWhenForced() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void TruncateNewerTransactionLogFileWhenForced() { GraphDatabaseAPI database = ( GraphDatabaseAPI )_databaseFactory.newEmbeddedDatabase(_storeDir); for (int i = 0; i < 10; i++) { GenerateTransaction(database); } TransactionIdStore transactionIdStore = GetTransactionIdStore(database); long numberOfClosedTransactions = transactionIdStore.LastClosedTransactionId - 1; database.Shutdown(); RemoveLastCheckpointRecordFromLastLogFile(); AddRandomBytesToLastLogFile(this.randomBytes); database = StartDbNoRecoveryOfCorruptedLogs(); database.Shutdown(); _logProvider.rawMessageMatcher().assertContains("Fail to read transaction log version 0."); _logProvider.rawMessageMatcher().assertContains("Fail to read transaction log version 0. Last valid transaction start offset is: 5668."); assertEquals(numberOfClosedTransactions, _recoveryMonitor.NumberOfRecoveredTransactions); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void skipMigrationIfStoreFormatNotSpecifiedButIsAvailableInRuntime() internal virtual void SkipMigrationIfStoreFormatNotSpecifiedButIsAvailableInRuntime() { GraphDatabaseService database = StartDatabaseWithFormatUnspecifiedUpgrade(_storeDir, StandardV3_2.NAME); using (Transaction transaction = database.BeginTx()) { Node node = database.CreateNode(); node.SetProperty("a", "b"); transaction.Success(); } database.Shutdown(); GraphDatabaseAPI nonUpgradedStore = ( GraphDatabaseAPI )(new GraphDatabaseFactory()).newEmbeddedDatabase(_storeDir); RecordStorageEngine storageEngine = nonUpgradedStore.DependencyResolver.resolveDependency(typeof(RecordStorageEngine)); assertEquals(StandardV3_2.NAME, storageEngine.TestAccessNeoStores().RecordFormats.name()); nonUpgradedStore.Shutdown(); }
private long PopulatePrototype(File prototypePath) { GraphDatabaseAPI prototype = Db(prototypePath); long txId; try { foreach (Transaction transaction in _work) { transaction.applyTo(prototype); } } finally { txId = prototype.DependencyResolver.resolveDependency(typeof(MetaDataStore)).LastCommittedTransactionId; prototype.Shutdown(); } return(txId); }
internal virtual void RecoverWithDatabase(Path databaseDirectory, PageCache pageCache, Config config) { DatabaseLayout databaseLayout = DatabaseLayout.of(databaseDirectory.toFile()); IDictionary <string, string> configParams = config.Raw; configParams[GraphDatabaseSettings.logical_logs_location.name()] = databaseDirectory.ToString(); configParams[GraphDatabaseSettings.active_database.name()] = databaseLayout.DatabaseName; configParams[GraphDatabaseSettings.pagecache_warmup_enabled.name()] = Settings.FALSE; GraphDatabaseAPI targetDb = startTemporaryDb(databaseLayout.DatabaseDirectory(), pageCache, configParams); targetDb.Shutdown(); // as soon as recovery will be extracted we will not gonna need this File lockFile = databaseLayout.StoreLayout.storeLockFile(); if (lockFile.exists()) { FileUtils.deleteFile(lockFile); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void repetitiveRecoveryIfCorruptedLogsWithCheckpoints() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void RepetitiveRecoveryIfCorruptedLogsWithCheckpoints() { GraphDatabaseAPI database = ( GraphDatabaseAPI )_databaseFactory.newEmbeddedDatabase(_storeDir); GenerateTransactionsAndRotate(database, 4, true); database.Shutdown(); while (_logFiles.HighestLogVersion > 0) { int bytesToTrim = 1 + _random.Next(100); TruncateBytesFromLastLogFile(bytesToTrim); _databaseFactory.newEmbeddedDatabase(_storeDir).shutdown(); int numberOfRecoveredTransactions = _recoveryMonitor.NumberOfRecoveredTransactions; assertThat(numberOfRecoveredTransactions, Matchers.greaterThanOrEqualTo(0)); } File corruptedLogArchives = new File(_storeDir, CorruptedLogsTruncator.CORRUPTED_TX_LOGS_BASE_NAME); assertThat(corruptedLogArchives.listFiles(), not(emptyArray())); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void repetitiveRecoveryOfCorruptedLogs() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void RepetitiveRecoveryOfCorruptedLogs() { GraphDatabaseAPI database = ( GraphDatabaseAPI )_databaseFactory.newEmbeddedDatabase(_storeDir); GenerateTransactionsAndRotate(database, 4, false); database.Shutdown(); RemoveLastCheckpointRecordFromLastLogFile(); int expectedRecoveredTransactions = 7; while (expectedRecoveredTransactions > 0) { TruncateBytesFromLastLogFile(1 + _random.Next(10)); _databaseFactory.newEmbeddedDatabase(_storeDir).shutdown(); int numberOfRecoveredTransactions = _recoveryMonitor.NumberOfRecoveredTransactions; assertEquals(expectedRecoveredTransactions, numberOfRecoveredTransactions); expectedRecoveredTransactions--; RemoveLastCheckpointRecordFromLastLogFile(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void crashAndRebuildSlowWithDynamicStringDeletions() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void CrashAndRebuildSlowWithDynamicStringDeletions() { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.kernel.internal.GraphDatabaseAPI db = (org.neo4j.kernel.internal.GraphDatabaseAPI) new org.neo4j.test.TestGraphDatabaseFactory().setFileSystem(fs.get()).newImpermanentDatabaseBuilder(testDir.databaseDir()).setConfig(org.neo4j.graphdb.factory.GraphDatabaseSettings.record_id_batch_size, "1").newGraphDatabase(); GraphDatabaseAPI db = ( GraphDatabaseAPI )(new TestGraphDatabaseFactory()).setFileSystem(Fs.get()).newImpermanentDatabaseBuilder(TestDir.databaseDir()).setConfig(GraphDatabaseSettings.record_id_batch_size, "1").newGraphDatabase(); IList <long> deletedNodeIds = ProduceNonCleanDefraggedStringStore(db); IDictionary <IdType, long> highIdsBeforeCrash = GetHighIds(db); // Make sure all of our changes are actually written to the files, since any background flushing could // mess up the check-sums in non-deterministic ways Db.DependencyResolver.resolveDependency(typeof(PageCache)).flushAndForce(); long checksumBefore = Fs.get().checksum(); long checksumBefore2 = Fs.get().checksum(); assertThat(checksumBefore, Matchers.equalTo(checksumBefore2)); EphemeralFileSystemAbstraction snapshot = Fs.snapshot(Db.shutdown); long snapshotChecksum = snapshot.Checksum(); if (snapshotChecksum != checksumBefore) { using (Stream @out = new FileStream(TestDir.file("snapshot.zip"), FileMode.Create, FileAccess.Write)) { snapshot.DumpZip(@out); } using (Stream @out = new FileStream(TestDir.file("fs.zip"), FileMode.Create, FileAccess.Write)) { Fs.get().dumpZip(@out); } } assertThat(snapshotChecksum, equalTo(checksumBefore)); // Recover with unsupported.dbms.id_generator_fast_rebuild_enabled=false AssertNumberOfFreeIdsEquals(TestDir.databaseDir(), snapshot, 0); GraphDatabaseAPI newDb = ( GraphDatabaseAPI )(new TestGraphDatabaseFactory()).setFileSystem(snapshot).newImpermanentDatabaseBuilder(TestDir.databaseDir()).setConfig(GraphDatabaseSettings.rebuild_idgenerators_fast, FALSE).newGraphDatabase(); IDictionary <IdType, long> highIdsAfterCrash = GetHighIds(newDb); assertEquals(highIdsBeforeCrash, highIdsAfterCrash); try { using (Transaction tx = newDb.BeginTx()) { // Verify that the data we didn't delete is still around int nameCount = 0; int relCount = 0; foreach (Node node in newDb.AllNodes) { nameCount++; assertThat(node, inTx(newDb, hasProperty("name"), true)); relCount += ( int )Iterables.count(node.GetRelationships(Direction.OUTGOING)); } assertEquals(16, nameCount); assertEquals(12, relCount); // Verify that the ids of the nodes we deleted are reused IList <long> newIds = new List <long>(); newIds.Add(newDb.CreateNode().Id); newIds.Add(newDb.CreateNode().Id); newIds.Add(newDb.CreateNode().Id); newIds.Add(newDb.CreateNode().Id); assertThat(newIds, @is(deletedNodeIds)); tx.Success(); } } finally { newDb.Shutdown(); snapshot.Dispose(); } }