Failed upsert operation with durability

Hi all!

I`m use Community Edition 7.0.0 build 5302 on Docker.
Couchbase Server image: couchbase:community-7.0.2 (sha256:45604b674bf5b0ae801b518454aa6086c6075a2a923060f05db894a113476296).
Couchbase C-lib version: 3.2.3
Couchbase PHP-SDK version: 3.2.1
PHP version: 8.0.9

Reproducing the problem

I am running the server via docker compose:

# file docker-compose.yml

version: '3.0'

services:
  couchbase:
    restart: unless-stopped
    image: couchbase:community-7.0.2
    volumes:
      - couchbase_data:/opt/couchbase
    ports:
      - "8091-8096:8091-8096"
      - "11210-11211:11210-11211"

volumes:
  couchbase_data:
    driver: local

My test script contains code like this:

# file test-couchbase.php

<?php

include 'vendor/autoload.php';

use Couchbase\Cluster;
use Couchbase\ClusterOptions;
use Couchbase\UpsertOptions;

$clusterOptions = new ClusterOptions();
$clusterOptions->credentials('user', 'password');
$cluster = new Cluster('couchbase://localhost:8091', $clusterOptions);

$bucket = $cluster->bucket('test-bucket');
$scope = $bucket->defaultScope();
$collection = $scope->collection('test-collection');

$options = new UpsertOptions();

## All this durability does not work
$options->durabilityLevel(Couchbase\DurabilityLevel::MAJORITY_AND_PERSIST_TO_ACTIVE);
// $options->durabilityLevel(Couchbase\DurabilityLevel::PERSIST_TO_MAJORITY);
// $options->durabilityLevel(Couchbase\DurabilityLevel::MAJORITY);

## Only this works fine
//$options->durabilityLevel(Couchbase\DurabilityLevel::NONE);

$collection->upsert('id-document', ['field' => 'value'], $options);

and I am getting the following error

/app $ php test-couchbase.php 
[cb,WARN] (server L:386 I:151288749) <10.110.3.17:11210> (CTX=0x7ffaef5077a0,memcached,SRV=0x7ffaef261aa0,IX=0) Received server error EINVAL (0x4) on packet: OP=0x1, RC=0x4, SEQ=1
PHP Fatal error:  Uncaught Couchbase\BindingsException: LCB_ERR_KVENGINE_INVALID_PACKET (1031) in /app/test-couchbase.php:22
Stack trace:
#0 /app/test-couchbase.php(22): Couchbase\Collection->upsert('id-document', Array, Object(Couchbase\UpsertOptions))
#1 {main}
  thrown in /app/test-couchbase.php on line 22

Fatal error: Uncaught Couchbase\BindingsException: LCB_ERR_KVENGINE_INVALID_PACKET (1031) in /app/test-couchbase.php:22
Stack trace:
#0 /app/test-couchbase.php(22): Couchbase\Collection->upsert('id-document', Array, Object(Couchbase\UpsertOptions))
#1 {main}
  thrown in /app/test-couchbase.php on line 22

All this durability does not work:

  1. MAJORITY_AND_PERSIST_TO_ACTIVE
  2. PERSIST_TO_MAJORITY
  3. MAJORITY

Only this works fine:

  1. NONE

Choosing the SDK version I followed this article https://www.couchbase.com/products/developer-sdk/compatibility. But I did not find which version of the C library I need to install for PHP-SDK 3.2.1, so I installed the last one I found on this page Tags · couchbase/libcouchbase · GitHub — 3.2.3.

Any thoughts?

hi @voskobovich libcouchbase 3.2.3 was released after PHP 3.2.1 the actual libcouchbase dependency is 3.2.2 which can be found in the release notes Couchbase PHP Release Notes and Archives | Couchbase Docs

1 Like

Thanks for your answer!
I have installed PHP-SDK 3.2.2 and C-lib 3.2.4 and the problem with LCB_ERR_KVENGINE_INVALID_PACKET has been fixed.

But i had new problem — LCB_ERR_DURABILITY_IMPOSSIBLE (308).
From this page Durability | Couchbase Docs I know what “Couchbase Server supports durability for up to two replicas: it does not support durability for three replicas.” but my dev cluster has only one node. Can I use durability with only one node cluster?

Durability requires replicas. You can disable it.

Checkout Note section

If using a single node cluster (for example, during development), then note that the default number of replicas for a newly created bucket is 1. If left at this default, then all Key-Value writes performed at with durabiltiy will fail with a DurabilityImpossibleException . In turn this will cause all transactions (which perform all Key-Value writes durably) to fail. This setting can be changed via GUI or command line. If the bucket already existed, then the server needs to be rebalanced for the setting to take affect.

1 Like