private void ReadMetaState() { PersistentQueueUtils.Read(Meta, stream => { using (BinaryReader binaryReader = new BinaryReader(stream)) { try { CurrentFileNumber = binaryReader.ReadInt32(); CurrentFilePosition = binaryReader.ReadInt64(); } catch (EndOfStreamException) { } } }); }
private void ReadTransactionLog() { var requireTxLogTrimming = false; PersistentQueueUtils.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. AssertTransactionSeparator(binaryReader, txCount, PersistentQueueMarkers.START, () => readingTransaction = true); var opsCount = binaryReader.ReadInt32(); var txOps = new List <PersistentQueueOperation>(opsCount); for (var i = 0; i < opsCount; i++) { AssertOperationSeparator(binaryReader); var operation = new PersistentQueueOperation( (PersistentQueueOperationTypes)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 != PersistentQueueOperationTypes.ENQUEUE) { requireTxLogTrimming = true; } } // check that the end marker is in place AssertTransactionSeparator(binaryReader, txCount, PersistentQueueMarkers.END, () => { }); readingTransaction = false; ApplyTransactionOperations(txOps); } } catch (EndOfStreamException) { // we have a truncated transaction, need to clear that if (readingTransaction) { requireTxLogTrimming = true; } } } }); if (requireTxLogTrimming) { FlushTrimmedTransactionLog(); } }