【问题标题】:Couchbase community edition 6.0 could not create index?Couchbase 社区版 6.0 无法创建索引?
【发布时间】:2020-05-30 07:02:38
【问题描述】:

我尝试通过使用以下步骤安装来测试 Couchbase 社区版:

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/

以及源代码:

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)
        }
    }

}

显示错误:

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."},
}

我错过了一些步骤吗?还是这是 Couchbase Community Edition 6.0 的限制?

在web UI上,集群已经有了“data,index,query”标签,那么不应该在那个集群上创建索引吗?

【问题讨论】:

  • 嗯...如果您尝试手动创建主索引会怎样?
  • @deniswsrosa 同样的错误"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."
  • 我刚刚使用相同的命令(cluster-init 然后 bucket-create)从头开始重新安装了我的 Couchbase Community 6.0,我能够毫无问题地创建主索引。我想知道是否与磁盘/机器有关的某些问题导致索引服务失败。
  • 再次尝试重新安装,同样的错误'__')

标签: ubuntu go couchbase


【解决方案1】:

虽然我不能肯定地说,问题的核心很可能是通过 REST 接口发送到 Couchbase 的命令是异步发生的。如错误所示,索引的某些组件可能尚未初始化,并且无法执行下一个命令。在编写命令脚本时,您可能会看到这种情况。 Couchbase 的 REST 接口确实表明该工作将与 HTTP 201 回复异步。也就是说,REST 接口无法检查是否完成,couchbase-cli 也无法检查,所以我相信它只会返回成功。

由于诸如索引创建之类的事情可能是幂等的,因此只需在一段时间内使用 backoff-retry 再试一次作为解决方法。

改进此界面的问题跟踪是MB-11484

【讨论】:

  • 没关系,我卸载了 couchbase 并尝试使用 mongodb XD
  • 很抱歉听到这个消息。我想说你遇到的问题很容易解决,而不是真正重要的部分——所以如果你只是添加一个循环,你可能会得到你想要的结果,并且能够检查 Couchbase 的其余部分。
【解决方案2】:

发生这种情况的一个可能原因是,有另一个进程正在同一端口上运行,Couchbase 也在侦听以创建索引。

您可以在此处查看 Couchbase 使用的端口:

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

要解决此问题,您可以按照文章中的说明更改索引端口,或者结束当前正在使用该端口的进程/服务。

要查找使用端口的进程的 PID,您可以在以管理员身份运行时在 Windows 命令提示符中运行 netstat -aob。

对我来说,我删除了在端口 9100 上运行的服务,然后能够创建索引。

【讨论】:

  • 啊这可能是对的,我有 prometheus 在端口 9100 上监听,但是太糟糕了,现在我对使用这个数据库没有兴趣了 XD
  • 你先生让我很开心,确实应该更好地处理这些错误消息。我的意思是打印一条消息有多难:“嘿,我想使用端口 9100,但它使用了我的其他东西,所以请杀了它”:D
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多