Couchbase gocb 批量操作提供部分为空的结果

Couchbase gocb bulk operation delivers partially empty results

在我们使用 gocb 的 go 代码中,我们正在查询 returns 32k ids 的视图。然后我们执行批量查询(参见下面的代码),如 CouchBase blog post 中所述。但是,我们只能得到部分结果。我们可以看到 ruleset, _ := items[i].(*gocb.GetOp).Value.(*RuleSet) 只有 return 是前 2048 个 id 的值。然后 ids 2049 - 11322 不包含值等等。我们的结果如下所示:

Line 1 Key: 12345678901234567890123456789012, Value: map[0.0.0.0/0:map[jsona:valueofjsona]]
...
Line 2018 Key: 12345678901234567890123456712345, Value: map[0.0.0.0/0:map[jsona:valueofjsona]]
Line 2019 Key: 12345678901234567890123456712345, Value: map[]
...
Line 11323 Key: 12345678901234567890123456712347, Value: map[jsonb:valueofjsonb]]

(以上几行是简化的,键与实际数据不匹配,值也不匹配。)

很大一部分请求的数据实际上并未 returned:

CB# grep '\[\]' result.out |wc -l
27042
CB# wc -l result.out
31988 rdmp.out

是否bucket.do return在完成处理所有查询之前?我们查看了 API 代码,但找不到解释。

知道如何解决这个问题吗?

type RuleSet struct {
    Rules map[string]interface{} "json:\"rules,\""
}

func DiffViaBulkQuery() {
  var items []gocb.BulkOp
  var row interface{}
  var cnt int = 0
  bucket := cbase.MyBucket()

// [...]
// add 600k entries to itemsget in a loop like 
// itemsGet = append(itemsGet, &gocb.GetOp{Key: key + "_" + strconv.Itoa(i), Value: &Doc{}})


// Perform the bulk operation to Get all documents
  err = bucket.Do(itemsGet)
  if err != nil {
    fmt.Println("ERRROR PERFORMING BULK GET:", err)
  }

// Print the output
  for i := 0; i < len(itemsGet); i++ {
    fmt.Println(itemsGet[i].(*gocb.GetOp).Key, itemsGet[i].(*gocb.GetOp).Value.(*Doc).Item)
  }

提前致谢, 托尔斯滕

值得检查您正在执行的每个操作的错误值。你可以通过 op.Err 来做到这一点,例如,那就是

    for i := 0; i < len(items); i++ {
    fmt.Println(items[i].(*gocb.GetOp).Key, items[i].(*gocb.GetOp).Value.(*Doc).Item, items[i].(*gocb.GetOp).Err)
}

我希望您看到的是遇到 queue overflowed 错误,gocb 调度程序队列已满,默认最大大小为 2048 个项目。解决方案通常是以较小的批次执行工作,以免使 gocb 过载。 https://forums.couchbase.com/t/bulk-upsert-data-into-couchbase/17354/2

上的示例也存在类似问题