public IEnumerable <CommitPoint> GetCommitPoints() { using (var inputStream = _persistenceManager.GetInputStream(_masterFilePath)) { if (inputStream.Length <= HeaderSize) { yield break; } long recordPos = inputStream.Length - CommitPoint.RecordSize; while (recordPos >= HeaderSize) { inputStream.Seek(recordPos, SeekOrigin.Begin); CommitPoint commitPoint = null; try { commitPoint = CommitPoint.Load(inputStream); } catch (InvalidCommitPointException) { Logging.LogError(BrightstarEventId.CommitPointReadError, "Could not read commit point at offset {0} in master file '{1}'", inputStream.Position, _masterFilePath); } if (commitPoint != null) { yield return(commitPoint); } recordPos = recordPos - CommitPoint.RecordSize; } } }
public CommitPoint GetCommitPoint(ulong commitPointLocation) { if (commitPointLocation < HeaderSize || ((commitPointLocation - HeaderSize) % (ulong)CommitPoint.RecordSize) != 0) { throw new ArgumentException("Invalid commit point offset", "commitPointLocation"); } using (var inputStream = _persistenceManager.GetInputStream(_masterFilePath)) { inputStream.Seek((long)commitPointLocation, SeekOrigin.Begin); return(CommitPoint.Load(inputStream)); } }
private CommitPoint _GetCommitPoint(long commitPointLocation, Stream stream) { CommitPoint ret; if (_commitPoints.TryGetValue(commitPointLocation, out ret)) { return(ret); } stream.Seek(commitPointLocation, SeekOrigin.Begin); ret = CommitPoint.Load(stream); _commitPoints.TryAdd(commitPointLocation, ret); return(ret); }
public CommitPoint GetLatestCommitPoint(int skipRecords = 0) { try { using (var stream = _persistenceManager.GetInputStream(_masterFilePath)) { if (stream.Length == HeaderSize) { if (skipRecords > 0) { throw new StoreManagerException(_directoryPath, "Master file is corrupt and no valid commit point information could be read."); } return(null); } long recordStart; if ((stream.Length - HeaderSize) % CommitPoint.RecordSize != 0) { recordStart = stream.Length - ((stream.Length - HeaderSize) % CommitPoint.RecordSize) - ((skipRecords + 1) * CommitPoint.RecordSize); } else { recordStart = stream.Length - ((skipRecords + 1) * CommitPoint.RecordSize); } stream.Seek(recordStart, SeekOrigin.Begin); var commitPoint = CommitPoint.Load(stream); if (skipRecords > 0) { // We skipped over one or more invalid records, so we record a higher next transaction id number in the commit point we return commitPoint.NextCommitNumber = commitPoint.NextCommitNumber + (ulong)skipRecords; // Master file is not truncated here like in the old implementation, // because this could potentially interfere with a master file write operation for a store commit // instead we will need to just always skip corrupt transactions. } return(commitPoint); } } catch (InvalidCommitPointException) { Logging.LogWarning(BrightstarEventId.CommitPointReadError, String.Format( "Failed to read valid commit point from master file '{0}'. Rewinding to previous commit point", _masterFilePath)); return(GetLatestCommitPoint(skipRecords + 1)); } }