Uploaded image for project: 'Couchbase PHP client library'
  1. Couchbase PHP client library
  2. PCBC-975

Inconsistent Behavior Between Method upsert() and upsertMulti() When Expiry Time Is in Use

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Major
    • 4.2.2
    • 4.1.6
    • extension
    • None
    • 0

    Description

      For the following code piece:

      $key = 'key';
       
      try {
          $collection->remove($key);
      } catch (Exception $e) {
          // Ignore.
      }
       
      $options = new Couchbase\UpsertOptions();
      $options->expiry((new DateTimeImmutable())->modify('+5 seconds'));
      $collection->upsert($key, 'dummy', $options);
      echo $collection->get($key)->content(), PHP_EOL;
       
      sleep(7);
       
      echo $collection->get($key)->content(), PHP_EOL; 

      It prints out an exception message when executed (as expected):

      dummyFatal error: Uncaught Couchbase\Exception\DocumentNotFoundException: document_not_found (101): "unable to execute KV operation "document_get"" in /var/www/couchbase-4.1.6/src/wrapper/connection_handle.cxx:499
      Stack trace:
      #0 /var/www/vendor/couchbase/couchbase/Couchbase/Collection.php(124): Couchbase\Extension\documentGet(Resource id #25, 'test', '_default', '_default', 'key', Array)
      #1 /var/www/temp/examples/upsert4-1.php(36): Couchbase\Collection->get('key')
      #2 {main}
        thrown in /var/www/couchbase-4.1.6/src/wrapper/connection_handle.cxx on line 499 

      Now, if we use method upsertMulti() instead of upsert():

      $key = 'key';
       
      try {
          $collection->remove($key);
      } catch (Exception $e) {
          // Ignore.
      }
       
      $options = new Couchbase\UpsertOptions();
      $options->expiry((new DateTimeImmutable())->modify('+5 seconds'));
      $collection->upsertMulti([[$key, 'dummy']], $options);
      echo $collection->get($key)->content(), PHP_EOL;
       
      sleep(7);
       
      echo $collection->get($key)->content(), PHP_EOL;
       

      It prints out the following message without any exception thrown out:

      dummy
      dummy 

      The only difference between the two code pieces is that we changed

      $collection->upsert($key, 'dummy', $options); 

      to

      $collection->upsertMulti([[$key, 'dummy']], $options); 

      Attachments

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

        Activity

          People

            avsej Sergey Avseyev
            deminy Demin Yin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty