本文介紹將數(shù)據(jù)從OSS導(dǎo)入至圖數(shù)據(jù)庫(kù)GDB的完整流程。

前提條件

準(zhǔn)備測(cè)試數(shù)據(jù)

本文將使用air-routes數(shù)據(jù)集作為測(cè)試數(shù)據(jù),圖數(shù)據(jù)庫(kù)GDB的數(shù)據(jù)分為點(diǎn)文件和邊文件,下載鏈接如下:

說(shuō)明 進(jìn)入點(diǎn)文件和邊文件網(wǎng)頁(yè)后,單擊右鍵,然后單擊另存為保存為CSV格式文件。

您也可以使用其它數(shù)據(jù)進(jìn)行導(dǎo)入測(cè)試,圖數(shù)據(jù)庫(kù)GDB對(duì)CSV數(shù)據(jù)的文件格式有要求,具體要求,請(qǐng)參見(jiàn)CSV數(shù)據(jù)文件格式

上傳數(shù)據(jù)至OSS

以下內(nèi)容為通過(guò)OSS控制臺(tái)上傳數(shù)據(jù)。如果您需要通過(guò)ossutil工具上傳數(shù)據(jù),請(qǐng)參見(jiàn)使用ossutil工具上傳數(shù)據(jù)文件

  1. 登錄OSS管理控制臺(tái)
  2. 單擊左側(cè)導(dǎo)航欄的Bucket列表,然后單擊目標(biāo)Bucket名稱(chēng)。
  3. 單擊上傳文件
  4. 上傳文件面板,配置文件存儲(chǔ)目錄、讀寫(xiě)權(quán)限并選擇待上傳文件。
  5. 單擊上傳文件

完成上傳后,您可以返回文件管理頁(yè)面查看文件存儲(chǔ)路徑,在導(dǎo)入數(shù)據(jù)到圖數(shù)據(jù)庫(kù)GDB時(shí)需要使用該路徑。

導(dǎo)入數(shù)據(jù)到OSS

如上圖所示,gdbOssDemo/node路徑存放了點(diǎn)文件,gdbOssDemo/edge路徑存放了邊文件,假如Bucket名稱(chēng)為gdbbucket,則點(diǎn)文件和邊文件的OSS路徑分別為:

  • 點(diǎn)文件
    oss://gdbbucket/gdbOssDemo/node/
  • 邊文件
    oss://gdbbucket/gdbOssDemo/edge/

導(dǎo)入數(shù)據(jù)到圖數(shù)據(jù)庫(kù)GDB

