Unable to create primary index automatically

Hello,

I’m currently setting up a docker-compose with a nodejs webserver and a couchbase container, in which the couchbase is supposed to be setup automatically.

I am running into problems frequently. Now I finally am able to automatically setup the bucket etc., but creating a primary key still fails.

This is my Dockerfile:

FROM couchbase

COPY configure-couchbase.sh /opt/couchbase
RUN ["chmod", "+x", "/opt/couchbase/configure-couchbase.sh"]
CMD ["/opt/couchbase/configure-couchbase.sh"]

This is my configure-couchbase.sh:

#!/bin/bash

set -x
set -m

/entrypoint.sh couchbase-server &

sleep 15

# Initialize Node
curl -u Administrator:password -v -X POST http://localhost:8091/nodes/self/controller/settings \
  -d 'path=%2Fopt%2Fcouchbase%2Fvar%2Flib%2Fcouchbase%2Fdata&' \
  -d 'index_path=%2Fopt%2Fcouchbase%2Fvar%2Flib%2Fcouchbase%2Fdata&' \
  -d 'cbas_path=%2Fopt%2Fcouchbase%2Fvar%2Flib%2Fcouchbase%2Fdata&' \
  -d 'eventing_path=%2Fopt%2Fcouchbase%2Fvar%2Flib%2Fcouchbase%2Fdata&'

sleep 3

# Rename Cluster
curl -u Administrator:password -v -X POST http://localhost:8091/node/controller/rename \
  -d 'hostname=127.0.0.1'

sleep 3

# Setup Services
curl  -u Administrator:password -v -X POST http://localhost:8091/node/controller/setupServices \
  -d 'services=kv%2Cn1ql%2Cindex%2Cfts'

sleep 3

# Setup Memory Quotas
curl  -u Administrator:password -v -X POST http://localhost:8091/pools/default \
  -d 'memoryQuota=1024' \
  -d 'indexMemoryQuota=1024' \
  -d 'ftsMemoryQuota=1024'

sleep 3

# Setup Administrator username and password
curl  -u Administrator:password -v -X POST http://localhost:8091/settings/web \
  -d 'password=dbaccess&username=dbaccess&port=SAME'

sleep 3

# Setup Bucket
curl  -u dbaccess:dbaccess -v -X POST http://localhost:8091/pools/default/buckets \
  -d 'flushEnabled=1&threadsNumber=3&replicaIndex=0&replicaNumber=0& \
  evictionPolicy=valueOnly&ramQuotaMB=256&bucketType=membase&name=fwdisplay'

sleep 10

# Create Index
# create primary index `fwdisplay` on fwdisplay using GSI
/opt/couchbase/bin/cbq -u dbaccess -p dbaccess --script="CREATE PRIMARY INDEX \`fwdisplay\` ON fwdisplay USING GSI"

fg 1

For some reason I get an error-message on the last command, when creating an index:

"code": 5000,
"msg": "GSI CreatePrimaryIndex() - cause: Please Set Indexer Storage Mode Before Create Index\n"

Here is the information about the cluster:

{
  "clusterUUID": "b4148c1f6e8fc0c908bd3837669b8569",
  "autoFailover": {
    "enabled": true,
    "timeout": 120
  },
  "autoReprovision": {
    "enabled": true,
    "max_nodes": 1,
    "count": 0
  },
  "orchestrator": "ns_1@127.0.0.1",
  "master": "ns_1@127.0.0.1",
  "isBalanced": true,
  "quotaInfo": {
    "memoryQuota": 313,
    "indexMemoryQuota": 512,
    "ftsMemoryQuota": 256,
    "cbasMemoryQuota": 1024,
    "eventingMemoryQuota": 256
  },
  "clusterCompatVersion": "6.6",
  "clientCertAuthState": "disable",
  "buckets": {
    "couchbase": {
      "fwdisplay": {
        "numReplicas": 0,
        "evictionPolicy": "value_only",
        "ramQuota": 268435456
      }
    }
  },
  "statsDescTable": {
    "curr_items": "Total docs in active vBuckets on this node for this bucket",
    "vb_replica_curr_items": "Total docs in replica vBuckets on this node for this bucket",
    "vb_pending_curr_items": "Total docs in pending vBuckets on this node for this bucket",
    "vb_active_resident_items_ratio": "Percentage of docs in active vBuckets in RAM on this node for this bucket",
    "vb_active_num": "Number of vBuckets in 'active' state on this node for this bucket",
    "vb_replica_num": "Number of vBuckets in 'replica' state on this node for this bucket",
    "vb_pending_num": "Number of vBuckets in 'pending' state on this node for this bucket",
    "ep_vb_total": "Number of vBuckets on this node for this bucket",
    "curr_connections": "Total connections to this node"
  },
  "nodes": [
    {
      "uptime": "2034",
      "memoryTotal": 2088206336,
      "memoryFree": 1195368448,
      "clusterMembership": "active",
      "status": "healthy",
      "hostname": "172.30.0.3:8091",
      "nodeUUID": "6985930322f336a947ba2126c0543eb9",
      "version": "6.6.0-7909-enterprise",
      "os": "x86_64-unknown-linux-gnu",
      "cpuCount": 2,
      "services": [
        "fts",
        "index",
        "kv",
        "n1ql"
      ],
      "swapTotal": 1073737728,
      "swapUsed": 63700992,
      "bucketStats": {
        "couchbase": {
          "fwdisplay": {
            "stats": {
              "curr_items": 1,
              "vb_replica_curr_items": 0,
              "vb_pending_curr_items": 0,
              "vb_active_resident_items_ratio": 100,
              "vb_active_num": 1024,
              "vb_replica_num": 0,
              "vb_pending_num": 0,
              "ep_vb_total": 1024,
              "curr_connections": 29
            },
            "statsTimestamp": 1602576623980
          }
        }
      },
      "storageConf": {
        "dbPath": "/opt/couchbase/var/lib/couchbase/data",
        "indexPath": "/opt/couchbase/var/lib/couchbase/data",
        "cbasDirs": [
          "/opt/couchbase/var/lib/couchbase/data"
        ]
      }
    }
  ]
}

Does anybody have any pointers for me on why the index creation fails?

Greetings,
EtzBetz

1 Like

Hi @EtzBetz,

The error returned by the create index statement suggests that the index storage mode is not set.

You can set it up from UI. Please follow https://docs.couchbase.com/server/current/manage/manage-settings/general-settings.html#index-storage-mode for more details.

For understanding storage modes in detail, please visit https://docs.couchbase.com/server/current/learn/services-and-indexes/indexes/storage-modes.html

You can use REST APIs to set storage mode. More details here: https://docs.couchbase.com/server/current/manage/manage-settings/general-settings.html#index-settings-via-rest

Hope this helps.

Thanks.

Hi @EtzBetz,

Also checkout couchbase-cli setup cluster/bucket other settings https://docs.couchbase.com/server/current/cli/cbcli/couchbase-cli.html

Thanks, these helped me sorting it out.