手把手教学:ArangoDB数据迁移至Galaxybase【图数据库数据迁移实践】

前言

Galaxybase是创邻科技自主研发的国内首款超大规模分布式并行原生图平台产品,拥有优异的数据读写查询性能、强⼤的可视化分析能力、丰富的可编程接口和开箱即用的图算法引擎,是集存储、计算、分析于一体的图数据全生命周期⼀站式管理平台,符合大数据时代下,客户对数据高效存储和查询的需求。
Galaxybase系统架构图
目前,Galaxybase已在金融、能源、政府、公安等行业完成落地,在需要复杂关联数据实时查询分析的场景下,可以实现原有关系型数据库或国外同类型产品的平滑替代,帮助企业激发数据价值。ArangoDB是国外较为流行的原生多模型数据库产品,兼有键值、文档、图三种数据模型,适用于开发需要具备灵活性的场景。本文将以创邻科技官网的MovieDemo数据集作为例子,教大家运用两种方案实现ArangoDB到Galaxybase的数据迁移。

数据迁移方案

Galaxybase-convert为创邻科技封装完成的数据迁移工具,在本方案中将使用convert工具将MovieDemo数据集从ArangoDB(v3.10)数据迁移至Galaxybase(v3.4.2),具体迁移流程图如下:
在这里插入图片描述

前提条件

  1. galaxybase-convert工具(下文统称"convert工具");
  2. Galaxybase数据库load权限;
  3. 当前导入的图项目,在Galaxybase图项目中不存在;
  4. 需要arangoexport工具,复制到galaxybase-convert所在的服务器上;
  5. 需要arangoexport.conf文件。

注意事项

  1. graphName参数需要填写ArangoDB的数据库名,本工具用于迁移一个库的所有数据;
  2. 导出过程中,点边不能增删;
  3. 由于Galaxybase为强schema,不能使用未定义的属性。ArangoDB为弱schema,可以使用未定义的属性。在迁移过程中,对于同一类型点边,将生成所有属性;
  4. ArangoDB数据导出时,以 _id 为主键,ArangoDB的 _id 包含类型信息,如people/11。

数据集说明

示例数据集为创邻科技官网提供的MovieDemo数据集,包含两个点类型、一条边类型。为将源数据导入ArangoDB,我们将对数据类型做一些修改,具体属性信息如下:

“人物”点数据,将其类型名改为people,并增加以下两列连续增长的 _key 及相应的 _id ;

属性名属性类型
_idSTRING
_keySTRING
姓名STRING
出生年份STRING
出生地STRING

“电影”点数据,将其类型名改为movie,并增加以下两列连续增长的 _key 及相应的 _id ;

属性名属性类型
_idSTRING
_keySTRING
上映年份STRING
语言STRING
评分INT
票房INT
类型STRING

“出演电影”边数据,起始点为“人物”,终止点为“电影”,将其类型名改为act,并增加 _from 和 _to ,分别对应“人物”和“电影”的 _id ,同时保留“电影名”和“演员”属性。

属性名属性类型
_fromSTRING
_toSTRING
电影名STRING
演员STRING
片酬INT
角色名称STRING
是否主演STRING

方案一:运行galaxybase-convert直接导入到Galaxybase

本方案适用于可以在Galaxybase服务器上直接访问到ArangoDB的情况,一步完成。否则,建议直接从跳到方案二。 执行方案一进行数据迁移时,针对可能出现的情况提出以下注意事项:

  1. 在Galaxybase服务器上,必须有arangoexport命令;
  2. dataDir参数需要直接指定到galaxybase内部的指定位置:galaxybase_home/graph/data (galaxybase_home是Galaxybase启动时home参数的值,启动命令示例:galaxybase-deploy build graph --home galaxybase_home)。

第一步:执行galaxybase-convert

使用以下命令调用convert工具,系统将指定ArangoDB的地址、用户名、密码,并导出某个数据库到预设路径下,再导入Galaxybase。