以下內(nèi)容僅為導(dǎo)入數(shù)據(jù)到圖數(shù)據(jù)庫(kù)GDB的示例步驟,更多參數(shù)說(shuō)明,請(qǐng)參見(jiàn)使用curl命令導(dǎo)入數(shù)據(jù)文件

  1. 在客戶(hù)端(例如ECS或本地客戶(hù)端)上執(zhí)行curl命令,導(dǎo)入點(diǎn)文件,示例如下:通過(guò)ramRoleArn與 accessKey和secretKey選擇一個(gè)即可。
    curl -u gdb_user:PassWord -X POST \
    -H 'Content-Type: application/json' \
    http://gds-*****.graphdb.rds.aliyuncs.com:8182/loader -d '
    {
       "source" : "oss://gdbbucket/gdbOssDemo/node/",
       "ramRoleArn" : "acs:ram::1***************:role/aliyunserviceroleforgdb"
    }'
    使用ramRoleArn方法進(jìn)行數(shù)據(jù)導(dǎo)入時(shí),導(dǎo)入任務(wù)受臨時(shí)安全令牌(STS)有效時(shí)間的限制,不能超過(guò)10小時(shí),超過(guò)會(huì)導(dǎo)致任務(wù)中斷(即數(shù)據(jù)不能全部導(dǎo)入)。如果您需要導(dǎo)入的數(shù)據(jù)量較大,建議您采用accessKey或secretKey的方法導(dǎo)入。
    curl -u gdb_user:PassWord -X POST \
    -H 'Content-Type: application/json' \
    http://gds-*****.graphdb.rds.aliyuncs.com:8182/loader -d '
    {
       "source" : "oss://gdbbucket/gdbOssDemo/node/",
       "accessKey": "XXXXXX",
       "secretKey": "XXXXXX"
    }'
    說(shuō)明 請(qǐng)將以上示例中的參數(shù)替換為您真實(shí)的數(shù)據(jù)庫(kù)信息,使用本地客戶(hù)端連接時(shí)請(qǐng)使用外網(wǎng)地址。

    圖數(shù)據(jù)庫(kù)GDB導(dǎo)入程序檢查參數(shù)無(wú)誤后,將返回導(dǎo)入任務(wù)IDloadId,示例如下:

    {
      "status" : "200 OK",
      "payload" : {
          "loadId" : "552617AF-4F1E-4CD8-9533-************"
      }
    }
  2. 在客戶(hù)端執(zhí)行curl命令,導(dǎo)入邊文件,示例如下:
    curl -u gdb_user:PassWord -X POST \
    -H 'Content-Type: application/json' \
    http://gds-*****.graphdb.rds.aliyuncs.com:8182/loader -d '
    {
       "source" : "oss://gdbbucket/gdbOssDemo/edge/",
       "ramRoleArn" : "acs:ram::1***************:role/aliyunserviceroleforgdb"
    }'
    說(shuō)明 請(qǐng)將以上示例中的參數(shù)替換為您真實(shí)的數(shù)據(jù)庫(kù)信息,使用本地客戶(hù)端連接時(shí)請(qǐng)使用外網(wǎng)地址。

    圖數(shù)據(jù)庫(kù)GDB導(dǎo)入程序檢查參數(shù)無(wú)誤后,將返回導(dǎo)入任務(wù)IDloadId,示例如下:

    {
      "status" : "200 OK",
      "payload" : {
          "loadId" : "552617AF-4F1E-4CD8-9533-************"
      }
    }

成功上傳后,您可以通過(guò)loadId查看導(dǎo)入任務(wù)的任務(wù)狀態(tài),示例如下:

curl -u gdb_user:PassWord -X GET 'http://gds-*****.graphdb.rds.aliyuncs.com:8182/loader/<loadId>'

常見(jiàn)問(wèn)題

  • Q:導(dǎo)入相同的文件后,系統(tǒng)返回LOAD_NOT_SUPPORT TO RESUME LOAD錯(cuò)誤。

    A:需要將之前導(dǎo)入數(shù)據(jù)生成的loadId刪除,刪除語(yǔ)句如下:

    curl -u gdb_account:******** -X DELETE 'http://gds-123.graphdb.rds.aliyuncs.com:****/loader/552617AF-4F1E-4CD8-9533-A2EC154688DC'

    如果有很多l(xiāng)oadId,您可以使用以下腳本批量刪除:

    #!/bin/bash
    
    GDB_HOST=YOU_GDB_HOST
    GDB_PORT=YOU_GDB_PORT
    GDB_USER=YOUR_GDB_USER
    GDB_PASSWORD=YOUR_GDB_PASSWORD
    curl -u "${GDB_USER}:${GDB_PASSWORD}" "http://${GDB_HOST}:${GDB_PORT}/loader"| python3 -c 'import json,sys;print("\n".join(json.load(sys.stdin)["payload"]["loadIds"]))'| while read TASK;
    do
      echo delete task: $TASK
      curl -u "${GDB_USER}:${GDB_PASSWORD}" -XDELETE  "http://${GDB_HOST}:${GDB_PORT}/loader/${TASK}"
    done
    curl -u "${GDB_USER}:${GDB_PASSWORD}" "http://${GDB_HOST}:${GDB_PORT}/loader"
  • Q:導(dǎo)入文件時(shí),提示Commit record Error(21-0)錯(cuò)誤。

    A:您需要將導(dǎo)入?yún)?shù)failOnError修改為false,修改操作,請(qǐng)參見(jiàn)導(dǎo)入接口介紹

更多錯(cuò)誤信息,請(qǐng)參見(jiàn)錯(cuò)誤信息列表