Skip to content

Commit

Permalink
add grpc retry to channels
Browse files Browse the repository at this point in the history
  • Loading branch information
siyuan0322 committed Apr 19, 2023
1 parent 2a91bbc commit 32250ad
Showing 1 changed file with 24 additions and 1 deletion.
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

0 comments on commit 32250ad

Please sign in to comment.