Uploaded image for project: 'Couchbase Server'
  1. Couchbase Server
  2. MB-50961

explicit close() of DML iterator returning values leaves partly executed statement

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • 7.1.0
    • 7.1.0
    • js-evaluator
    • None
    • Untriaged
    • 1
    • Unknown

    Description

      This is not too dissimiar to MB-50828, but it entails explicitly closing the iterator half way.

      Create a bucket default and insert a few documents:

      INSERT INTO default VALUES(uuid(),

      {"f1": 1}

      );
      INSERT INTO default VALUES(uuid(),

      {"f1": 1}

      );
      INSERT INTO default VALUES(uuid(),

      {"f1": 1}

      );
      INSERT INTO default VALUES(uuid(),

      {"f1": 1}

      );
      INSERT INTO default VALUES(uuid(),

      {"f1": 1}

      );
      INSERT INTO default VALUES(uuid(),

      {"f1": 1}

      );
      ....(do it a few hundred times)

      create the following javascript function:

      function somedml()

      { var q = UPDATE default SET f1 = 2; q.close() }

      create and execute the UDF:

      CREATE FUNCTION somedml() LANGUAGE javascript AS "somedml" AT "test";
      EXECUTE FUNCTION dml();

      This function updates default, and q.close is a noop..
      Now try with a RETURNING clause:

      function somedml()

      { var q = UPDATE default SET f1 = 2 RETURNING f1; q.close() }

      Here, by the time q.close() is called, some documents will have been updates, some will be pending awaiting being pulled from the iterator, and the close() cancels the iterator.

      I think the moral here is clear - much like cancelling left over requests and the end of the function should complete pending DML rather than cancelling it, an explicit q.close() should check mutations, and if it is > 0 should complete rather than cancel.

      Attachments

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

        Activity

          People

            pierre.regazzoni Pierre Regazzoni
            marco.greco Marco Greco (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty