{"record":{"id":"4e5e57d6864d0fc7","repo":"weaviate/weaviate","slug":"error-while-getting-object-count-for-shard-s-w","errorCode":null,"errorMessage":"error while getting object count for shard %s: %w","messagePattern":"error while getting object count for shard (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"adapters/repos/db/shard_lazyloader.go","lineNumber":287,"sourceCode":"\tl.mutex.Lock()\n\tdefer l.mutex.Unlock()\n\n\tif l.loaded {\n\t\treturn l.shard.ObjectCountAsync(ctx)\n\t}\n\tif l.unloadedCount != nil {\n\t\treturn *l.unloadedCount, nil\n\t}\n\n\t// The disk read stays under the lock: a load writes segment sidecars and\n\t// recovers the write-ahead log, so a read overlapping one can sum a mix of\n\t// old and new segments and then cache the result. Everything else on this\n\t// shard waits for one directory listing. A failed read caches nothing, so a\n\t// shard whose sidecars stay unreadable repeats that listing on every call.\n\tidx := l.shardOpts.index\n\tobjectUsage, err := shardusage.CalculateUnloadedObjectsMetrics(idx.logger, idx.path(), l.shardOpts.name, true)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"error while getting object count for shard %s: %w\", l.shardOpts.name, err)\n\t}\n\n\tcount := objectUsage.Count\n\tl.unloadedCount = &count\n\n\treturn count, nil\n}\n\nfunc (l *LazyLoadShard) GetPropertyLengthTracker() *inverted.JsonShardMetaData {\n\tl.mustLoad()\n\treturn l.shard.GetPropertyLengthTracker()\n}\n\nfunc (l *LazyLoadShard) PutObject(ctx context.Context, object *storobj.Object) error {\n\tif err := l.Load(ctx); err != nil {\n\t\treturn err\n\t}\n\treturn l.shard.PutObject(ctx, object)","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/weaviate/weaviate/blob/75aa4b6d11f8818305aafd4440b4e32794f7ca04/adapters/repos/db/shard_lazyloader.go#L269-L305","documentation":"ObjectCountAsync computes the object count of an unloaded shard by scanning segment sidecars on disk via shardusage.CalculateUnloadedObjectsMetrics. This error wraps a failure of that directory listing/parse (unreadable shard directory, missing or corrupt sidecar files). Nothing is cached on failure, so every subsequent call retries the listing and fails again.","triggerScenarios":"Calling ObjectCountAsync on a cold shard whose shard directory or segment sidecar files are unreadable, deleted, or corrupted.","commonSituations":"Shard files partially deleted or moved on disk; permission problems on the data directory; corruption from a crash; monitoring/replication tooling polling counts on a shard with broken sidecars.","solutions":["Check the wrapped error and verify the shard directory and sidecar files exist and are readable by the weaviate process.","Fix filesystem permissions or restore/repair the shard directory (e.g. from replication or backup).","Recreate/re-sync the shard from a replica if files are corrupt.","After repair, call ObjectCountAsync again so the count is cached."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// verify the shard directory is readable before asking for counts\nif _, err := os.ReadDir(filepath.Join(dataPath, className, shardName)); err != nil {\n\treturn fmt.Errorf(\"shard dir unreadable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"count, err := shard.ObjectCountAsync(ctx)\nif err != nil {\n\tlogger.Warnf(\"object count unavailable for shard %s: %v\", shardName, err)\n\treturn lastKnownCount, nil // fallback: nothing was cached, so serve last known value\n}","preventionTips":["Ensure the weaviate process owns and can read all shard directories.","Restore broken shards from replicas or backups promptly.","Watch for repeated 'error while getting object count' logs — nothing is cached on failure, so each call re-lists the directory.","Avoid moving/deleting shard files while the node runs."],"tags":["storage","shard","monitoring","filesystem"],"backgroundTag":"shard-files-unreadable","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"}