$ galaxybase-convert \ 
--arangodb tcp://192.168.20.76:8529 \ 
--arangoUser root --arangoPass 1 \ 
--graphName _system \ 
--dataDir ~/galaxybase_home/graph/data \ 
--arangoexport ~/arangoexport \ 
--arangoConfiguration ./arangoexport.conf \ 
--graph 127.0.0.1:18088 \--username admin --password admin 
2022/11/09 11:04:23 Statistics vertexes and edges information... 
2022/11/09 11:04:23 vertexes count is : [8885], edges count is : [6154] 
2022/11/09 11:04:23 Analytic graph structure... 
2022/11/09 11:04:23 Get vertex information... 
2022/11/09 11:04:23 Analyze the vertex structure : 
[==================================================] 100.00% 
2022/11/09 11:04:23 Get edge information... 
2022/11/09 11:04:24 Analyze the edge structure progress : 
[==================================================] 100.00% 
2022/11/09 11:04:24 Draws the vertex structure to the schema... 
2022/11/09 11:04:24 Draws the edge structure to the schema... 
2022/11/09 11:04:24 Generating schema file... 
2022/11/09 11:04:24 Draws the vertex structure to the mapping... 
2022/11/09 11:04:24 Draws the edge structure to the mapping... 
2022/11/09 11:04:24 Generating mapping file... 
2022/11/09 11:04:24 Start exporting data to CSV files... 
2022/11/09 11:04:24 Will load vertexes: [ movie people ] 
2022/11/09 11:04:24 Will load edges: [ people-act-movie ] 
2022/11/09 11:04:24 Start loading the graph... 
2022/11/09 11:04:24 The graph [_system] does not exist, start creating the graph 
2022/11/09 11:04:24 create graph successfully 
2022/11/09 11:04:24 save mapping successfully 
2022/11/09 11:04:24 Start loading data... 
current time : 2022-11-09 11:05:04 graph name : _system 
start time : 2022-11-09 11:04:24 end time : 2022-11-09 11:05:03 
load state : loadSuccessful use time : 40.112 s 
vertexLoad speed : -/s edgeLoad speed : -/s 
vertexLoad speed avg : 1714 /s edgeLoad speed avg : 34379 /s 
vertex line scan : 8885 edge line scan : 6154 
file error line : 0 
2022/11/09 11:05:04 load successfully

命令参数说明:

参数说明
–arangodbArangoDB的协议、IP、端口
–arangoUserArangoDB的用户名
–arangoPassArangoDB的密码
–graphName需要导出的数据库名,在ArangoDB中将导入整个库
–dataDir导出文件存放路径。注意,最终存放路径为dataDir/graphName/
–arangoexportarangoexport命令的路径
–arangoConfigurationaranfoexport的配置文件
–graphGalaxybase的IP地址和端口
–usernameGalaxybase的用户名
–passwordGalaxybase的密码

命令执行完成后,“MovieDemo”图将从ArangoDB迁移至Galaxybase,可以访问Galaxybase图可视化平台查看图项目。

方案二:运行galaxybase-convert导出数据为csv,再导入Galaxybase

本方案适用于在Galaxybase服务器上无法访问ArangoDB的情况。 操作总共分为三步:执行galaxybase-convert导出数据为csv、移动数据到Galaxybase服务器上、实现galaxybase-load执行数据导入,下面讲解迁移实现过程。

第一步:执行galaxybase-convert导出数据为csv

使用以下命令调用convert工具,系统将指定ArangoDB的地址、用户名、密码,并导出某个数据库到预设路径下。

$ galaxybase-convert \ 
--arangodb tcp://192.168.20.76:8529 \ 
--arangoUser root --arangoPass 1 \ 
--graphName _system \ 
--dataDir ~/galaxybase_home/graph/data \ 
--arangoexport ~/arangoexport \ 
--arangoConfiguration ./arangoexport.conf \ 
--onlyOutput 

