From 3b345dece9228ce5ec8b8b97249e03b0b29cbbdf Mon Sep 17 00:00:00 2001 From: Aiee <18348405+Aiee@users.noreply.github.com> Date: Wed, 4 Jan 2023 11:09:33 +0800 Subject: [PATCH 1/3] Replace the protocol with header protocol --- example/GraphClientSimpleExample.py | 34 ++--------------------------- nebula3/gclient/net/Connection.py | 10 +++++---- 2 files changed, 8 insertions(+), 36 deletions(-) diff --git a/example/GraphClientSimpleExample.py b/example/GraphClientSimpleExample.py index 34a9f70b..6d24d2e4 100644 --- a/example/GraphClientSimpleExample.py +++ b/example/GraphClientSimpleExample.py @@ -22,48 +22,18 @@ config.max_connection_pool_size = 2 # init connection pool connection_pool = ConnectionPool() - assert connection_pool.init([('127.0.0.1', 9669)], config) + assert connection_pool.init([('192.168.15.8', 9669)], config) # get session from the pool client = connection_pool.get_session('root', 'nebula') assert client is not None - # get the result in json format - resp_json = client.execute_json("yield 1") - json_obj = json.loads(resp_json) - print(json.dumps(json_obj, indent=2, sort_keys=True)) - - client.execute( - 'CREATE SPACE IF NOT EXISTS test(vid_type=FIXED_STRING(30)); USE test;' - 'CREATE TAG IF NOT EXISTS person(name string, age int);' - 'CREATE EDGE like (likeness double);' - ) - - # insert data need to sleep after create schema - time.sleep(6) - # insert vertex resp = client.execute( - 'INSERT VERTEX person(name, age) VALUES "Bob":("Bob", 10), "Lily":("Lily", 9)' + 'use sf100;lookup on Person yield id(vertex) as vid | limit 500000 | go from $-.vid over LIKES yield distinct LIKES._src as src, LIKES._dst as dst' ) assert resp.is_succeeded(), resp.error_msg() - # insert edges - resp = client.execute('INSERT EDGE like(likeness) VALUES "Bob"->"Lily":(80.0);') - assert resp.is_succeeded(), resp.error_msg() - - resp = client.execute('FETCH PROP ON person "Bob" YIELD vertex as node') - assert resp.is_succeeded(), resp.error_msg() - print_resp(resp) - - resp = client.execute('FETCH PROP ON like "Bob"->"Lily" YIELD edge as e') - assert resp.is_succeeded(), resp.error_msg() - print_resp(resp) - - # drop space - resp = client.execute('DROP SPACE test') - assert resp.is_succeeded(), resp.error_msg() - print("Example finished") except Exception as x: diff --git a/nebula3/gclient/net/Connection.py b/nebula3/gclient/net/Connection.py index 87f7987e..f831439f 100644 --- a/nebula3/gclient/net/Connection.py +++ b/nebula3/gclient/net/Connection.py @@ -7,9 +7,9 @@ import time -from nebula3.fbthrift.transport import TSocket, TTransport, TSSLSocket +from nebula3.fbthrift.transport import TSocket, TSSLSocket, THeaderTransport from nebula3.fbthrift.transport.TTransport import TTransportException -from nebula3.fbthrift.protocol import TBinaryProtocol +from nebula3.fbthrift.protocol import THeaderProtocol from nebula3.common.ttypes import ErrorCode from nebula3.graph import GraphService @@ -77,8 +77,10 @@ def open_SSL(self, ip, port, timeout, ssl_config=None): s = TSocket.TSocket(self._ip, self._port) if timeout > 0: s.setTimeout(timeout) - transport = TTransport.TBufferedTransport(s) - protocol = TBinaryProtocol.TBinaryProtocol(transport) + transport = THeaderTransport.THeaderTransport(s) + protocol = THeaderProtocol.THeaderProtocol(transport) + # protocol = TCompactProtocol.TCompactProtocol(transport) # using compact protocol still cause nebula3.Exception.IOErrorException: Header transport frame was too large + transport.open() self._connection = GraphService.Client(protocol) resp = self._connection.verifyClientVersion(VerifyClientVersionReq()) From b2ded2382e9dff9c098ff3634364afef2de0fa73 Mon Sep 17 00:00:00 2001 From: Aiee <18348405+Aiee@users.noreply.github.com> Date: Wed, 4 Jan 2023 12:49:13 +0800 Subject: [PATCH 2/3] Revert changes --- example/GraphClientSimpleExample.py | 34 +++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/example/GraphClientSimpleExample.py b/example/GraphClientSimpleExample.py index 6d24d2e4..34a9f70b 100644 --- a/example/GraphClientSimpleExample.py +++ b/example/GraphClientSimpleExample.py @@ -22,18 +22,48 @@ config.max_connection_pool_size = 2 # init connection pool connection_pool = ConnectionPool() - assert connection_pool.init([('192.168.15.8', 9669)], config) + assert connection_pool.init([('127.0.0.1', 9669)], config) # get session from the pool client = connection_pool.get_session('root', 'nebula') assert client is not None + # get the result in json format + resp_json = client.execute_json("yield 1") + json_obj = json.loads(resp_json) + print(json.dumps(json_obj, indent=2, sort_keys=True)) + + client.execute( + 'CREATE SPACE IF NOT EXISTS test(vid_type=FIXED_STRING(30)); USE test;' + 'CREATE TAG IF NOT EXISTS person(name string, age int);' + 'CREATE EDGE like (likeness double);' + ) + + # insert data need to sleep after create schema + time.sleep(6) + # insert vertex resp = client.execute( - 'use sf100;lookup on Person yield id(vertex) as vid | limit 500000 | go from $-.vid over LIKES yield distinct LIKES._src as src, LIKES._dst as dst' + 'INSERT VERTEX person(name, age) VALUES "Bob":("Bob", 10), "Lily":("Lily", 9)' ) assert resp.is_succeeded(), resp.error_msg() + # insert edges + resp = client.execute('INSERT EDGE like(likeness) VALUES "Bob"->"Lily":(80.0);') + assert resp.is_succeeded(), resp.error_msg() + + resp = client.execute('FETCH PROP ON person "Bob" YIELD vertex as node') + assert resp.is_succeeded(), resp.error_msg() + print_resp(resp) + + resp = client.execute('FETCH PROP ON like "Bob"->"Lily" YIELD edge as e') + assert resp.is_succeeded(), resp.error_msg() + print_resp(resp) + + # drop space + resp = client.execute('DROP SPACE test') + assert resp.is_succeeded(), resp.error_msg() + print("Example finished") except Exception as x: From 97acc4189870eaa012acea3d4b51d5516d800771 Mon Sep 17 00:00:00 2001 From: Aiee <18348405+Aiee@users.noreply.github.com> Date: Wed, 18 Jan 2023 18:31:20 +0800 Subject: [PATCH 3/3] Update storage client as well --- nebula3/gclient/net/Connection.py | 1 - nebula3/sclient/net/__init__.py | 9 ++++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/nebula3/gclient/net/Connection.py b/nebula3/gclient/net/Connection.py index f831439f..831ba1ab 100644 --- a/nebula3/gclient/net/Connection.py +++ b/nebula3/gclient/net/Connection.py @@ -79,7 +79,6 @@ def open_SSL(self, ip, port, timeout, ssl_config=None): s.setTimeout(timeout) transport = THeaderTransport.THeaderTransport(s) protocol = THeaderProtocol.THeaderProtocol(transport) - # protocol = TCompactProtocol.TCompactProtocol(transport) # using compact protocol still cause nebula3.Exception.IOErrorException: Header transport frame was too large transport.open() self._connection = GraphService.Client(protocol) diff --git a/nebula3/sclient/net/__init__.py b/nebula3/sclient/net/__init__.py index 2c9f3f8a..9e8ad74d 100644 --- a/nebula3/sclient/net/__init__.py +++ b/nebula3/sclient/net/__init__.py @@ -10,9 +10,8 @@ from nebula3.Exception import InValidHostname from nebula3.storage import GraphStorageService -from nebula3.storage.ttypes import ScanVertexRequest, ScanEdgeRequest -from nebula3.fbthrift.transport import TSocket, TTransport -from nebula3.fbthrift.protocol import TBinaryProtocol +from nebula3.fbthrift.transport import TSocket, THeaderTransport +from nebula3.fbthrift.protocol import THeaderProtocol class GraphStorageConnection(object): @@ -35,8 +34,8 @@ def open(self): s = TSocket.TSocket(self._address.host, self._address.port) if self._timeout > 0: s.setTimeout(self._timeout) - transport = TTransport.TBufferedTransport(s) - protocol = TBinaryProtocol.TBinaryProtocol(transport) + transport = THeaderTransport.THeaderTransport(s) + protocol = THeaderProtocol.THeaderProtocol(transport) transport.open() self._connection = GraphStorageService.Client(protocol) except Exception: