//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public TransactionCursor getTransactions(final long transactionIdToStartFrom) throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
        public override TransactionCursor GetTransactions(long transactionIdToStartFrom)
        {
            // look up in position cache
            try
            {
                TransactionMetadataCache.TransactionMetadata transactionMetadata = _transactionMetadataCache.getTransactionMetadata(transactionIdToStartFrom);
                if (transactionMetadata != null)
                {
                    // we're good
                    ReadableLogChannel channel = _logFile.getReader(transactionMetadata.StartPosition);
                    return(new PhysicalTransactionCursor <>(channel, _logEntryReader));
                }

                // ask logFiles about the version it may be in
                LogVersionLocator headerVisitor = new LogVersionLocator(transactionIdToStartFrom);
                _logFiles.accept(headerVisitor);

                // ask LogFile
                TransactionPositionLocator transactionPositionLocator = new TransactionPositionLocator(transactionIdToStartFrom, _logEntryReader);
                _logFile.accept(transactionPositionLocator, headerVisitor.LogPosition);
                LogPosition position = transactionPositionLocator.GetAndCacheFoundLogPosition(_transactionMetadataCache);
                return(new PhysicalTransactionCursor <>(_logFile.getReader(position), _logEntryReader));
            }
            catch (FileNotFoundException e)
            {
                throw new NoSuchTransactionException(transactionIdToStartFrom, "Log position acquired, but couldn't find the log file itself. Perhaps it just recently was " + "deleted? [" + e.Message + "]", e);
            }
        }
 public TransactionMetadata(int masterId, int authorId, LogPosition startPosition, long checksum, long timeWritten)
 {
     this.MasterIdConflict      = masterId;
     this.AuthorIdConflict      = authorId;
     this.StartPositionConflict = startPosition;
     this.ChecksumConflict      = checksum;
     this.TimeWrittenConflict   = timeWritten;
 }
            public override bool Visit(LogPosition position, long firstTransactionIdInLog, long lastTransactionIdInLog)
            {
                bool foundIt = TransactionId >= firstTransactionIdInLog && TransactionId <= lastTransactionIdInLog;

                if (foundIt)
                {
                    FoundPosition = position;
                }
                return(!foundIt);                        // continue as long we don't find it
            }
        public virtual TransactionMetadata CacheTransactionMetadata(long txId, LogPosition position, int masterId, int authorId, long checksum, long timeWritten)
        {
            if (position.ByteOffset == -1)
            {
                throw new Exception("StartEntry.position is " + position);
            }

            TransactionMetadata result = new TransactionMetadata(masterId, authorId, position, checksum, timeWritten);

            _txStartPositionCache.put(txId, result);
            return(result);
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void checkPoint(LogPosition logPosition, org.neo4j.kernel.impl.transaction.tracing.LogCheckPointEvent logCheckPointEvent) throws java.io.IOException
        public override void CheckPoint(LogPosition logPosition, LogCheckPointEvent logCheckPointEvent)
        {
            // Synchronized with logFile to get absolute control over concurrent rotations happening
            lock ( _logFile )
            {
                try
                {
                    _transactionLogWriter.checkPoint(logPosition);
                }
                catch (Exception cause)
                {
                    _databaseHealth.panic(cause);
                    throw cause;
                }
            }
            ForceAfterAppend(logCheckPointEvent);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReadOlderLogs() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReadOlderLogs()
        {
            // GIVEN
            FileSystemAbstraction fs = _fileSystemRule.get();
            LogFiles logFiles        = LogFilesBuilder.builder(_directory.databaseLayout(), fs).withTransactionIdStore(_transactionIdStore).withLogVersionRepository(_logVersionRepository).build();

            _life.start();
            _life.add(logFiles);

            // WHEN
            LogFile logFile = logFiles.LogFile;
            FlushablePositionAwareChannel writer         = logFile.Writer;
            LogPositionMarker             positionMarker = new LogPositionMarker();

            writer.GetCurrentPosition(positionMarker);
            LogPosition position1 = positionMarker.NewPosition();
            int         intValue  = 45;
            long        longValue = 4854587;

            sbyte[] someBytes = someBytes(40);
            writer.PutInt(intValue);
            writer.PutLong(longValue);
            writer.Put(someBytes, someBytes.Length);
            writer.PrepareForFlush().flush();
            writer.GetCurrentPosition(positionMarker);
            LogPosition position2  = positionMarker.NewPosition();
            long        longValue2 = 123456789L;

            writer.PutLong(longValue2);
            writer.Put(someBytes, someBytes.Length);
            writer.PrepareForFlush().flush();

            // THEN
            using (ReadableClosableChannel reader = logFile.GetReader(position1))
            {
                assertEquals(intValue, reader.Int);
                assertEquals(longValue, reader.Long);
                assertArrayEquals(someBytes, ReadBytes(reader, 40));
            }
            using (ReadableClosableChannel reader = logFile.GetReader(position2))
            {
                assertEquals(longValue2, reader.Long);
                assertArrayEquals(someBytes, ReadBytes(reader, 40));
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void skipLogFileWithoutHeader() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SkipLogFileWithoutHeader()
        {
            FileSystemAbstraction fs = _fileSystemRule.get();
            LogFiles logFiles        = LogFilesBuilder.builder(_directory.databaseLayout(), fs).withTransactionIdStore(_transactionIdStore).withLogVersionRepository(_logVersionRepository).build();

            _life.add(logFiles);
            _life.start();

            // simulate new file without header presence
            _logVersionRepository.incrementAndGetVersion();
            fs.Create(logFiles.GetLogFileForVersion(_logVersionRepository.CurrentLogVersion)).close();
            _transactionIdStore.transactionCommitted(5L, 5L, 5L);

            PhysicalLogicalTransactionStore.LogVersionLocator versionLocator = new PhysicalLogicalTransactionStore.LogVersionLocator(4L);
            logFiles.Accept(versionLocator);

            LogPosition logPosition = versionLocator.LogPosition;

            assertEquals(1, logPosition.LogVersion);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSeeCorrectPositionEvenBeforeEmptyingDataIntoChannel() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSeeCorrectPositionEvenBeforeEmptyingDataIntoChannel()
        {
            // GIVEN
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.io.File file = new java.io.File(directory.directory(), "file");
            File         file         = new File(Directory.directory(), "file");
            StoreChannel storeChannel = FileSystemRule.get().open(file, OpenMode.READ_WRITE);
            PhysicalLogVersionedStoreChannel      versionedStoreChannel = new PhysicalLogVersionedStoreChannel(storeChannel, 1, ( sbyte )-1);
            PositionAwarePhysicalFlushableChannel channel = new PositionAwarePhysicalFlushableChannel(versionedStoreChannel);
            LogPositionMarker positionMarker  = new LogPositionMarker();
            LogPosition       initialPosition = channel.GetCurrentPosition(positionMarker).newPosition();

            // WHEN
            channel.PutLong(67);
            channel.PutInt(1234);
            LogPosition positionAfterSomeData = channel.GetCurrentPosition(positionMarker).newPosition();

            // THEN
            assertEquals(12, positionAfterSomeData.ByteOffset - initialPosition.ByteOffset);
            channel.Dispose();
        }
Exemple #9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void appendCheckpoint(org.neo4j.kernel.impl.transaction.log.entry.LogEntryVersion logVersion) throws java.io.IOException
        private void AppendCheckpoint(LogEntryVersion logVersion)
        {
            PageCache pageCache = _pageCacheRule.getPageCache(_fs);
            VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>();
            LogFiles       logFiles    = LogFilesBuilder.activeFilesBuilder(_storeDirectory.databaseLayout(), _fs, pageCache).withLogEntryReader(logEntryReader).build();
            LogTailScanner tailScanner = new LogTailScanner(logFiles, logEntryReader, new Monitors());

            LogTailScanner.LogTailInformation tailInformation = tailScanner.TailInformation;

            using (Lifespan lifespan = new Lifespan(logFiles))
            {
                FlushablePositionAwareChannel channel = logFiles.LogFile.Writer;

                LogPosition logPosition = tailInformation.LastCheckPoint.LogPosition;

                // Fake record
                channel.Put(logVersion.byteCode()).put(CHECK_POINT).putLong(logPosition.LogVersion).putLong(logPosition.ByteOffset);

                channel.PrepareForFlush().flush();
            }
        }
Exemple #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFindTransactionLogPosition() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldFindTransactionLogPosition()
        {
            // given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final PhysicalLogicalTransactionStore.TransactionPositionLocator locator = new PhysicalLogicalTransactionStore.TransactionPositionLocator(txId, logEntryReader);
            PhysicalLogicalTransactionStore.TransactionPositionLocator locator = new PhysicalLogicalTransactionStore.TransactionPositionLocator(_txId, _logEntryReader);

            when(_logEntryReader.readLogEntry(_channel)).thenReturn(_start, _command, _commit, null);

            // when
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final boolean result = locator.visit(channel);
            bool result = locator.Visit(_channel);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LogPosition position = locator.getAndCacheFoundLogPosition(metadataCache);
            LogPosition position = locator.GetAndCacheFoundLogPosition(_metadataCache);

            // then
            assertFalse(result);
            assertEquals(_startPosition, position);
            verify(_metadataCache, times(1)).cacheTransactionMetadata(_txId, _startPosition, _start.MasterId, _start.LocalId, LogEntryStart.checksum(_start), _commit.TimeWritten);
        }
        /// <returns> A TransactionCommitment instance with metadata about the committed transaction, such as whether or not
        /// this transaction contains any explicit index changes. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private TransactionCommitment appendToLog(org.neo4j.kernel.impl.transaction.TransactionRepresentation transaction, long transactionId) throws java.io.IOException
        private TransactionCommitment AppendToLog(TransactionRepresentation transaction, long transactionId)
        {
            // Reset command writer so that we, after we've written the transaction, can ask it whether or
            // not any explicit index command was written. If so then there's additional ordering to care about below.
            _indexCommandDetector.reset();

            // The outcome of this try block is either of:
            // a) transaction successfully appended, at which point we return a Commitment to be used after force
            // b) transaction failed to be appended, at which point a kernel panic is issued
            // The reason that we issue a kernel panic on failure in here is that at this point we're still
            // holding the logFile monitor, and a failure to append needs to be communicated with potential
            // log rotation, which will wait for all transactions closed or fail on kernel panic.
            try
            {
                LogPosition logPositionBeforeCommit = _writer.getCurrentPosition(_positionMarker).newPosition();
                _transactionLogWriter.append(transaction, transactionId);
                LogPosition logPositionAfterCommit = _writer.getCurrentPosition(_positionMarker).newPosition();

                long transactionChecksum = checksum(transaction.AdditionalHeader(), transaction.MasterId, transaction.AuthorId);
                _transactionMetadataCache.cacheTransactionMetadata(transactionId, logPositionBeforeCommit, transaction.MasterId, transaction.AuthorId, transactionChecksum, transaction.TimeCommitted);

                transaction.Accept(_indexCommandDetector);
                bool hasExplicitIndexChanges = _indexCommandDetector.hasWrittenAnyExplicitIndexCommand();
                if (hasExplicitIndexChanges)
                {
                    // Offer this transaction id to the queue so that the explicit index applier can take part in the ordering
                    _explicitIndexTransactionOrdering.offer(transactionId);
                }
                return(new TransactionCommitment(hasExplicitIndexChanges, transactionId, transactionChecksum, transaction.TimeCommitted, logPositionAfterCommit, _transactionIdStore));
            }
//JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#:
//ORIGINAL LINE: catch (final Throwable panic)
            catch (Exception panic)
            {
                _databaseHealth.panic(panic);
                throw panic;
            }
        }
Exemple #12
0
 public override void FailToRecoverTransactionsAfterPosition(Exception t, LogPosition recoveryFromPosition)
 {
     _log.warn(format("Fail to recover all transactions. Any later transactions after position %s are " + "unreadable and will be truncated.", recoveryFromPosition), t);
 }
Exemple #13
0
 public override void FailToRecoverTransactionsAfterCommit(Exception t, LogEntryCommit commitEntry, LogPosition recoveryToPosition)
 {
     _log.warn(format("Fail to recover all transactions. Last recoverable transaction id:%d, committed " + "at:%d. Any later transaction after %s are unreadable and will be truncated.", commitEntry.TxId, commitEntry.TimeWritten, recoveryToPosition), t);
 }
Exemple #14
0
 public override void RecoveryRequired(LogPosition startPosition)
 {
     _log.info("Recovery required from position " + startPosition);
 }
Exemple #15
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public TransactionCursor getTransactions(LogPosition position) throws java.io.IOException
            public TransactionCursor getTransactions(LogPosition position)
            {
                return(_txStore.getTransactions(position));
            }
 public override TransactionCursor GetTransactionsInReverseOrder(LogPosition backToPosition)
 {
     return(ReversedMultiFileTransactionCursor.fromLogFile(_logFiles, _logFile, backToPosition, _failOnCorruptedLogFiles, _monitors.newMonitor(typeof(ReversedTransactionCursorMonitor))));
 }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public TransactionCursor getTransactions(LogPosition position) throws java.io.IOException
        public override TransactionCursor GetTransactions(LogPosition position)
        {
            return(new PhysicalTransactionCursor <>(_logFile.getReader(position), new VersionAwareLogEntryReader <>()));
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public TransactionCursor getTransactions(LogPosition position) throws java.io.IOException
        public override TransactionCursor GetTransactions(LogPosition position)
        {
            return(_physicalStore.getTransactions(position));
        }
 public override void CheckPoint(LogPosition logPosition, LogCheckPointEvent logCheckPointEvent)
 {
 }
Exemple #20
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void checkPoint(LogPosition logPosition) throws java.io.IOException
        public virtual void CheckPoint(LogPosition logPosition)
        {
            _writer.writeCheckPointEntry(logPosition);
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public TransactionCursor getTransactionsInReverseOrder(LogPosition backToPosition) throws java.io.IOException
        public override TransactionCursor GetTransactionsInReverseOrder(LogPosition backToPosition)
        {
            return(_physicalStore.getTransactionsInReverseOrder(backToPosition));
        }
Exemple #22
0
 public override void NoCommitsAfterLastCheckPoint(LogPosition logPosition)
 {
     _log.info(format("No commits found after last check point (which is at %s)", logPosition != null ? logPosition.ToString() : "<no log position given>"));
 }
Exemple #23
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public TransactionCursor getTransactionsInReverseOrder(LogPosition position) throws java.io.IOException
            public TransactionCursor getTransactionsInReverseOrder(LogPosition position)
            {
                return(_txStore.getTransactionsInReverseOrder(position));
            }
Exemple #24
0
 public override void CommitsAfterLastCheckPoint(LogPosition logPosition, long firstTxIdAfterLastCheckPoint)
 {
     _log.info(format("Commits found after last check point (which is at %s). First txId after last checkpoint: %d ", logPosition, firstTxIdAfterLastCheckPoint));
 }
Exemple #25
0
 public void transactionsRecovered(CommittedTransactionRepresentation lastRecoveredTransaction, LogPosition positionAfterLastRecoveredTransaction)
 {
 }