Ejemplo n.º 1
0
        private void ProcessLogRecord(SeqReadResult result)
        {
            switch (result.LogRecord.RecordType)
            {
            case LogRecordType.Prepare:
            {
                var record = (PrepareLogRecord)result.LogRecord;
                ProcessPrepareRecord(record, result.Eof);
                break;
            }

            case LogRecordType.Commit:
            {
                _commitsAfterEof = !result.Eof;
                var record = (CommitLogRecord)result.LogRecord;
                ProcessCommitRecord(record, result.Eof);
                break;
            }

            case LogRecordType.System:
            {
                var record = (SystemLogRecord)result.LogRecord;
                ProcessSystemRecord(record);
                break;
            }

            default:
                throw new ArgumentOutOfRangeException();
            }
            if (result.Eof && result.LogRecord.RecordType != LogRecordType.Commit && _commitsAfterEof)
            {
                _commitsAfterEof = false;
                _masterBus.Publish(new StorageMessage.TfEofAtNonCommitRecord());
            }
        }
Ejemplo n.º 2
0
        private void ProcessLogRecord(SeqReadResult result)
        {
            switch (result.LogRecord.RecordType)
            {
            case LogRecordType.Prepare:
            {
                var record = (PrepareLogRecord)result.LogRecord;
                ProcessPrepareRecord(record);
                break;
            }

            case LogRecordType.Commit:
            {
                var record = (CommitLogRecord)result.LogRecord;
                ProcessCommitRecord(record);
                break;
            }

            case LogRecordType.System:
            {
                var record = (SystemLogRecord)result.LogRecord;
                ProcessSystemRecord(record);
                break;
            }

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 3
0
        private SeqReadResult TryReadPrevInternal(int retries)
        {
            while (true)
            {
                var pos       = _curPos;
                var writerChk = _writerCheckpoint.Read();
                // we allow == writerChk, that means read the very last record
                if (pos > writerChk)
                {
                    throw new Exception(string.Format("Requested position {0} is greater than writer checkpoint {1} when requesting to read previous record from TF.", pos, writerChk));
                }
                if (pos <= 0)
                {
                    return(SeqReadResult.Failure);
                }

                var  chunk    = _db.Manager.GetChunkFor(pos);
                bool readLast = false;
                if (pos == chunk.ChunkHeader.ChunkStartPosition)
                {
                    // we are exactly at the boundary of physical chunks
                    // so we switch to previous chunk and request TryReadLast
                    readLast = true;
                    chunk    = _db.Manager.GetChunkFor(pos - 1);
                }

                RecordReadResult result;
                try
                {
                    result = readLast ? chunk.TryReadLast() : chunk.TryReadClosestBackward(chunk.ChunkHeader.GetLocalLogPosition(pos));
                    CountRead(chunk.IsCached);
                }
                catch (FileBeingDeletedException)
                {
                    if (retries > MaxRetries)
                    {
                        throw new Exception(string.Format("Got a file that was being deleted {0} times from TFChunkDb, likely a bug there.", MaxRetries));
                    }
                    return(TryReadPrevInternal(retries + 1));
                }

                if (result.Success)
                {
                    _curPos = chunk.ChunkHeader.ChunkStartPosition + result.NextPosition;
                    var postPos = result.LogRecord.GetNextLogPosition(result.LogRecord.LogPosition, result.RecordLength);
                    var eof     = postPos == writerChk;
                    var res     = new SeqReadResult(true, eof, result.LogRecord, result.RecordLength, result.LogRecord.LogPosition, postPos);
                    return(res);
                }

                // we are the beginning of chunk, so need to switch to previous one
                // to do that we set cur position to the exact boundary position between current and previous chunk,
                // this will be handled correctly on next iteration
                _curPos = chunk.ChunkHeader.ChunkStartPosition;
            }
        }
Ejemplo n.º 4
0
 private static bool TryReadNextLogRecord(TFReaderLease reader, out SeqReadResult result)
 {
     result = reader.TryReadNext();
     return(result.Success);
 }