Uploaded image for project: 'Java Couchbase JVM Core'
  1. Java Couchbase JVM Core
  2. JVMCBC-1153

No way to do Transaction replace with a CAS check (Optimistic Locking)

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Unresolved
    • Major
    • None
    • 2.3.4
    • Core
    • None
    • 1

    Description

      Hello,

      Code below describes the problem:

      see: My (impossible) goal here is to use casOfMyLatestDocVersion to validate with Optimistic locking

      This problem prevents us completely from using optimistic locking when we need to update something inside a Transaction.

      Also, its similar, but different and (more critical) of the "problem 2" referred in the comments of JVMCBC-1149 that prevent us for getting the new CAS from a create.

       

      //Optimistic locking (aka: CAS check) is impossible since:
      // 1. ctx.replace does not provide CAS check
      // 2.* ctx.get response does not give public access to TransactionGetResult.internal().cas()
      // that would give us the ability to do this check manually.
       
      // * Fyi: We manage to implement #2 using java reflection to get the hidden cas, and it worked perfectly. Of course its not a proper solution.
       
      Collection collection = cluster.bucket(MYBUCKET).scope(MY_SCOPE).collection(MY_COLLECTION);
      long casOfMyLatestDocVersion = collection.insert("doc1", JsonObject.create()).cas();
       
       
      //My (impossible) goal here is to use casOfMyLatestDocVersion to validate with Optimistic locking
      cluster.transactions().run((ctx) -> {
       
          //Mandatory get before replace (Mandatory only with Transactions but not a problem)
          TransactionGetResult getResult = ctx.get(collection, "doc1");
          ctx.replace(getResult, JsonObject.create());
      });
       
      //Here, just for reference, the non-Transactional approach that works as expected
      collection.replace("doc1", JsonObject.create(), ReplaceOptions.replaceOptions().cas(casOfMyLatestDocVersion)); 

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            graham.pople Graham Pople
            spiros Spiros Tzoras
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty