private async Task WaitForCommit(SequenceNumber currentSequenceNumber, CancellationToken cancellationToken) { this.logger.Log( $"Needing to replicate {this.upToSequenceNumber}, but no records remain and have only seen {this.highestLsn}"); var iterations = 0; do { if (iterations++ > 1) { await Task.Delay(TimeSpan.FromMilliseconds(100), cancellationToken); } if (iterations > 50) { this.logger.Log($"Warning, waited {iterations * 100}ms for commit of {this.upToSequenceNumber}"); } await this.replicationNotifier.WaitForCommit(this.upToSequenceNumber); this.records = this.log.GetRecords(currentSequenceNumber, LogRecordEnumeratorType.Next).GetEnumerator(); this.hasRecord = this.records.MoveNext(); }while (this.hasRecord && this.log.LastSequenceNumber == currentSequenceNumber); var from = currentSequenceNumber.Identifier(); var to = this.hasRecord ? this.records.Current.SequenceNumber.Identifier() : SequenceNumber.Invalid.Identifier(); this.logger.Log( $"CopyStateStream: {this.upToSequenceNumber} was committed, continuing." + $"HasNext: {this.hasRecord}. Moving from SequenceNumber: {@from} to {to}"); }
private async Task WaitForCommit(SequenceNumber currentSequenceNumber, CancellationToken cancellationToken) { this.logger.Log( $"Needing to replicate {this.upToSequenceNumber}, but no records remain and have only seen {this.highestLsn}"); var iterations = 0; do { if (iterations++ > 1) { await Task.Delay(TimeSpan.FromMilliseconds(100), cancellationToken); } if (iterations > 50) { this.logger.Log($"Warning, waited {iterations * 100}ms for commit of {this.upToSequenceNumber}"); } await this.replicationNotifier.WaitForCommit(this.upToSequenceNumber); this.records = this.log.GetRecords(currentSequenceNumber, LogRecordEnumeratorType.Next).GetEnumerator(); this.hasRecord = this.records.MoveNext(); } while (this.hasRecord && this.log.LastSequenceNumber == currentSequenceNumber); var from = currentSequenceNumber.Identifier(); var to = this.hasRecord ? this.records.Current.SequenceNumber.Identifier() : SequenceNumber.Invalid.Identifier(); this.logger.Log( $"CopyStateStream: {this.upToSequenceNumber} was committed, continuing." + $"HasNext: {this.hasRecord}. Moving from SequenceNumber: {@from} to {to}"); }