Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

add grpc retry to channels #2624

Merged
merged 1 commit into from
Apr 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion python/graphscope/client/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"""

import base64
import json

import grpc
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
Expand Down Expand Up @@ -94,7 +95,8 @@ class Connection:
def __init__(self, addr, gremlin_endpoint, username="", password="") -> None:
self._addr = addr
self._gremlin_endpoint = gremlin_endpoint
channel = grpc.insecure_channel(addr)
options = self._get_channel_options()
channel = grpc.insecure_channel(addr, options=options)
self._ddl_service_stub = ddl_service_pb2_grpc.ClientDdlStub(channel)
self._write_service_stub = write_service_pb2_grpc.ClientWriteStub(channel)
self._client_id = None
Expand All @@ -104,6 +106,27 @@ def __init__(self, addr, gremlin_endpoint, username="", password="") -> None:
graph_url, "g", username=username, password=password
)

def _get_channel_options(self):
json_config = json.dumps(
{
"methodConfig": [
{
"name": [{"service": "gs.rpc.ddl_service.v1.ClientDdl"}],
"retryPolicy": {
"maxAttempts": 5,
"initialBackoff": "0.1s",
"maxBackoff": "10s",
"backoffMultiplier": 2,
"retryableStatusCodes": ["UNAVAILABLE"],
},
}
]
}
)

options = [("grpc.service_config", json_config)]
return options

def __del__(self):
self.close()

Expand Down
Loading