【问题标题】:Transaction on Graph Cosmos DBGraph Cosmos DB 上的交易
【发布时间】:2018-01-23 06:25:12
【问题描述】:

我在 gremlin 中有两个查询,第一个是添加一个顶点,第二个是在添加的顶点和图中已存在的顶点之间添加一条边。

string query1 = $"g.addV('session').property('id','{session_id}').property('initialState', 'start')";
string query2 = $"g.V('{session_id}').addE('belongs').to(g.V('{userId}'))";

当我用 C# 编写程序时,要确保上述两个命令都运行或都不运行,第一个想法是在 C# 中使用 TransactionScope。但是,它没有解决我的问题,因为它不在 Cosmos DB 上。问题是如何在 C# 中的 Graph Cosmos DB 上的 事务 中执行这些命令?

在 gremlin 中有什么技术可以解决这个问题吗? graph.tx().commit() 是否适用于 Cosmos DB?

// In A Transaction Scope
IDocumentQuery<dynamic> query = database.Client.CreateGremlinQuery<dynamic>(database.Graph, query1);
query.ExecuteNextAsync().Result;

query = database.Client.CreateGremlinQuery<dynamic>(database.Graph, query2);
query.ExecuteNextAsync().Result;

【问题讨论】:

    标签: c# transactions gremlin azure-cosmosdb


    【解决方案1】:

    很遗憾,CosmosDB 在执行 gremlin 命令时不支持事务。

    如果您还没有,我建议您至少使用 Session consistency level。这将保证您在同一会话中执行的多个 gremlin 命令中读取您的写入。默认情况下,DocumentClient 假定目标 Document 集合配置的一致性级别。

    除此之外,SDK 中当前对 gremlin 命令的支持不提供其他可以近似交易的技术。如果选择使用 Cosmos DB SQL 命令或存储过程,还有其他选项可用,但这会阻止您使用 gremlin 查询对数据进行操作。

    【讨论】:

    • 你好,因为这个答案已经写了一年多 - 有什么变化吗?是否有任何计划包括对 Microsoft.Azure.Graphs 的事务支持?谢谢
    【解决方案2】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-05
      • 2021-11-08
      • 1970-01-01
      • 1970-01-01
      • 2018-08-06
      • 2021-12-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多