Beispiel #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void execute() throws java.io.IOException, org.neo4j.commandline.admin.CommandFailed
        public virtual void Execute()
        {
            if (!_fs.fileExists(_fromDatabasePath))
            {
                throw new System.ArgumentException(format("Source directory does not exist [%s]", _fromDatabasePath));
            }

            try
            {
                Validators.CONTAINS_EXISTING_DATABASE.validate(_fromDatabasePath);
            }
            catch (System.ArgumentException)
            {
                throw new System.ArgumentException(format("Source directory is not a database backup [%s]", _fromDatabasePath));
            }

            if (_fs.fileExists(_toDatabaseDir) && !_forceOverwrite)
            {
                throw new System.ArgumentException(format("Database with name [%s] already exists at %s", _toDatabaseName, _toDatabaseDir));
            }

            checkLock(DatabaseLayout.of(_toDatabaseDir).StoreLayout);

            _fs.deleteRecursively(_toDatabaseDir);

            if (!isSameOrChildFile(_toDatabaseDir, _transactionLogsDirectory))
            {
                _fs.deleteRecursively(_transactionLogsDirectory);
            }
            LogFiles backupLogFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(_fromDatabasePath, _fs).build();

            RestoreDatabaseFiles(backupLogFiles, _fromDatabasePath.listFiles());
        }
Beispiel #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.neo4j.kernel.impl.transaction.log.ReadableLogChannel openLogFile(org.neo4j.io.fs.FileSystemAbstraction fs, int version) throws java.io.IOException
            internal virtual ReadableLogChannel OpenLogFile(FileSystemAbstraction fs, int version)
            {
                LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(WorkingDirectory, fs).build();
                PhysicalLogVersionedStoreChannel channel = logFiles.OpenForVersion(version);

                return(new ReadAheadLogChannel(channel, new ReaderLogVersionBridge(logFiles)));
            }
Beispiel #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public TemporaryStoreDirectory(org.neo4j.io.fs.FileSystemAbstraction fs, org.neo4j.io.pagecache.PageCache pageCache, java.io.File parent) throws java.io.IOException
        public TemporaryStoreDirectory(FileSystemAbstraction fs, PageCache pageCache, File parent)
        {
            this._tempStoreDir       = new File(parent, TEMP_COPY_DIRECTORY_NAME);
            this._tempDatabaseLayout = DatabaseLayout.of(_tempStoreDir, GraphDatabaseSettings.DEFAULT_DATABASE_NAME);
            _storeFiles   = new StoreFiles(fs, pageCache, (directory, name) => true);
            _tempLogFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(_tempDatabaseLayout.databaseDirectory(), fs).build();
            _storeFiles.delete(_tempStoreDir, _tempLogFiles);
        }
Beispiel #4
0
        /// <summary>
        /// Analyzes transactions found in log file(s) specified by {@code storeDirOrLogFile} calling methods on the supplied
        /// <seealso cref="Monitor"/> for each encountered data item.
        /// </summary>
        /// <param name="fileSystem"> <seealso cref="FileSystemAbstraction"/> to find the files on. </param>
        /// <param name="storeDirOrLogFile"> <seealso cref="File"/> pointing either to a directory containing transaction log files, or directly
        /// pointing to a single transaction log file to analyze. </param>
        /// <param name="invalidLogEntryHandler"> <seealso cref="InvalidLogEntryHandler"/> to pass in to the internal <seealso cref="LogEntryReader"/>. </param>
        /// <param name="monitor"> <seealso cref="Monitor"/> receiving call-backs for all <seealso cref="Monitor.transaction(LogEntry[]) transactions"/>,
        /// <seealso cref="Monitor.checkpoint(CheckPoint, LogPosition) checkpoints"/> and <seealso cref="Monitor.logFile(File, long) log file transitions"/>
        /// encountered during the analysis. </param>
        /// <exception cref="IOException"> on I/O error. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static void analyze(org.neo4j.io.fs.FileSystemAbstraction fileSystem, java.io.File storeDirOrLogFile, org.neo4j.kernel.impl.transaction.log.entry.InvalidLogEntryHandler invalidLogEntryHandler, Monitor monitor) throws java.io.IOException
        public static void Analyze(FileSystemAbstraction fileSystem, File storeDirOrLogFile, InvalidLogEntryHandler invalidLogEntryHandler, Monitor monitor)
        {
            File                firstFile;
            LogVersionBridge    bridge;
            ReadAheadLogChannel channel;
            LogEntryReader <ReadableClosablePositionAwareChannel> entryReader;
            LogPositionMarker positionMarker;

            if (storeDirOrLogFile.Directory)
            {
                // Use natural log version bridging if a directory is supplied
//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.logFilesBasedOnlyBuilder(storeDirOrLogFile, fileSystem).build();
                LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(storeDirOrLogFile, fileSystem).build();
                bridge = new ReaderLogVersionBridgeAnonymousInnerClass(logFiles, monitor, channel);
                long lowestLogVersion = logFiles.LowestLogVersion;
                if (lowestLogVersion < 0)
                {
                    throw new System.InvalidOperationException(format("Transaction logs at '%s' not found.", storeDirOrLogFile));
                }
                firstFile = logFiles.GetLogFileForVersion(lowestLogVersion);
                monitor.LogFile(firstFile, lowestLogVersion);
            }
            else
            {
                // Use no bridging, simply reading this single log file if a file is supplied
                firstFile = storeDirOrLogFile;
//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.logFilesBasedOnlyBuilder(storeDirOrLogFile, fileSystem).build();
                LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(storeDirOrLogFile, fileSystem).build();
                monitor.LogFile(firstFile, logFiles.GetLogVersion(firstFile));
                bridge = NO_MORE_CHANNELS;
            }

            channel        = new ReadAheadLogChannel(openVersionedChannel(fileSystem, firstFile), bridge);
            entryReader    = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(new RecordStorageCommandReaderFactory(), invalidLogEntryHandler);
            positionMarker = new LogPositionMarker();
            using (TransactionLogEntryCursor cursor = new TransactionLogEntryCursor(new LogEntryCursor(entryReader, channel)))
            {
                channel.GetCurrentPosition(positionMarker);
                while (cursor.Next())
                {
                    LogEntry[] tx = cursor.Get();
                    if (tx.Length == 1 && tx[0].Type == CHECK_POINT)
                    {
                        monitor.Checkpoint(tx[0].As(), positionMarker.NewPosition());
                    }
                    else
                    {
                        monitor.Transaction(tx);
                    }
                }
            }
        }
Beispiel #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void appendDropTransactionToTransactionLog(java.io.File databaseDirectory, org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation dropTransaction) throws java.io.IOException
        private void AppendDropTransactionToTransactionLog(File databaseDirectory, CommittedTransactionRepresentation dropTransaction)
        {
            LogFiles     logFiles          = LogFilesBuilder.logFilesBasedOnlyBuilder(databaseDirectory, Fs).build();
            File         logFile           = logFiles.GetLogFileForVersion(logFiles.HighestLogVersion);
            StoreChannel writeStoreChannel = Fs.open(logFile, OpenMode.READ_WRITE);

            writeStoreChannel.Position(writeStoreChannel.size());
            using (PhysicalFlushableChannel writeChannel = new PhysicalFlushableChannel(writeStoreChannel))
            {
                (new LogEntryWriter(writeChannel)).serialize(dropTransaction);
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldOpenInFreshDirectoryAndFinallyAddHeader() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldOpenInFreshDirectoryAndFinallyAddHeader()
        {
            // GIVEN
            string name = "log";
            FileSystemAbstraction fs = _fileSystemRule.get();
            LogFiles logFiles        = LogFilesBuilder.builder(_directory.databaseLayout(), fs).withTransactionIdStore(_transactionIdStore).withLogVersionRepository(_logVersionRepository).build();

            // WHEN
            _life.start();
            _life.add(logFiles);
            _life.shutdown();

            // THEN
            File      file   = LogFilesBuilder.logFilesBasedOnlyBuilder(_directory.databaseDir(), fs).build().getLogFileForVersion(1L);
            LogHeader header = readLogHeader(fs, file);

            assertEquals(1L, header.LogVersion);
            assertEquals(2L, header.LastCommittedTxId);
        }
Beispiel #7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static void removeCheckPointFromTxLog(org.neo4j.io.fs.FileSystemAbstraction fileSystem, java.io.File databaseDirectory) throws java.io.IOException
        public static void RemoveCheckPointFromTxLog(FileSystemAbstraction fileSystem, File databaseDirectory)
        {
            LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(databaseDirectory, fileSystem).build();
            LogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>();
            LogTailScanner tailScanner = new LogTailScanner(logFiles, logEntryReader, new Monitors());

            LogTailScanner.LogTailInformation logTailInformation = tailScanner.TailInformation;

            if (logTailInformation.CommitsAfterLastCheckpoint())
            {
                // done already
                return;
            }

            // let's assume there is at least a checkpoint
            assertNotNull(logTailInformation.LastCheckPoint);

            LogPosition logPosition = logTailInformation.LastCheckPoint.LogPosition;
            File        logFile     = logFiles.GetLogFileForVersion(logPosition.LogVersion);

            fileSystem.Truncate(logFile, logPosition.ByteOffset);
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.neo4j.kernel.impl.transaction.log.files.LogFiles prepareLogFiles() throws java.io.IOException
        private LogFiles PrepareLogFiles()
        {
            return(LogFilesBuilder.logFilesBasedOnlyBuilder(TestDirectory.directory(), _fs).build());
        }