From 6c541010dd90bc58cb721d196dfb8fb002831ea9 Mon Sep 17 00:00:00 2001 From: knwng Date: Tue, 18 May 2021 11:07:40 +0800 Subject: [PATCH 1/3] allow graph storage client to skip some broken connections --- nebula2/sclient/GraphStorageClient.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/nebula2/sclient/GraphStorageClient.py b/nebula2/sclient/GraphStorageClient.py index cfcdd996..b8d72791 100644 --- a/nebula2/sclient/GraphStorageClient.py +++ b/nebula2/sclient/GraphStorageClient.py @@ -58,14 +58,15 @@ def _create_connection(self): storage_addrs = self._meta_cache.get_all_storage_addrs() if len(storage_addrs) == 0: raise RuntimeError('Get storage address from meta cache is empty') - try: - for addr in storage_addrs: + for addr in storage_addrs: + try: conn = GraphStorageConnection(addr, self._time_out, self._meta_cache) conn.open() self._connections.append(conn) - except Exception as e: - logging.error('Create storage connection failed: {}'.format(e)) - raise + except Exception as e: + logging.warning('Create storage connection to {} failed: {}'.format(addr, e)) + if len(self._connections) == 0: + raise RuntimeError('No valid storage connection created successfully') def get_space_addrs(self, space_name): return self.meta_cache.get_space_addrs(space_name) From 193963af6566e91eaac8fe0c8eedb38d397331de Mon Sep 17 00:00:00 2001 From: knwng Date: Thu, 20 May 2021 16:17:38 +0800 Subject: [PATCH 2/3] remove offline hosts in MetaClient --- nebula2/mclient/__init__.py | 6 +++++- nebula2/sclient/GraphStorageClient.py | 11 +++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/nebula2/mclient/__init__.py b/nebula2/mclient/__init__.py index 20c7b62d..da239e6f 100644 --- a/nebula2/mclient/__init__.py +++ b/nebula2/mclient/__init__.py @@ -140,7 +140,11 @@ def list_hosts(self): continue raise RuntimeError("List spaces failed, error code: {}" .format(ErrorCode._VALUES_TO_NAMES(resp.code))) - return resp.hosts + valid_hosts = [] + for host in resp.hosts: + if host.status == 0: + valid_hosts.append(host) + return valid_hosts raise RuntimeError("List spaces failed, error code: {}" .format(ErrorCode._VALUES_TO_NAMES(resp.code))) diff --git a/nebula2/sclient/GraphStorageClient.py b/nebula2/sclient/GraphStorageClient.py index b8d72791..cfcdd996 100644 --- a/nebula2/sclient/GraphStorageClient.py +++ b/nebula2/sclient/GraphStorageClient.py @@ -58,15 +58,14 @@ def _create_connection(self): storage_addrs = self._meta_cache.get_all_storage_addrs() if len(storage_addrs) == 0: raise RuntimeError('Get storage address from meta cache is empty') - for addr in storage_addrs: - try: + try: + for addr in storage_addrs: conn = GraphStorageConnection(addr, self._time_out, self._meta_cache) conn.open() self._connections.append(conn) - except Exception as e: - logging.warning('Create storage connection to {} failed: {}'.format(addr, e)) - if len(self._connections) == 0: - raise RuntimeError('No valid storage connection created successfully') + except Exception as e: + logging.error('Create storage connection failed: {}'.format(e)) + raise def get_space_addrs(self, space_name): return self.meta_cache.get_space_addrs(space_name) From fa0075f072537d4b705aea03d7fb9e638ca57ae4 Mon Sep 17 00:00:00 2001 From: knwng Date: Mon, 24 May 2021 10:42:48 +0800 Subject: [PATCH 3/3] use HostStatus.ONLINE to represent host status --- nebula2/mclient/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nebula2/mclient/__init__.py b/nebula2/mclient/__init__.py index 7dbca985..7816cba2 100644 --- a/nebula2/mclient/__init__.py +++ b/nebula2/mclient/__init__.py @@ -19,6 +19,7 @@ ) from nebula2.common.ttypes import HostAddr, ErrorCode from nebula2.meta.ttypes import ( + HostStatus, ListTagsReq, ListEdgesReq, ListSpacesReq, @@ -141,7 +142,7 @@ def list_hosts(self): .format(ErrorCode._VALUES_TO_NAMES.get(resp.code))) valid_hosts = [] for host in resp.hosts: - if host.status == 0: + if host.status == HostStatus.ONLINE: valid_hosts.append(host) return valid_hosts raise RuntimeError("List spaces failed, error code: {}"