Couchbase with Docker Compose: Unable to insert - DurabilityImpossibleError

Viewed 316

I'm trying to set up Couchbase as part of a collection of servers using Docker-Compose. The sole purpose of this is for local application development.

The problem is that, once set up, I'm unable to write to the database. Insert and Upsert operations give me a DurabilityImpossibleError.

Docker compose file:

version: '3.4'

services:

...


  couchbase-db:
    image: couchbase/server
    volumes:
      - ./docker-data/couchbase/node3:/opt/couchbase/var
      - ./provision/couchbase:/opt/startup/
    ports:
      - 8091:8091
      - 8092:8092 
      - 8093:8093 
      - 8094:8094
      - 11210:11210

The startup bash script, run after building, is an attempt to perform database setup without requiring a manual step:


#!/bin/bash

# Enables job control
set -m

# Enables error propagation
set -e

# Run the server and send it to the background
/entrypoint.sh couchbase-server &

# Check if couchbase server is up
check_db() {
  curl --silent http://${1}:8091/pools > /dev/null
  echo $?
}

# Variable used in echo
i=1
# Echo with
log() {
  echo "[$i] [$(date +"%T")] $@"
  i=`expr $i + 1`
}

# Wait until main server is ready
until [[ $(check_db 127.0.0.1) = 0 ]]; do
  >&2 log "Waiting for Couchbase Server to be available ..."
  sleep 1
done

couchbase-cli cluster-init -c localhost:8091 \
        --cluster-username Administrator --cluster-password password \
        --cluster-password password --services data,index,query --cluster-ramsize 512 \
        --cluster-index-ramsize 256 || true
couchbase-cli setting-cluster -c localhost:8091 -u Administrator -p password \
        --cluster-username Administrator --cluster-password password \
        --cluster-password password --cluster-ramsize 512 \
        --cluster-index-ramsize 256;
couchbase-cli setting-cluster -c localhost:8091 \
        -u Administrator -p password --cluster-username Administrator \
        --cluster-password password --cluster-ramsize 512 --cluster-index-ramsize 256;
curl -v POST http://localhost:8091/pools/default/buckets \
        -u Administrator:password \
        -d name=organisations \
        -d bucketType=couchbase \
        -d ramQuotaMB=512 \
        -d durabilityMinLevel=majorityAndPersistActive
curl -v -X POST -u Administrator:password \
        http://localhost:8091/settings/indexes \
        -d indexerThreads=4 \
        -d logLevel=verbose \
        -d maxRollbackPoints=10 \
        -d storageMode=plasma \
        -d memorySnapshotInterval=150 \
        -d stableSnapshotInterval=40000

# Need to wait until query service is ready to process N1QL queries
echo "$(date +"%T") Waiting ........."
sleep 20

# Create bucket1 indexes
echo "$(date +"%T") Create bucket1 indexes ........."
cbq -u Administrator -p password -s "CREATE PRIMARY INDEX idx_primary ON \`organisations\`;"
cbq -u Administrator -p password -s "CREATE INDEX idx_type ON \`organisations\`(_type);"

If I try to add a document via the web interface, I get:

 Errors from server: ["Unexpected server error, request logged."]

If I try to add a document via the JavaScript SDK, I get:


DurabilityImpossibleError  durability impossible
details:
{
   name: 'DurabilityImpossibleError',
   cause: LibcouchbaseError: libcouchbase error 308
   at Object.translateCppError 
   (/app/node_modules/couchbase/dist/bindingutilities.js:174:21)
   at /app/node_modules/couchbase/dist/connection.js:245:54 {
      code: 308
   },
   context: KeyValueErrorContext {
     status_code: 0,
     opaque: 0,
     cas: CbCas {
       '0': <Buffer 00 00 00 00 00 00 00 00>
     },
     key: '22738bd4-7972-4370-85a3-71399d96ef05',
     bucket: '',
     collection: '',
     scope: '',
     context: '',
     ref: ''
   }
 }

I've also attempted to send the following settings with the insert/upsert, to no effect:


  insertOptions: {
    durabilityLevel: 0,
    durabilityPersistTo: 1,
    durabilityReplicateTo: 0,
    timeout: 5000,
  },

My most recent attempt at a fix was to build a cluster of 3 nodes within docker-compose, and call the API commands to "add server" as part of a build script. However, "add server" takes a static IP, so the second time I run the servers, the IPs change and the database becomes unresponsive. I do get a functioning database on that first run though.

I'm looking for either a fix for a single node system (or an idea of where I'm going wrong), or a way of getting a cluster working in Docker-Compose after a down/up cycle. Anything that will give me a stable environment to develop in.

Thanks!

1 Answers

The bucket is created with -d durabilityMinLevel=majorityAndPersistActive, By default bucket enables replica with 1.

For single node cluster you will not have enough data nodes to satisfy durability (https://docs.couchbase.com/server/current/learn/data/durability.html). You can disable replica via UI and rebalance to take affect or change the bucket setting not include Minimum durability.

I have no idea about the 3 node docker compose error.

Related