The GraphStorageClient allows you to scan vertices and edges directly from the storage service, bypassing the graph service and nGQL/Cypher. This is optimized for scanning large volumes of data.
To use it, you must provide a MetaCache containing the addresses of your Meta servers. You can either let the client automatically discover storage addresses via the Meta servers or manually specify them using HostAddr objects (obtained via SHOW HOSTS in NebulaGraph).
from nebula3.mclient import MetaCache, HostAddr
from nebula3.sclient.GraphStorageClient import GraphStorageClient
# The metad servers's address
meta_cache = MetaCache([('172.28.1.1', 9559),
('172.28.1.2', 9559),
('172.28.1.3', 9559)],
50000)
# Option 1: metad usually discovers the storage address automatically
graph_storage_client = GraphStorageClient(meta_cache)
# Option 2: manually specify the storage address
storage_addrs = [HostAddr(host='172.28.1.4', port=9779),
HostAddr(host='172.28.1.5', port=9779),
HostAddr(host='172.28.1.6', port=9779)]
graph_storage_client = GraphStorageClient(meta_cache, storage_addrs)
# Scanning vertices
resp = graph_storage_client.scan_vertex(
space_name='ScanSpace',
tag_name='person')
while resp.has_next():
result = resp.next()
for vertex_data in result:
print(vertex_data)
# Scanning edges
resp = graph_storage_client.scan_edge(
space_name='ScanSpace',
edge_name='friend')
while resp.has_next():
result = resp.next()
for edge_data in result:
print(edge_data)