private void ReadTransactionLog() { var requireTxLogTrimming = false; Atomic.Read(TransactionLog, stream => { using (var binaryReader = new BinaryReader(stream)) { bool readingTransaction = false; try { int txCount = 0; while (true) { txCount += 1; // this code ensures that we read the full transaction // before we start to apply it. The last truncated transaction will be // ignored automatically. AssertTransactionSeperator(binaryReader, txCount, Constants.StartTransactionSeparatorGuid, () => readingTransaction = true); var opsCount = binaryReader.ReadInt32(); var txOps = new List <Operation>(opsCount); for (var i = 0; i < opsCount; i++) { AssertOperationSeparator(binaryReader); var operation = new Operation( ( OperationType )binaryReader.ReadByte(), binaryReader.ReadInt32(), binaryReader.ReadInt32(), binaryReader.ReadInt32() ); txOps.Add(operation); //if we have non enqueue entries, this means // that we have not closed properly, so we need // to trim the log if (operation.Type != OperationType.Enqueue) { requireTxLogTrimming = true; } } AssertTransactionSeperator(binaryReader, txCount, Constants.EndTransactionSeparatorGuid, () => { }); readingTransaction = false; ApplyTransactionOperations(txOps); } } catch (EndOfStreamException) { // we have a truncated transaction, need to clear that if (readingTransaction) { requireTxLogTrimming = true; } } } }); if (requireTxLogTrimming) { FlushTrimmedTransactionLog(); } }
private void ReadMetaState() { Atomic.Read(Meta, stream => { using (var binaryReader = new BinaryReader(stream)) { try { CurrentFileNumber = binaryReader.ReadInt32(); CurrentFilePosition = binaryReader.ReadInt64(); } catch (EndOfStreamException) { } } }); }