Transactions Support for Eventing

Hello,

With the latest versions of Couchbase and Couchbase SDKs, support for transactions has been provided for both N1QL Statements as well as KV Ops.

What is the current state of support for transactions within the Eventing service on the latest version of couchbase? If not supported, is it on the roadmap? or is it generally advised to make a CURL to an internal API that can facilitate that transaction business logic there.

Best,
Alex Frye

N1QL javascript udf supports transactions see if that can be option to add your logic. cc @Marco_Greco

Is there a docs page reference with an example of this?

Java Script udf : You searched for java script udf - The Couchbase Blog
If accessable UDFs with transactions examples : py-tpcc/tpccfuncswithN1QL.js at py3 · couchbaselabs/py-tpcc · GitHub

As mentioned in the blog From N1QL to JavaScript and Back - Part 3: Iterating over Documents and DML - The Couchbase Blog DML statements examples you can add

var qb = BEGIN WORK;
var qc = COMMIT WORK;
var qr = ROLLBACK WORK;

Hey Alex one thing to be aware of in Eventing transactions “begin work”, “commit work”, and “rollback work” currently can “leak” some unexpected mutations so that you might get extra document(s) that are unexpected on a update/insert or on a delete so you have to be very careful about when you use transactions and eventing together.

Of course we plan to fix this but there is no definitive roadmap or release time for this I’m pushing to get it fixed sooner than later hope this helps.

@jon.strabala
What do you mean by “leak” unexpected mutations?
As in, eventing may pick up the uncommitted transaction state and process the mutation?

Also, are there any solutions for KV and transactions? Looks like the solution provided are for DML Query Statements Only. SDKs have the ability to perform both KV and Query operations within a ctx context.

sample from NodeJS sdk

cluster.transactions().run(async (ctx) => {
  await ctx.insert(collection, 'docId', {})
})

Hi @alex.frye

Yes as you surmised:

I will DM you the complete details

Best

Jon Strabala
Principal Product Manager - Server‌

Hi @jon.strabala , is this topic fixed in any version of Couchbase or is still present in the version 7.2? I see this in the documentation “All Couchbase services only see committed data. Uncommitted transaction modifications (i.e. dirty data) are never visible to any Couchbase service.”
Many thanks in advance

Can you send me the link, I’m pretty sure Eventing still leaks intermittent transaction mutations. Once I read the do I’ll retest and get back to (and get the docs updated if they are incorrect)

In 7.6.3 you might try the following mutation suppression technique in your OnUpdate() handler - code sample below:

function OnUpdate(doc, meta, xattrs) {
    if (xattrs.txn && xattrs.txn.id && xattrs.txn.op) return;
    log("OnUpdate Doc created/updated doc: " + JSON.stringify(doc) + ", meta: ", meta, "xattrs", xattrs);
}

function OnDelete(meta, options) {
    log("OnDelete Doc deleted/expired options: " + JSON.stringify(options) + ", meta:", meta);
}

I believe it will fix the transaction leak issue in OnUpdate() handler by suppressing the documents with the xattr.txn values. However there still will be an occasional transaction leak in the OnDelete().

This may only work for SQL++ queries and might not support the SDK request, it’s the best I can offer up right now.

Best

Jon Strabala
Principal Product Manager - Server‌