1

enter image description here

I have two databases, 1 cosmos DB core, 2 cosmos gremlin. I perform an action of creating a new user (or updating or deleting) and I want to make sure that Atomicity guarantees that all the operations done inside a transaction are treated as a single unit, and either all of them are committed or none of them are. Now, making sure a transaction only on the cosmosDb core does not suffice me. Because it does not include the gremlin db. How to make a full transaction on both cosmos db core and cosmos db gremlin

for example

    public async Task CreateInstitute(Institute institute)
    {
        if (string.IsNullOrEmpty(institute.Id))
        {
            institute.Id = Helper.NewId();
        }
        // TODO: transaction
        var batch = _coreDb.Institutes.CreateTransactionalBatch(new Microsoft.Azure.Cosmos.PartitionKey(CORE_PARTITION));
        JObject coreInstitute = JsonHelper.CombineObjects(institute, new CreationSystemProperties(CORE_PARTITION));
        batch.CreateItem(coreInstitute);
        var results = await batch.ExecuteAsync();
        if (results.IsSuccessStatusCode)
        {

            JObject graphInstitute = JsonHelper.CombineObjects(new InstituteSummary(institute), new SummaryCreationSystemProperties(institute.Id));
            JObject graphYear = JsonHelper.ToJObject(new Year(Helper.GetSchoolYear(DateTime.Now)));
            var bindings = new Dictionary<string, object>();
            string gremlin = Functions.FinalizeQuery(WriteQueries.AddVertex("Institute", graphInstitute, institute.Id, bindings), WriteQueries.AddChildVertex("Period", "Year", graphYear, institute.Id, bindings));
            await _graphDb.GremlinClient.SubmitAsync(gremlin, bindings);
            // if this action is bad => how to roll back cosmos db core
        }
    }
  • Not entirely sure what you're trying to do, but... there's no concept of transaction scope outside of a single partition of a single container/collection in Cosmos DB. You'd need to implement something on your own. – David Makogon May 23 '22 at 11:52
  • we would like to use Cosmos-DB through the Gremlin-API. The thing which we are not sure about is how to handle atomic writes. Cosmos' consistency levels (from strong to eventual) are fine for us, but we haven't found a way to have atomic write operations through the Gremlin API. I have found following question but there is no answer so far: Azure Cosmos Gremlin API: transactions and efficient graph traversal. https://stackoverflow.com/questions/65161755/azure-cosmos-gremlin-api-transactions-and-efficient-graph-traversal If I had not been clear enough – יעקב פרידמן May 23 '22 at 12:17

0 Answers0