{"record":{"id":"bfb03229f9d5fa41","repo":"juicedata/juicefs","slug":"invalid-sustainedkey-s","errorCode":null,"errorMessage":"invalid sustainedKey: %s","messagePattern":"invalid sustainedKey: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/meta/tkv.go","lineNumber":4129,"sourceCode":"\tif err != nil {\n\t\treturn err\n\t}\n\tcs := make([]int64, len(rs))\n\tfor i, r := range rs {\n\t\tif r != nil {\n\t\t\tcs[i] = parseCounter(r)\n\t\t}\n\t}\n\n\tvals, err = m.scanValues(ctx, m.fmtKey(\"SS\"), -1, nil)\n\tif err != nil {\n\t\treturn err\n\t}\n\tss := make(map[uint64][]Ino)\n\tfor k := range vals {\n\t\tb := utils.FromBuffer([]byte(k[2:])) // \"SS\"\n\t\tif b.Len() != 16 {\n\t\t\treturn fmt.Errorf(\"invalid sustainedKey: %s\", k)\n\t\t}\n\t\tsid := b.Get64()\n\t\tinode := m.decodeInode(b.Get(8))\n\t\tss[sid] = append(ss[sid], inode)\n\t}\n\tsessions := make([]*DumpedSustained, 0, len(ss))\n\tfor k, v := range ss {\n\t\tsessions = append(sessions, &DumpedSustained{k, v})\n\t}\n\n\t// Fetch dir quotas\n\tpairs, err := m.scanValues(ctx, m.fmtKey(\"QD\"), -1, func(k, v []byte) bool {\n\t\treturn len(k) == 10 && len(v) == 32\n\t})\n\tif err != nil {\n\t\treturn err\n\t}\n\tdirQuotas := make(map[Ino]*DumpedQuota, len(pairs))","sourceCodeStart":4111,"sourceCodeEnd":4147,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/meta/tkv.go#L4111-L4147","documentation":"When dumping session info (dumpSessions), kvMeta parses sustained ('SS' prefixed) keys as 2-byte prefix + 16 bytes (8-byte session id + 8-byte inode). A key whose remaining buffer is not exactly 16 bytes is malformed and aborts the dump with this error.","triggerScenarios":"Running 'juicefs dump' (or session listing) on a TKV engine whose 'SS' key space contains a truncated or foreign key — partial restore, manual KV edits, cross-version key encoding.","commonSituations":"Restored metadata from an incomplete backup; another application sharing the KV namespace; corrupted key bytes in the store.","solutions":["Inspect and remove/repair malformed 'SS'-prefixed keys in the metadata store","Restore metadata from a consistent 'juicefs dump' backup","Ensure the KV namespace is not shared with other applications","Clear stale sessions with 'juicefs status'/'--kill-session' style flows and let clients re-create them"],"exampleFix":"// before\nb := utils.FromBuffer([]byte(k[2:]))\nif b.Len() != 16 {\n\treturn fmt.Errorf(\"invalid sustainedKey: %s\", k)\n}\n// after (skip bad keys during dump)\nb := utils.FromBuffer([]byte(k[2:]))\nif b.Len() != 16 {\n\tlogger.Warnf(\"skip invalid sustainedKey: %s\", k)\n\tcontinue\n}","handlingStrategy":"try-catch","validationCode":"// before dump, ensure metadata is consistent\njuicefs fsck <meta-url>","typeGuard":null,"tryCatchPattern":"if err := dumpMeta(url, out); err != nil {\n\tif strings.Contains(err.Error(), \"invalid sustainedKey\") {\n\t\t// inspect SS-prefix keys; clean stale sessions or restore backup\n\t}\n}","preventionTips":["Do not share the KV namespace with other applications","Restore only from complete, consistent dumps","Clean up dead sessions after unclean client shutdowns","Run fsck after manual KV maintenance"],"tags":["sessions","kv-store","dump","corruption"],"backgroundTag":"schema-validation-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"}