Exemplo n.º 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void nonRecoveredDatabase() throws java.io.IOException
        private void NonRecoveredDatabase()
        {
            File tmpLogDir = new File(_testDirectory.directory(), "logs");

            _fs.mkdir(tmpLogDir);
            File             storeDir = _testDirectory.databaseDir();
            GraphDatabaseAPI db       = ( GraphDatabaseAPI )(new TestGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(storeDir).setConfig(GraphDatabaseSettings.record_format, RecordFormatName).setConfig("dbms.backup.enabled", "false").newGraphDatabase();

            RelationshipType relationshipType = RelationshipType.withName("testRelationshipType");

            using (Transaction tx = Db.beginTx())
            {
                Node node1 = set(Db.createNode());
                Node node2 = set(Db.createNode(), property("key", "value"));
                node1.CreateRelationshipTo(node2, relationshipType);
                tx.Success();
            }
            File[] txLogs = LogFilesBuilder.logFilesBasedOnlyBuilder(storeDir, _fs).build().logFiles();
            foreach (File file in txLogs)
            {
                _fs.copyToDirectory(file, tmpLogDir);
            }
            Db.shutdown();
            foreach (File txLog in txLogs)
            {
                _fs.deleteFile(txLog);
            }

            foreach (File file in LogFilesBuilder.logFilesBasedOnlyBuilder(tmpLogDir, _fs).build().logFiles())
            {
                _fs.moveToDirectory(file, storeDir);
            }
        }
Exemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void pullRotatesWhenThresholdCrossedAndExplicitlySet() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void PullRotatesWhenThresholdCrossedAndExplicitlySet()
        {
            // given
            Config config = Config.defaults();

            config.Augment(GraphDatabaseSettings.logical_log_rotation_threshold, "1M");                 // 1 mebibyte

            // and
            Org.Neo4j.Storageengine.Api.StoreId storeId = SimulateStoreCopy();

            // and
            long fromTxId = BASE_TX_ID;
            TransactionLogCatchUpWriter subject = new TransactionLogCatchUpWriter(_databaseLayout, _fs, _pageCache, config, NullLogProvider.Instance, fromTxId, PartOfStoreCopyConflict, false, true);

            // when a bunch of transactions received
            LongStream.range(fromTxId, _manyTransactions).mapToObj(TransactionLogCatchUpWriterTest.tx).map(tx => new TxPullResponse(ToCasualStoreId(storeId), tx)).forEach(subject.onTxReceived);
            subject.Close();

            // then there was a rotation
            LogFilesBuilder logFilesBuilder = LogFilesBuilder.activeFilesBuilder(_databaseLayout, _fs, _pageCache);
            LogFiles        logFiles        = logFilesBuilder.Build();

            assertNotEquals(logFiles.LowestLogVersion, logFiles.HighestLogVersion);
            VerifyTransactionsInLog(logFiles, fromTxId, _manyTransactions);
            VerifyCheckpointInLog(logFiles, PartOfStoreCopyConflict);
        }
Exemplo n.º 3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: org.neo4j.kernel.impl.transaction.log.LogPosition extractTransactionLogPosition(java.io.File neoStore, org.neo4j.io.layout.DatabaseLayout sourceDirectoryStructure, long lastTxId) throws java.io.IOException
        internal virtual LogPosition ExtractTransactionLogPosition(File neoStore, DatabaseLayout sourceDirectoryStructure, long lastTxId)
        {
            long lastClosedTxLogVersion    = MetaDataStore.getRecord(_pageCache, neoStore, MetaDataStore.Position.LAST_CLOSED_TRANSACTION_LOG_VERSION);
            long lastClosedTxLogByteOffset = MetaDataStore.getRecord(_pageCache, neoStore, MetaDataStore.Position.LAST_CLOSED_TRANSACTION_LOG_BYTE_OFFSET);

            if (lastClosedTxLogVersion != MetaDataRecordFormat.FIELD_NOT_PRESENT && lastClosedTxLogByteOffset != MetaDataRecordFormat.FIELD_NOT_PRESENT)
            {
                return(new LogPosition(lastClosedTxLogVersion, lastClosedTxLogByteOffset));
            }

            // The legacy store we're migrating doesn't have this record in neostore so try to extract it from tx log
            if (lastTxId == Org.Neo4j.Kernel.impl.transaction.log.TransactionIdStore_Fields.BASE_TX_ID)
            {
                return(new LogPosition(BASE_TX_LOG_VERSION, BASE_TX_LOG_BYTE_OFFSET));
            }

            LogFiles logFiles   = LogFilesBuilder.activeFilesBuilder(sourceDirectoryStructure, _fileSystem, _pageCache).withConfig(_config).build();
            long     logVersion = logFiles.HighestLogVersion;

            if (logVersion == -1)
            {
                return(new LogPosition(BASE_TX_LOG_VERSION, BASE_TX_LOG_BYTE_OFFSET));
            }
            long offset = _fileSystem.getFileSize(logFiles.HighestLogFile);

            return(new LogPosition(logVersion, offset));
        }
Exemplo n.º 4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void appendNullTransactionLogEntryToSetRaftIndexToMinusOne() throws java.io.IOException
        private void AppendNullTransactionLogEntryToSetRaftIndexToMinusOne()
        {
            ReadOnlyTransactionIdStore readOnlyTransactionIdStore = new ReadOnlyTransactionIdStore(_pageCache, _databaseLayout);
            LogFiles logFiles = LogFilesBuilder.activeFilesBuilder(_databaseLayout, _fs, _pageCache).withConfig(_config).withLastCommittedTransactionIdSupplier(() => readOnlyTransactionIdStore.LastClosedTransactionId - 1).build();

            long dummyTransactionId;

            using (Lifespan lifespan = new Lifespan(logFiles))
            {
                FlushableChannel     channel = logFiles.LogFile.Writer;
                TransactionLogWriter writer  = new TransactionLogWriter(new LogEntryWriter(channel));

                long lastCommittedTransactionId      = readOnlyTransactionIdStore.LastCommittedTransactionId;
                PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation(Collections.emptyList());
                sbyte[] txHeaderBytes = LogIndexTxHeaderEncoding.encodeLogIndexAsTxHeader(-1);
                tx.SetHeader(txHeaderBytes, -1, -1, -1, lastCommittedTransactionId, -1, -1);

                dummyTransactionId = lastCommittedTransactionId + 1;
                writer.Append(tx, dummyTransactionId);
                channel.PrepareForFlush().flush();
            }

            File neoStoreFile = _databaseLayout.metadataStore();

            MetaDataStore.setRecord(_pageCache, neoStoreFile, LAST_TRANSACTION_ID, dummyTransactionId);
        }
Exemplo n.º 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldOpenCleanStore() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldOpenCleanStore()
        {
            // GIVEN
            TransactionIdStore       transactionIdStore = new SimpleTransactionIdStore();
            TransactionMetadataCache positionCache      = new TransactionMetadataCache();

            LifeSupport life = new LifeSupport();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.transaction.log.files.LogFiles logFiles = org.neo4j.kernel.impl.transaction.log.files.LogFilesBuilder.builder(dir.databaseLayout(), fileSystemRule.get()).withTransactionIdStore(transactionIdStore).withLogVersionRepository(mock(LogVersionRepository.class)).build();
            LogFiles logFiles = LogFilesBuilder.builder(Dir.databaseLayout(), FileSystemRule.get()).withTransactionIdStore(transactionIdStore).withLogVersionRepository(mock(typeof(LogVersionRepository))).build();

            life.Add(logFiles);

            life.Add(new BatchingTransactionAppender(logFiles, NO_ROTATION, positionCache, transactionIdStore, BYPASS, _databaseHealth));

            try
            {
                // WHEN
                life.Start();
            }
            finally
            {
                life.Shutdown();
            }
        }
Exemplo n.º 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void pruningStrategyShouldBeDynamic() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void PruningStrategyShouldBeDynamic()
        {
            CheckPointer          checkPointer = GetInstanceFromDb(typeof(CheckPointer));
            Config                config       = GetInstanceFromDb(typeof(Config));
            FileSystemAbstraction fs           = GetInstanceFromDb(typeof(FileSystemAbstraction));

            LogFiles logFiles = LogFilesBuilder.builder(Db.databaseLayout(), fs).withLogVersionRepository(new SimpleLogVersionRepository()).withLastCommittedTransactionIdSupplier(() => 1).withTransactionIdStore(new SimpleTransactionIdStore()).build();

            // Force transaction log rotation
            WriteTransactionsAndRotateTwice();

            // Checkpoint to make sure strategy is evaluated
            checkPointer.ForceCheckPoint(_triggerInfo);

            // Make sure file is still there since we have disable pruning
            assertThat(CountTransactionLogs(logFiles), @is(3));

            // Change pruning to true
            config.UpdateDynamicSetting(keep_logical_logs.name(), "false", "test");

            // Checkpoint to make sure strategy is evaluated
            checkPointer.ForceCheckPoint(_triggerInfo);

            // Make sure file is removed
            assertThat(CountTransactionLogs(logFiles), @is(2));
        }
Exemplo n.º 7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void createTransactionLogWithCheckpoint(org.neo4j.kernel.configuration.Config config, boolean logsInStoreDir) throws java.io.IOException
        private void CreateTransactionLogWithCheckpoint(Config config, bool logsInStoreDir)
        {
            Org.Neo4j.Storageengine.Api.StoreId storeId = SimulateStoreCopy();

            int fromTxId = 37;
            int endTxId  = fromTxId + 5;

            TransactionLogCatchUpWriter catchUpWriter = new TransactionLogCatchUpWriter(_databaseLayout, _fs, _pageCache, config, NullLogProvider.Instance, fromTxId, PartOfStoreCopyConflict, logsInStoreDir, true);

            // when
            for (int i = fromTxId; i <= endTxId; i++)
            {
                catchUpWriter.OnTxReceived(new TxPullResponse(ToCasualStoreId(storeId), Tx(i)));
            }

            catchUpWriter.Close();

            // then
            LogFilesBuilder logFilesBuilder = LogFilesBuilder.activeFilesBuilder(_databaseLayout, _fs, _pageCache);

            if (!logsInStoreDir)
            {
                logFilesBuilder.WithConfig(config);
            }
            LogFiles logFiles = logFilesBuilder.Build();

            VerifyTransactionsInLog(logFiles, fromTxId, endTxId);
            VerifyCheckpointInLog(logFiles, PartOfStoreCopyConflict);
        }
Exemplo n.º 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setUp() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SetUp()
        {
            _fs         = FileSystemRule.get();
            _pageCache  = PageCacheRule.getPageCache(_fs);
            _storeFiles = new StoreFiles(_fs, _pageCache);
            _logFiles   = LogFilesBuilder.logFilesBasedOnlyBuilder(TestDirectory.directory(), _fs).build();
        }
Exemplo n.º 9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void backupDatabaseWithCustomTransactionLogsLocation() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void BackupDatabaseWithCustomTransactionLogsLocation()
        {
            int backupPort          = PortAuthority.allocatePort();
            GraphDatabaseService db = StartGraphDatabase(_serverStorePath, true, backupPort, "customLogLocation");

            try
            {
                CreateInitialDataSet(db);

                OnlineBackup backup      = OnlineBackup.From("127.0.0.1", backupPort);
                string       backupStore = _backupDatabasePath.Path;
                LogFiles     logFiles    = LogFilesBuilder.logFilesBasedOnlyBuilder(new File(backupStore), _fileSystemRule.get()).build();

                backup.Full(backupStore);
                assertThat(logFiles.LogFilesConflict(), Matchers.arrayWithSize(1));

                DbRepresentation representation = AddLotsOfData(db);
                backup.Incremental(backupStore);
                assertThat(logFiles.LogFilesConflict(), Matchers.arrayWithSize(1));

                assertEquals(representation, DbRepresentation);
            }
            finally
            {
                Db.shutdown();
            }
        }
Exemplo n.º 10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void restoreTransactionLogsInCustomDirectoryForTargetDatabaseWhenConfigured() throws java.io.IOException, org.neo4j.commandline.admin.CommandFailed
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void RestoreTransactionLogsInCustomDirectoryForTargetDatabaseWhenConfigured()
        {
            string databaseName                  = "to";
            Config config                        = ConfigWith(databaseName, Directory.absolutePath().AbsolutePath);
            File   customTxLogDirectory          = Directory.directory("customLogicalLog");
            string customTransactionLogDirectory = customTxLogDirectory.AbsolutePath;

            config.AugmentDefaults(GraphDatabaseSettings.logical_logs_location, customTransactionLogDirectory);

            File fromPath      = new File(Directory.absolutePath(), "from");
            File toPath        = config.Get(GraphDatabaseSettings.database_path);
            int  fromNodeCount = 10;
            int  toNodeCount   = 20;

            CreateDbAt(fromPath, fromNodeCount);

            GraphDatabaseService db = CreateDatabase(toPath, customTransactionLogDirectory);

            CreateTestData(toNodeCount, db);
            Db.shutdown();

            // when
            (new RestoreDatabaseCommand(FileSystemRule.get(), fromPath, config, databaseName, true)).execute();

            LogFiles fromStoreLogFiles         = LogFilesBuilder.logFilesBasedOnlyBuilder(fromPath, FileSystemRule.get()).build();
            LogFiles toStoreLogFiles           = LogFilesBuilder.logFilesBasedOnlyBuilder(toPath, FileSystemRule.get()).build();
            LogFiles customLogLocationLogFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(customTxLogDirectory, FileSystemRule.get()).build();

            assertThat(toStoreLogFiles.LogFilesConflict(), emptyArray());
            assertThat(customLogLocationLogFiles.LogFilesConflict(), arrayWithSize(1));
            assertEquals(fromStoreLogFiles.GetLogFileForVersion(0).length(), customLogLocationLogFiles.GetLogFileForVersion(0).length());
        }
Exemplo n.º 11
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static void run(final org.neo4j.io.fs.FileSystemAbstraction fs, final java.io.File storeDirectory, org.neo4j.kernel.configuration.Config config, org.neo4j.logging.LogProvider userLogProvider) throws Exception
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
        public static void Run(FileSystemAbstraction fs, File storeDirectory, Config config, LogProvider userLogProvider)
        {
            StoreLogService logService = StoreLogService.withUserLogProvider(userLogProvider).withInternalLog(config.Get(store_internal_log_path)).build(fs);

            VisibleMigrationProgressMonitor progressMonitor = new VisibleMigrationProgressMonitor(logService.GetUserLog(typeof(StoreMigration)));

            LifeSupport life = new LifeSupport();

            life.Add(logService);

            // Add participants from kernel extensions...
            DefaultExplicitIndexProvider migrationIndexProvider = new DefaultExplicitIndexProvider();

            Log          log          = userLogProvider.GetLog(typeof(StoreMigration));
            JobScheduler jobScheduler = JobSchedulerFactory.createInitialisedScheduler();

            try
            {
                using (PageCache pageCache = createPageCache(fs, config, jobScheduler))
                {
                    Dependencies deps     = new Dependencies();
                    Monitors     monitors = new Monitors();
                    deps.SatisfyDependencies(fs, config, migrationIndexProvider, pageCache, logService, monitors, RecoveryCleanupWorkCollector.immediate());

                    KernelContext            kernelContext    = new SimpleKernelContext(storeDirectory, DatabaseInfo.UNKNOWN, deps);
                    DatabaseKernelExtensions kernelExtensions = life.Add(new DatabaseKernelExtensions(kernelContext, GraphDatabaseDependencies.newDependencies().kernelExtensions(), deps, ignore()));

                    DatabaseLayout databaseLayout = DatabaseLayout.of(storeDirectory);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.transaction.log.files.LogFiles logFiles = org.neo4j.kernel.impl.transaction.log.files.LogFilesBuilder.activeFilesBuilder(databaseLayout, fs, pageCache).withConfig(config).build();
                    LogFiles       logFiles    = LogFilesBuilder.activeFilesBuilder(databaseLayout, fs, pageCache).withConfig(config).build();
                    LogTailScanner tailScanner = new LogTailScanner(logFiles, new VersionAwareLogEntryReader <Org.Neo4j.Kernel.impl.transaction.log.ReadableClosablePositionAwareChannel>(), monitors);

                    DefaultIndexProviderMap indexProviderMap = life.Add(new DefaultIndexProviderMap(kernelExtensions, config));

                    // Add the kernel store migrator
                    life.Start();

                    long             startTime = DateTimeHelper.CurrentUnixTimeMillis();
                    DatabaseMigrator migrator  = new DatabaseMigrator(progressMonitor, fs, config, logService, indexProviderMap, migrationIndexProvider, pageCache, RecordFormatSelector.selectForConfig(config, userLogProvider), tailScanner, jobScheduler);
                    migrator.Migrate(databaseLayout);

                    // Append checkpoint so the last log entry will have the latest version
                    AppendCheckpoint(logFiles, tailScanner);

                    long duration = DateTimeHelper.CurrentUnixTimeMillis() - 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();
                jobScheduler.close();
            }
        }
Exemplo n.º 12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldOpenAndRecoverExistingData() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldOpenAndRecoverExistingData()
        {
            // GIVEN
            TransactionIdStore       transactionIdStore = new SimpleTransactionIdStore();
            TransactionMetadataCache positionCache      = new TransactionMetadataCache();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final byte[] additionalHeader = new byte[]{1, 2, 5};
            sbyte[]     additionalHeader             = new sbyte[] { 1, 2, 5 };
            const int   masterId                     = 2;
            int         authorId                     = 1;
            const long  timeStarted                  = 12345;
            long        latestCommittedTxWhenStarted = 4545;
            long        timeCommitted                = timeStarted + 10;
            LifeSupport life = new LifeSupport();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.transaction.log.files.LogFiles logFiles = org.neo4j.kernel.impl.transaction.log.files.LogFilesBuilder.builder(dir.databaseLayout(), fileSystemRule.get()).withTransactionIdStore(transactionIdStore).withLogVersionRepository(mock(LogVersionRepository.class)).build();
            LogFiles logFiles = LogFilesBuilder.builder(Dir.databaseLayout(), FileSystemRule.get()).withTransactionIdStore(transactionIdStore).withLogVersionRepository(mock(typeof(LogVersionRepository))).build();

            life.Start();
            life.Add(logFiles);
            try
            {
                AddATransactionAndRewind(life, logFiles, positionCache, transactionIdStore, additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted);
            }
            finally
            {
                life.Shutdown();
            }

            life = new LifeSupport();
            life.Add(logFiles);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean recoveryRequired = new java.util.concurrent.atomic.AtomicBoolean();
            AtomicBoolean       recoveryRequired = new AtomicBoolean();
            FakeRecoveryVisitor visitor          = new FakeRecoveryVisitor(additionalHeader, masterId, authorId, timeStarted, timeCommitted, latestCommittedTxWhenStarted);

            LogicalTransactionStore txStore = new PhysicalLogicalTransactionStore(logFiles, positionCache, new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(), _monitors, true);

            life.Add(new BatchingTransactionAppender(logFiles, NO_ROTATION, positionCache, transactionIdStore, BYPASS, _databaseHealth));
            CorruptedLogsTruncator logPruner = new CorruptedLogsTruncator(_databaseDirectory, logFiles, FileSystemRule.get());

            life.add(new Recovery(new RecoveryServiceAnonymousInnerClass(this, recoveryRequired, visitor, txStore)
                                  , logPruner, new LifecycleAdapter(), mock(typeof(RecoveryMonitor)), SilentProgressReporter.INSTANCE, false));

            // WHEN
            try
            {
                life.Start();
            }
            finally
            {
                life.Shutdown();
            }

            // THEN
            assertEquals(1, visitor.VisitedTransactions);
            assertTrue(recoveryRequired.get());
        }
Exemplo n.º 13
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.neo4j.kernel.impl.storemigration.UpgradableDatabase getUpgradableDatabase(org.neo4j.kernel.impl.storemigration.StoreVersionCheck check) throws java.io.IOException
        private UpgradableDatabase GetUpgradableDatabase(StoreVersionCheck check)
        {
            VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>();
            LogFiles       logFiles    = LogFilesBuilder.logFilesBasedOnlyBuilder(_workingDatabaseLayout.databaseDirectory(), _fs).build();
            LogTailScanner tailScanner = new LogTailScanner(logFiles, logEntryReader, new Monitors());

            return(new UpgradableDatabase(check, Standard.LATEST_RECORD_FORMATS, tailScanner));
        }
Exemplo n.º 14
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private UpgradableDatabase getUpgradableDatabase(org.neo4j.io.pagecache.PageCache pageCache) throws java.io.IOException
        private UpgradableDatabase GetUpgradableDatabase(PageCache pageCache)
        {
            VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel> entryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>();
            LogFiles       logFiles    = LogFilesBuilder.logFilesBasedOnlyBuilder(_databaseLayout.databaseDirectory(), _fileSystem).withLogEntryReader(entryReader).build();
            LogTailScanner tailScanner = new LogTailScanner(logFiles, entryReader, new Monitors());

            return(new UpgradableDatabase(new StoreVersionCheck(pageCache), RecordFormats, tailScanner));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setUp() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SetUp()
        {
            LogVersionRepository     logVersionRepository = new SimpleLogVersionRepository();
            SimpleTransactionIdStore transactionIdStore   = new SimpleTransactionIdStore();
            LogFiles logFiles = LogFilesBuilder.builder(_directory.databaseLayout(), _fs).withLogVersionRepository(logVersionRepository).withTransactionIdStore(transactionIdStore).build();

            _life.add(logFiles);
            _logFile = logFiles.LogFile;
        }
Exemplo n.º 16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
            public virtual void Setup()
            {
                FileSystem     = FileSystemRule.get();
                DatabaseLayout = TestDirectory.databaseLayout();
                MigrationTestUtils.FindFormatStoreDirectoryForVersion(Version, DatabaseLayout.databaseDirectory());
                VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>();
                LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(DatabaseLayout.databaseDirectory(), FileSystem).build();

                TailScanner = new LogTailScanner(logFiles, logEntryReader, new Monitors());
            }
Exemplo n.º 17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setUp() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SetUp()
        {
            _databaseDirectory = TestDirectory.databaseDir();
            SimpleLogVersionRepository logVersionRepository = new SimpleLogVersionRepository();
            SimpleTransactionIdStore   transactionIdStore   = new SimpleTransactionIdStore();

            _logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(_databaseDirectory, FileSystemRule).withRotationThreshold(LogHeader.LOG_HEADER_SIZE + 9L).withLogVersionRepository(logVersionRepository).withTransactionIdStore(transactionIdStore).build();
            Life.add(_logFiles);
            _logPruner = new CorruptedLogsTruncator(_databaseDirectory, _logFiles, FileSystemRule);
        }
Exemplo n.º 18
0
 private static LogFiles BuildLocalDatabaseLogFiles(PlatformModule platformModule, FileSystemAbstraction fileSystem, DatabaseLayout databaseLayout, Config config)
 {
     try
     {
         return(LogFilesBuilder.activeFilesBuilder(databaseLayout, fileSystem, platformModule.PageCache).withConfig(config).build());
     }
     catch (IOException e)
     {
         throw new Exception(e);
     }
 }
        /*
         * There was an issue where if multiple concurrent appending threads did append and they moved on
         * to await a force, where the force would fail and the one doing the force would raise a panic...
         * the other threads may not notice the panic and move on to mark those transactions as committed
         * and notice the panic later (which would be too late).
         */
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHaveAllConcurrentAppendersSeePanic() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldHaveAllConcurrentAppendersSeePanic()
        {
            // GIVEN
            Adversary adversary = new ClassGuardedAdversary(new CountingAdversary(1, true), FailMethod(typeof(BatchingTransactionAppender), "force"));
            EphemeralFileSystemAbstraction efs = new EphemeralFileSystemAbstraction();
            FileSystemAbstraction          fs  = new AdversarialFileSystemAbstraction(adversary, efs);

            _life.add(new FileSystemLifecycleAdapter(fs));
            DatabaseHealth databaseHealth = new DatabaseHealth(mock(typeof(DatabasePanicEventGenerator)), NullLog.Instance);
            LogFiles       logFiles       = LogFilesBuilder.builder(_testDirectory.databaseLayout(), fs).withLogVersionRepository(_logVersionRepository).withTransactionIdStore(_transactionIdStore).build();

            _life.add(logFiles);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final BatchingTransactionAppender appender = life.add(new BatchingTransactionAppender(logFiles, logRotation, transactionMetadataCache, transactionIdStore, explicitIndexTransactionOrdering, databaseHealth));
            BatchingTransactionAppender appender = _life.add(new BatchingTransactionAppender(logFiles, _logRotation, _transactionMetadataCache, _transactionIdStore, _explicitIndexTransactionOrdering, databaseHealth));

            _life.start();

            // WHEN
            int numberOfAppenders = 10;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.CountDownLatch trap = new java.util.concurrent.CountDownLatch(numberOfAppenders);
            System.Threading.CountdownEvent trap = new System.Threading.CountdownEvent(numberOfAppenders);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.transaction.tracing.LogAppendEvent beforeForceTrappingEvent = new org.neo4j.kernel.impl.transaction.tracing.LogAppendEvent_Empty()
            LogAppendEvent beforeForceTrappingEvent = new LogAppendEvent_EmptyAnonymousInnerClass(this, trap);
            Race           race = new Race();

            for (int i = 0; i < numberOfAppenders; i++)
            {
                race.AddContestant(() =>
                {
                    try
                    {
                        // Append to the log, the LogAppenderEvent will have all of the appending threads
                        // do wait for all of the other threads to start the force thing
                        appender.Append(Tx(), beforeForceTrappingEvent);
                        fail("No transaction should be considered appended");
                    }
                    catch (IOException)
                    {
                        // Good, we know that this test uses an adversarial file system which will throw
                        // an exception in BatchingTransactionAppender#force, and since all these transactions
                        // will append and be forced in the same batch, where the force will fail then
                        // all these transactions should fail. If there's any transaction not failing then
                        // it just didn't notice the panic, which would be potentially hazardous.
                    }
                });
            }

            // THEN perform the race. The relevant assertions are made inside the contestants.
            race.Go();
        }
Exemplo n.º 20
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void deleteAllLogsOn(java.io.File storeDirectory) throws java.io.IOException
        private static void DeleteAllLogsOn(File storeDirectory)
        {
            using (DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction())
            {
                LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(storeDirectory, fileSystem).build();
                foreach (File file in logFiles.LogFilesConflict())
                {
                    fileSystem.DeleteFile(file);
                }
            }
        }
Exemplo n.º 21
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void deleteLogs(org.neo4j.io.layout.DatabaseLayout databaseLayout) throws java.io.IOException
        private static void DeleteLogs(DatabaseLayout databaseLayout)
        {
            using (DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction())
            {
                LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(databaseLayout.DatabaseDirectory(), fileSystem).build();
                foreach (File file in logFiles.LogFilesConflict())
                {
                    fileSystem.DeleteFile(file);
                }
            }
        }
Exemplo n.º 22
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void before() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void Before()
        {
            _lastCommittedTxId    = new AtomicLong(BASE_TX_ID);
            _logVersionRepository = new SimpleLogVersionRepository();
            _logFiles             = LogFilesBuilder.builder(_directory.databaseLayout(), _fs).withLogVersionRepository(_logVersionRepository).withTransactionIdStore(new SimpleTransactionIdStore()).build();
            _life.add(_logFiles);
            _logFile = _logFiles.LogFile;
            _writer  = _logFile.Writer;
            _transactionLogWriter = new TransactionLogWriter(new LogEntryWriter(_writer));
            _monitor = new VerifyingMonitor();
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldKeepTransactionsIntactWhenConcurrentlyRotationAndAppending() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldKeepTransactionsIntactWhenConcurrentlyRotationAndAppending()
        {
            // GIVEN
            LogVersionRepository logVersionRepository = new SimpleLogVersionRepository();
            LogFiles             logFiles             = LogFilesBuilder.builder(_directory.databaseLayout(), _fileSystemRule.get()).withLogVersionRepository(logVersionRepository).withRotationThreshold(ByteUnit.mebiBytes(1)).withTransactionIdStore(new SimpleTransactionIdStore()).build();

            _life.add(logFiles);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean end = new java.util.concurrent.atomic.AtomicBoolean();
            AtomicBoolean            end           = new AtomicBoolean();
            AllTheMonitoring         monitoring    = new AllTheMonitoring(end, 100);
            TransactionIdStore       txIdStore     = new SimpleTransactionIdStore();
            TransactionMetadataCache metadataCache = new TransactionMetadataCache();

            monitoring.LogFile = logFiles.LogFile;
            DatabaseHealth health   = new DatabaseHealth(mock(typeof(DatabasePanicEventGenerator)), NullLog.Instance);
            LogRotation    rotation = new LogRotationImpl(monitoring, logFiles, health);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final TransactionAppender appender = life.add(new BatchingTransactionAppender(logFiles, rotation, metadataCache, txIdStore, BYPASS, health));
            TransactionAppender appender = _life.add(new BatchingTransactionAppender(logFiles, rotation, metadataCache, txIdStore, BYPASS, health));

            // WHEN
            Race race = new Race();

            for (int i = 0; i < 10; i++)
            {
                race.AddContestant(() =>
                {
                    while (!end.get())
                    {
                        try
                        {
                            appender.Append(new TransactionToApply(SillyTransaction(1_000)), NULL);
                        }
                        catch (Exception e)
                        {
                            e.printStackTrace(System.out);
                            end.set(true);
                            fail(e.Message);
                        }
                    }
                });
            }
            race.AddContestant(EndAfterMax(10, SECONDS, end));
            race.Go();

            // THEN
            assertTrue(monitoring.NumberOfRotations() > 0);
        }
Exemplo n.º 24
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void verifyTransactionLogs(java.io.File txDirectory, java.io.File storeDir) throws java.io.IOException
        private void VerifyTransactionLogs(File txDirectory, File storeDir)
        {
            FileSystemAbstraction fileSystem = FileSystemRule.get();
            LogFiles storeDirLogs            = LogFilesBuilder.logFilesBasedOnlyBuilder(storeDir, fileSystem).build();

            assertFalse(storeDirLogs.VersionExists(0));

            LogFiles txDirectoryLogs = LogFilesBuilder.logFilesBasedOnlyBuilder(txDirectory, fileSystem).build();

            assertTrue(txDirectoryLogs.VersionExists(0));
            using (PhysicalLogVersionedStoreChannel physicalLogVersionedStoreChannel = txDirectoryLogs.OpenForVersion(0))
            {
                assertThat(physicalLogVersionedStoreChannel.Size(), greaterThan(0L));
            }
        }
 /// <summary>
 /// Add all available log files as sources.
 /// </summary>
 /// <param name="sources"> destination of the sources. </param>
 private void GetTransactionLogFiles(IList <DiagnosticsReportSource> sources)
 {
     try
     {
         LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(_databaseLayout.databaseDirectory(), _fs).build();
         foreach (File file in logFiles.LogFilesConflict())
         {
             sources.Add(DiagnosticsReportSources.NewDiagnosticsFile("tx/" + file.Name, _fs, file));
         }
     }
     catch (IOException e)
     {
         sources.Add(DiagnosticsReportSources.NewDiagnosticsString("tx.txt", () => "Error getting tx logs: " + e.Message));
     }
 }
Exemplo n.º 26
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
            public virtual void Setup()
            {
                FileSystem     = FileSystemRule.get();
                DatabaseLayout = TestDirectory.databaseLayout();
                // doesn't matter which version we pick we are changing it to the wrong one...
                MigrationTestUtils.FindFormatStoreDirectoryForVersion(StandardV2_3.STORE_VERSION, DatabaseLayout.databaseDirectory());
                changeVersionNumber(FileSystem, DatabaseLayout.file(NEOSTORE_FILENAME), Version);
                File      metadataStore = DatabaseLayout.metadataStore();
                PageCache pageCache     = PageCacheRule.getPageCache(FileSystem);

                MetaDataStore.setRecord(pageCache, metadataStore, STORE_VERSION, MetaDataStore.versionStringToLong(Version));
                VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>();
                LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(DatabaseLayout.databaseDirectory(), FileSystem).build();

                TailScanner = new LogTailScanner(logFiles, logEntryReader, new Monitors());
            }
Exemplo n.º 27
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldExtractMetadataFromExistingTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldExtractMetadataFromExistingTransaction()
        {
            // GIVEN
            TransactionIdStore       transactionIdStore = new SimpleTransactionIdStore();
            TransactionMetadataCache positionCache      = new TransactionMetadataCache();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final byte[] additionalHeader = new byte[]{1, 2, 5};
            sbyte[]     additionalHeader             = new sbyte[] { 1, 2, 5 };
            const int   masterId                     = 2;
            int         authorId                     = 1;
            const long  timeStarted                  = 12345;
            long        latestCommittedTxWhenStarted = 4545;
            long        timeCommitted                = timeStarted + 10;
            LifeSupport life = new LifeSupport();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.transaction.log.files.LogFiles logFiles = org.neo4j.kernel.impl.transaction.log.files.LogFilesBuilder.builder(dir.databaseLayout(), fileSystemRule.get()).withTransactionIdStore(transactionIdStore).withLogVersionRepository(mock(LogVersionRepository.class)).build();
            LogFiles logFiles = LogFilesBuilder.builder(Dir.databaseLayout(), FileSystemRule.get()).withTransactionIdStore(transactionIdStore).withLogVersionRepository(mock(typeof(LogVersionRepository))).build();

            life.Start();
            life.Add(logFiles);
            try
            {
                AddATransactionAndRewind(life, logFiles, positionCache, transactionIdStore, additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted);
            }
            finally
            {
                life.Shutdown();
            }

            life = new LifeSupport();
            life.Add(logFiles);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LogicalTransactionStore store = new PhysicalLogicalTransactionStore(logFiles, positionCache, new org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader<>(), monitors, true);
            LogicalTransactionStore store = new PhysicalLogicalTransactionStore(logFiles, positionCache, new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(), _monitors, true);

            // WHEN
            life.Start();
            try
            {
                VerifyTransaction(transactionIdStore, positionCache, additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted, store);
            }
            finally
            {
                life.Shutdown();
            }
        }
Exemplo n.º 28
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void backupDatabaseTransactionLogsStoredWithDatabase() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void BackupDatabaseTransactionLogsStoredWithDatabase()
        {
            int backupPort = PortAuthority.allocatePort();

            StartDb(backupPort);
            string ip   = ":" + backupPort;
            string name = "backupWithTxLogs" + RecordFormat;

            assertEquals(0, RunBackupTool(_testDirectory.absolutePath(), "--from", ip, "--cc-report-dir=" + _backupDir, "--backup-dir=" + _backupDir, "--name=" + name));
            _db.shutdown();

            using (DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction())
            {
                LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(new File(_backupDir, name), fileSystem).build();
                assertTrue(logFiles.VersionExists(0));
                assertThat(logFiles.GetLogFileForVersion(0).length(), greaterThan(50L));
            }
        }
Exemplo n.º 29
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.neo4j.storageengine.api.StoreId simulateStoreCopy() throws java.io.IOException
        private Org.Neo4j.Storageengine.Api.StoreId SimulateStoreCopy()
        {
            // create an empty store
            Org.Neo4j.Storageengine.Api.StoreId storeId;
            NeoStoreDataSource ds = DsRule.getDataSource(_databaseLayout, _fs, _pageCache);

            using (Lifespan ignored = new Lifespan(ds))
            {
                storeId = ds.StoreId;
            }

            // we don't have log files after a store copy
            LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(_databaseLayout.databaseDirectory(), FsRule.get()).build();

            //noinspection ResultOfMethodCallIgnored
            logFiles.Accept((file, version) => file.delete());

            return(storeId);
        }
Exemplo n.º 30
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void addCorruptedCommandsToLastLogFile() throws java.io.IOException
        private void AddCorruptedCommandsToLastLogFile()
        {
            PositiveLogFilesBasedLogVersionRepository versionRepository = new PositiveLogFilesBasedLogVersionRepository(_logFiles);
            LogFiles internalLogFiles = LogFilesBuilder.builder(_directory.databaseLayout(), _fileSystemRule).withLogVersionRepository(versionRepository).withTransactionIdStore(new SimpleTransactionIdStore()).build();

            using (Lifespan lifespan = new Lifespan(internalLogFiles))
            {
                LogFile transactionLogFile = internalLogFiles.LogFile;

                FlushablePositionAwareChannel channel = transactionLogFile.Writer;
                TransactionLogWriter          writer  = new TransactionLogWriter(new CorruptedLogEntryWriter(channel));

                ICollection <StorageCommand> commands = new List <StorageCommand>();
                commands.Add(new Command.PropertyCommand(new PropertyRecord(1), new PropertyRecord(2)));
                commands.Add(new Command.NodeCommand(new NodeRecord(2), new NodeRecord(3)));
                PhysicalTransactionRepresentation transaction = new PhysicalTransactionRepresentation(commands);
                writer.Append(transaction, 1000);
            }
        }