Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Handle out of band seeks (#158)
- Handles RESET signal (out of band seek notification) from the server. - Sets the InitialSubscribeRequest.initial_location field when reconnecting subscribe streams.
- Loading branch information
Showing
16 changed files
with
596 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Copyright 2021 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from google.api_core.exceptions import GoogleAPICallError | ||
from google.cloud.pubsublite.internal.status_codes import is_retryable | ||
from google.rpc.error_details_pb2 import ErrorInfo | ||
from grpc_status import rpc_status | ||
|
||
|
||
def is_reset_signal(error: GoogleAPICallError) -> bool: | ||
""" | ||
Determines whether the given error contains the stream RESET signal, sent by | ||
the server to instruct clients to reset stream state. | ||
Returns: True if the error contains the RESET signal. | ||
""" | ||
if not is_retryable(error) or not error.response: | ||
return False | ||
try: | ||
status = rpc_status.from_call(error.response) | ||
for detail in status.details: | ||
info = ErrorInfo() | ||
if ( | ||
detail.Unpack(info) | ||
and info.reason == "RESET" | ||
and info.domain == "pubsublite.googleapis.com" | ||
): | ||
return True | ||
except ValueError: | ||
pass | ||
return False |
Oops, something went wrong.