Gremlin ConcurrentModificationException 在写入 AWS Neptune 时终止 Node.js 服务器,永远不会到达“catch”子句

问题描述 投票:0回答:1

信息
节点:16.20.2
小鬼:3.6.5

ResponseError: Server error: 
{
  "detailedMessage": "Failed to complete Insert operation for a Vertex due to conflicting concurrent operations. Please retry. 0 transactions are currently rolling back.",
  "requestId": "804258c5-6b10-4abc-8d7f-659acaad0f15",
  "code": "ConcurrentModificationException"
} (500)

我提供的代码大多数时候都能成功将数据插入到 AWS Neptune 中,但偶尔会失败,这是预期的。不幸的是,我无法到达 catch 子句,因为 Gremlin 驱动程序错误终止了服务器。我尝试了不同范围内的各种 catch 子句,但问题仍然存在。 当函数是异步 Promise 时,错误率要高得多。

private insertOrUpdateVertex(vertex) {
    const availableSince = new Date(vertex['available_since']);
    let insertQuery = addV(vertex.label).property(t.id, vertex.id);
    insertQuery = this.addProperties(insertQuery, vertex);
    let insertOrUpdateQuery: process.GraphTraversal;
    try {
      insertOrUpdateQuery = this.g
        .V(vertex.id)
        .fold()
        .coalesce(unfold(), insertQuery)
        .has('available_since', P.gt(availableSince))
        .property(single, 'available_since', availableSince);
    } catch (err) {
      this.insertOrUpdateVertex(vertex); //never reaches here to retry
    } finally {
      insertOrUpdateQuery.next();
    }
  }

node.js gremlin amazon-neptune
1个回答
1
投票

看起来您直到

finally{}
块才将终端步骤 [1] 添加到查询中。需要终端步骤将查询发送到数据库。您应该在
next()
块中使用终端步骤(在本例中为
try{}
)。如果抛出异常,那么它将在此时被捕获在
catch{}
块中。

[1] https://tinkerpop.apache.org/docs/current/reference/#terminal-steps

© www.soinside.com 2019 - 2024. All rights reserved.