{"record":{"id":"04480db2fa442b9c","repo":"juicedata/juicefs","slug":"get-prefix-v-with-count-only-s","errorCode":null,"errorMessage":"get prefix %v with count only: %s","messagePattern":"get prefix (.+?) with count only: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/meta/tkv_etcd.go","lineNumber":130,"sourceCode":"\tif keysOnly {\n\t\topts = append(opts, etcd.WithKeysOnly())\n\t}\n\tresp, err := tx.kv.Get(tx.ctx, string(begin), opts...)\n\tif err != nil {\n\t\tpanic(fmt.Errorf(\"get range [%v-%v): %s\", string(begin), string(end), err))\n\t}\n\tfor _, kv := range resp.Kvs {\n\t\ttx.observed[string(kv.Key)] = kv.ModRevision\n\t\tif !handler(kv.Key, kv.Value) {\n\t\t\tbreak\n\t\t}\n\t}\n}\n\nfunc (tx *etcdTxn) exist(prefix []byte) bool {\n\tresp, err := tx.kv.Get(tx.ctx, string(prefix), etcd.WithPrefix(), etcd.WithCountOnly())\n\tif err != nil {\n\t\tpanic(fmt.Errorf(\"get prefix %v with count only: %s\", string(prefix), err))\n\t}\n\treturn resp.Count > 0\n}\n\nfunc (tx *etcdTxn) set(key, value []byte) {\n\ttx.buffer[string(key)] = value\n\tif len(tx.buffer) >= 128 {\n\t\terr := tx.commmit()\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t\ttx.observed = make(map[string]int64)\n\t\ttx.buffer = make(map[string][]byte)\n\t}\n}\n\nfunc (tx *etcdTxn) append(key []byte, value []byte) {\n\tnew := append(tx.get(key), value...)","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/meta/tkv_etcd.go#L112-L148","documentation":"`etcdTxn.exist` checks whether any key exists under a prefix using an etcd Get with `WithPrefix` and `WithCountOnly`. A transport/etcd error on that count query panics with this message. Unlike plain `exist` used inside transactions, this is the count-only existence probe.","triggerScenarios":"Any existence check against a key prefix when the count-only Get fails: etcd unreachable, gRPC timeout, auth failure, or server error during the request.","commonSituations":"etcd down or restarting; credentials misconfigured; network partition; context deadline exceeded under cluster load — typically encountered at startup or when checking max slice/session keys.","solutions":["Check etcd endpoint health and client log for the wrapped gRPC error","Correct endpoint/TLS/credentials in the metadata URL","Retry once etcd is reachable; tune timeouts if deadline errors recur"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"etcdctl --endpoints=host:2379 get /your-prefix --prefix --count-only","typeGuard":null,"tryCatchPattern":"if err := mountCmd.Run(); err != nil {\n    if strings.Contains(err.Error(), \"count only\") { healthCheckEtcd(); retry(mountCmd) }\n}","preventionTips":["Pre-check etcd health before mounts/loads","Verify TLS and auth parameters in the metadata URL","Alert on etcd downtime to correlate with client errors"],"tags":["etcd","exists","network","juicefs"],"backgroundTag":"database-query-failed","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}