2

I tried to test Couchbase community edition, by installing using these steps:

echo '
deb [ arch=amd64 ] http://packages.couchbase.com/releases/couchbase-server/enterprise/deb/ xenial xenial/main
deb [ arch=amd64 ] http://packages.couchbase.com/releases/couchbase-server/community/deb/ xenial xenial/main
deb http://packages.couchbase.com/ubuntu xenial xenial/main
' | sudo tee /etc/apt/sources.list.d/couchbase.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 6EF1EAC479CF7903
sudo apt-get update
sudo apt-get install couchbase-server-community
apt list -a couchbase-server-community

# make command line available
echo '
export PATH=$PATH:/opt/couchbase/bin
' | tee -a .bashrc
export PATH=$PATH:/opt/couchbase/bin

# init cluster
couchbase-cli cluster-init -c 127.0.0.1 \
--cluster-username Administrator \
--cluster-password YourPassword \
--services data,index,query \
--cluster-ramsize 512 \
--cluster-index-ramsize 256

# create bucket
couchbase-cli bucket-create -c 127.0.0.1:8091 --username Administrator \
 --password YourPassword --bucket test1 --bucket-type couchbase \
 --bucket-ramsize 512

# start n1ql
cbq -u Administrator -p YourPassword -engine=http://127.0.0.1:8091/

And the source code:

package main

import (
    "fmt"
    "github.com/kokizzu/gotro/L"
    "gopkg.in/couchbase/gocb.v1"
    "math/rand"
    "time"
)

const Username = `Administrator`
const Password = `YourPassword`
const Bucket = `test1`

type Score struct {
    User  int64  `json:"user"`
    RefId int64  `json:"ref_id"`
    Epoch int64  `json:"epoch"`
    Score int    `json:"score"`
    Type  string `json:"type"`
}

func main() {
    cluster, err := gocb.Connect("couchbase://127.0.0.1")
    if L.IsError(err,`cannot connect to couchbase`) {
        return
    }
    cluster.Authenticate(gocb.PasswordAuthenticator{Username: Username, Password: Password})
    bucket, _ := cluster.OpenBucket(Bucket, "")
    m := bucket.Manager("", "")
    err = m.CreatePrimaryIndex("", true, false)
    if L.IsError(err, `failed create primary index`) {
        return
    }
    indexes := []string{`type`, `epoch`, `user`, `refid`}
    for _, index := range indexes {
        err = m.CreateIndex(index, []string{index}, true, false)
        if L.IsError(err, `failed create index %s`, index) {
            return
        }
    }

    for x := 0; x < 10000; x++ {
        userId := 1 + rand.Intn(1000)
        refId := 1 + rand.Intn(100)
        epoch := time.Now().AddDate(0, 0, rand.Intn(365)+1).Unix()
        score := 10 + rand.Intn(100)
        _, err := bucket.Upsert(
            fmt.Sprintf("user%dref%d", userId, refId),
            Score{
                User:  int64(userId),
                RefId: int64(refId),
                Epoch: epoch,
                Score: score,
                Type:  `score`,
            }, 0)
        if L.IsError(err, `failed upsert`) {
            return
        }
    }

    // Use query
    sql := `SELECT user,SUM(score) FROM ` + Bucket + ` WHERE epoch > $1 GROUP BY user ORDER BY 2 DESC`
    query := gocb.NewN1qlQuery(sql)
    window := []int{1, 7, 30, 365}
    for _, delta := range window {
        fmt.Println(delta)
        epoch := time.Now().AddDate(0, 0, delta).Unix()
        rows, err := bucket.ExecuteN1qlQuery(query, []interface{}{epoch})
        if L.IsError(err, `failed query %s`, sql) {
            return
        }
        var row interface{}
        defer rows.Close()
        for rows.Next(&row) {
            fmt.Printf("Row: %v", row)
        }
    }

}

It shows error:

2020-02-15 23:58:33.271 IsError ▶ &gocb.n1qlMultiError{
    {Code:0x1388, Message:"GSI CreateIndex() - cause: Fails to create index.  There is no available index service that can process this request at this time. Index Service can be in bootstrap, recovery, or non-reachable. Please retry the operation at a later time."},
}

Am I missing some steps? or is this the limitation of Couchbase Community Edition 6.0?

On the web UI, the cluster already has "data,index,query" label, so shouldn't index can be created on that cluster?

Kokizzu
  • 24,974
  • 37
  • 137
  • 233
  • Possible duplicates: https://stackoverflow.com/q/37109050/13860, https://stackoverflow.com/q/57406312/13860 – Jonathan Hall Feb 15 '20 at 18:02
  • Hummm... What happens if you try to create the primary index manually? – deniswsrosa Feb 15 '20 at 18:36
  • @deniswsrosa same error `"code": 5000, "msg": "GSI CreateIndex() - cause: Fails to create index. There is no available index service that can process this request at this time. Index Service can be in bootstrap, recovery, or non-reachable. Please retry the operation at a later time."` – Kokizzu Feb 15 '20 at 18:40
  • I just reinstalled my Couchbase Community 6.0 from scratch with the same commands (cluster-init then bucket-create) and I was able to create the primary index without any issues. I wonder if is some problem related with the disk/machine that somehow made the index service to fail. – deniswsrosa Feb 15 '20 at 19:09
  • tried reinstall again, same error '__') – Kokizzu Feb 15 '20 at 19:42
  • try to find any hints in the Couchbase error logs, I suppose it is something with the machine. Or try to install it manually and see if it works for you. – deniswsrosa Feb 15 '20 at 19:51

2 Answers2

2

While I can't say for certain, it is likely that the core of the problem is that commands to Couchbase through the REST interface happen asynchronously. As the error indicates, some components of indexing may not have initialized, and it can't take that next command. You'll likely see this sort of thing when scripting commands. Couchbase's REST interface does indicate the work will be async with an HTTP 201 reply. That said, the REST interface has no way to check for completion and couchbase-cli cannot check either, so it just returns success I believe.

Since something like an index creation may be idempotent, just try again with backoff-retry for a period of time as a workaround.

The issue tracking improving this interface is MB-11484.

Matt Ingenthron
  • 1,894
  • 14
  • 14
  • nevermind, i uninstalled couchbase and try using mongodb instead XD – Kokizzu Feb 20 '20 at 20:55
  • Sorry to hear that. I'd say what you're running into is straightforward to work around and not really the important bits-- so if you just add a loop you'll probably get the result you want and be able to check out the rest of Couchbase. – Matt Ingenthron Feb 20 '20 at 22:23
2

A likely reason this is occurring is because there is another process that is running on the same port that Couchbase is listening too in order to create indexes.

You can view the ports Couchbase uses here:

https://docs.couchbase.com/server/current/install/install-ports.html

To fix this you can either change the index port as stated in the article, or end the process/service that currently is using that port.

To find the PID of the process using the port, you can run netstat -aob in the Windows Command Prompt when running as an admin.

For me, I removed a service running on port 9100 and was then able to create the index.

mcsj120
  • 89
  • 1
  • 3
  • ah probably this is right, i have prometheus listening on port 9100, but too bad, now i have no more interest using this database XD – Kokizzu May 30 '20 at 06:15
  • You sir made my day, there really should work better on these error messages. I mean how hard would it be to just print a message : "hey, i wanna use port 9100, but its used my something else so kill it please" :D – Naser Arab Dec 11 '21 at 19:17