Does Azure Cosmos Gremlin Supports Transaction Management?

Vamshi, Merugu 20 Reputation points
2024-10-29T11:01:47.5433333+00:00

Im trying to achieve transaction management in cosmos gremlin. Like i should be able to create some nodes and edges in a single transaction, if one of the operation fails the entire transaction should be discarded, like in sql terms commit and rollback. Would i be able to achieve that ?

I tried using DriverRemoteConnection from gremlin driver, which seems to have commit and rollback, but i cant run any queries using connection.submit(), because this strictly uses Bytecode traversal, which is an unsupported feature of cosmos gremlin https://learn.microsoft.com/en-us/azure/cosmos-db/gremlin/support#unsupported-features.

im using node gremlin package

export const connection : driver.DriverRemoteConnection = new driver.DriverRemoteConnection(
  endpoint,
  {
    authenticator,
    traversalsource: 'g',
    rejectUnauthorized: true,
    mimeType: 'application/vnd.gremlin-v2.0+json',
  }
);


const query = "g.addV('TEST').property('id', 'test').property('partitionKey', 'test').property('name', 'test')";
await connection.open();
const res1 = await connection.submit(query) // fails here saying 'Argument of type 'string' is not assignable to parameter of type 'Bytecode''
await connection.commit();

So, i changed my approach little bit using process.traversal from gremlin package

const tx = process.traversal().withRemote(connection).tx();
  const g = tx.begin();
  const res1 = await g.addV('VMER').property('id', '2').property('partitionKey', '2').iterate();
  Logger.info('Query executed successfully', res1);
  await tx.commit();

this fails with below error

Stack: ResponseError: Server error: 
[2024-10-29T10:26:46.172Z] 
[2024-10-29T10:26:46.172Z] ActivityId : 8cfb0fcf-7ae1-42c5-9759-d1aa7b23f984
[2024-10-29T10:26:46.172Z] ExceptionType : GraphMalformedException
[2024-10-29T10:26:46.172Z] ExceptionMessage : 
[2024-10-29T10:26:46.172Z]      Gremlin Malformed Request: Unsupported request operation: 'bytecode'.
[2024-10-29T10:26:46.173Z]      GremlinRequestId : e1dda306-ac20-454f-a9c0-7c075c75923b
[2024-10-29T10:26:46.173Z]      Context : global
[2024-10-29T10:26:46.173Z]      GraphInterOpStatusCode : MalformedRequest
[2024-10-29T10:26:46.173Z]      HResult : 0x80131500

Any suggestions?

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
{count} votes

Answer accepted by question author
  1. Oury Ba-MSFT 21,126 Reputation points Microsoft Employee Moderator
    2024-10-29T22:35:10.2666667+00:00

    Hi Vamshi, Merugu, Thank you for reaching out.

    You are correct, the error you’re encountering is indeed due to a compatibility issue. Azure Cosmos DB for Gremlin does not support bytecode traversals. This limitation means that you cannot use the DriverRemoteConnection with bytecode traversal in Cosmos DB for Gremlin.

    Please see the unsupported features.

    Cosmos DB for Gremlin does not support transactions in the traditional sense, you won’t be able to use commit and rollback as you would in SQL databases.

    The doc https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/database-transactions-optimistic-concurrency you pointed out is only for nosql API.

    Please file feedback at https://aka.ms/sqlfeedback (or add your vote to an existing feedback item if one already exists). A highly voted customer feedback item helps the product team prioritize the investment into the requested feature.

    If you have any more questions or need further assistance, feel free to ask!

    Regards,

    Oury


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.