{"record":{"id":"411e3b6075edabe3","repo":"weaviate/weaviate","slug":"write-metadata","errorCode":null,"errorMessage":"write metadata","messagePattern":"write metadata","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"adapters/repos/db/vector/hnsw/compact/snapshot_writer.go","lineNumber":279,"sourceCode":"// is always removed, including on the error paths.\nfunc (s *SnapshotWriter) Flush() error {\n\tif s.body != nil {\n\t\tdefer s.body.close()\n\t}\n\tif s.firstErr != nil {\n\t\treturn s.firstErr\n\t}\n\n\tvar nodeCount uint32\n\tif s.body != nil {\n\t\tif err := s.body.finish(); err != nil {\n\t\t\treturn errors.Wrap(err, \"finalize snapshot body\")\n\t\t}\n\t\tnodeCount = uint32(s.body.count)\n\t}\n\n\tif err := s.writeMetadata(nodeCount); err != nil {\n\t\treturn errors.Wrap(err, \"write metadata\")\n\t}\n\n\tif s.body != nil && nodeCount > 0 {\n\t\tif err := s.body.copyTo(s.w); err != nil {\n\t\t\treturn errors.Wrap(err, \"write body\")\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// writeMetadata writes the snapshot metadata header. nodeCount is the total\n// slot count (maxNodeID+1), sized so the reader can pre-allocate Graph.Nodes.\nfunc (s *SnapshotWriter) writeMetadata(nodeCount uint32) error {\n\tvar buf bytes.Buffer\n\n\t// Metadata content\n\t_ = writeUint64(&buf, s.entrypoint)","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/weaviate/weaviate/blob/75aa4b6d11f8818305aafd4440b4e32794f7ca04/adapters/repos/db/vector/hnsw/compact/snapshot_writer.go#L261-L297","documentation":"Wraps a failure from writeMetadata during snapshot Flush. Metadata (format version, flags, compression/Muvera settings, node count) is the snapshot header; failing here means the header could not be encoded into the metadata buffer.","triggerScenarios":"Calling Flush when writeCompressionData or writeMuveraData inside writeMetadata fails (see 6186/6187), or internal buffer encoding panics/fails due to unsupported compression or Muvera state.","commonSituations":"Snapshot writer configured with compression whose parameters could not be serialized; Muvera (multi-vector encoding) state partially initialized; version skew where a newer field cannot be encoded by this build.","solutions":["Read the wrapped cause — it will point at writeCompressionData or writeMuveraData.","If compression-related, verify PQ/BQ/SQ compression settings on the shard are fully initialized before exporting the snapshot.","If Muvera-related, check the multi-vector/Muvera configuration is valid; disable Muvera encoding if not needed and retry.","Discard the partial snapshot output and re-run Flush on a fresh writer; the target file is invalid after a metadata failure."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// confirm compression and Muvera config are fully initialized before writing\nif shard.HasCompression() && !shard.CompressionReady() { return errors.New(\"compression not initialized\") }","typeGuard":null,"tryCatchPattern":"if err := writer.Flush(); err != nil {\n    var wrapped interface{ Unwrap() error }\n    if errors.As(err, &wrapped) { log.Printf(\"metadata write cause: %v\", wrapped) }\n    return err\n}","preventionTips":["Fully initialize compression and Muvera state before snapshotting.","Match Weaviate versions between shard creation and snapshot export.","Delete partial output after any Flush failure."],"tags":["go","hnsw","snapshot","metadata","serialization"],"backgroundTag":"snapshot-serialization-failed","analyzedSha":"75aa4b6d11f8818305aafd4440b4e32794f7ca04","analyzedAt":"2026-09-04T14:58:20.392Z","contentChangedAt":"2026-09-04T14:58:20.392Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}