ArangoDB批处理模式不适用于Java Driver

时间:2014-12-23 11:25:32

标签: arangodb

我正在使用弹簧批评估ArangoDB。

我尝试插入一些数据,没有批处理模式,它按预期工作。

但是,如果启用了批处理模式,则程序的执行会挂起。

我正在使用 arango 2.3.3 com.arangodb:arangodb-java-driver:[2.2-SNAPSHOT,2.2]

    arangoDriver.startBatchMode();

    for(Account acc : items){
        acc.getRecordHash();
        acc.getIdHash();
        arangoDriver.createDocument("AccountCollection", acc);
    }

    arangoDriver.executeBatch();

任何想法我做错了什么?

3 个答案:

答案 0 :(得分:1)

我试图重现你正在尝试的东西,首先是收集" AccountCollection"存在吗?如果不是,您将在批处理结果中出现错误,但程序仍然不应该挂起。我创建了一个单元测试:

@Test
  public void test_StartCancelExecuteBatchMode() throws ArangoException {

    driver.startBatchMode();

    ArrayList<Account> items = new ArrayList<Account>();
    items.add(new Account());
    items.add(new Account());
    items.add(new Account());
    items.add(new Account());

    for(Account acc : items){
      acc.getRecordHash();
      acc.getIdHash();
      driver.createDocument("AccountCollection", acc, true, false);
    }

    driver.executeBatch();

  }

这完美无缺,并返回:

<强> EOB 16:47:01.862 [main] DEBUG com.arangodb.http.HttpManager - [RES] http-POST:statusCode = 200 16:47:01.862 [main] DEBUG com.arangodb.http.HttpManager - [RES] http-POST:text = - dlmtrMLTPRT 内容类型:application / x-arango-batchpart Content-Id:request1

HTTP / 1.1 202接受 位置:/ _db / unitTestDatabase / _api / document / AccountCollection / 48033214501 Content-Type:application / json;字符集= utf-8的 Etag:&#34; 48033214501&#34; 内容长度:95

{&#34;错误&#34;:假,&#34; _id&#34;:&#34; AccountCollection / 48033214501&#34;&#34; _rev&#34;:&#34; 48033214501&# 34;,&#34; _key&#34;:&#34; 48033214501&#34;} --dlmtrMLTPRT 内容类型:application / x-arango-batchpart Content-Id:request2

HTTP / 1.1 202接受 位置:/ _db / unitTestDatabase / _api / document / AccountCollection / 48033411109 Content-Type:application / json;字符集= utf-8的 Etag:&#34; 48033411109&#34; 内容长度:95

{&#34;错误&#34;:假,&#34; _id&#34;:&#34; AccountCollection / 48033411109&#34;&#34; _rev&#34;:&#34; 48033411109&# 34;,&#34; _key&#34;:&#34; 48033411109&#34;} --dlmtrMLTPRT 内容类型:application / x-arango-batchpart Content-Id:request3

HTTP / 1.1 202接受 位置:/ _db / unitTestDatabase / _api / document / AccountCollection / 48033607717 Content-Type:application / json;字符集= utf-8的 Etag:&#34; 48033607717&#34; 内容长度:95

{&#34;错误&#34;:假,&#34; _id&#34;:&#34; AccountCollection / 48033607717&#34;&#34; _rev&#34;:&#34; 48033607717&# 34;,&#34; _key&#34;:&#34; 48033607717&#34;} --dlmtrMLTPRT 内容类型:application / x-arango-batchpart Content-Id:request4

HTTP / 1.1 202接受 位置:/ _db / unitTestDatabase / _api / document / AccountCollection / 48033804325 Content-Type:application / json;字符集= utf-8的 Etag:&#34; 48033804325&#34; 内容长度:95

{&#34;错误&#34;:假,&#34; _id&#34;:&#34; AccountCollection / 48033804325&#34;&#34; _rev&#34;:&#34; 48033804325&# 34;,&#34; _key&#34;:&#34; 48033804325&#34;} --dlmtrMLTPRT -

但即使我创造故意错误,应用程序永远不会挂起&#34;。 Frank刚给我发了你的源代码,我看看它。你能试着找出程序挂起的地方吗?是&#34; executeBatch&#34;到达了什么?

答案 1 :(得分:0)

我已经使用您的代码导入了1.6 Mio文档,但一切正常。 我想可能有必要在导入期间监视您的系统资源,如果发生任何异常现在让我们。一般来说,使用java api执行这样的一次性批量导入似乎不是最佳实践。我建议使用 arangoimp 将数据直接导入数据库,这样会快得多。它记录在here

答案 2 :(得分:0)

您需要增加打开文件描述符的数量。 Mac有一个非常低的限制(256)。 ArangoDB将数据存储在特定块大小的数据文件中。对于大型数据集,需要更多文件(并且一些fd已经用于通信和其他内容)。

当ArangoDB用完文件描述符时,它既不能扩展数据集,也不能回答新问题。因此导入过程将会挂起。