2022/11/08 10:31:57 Statistics vertexes and edges information... 
2022/11/08 10:31:57 vertexes count is : [8885], edges count is : [6156] 
2022/11/08 10:31:57 Analytic graph structure... 
2022/11/08 10:31:57 Get vertex information... 
2022/11/08 10:31:57 Analyze the vertex structure : 
[==================================================] 100.00% 
2022/11/08 10:31:57 Get edge information... 
2022/11/08 10:31:57 Analyze the edge structure progress : 
[==================================================] 100.00% 
2022/11/08 10:31:57 Draws the vertex structure to the schema... 
2022/11/08 10:31:57 Draws the edge structure to the schema...
2022/11/08 10:31:57 Generating schema file... 
2022/11/08 10:31:57 Draws the vertex structure to the mapping... 
2022/11/08 10:31:57 Draws the edge structure to the mapping... 
2022/11/08 10:31:57 Generating mapping file... 
2022/11/08 10:31:57 Start exporting data to CSV files... 
2022/11/08 10:31:57 Will load this vertex: [ movie people ] 
2022/11/08 10:31:57 Will load this edges: [ people-act-movie movie-act-people ]

命令参数说明:

参数说明
–arangodbArangoDB的协议、IP、端口
–arangoUserArangoDB的用户名
–arangoPassArangoDB的密码
–graphName需要导出的数据库名,在ArangoDB中将导入整个库
–dataDir导出文件存放路径。注意,最终存放路径为dataDir/graphName/
–arangoexportarangoexport命令的路径
–arangoConfigurationaranfoexport的配置文件
–onlyOutput仅导出数据,不导入Galaxybase

第二步:移动数据到Galaxybase服务器上

从ArangoDB导出时的文件内容如下:

  • ~/arangodb_data:dataDir参数指定的路径
  • MovieDemo:graphName参数指定的数据库名
    schema.json
    mapping.json
    VERTEX@@people.csv(people点文件)
    VERTEX@@movie.csv(movie点文件)
    EDGE@@people@@act@@movie(act的边文件夹(仅含people指向movie的部分))

将生成的MovieDemo文件夹,移动到Galaxybase服务器上,移动路径如下所示:

  • galaxybase_home/graph/data:galaxybase_home是Galaxybase启动时home参数的值。将文件移动到上述路径下 。

第三步:使用galaxybase-load执行数据导入

执行以下命令,使用galaxybase-load工具将MovieDemo数据集导入,schema存放在schema.json路径,mapping存放在mapping.json路径,两个文件的路径可自行调整。具体调用命令如下:


$ galaxybase-load -g MovieDemo -s ~/galaxybase_home/graph/data/MovieDemo/schema.json - 
m ~/galaxybase_home/graph/data/MovieDemo/mapping.json --disableStudio 

2022/10/28 09:40:07 The graph [MovieDemo] does not exist, start creating the graph 
2022/10/28 09:40:07 create graph successfully 
2022/10/28 09:40:08 save mapping successfully 
2022/10/28 09:40:08 Start loading data... 
current time : 2022-10-28 09:41:17  graph name : MovieDemo 
start time : 2022-10-28 09:40:08  end time : 2022-10-28 09:41:16 
load state : loadSuccessful  use time : 1m9.133s 
vertexLoad speed : -/s  edgeLoad speed : -/s 
vertexLoad speed avg : 1638/s  edgeLoad speed avg:1171/s 
vertex line scan : 8885  edge line scan : 6154 
file error line : 0 
2022/10/28 09:41:17 load successfully

迁移结果展示

访问Galaxybase图可视化平台查看迁移结果,可以看到图名称为MovieDemo,点数量为8592个,边数量为6154条,和命令行中名称、数量一致;图模型为人物-出演-电影,属性信息和原数据集一致。
在这里插入图片描述
在这里插入图片描述

结语

本文讲述了通过命令行工具galaxybase-convert,以MovieDemo数据集为例,进行第三方数据库ArangoDB数据迁移至Galaxybase的操作流程。此外,该工具还支持多项数据源的数据迁移,目前支持的数据源有Neo4j 3.x版本、4.x版本,ArangoDB <=3.10版本,一般应用在实体关系复杂且难以获取的场景中,如果场景中实体结构清晰,建议使用图构建工具galaxybase-load进行数据的迁移工作。具体迁移工具使用详情可以移步创邻科技官网-资源中心-开发者资源-技术文档-命令行工具-图构建数据导入工具,查看图模型定义文件(schema.json)和图数据映射文件(mapping.json)。

后续,我们将统计读者在使用Galaxybase进行替换的过程中,对数据迁移提出的共性问题产出实践文案。针对细节性问题,可以再Galaxybase公众号留言或在官方论坛提问,我们将给予答复。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值