/// <summary> /// Connects or reconnects to Spanner, fast forwarding to where we left off based on /// our _resumeToken and _resumeSkipCount. /// </summary> private async Task <bool> ReliableConnectAsync(CancellationToken cancellationToken) { if (_currentCall == null) { await WithTiming(ConnectAsync(), "ConnectAsync").ConfigureAwait(false); Debug.Assert(_currentCall != null, "_currentCall != null"); for (int i = 0; i <= _resumeSkipCount; i++) { ThrowIfCancellationRequested(cancellationToken); _isReading = await WithTiming( _currentCall.ResponseStream.MoveNext(cancellationToken) .WithSessionChecking(() => _session), "ResponseStream.MoveNext") .ConfigureAwait(false); if (!_isReading || _currentCall.ResponseStream.Current == null) { return(false); } if (_metadata == null) { _metadata = _currentCall.ResponseStream.Current.Metadata; } } RecordResumeToken(); RecordStatistics(); } return(_isReading); }
/// <summary> /// Connects or reconnects to Spanner, fast forwarding to where we left off based on /// our _resumeToken and _resumeSkipCount. /// </summary> /// <returns></returns> private async Task <bool> ReliableConnectAsync(CancellationToken cancellationToken) { if (_currentCall == null) { await ConnectAsync().ConfigureAwait(false); Debug.Assert(_currentCall != null, "_currentCall != null"); cancellationToken.ThrowIfCancellationRequested(); for (int i = 0; i <= _resumeSkipCount; i++) { //This calls a simple movenext on purpose. If we get an error here, we'll fail out. _isReading = await _currentCall.ResponseStream.MoveNext(cancellationToken).WithSessionChecking(() => _session).ConfigureAwait(false); if (!_isReading || _currentCall.ResponseStream.Current == null) { return(false); } if (_metadata == null) { _metadata = _currentCall.ResponseStream.Current.Metadata; } } RecordResumeToken(); } return(_isReading); }
/// <summary> /// Connects or reconnects to Spanner, fast forwarding to where we left off based on /// our _resumeToken and _resumeSkipCount. /// </summary> /// <returns></returns> private async Task <bool> ReliableConnectAsync(CancellationToken cancellationToken) { if (_currentCall == null) { await WithTiming(ConnectAsync(), "ConnectAsync").ConfigureAwait(false); Debug.Assert(_currentCall != null, "_currentCall != null"); for (int i = 0; i <= _resumeSkipCount; i++) { ThrowIfCancellationRequested(cancellationToken); //This calls a simple movenext on purpose. If we get an error here, we'll fail out. //TODO(benwu): Fix cancel on MoveNext in a subsequent change targeting spanner GA _isReading = await WithTiming( _currentCall.ResponseStream.MoveNext(CancellationToken.None) .WithSessionChecking(() => _session), "ResponseStream.MoveNext") .ConfigureAwait(false); if (!_isReading || _currentCall.ResponseStream.Current == null) { return(false); } if (_metadata == null) { _metadata = _currentCall.ResponseStream.Current.Metadata; } } RecordResumeToken(); } return(_isReading); }
// Note: internal infrastructure will optimize this to return a singleton completed task when // we're already initialized. private async Task EnsureInitializedAsync(CancellationToken cancellationToken) { if (_initialized) { return; } await MoveNextAsync(cancellationToken).ConfigureAwait(false); _metadata = _currentResultSet?.Metadata; _initialized = true; }
/// <summary> /// Connects or reconnects to Spanner, fast forwarding to where we left off based on /// our _resumeToken and _resumeSkipCount. /// </summary> private async Task <bool> ReliableConnectAsync(CancellationToken cancellationToken) { if (_currentCall == null) { await WithTiming(ConnectAsync(), "ConnectAsync").ConfigureAwait(false); GaxPreconditions.CheckState(_currentCall != null, "Failed to connect"); bool success = false; try { for (int i = 0; i <= _resumeSkipCount; i++) { ThrowIfCancellationRequested(cancellationToken); _isReading = await WithTiming( _currentCall.ResponseStream.MoveNext(cancellationToken) .WithSessionExpiryChecking(_session), "ResponseStream.MoveNext") .ConfigureAwait(false); if (!_isReading || _currentCall.ResponseStream.Current == null) { return(false); } if (_metadata == null) { _metadata = _currentCall.ResponseStream.Current.Metadata; } } RecordResumeToken(); RecordStatistics(); success = true; } finally { // If we failed at any point, dispose the call and forget it. if (!success) { _currentCall?.Dispose(); _currentCall = null; } } } return(_isReading); }