File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -829,4 +829,26 @@ SearchStats ShardDocIndices::GetStats() const {
829829 return {GetUsedMemory (), indices_.size (), total_entries};
830830}
831831
832+ ssize_t ShardDocIndices::Defragment (PageUsage* page_usage, ssize_t quota) {
833+ auto it = next_defrag_index_.empty () ? indices_.end () : indices_.find (next_defrag_index_);
834+ if (it == indices_.end ()) {
835+ it = indices_.begin ();
836+ }
837+
838+ for (; it != indices_.end () && quota > 0 ; ++it) {
839+ auto & [name, index] = *it;
840+ quota = index->Defragment (page_usage, quota);
841+ if (quota == 0 ) {
842+ next_defrag_index_ = name;
843+ break ;
844+ }
845+ }
846+
847+ if (it == indices_.end ()) {
848+ next_defrag_index_.clear ();
849+ }
850+
851+ return quota;
852+ }
853+
832854} // namespace dfly
Original file line number Diff line number Diff line change @@ -306,6 +306,13 @@ class ShardDocIndex {
306306 search::DocId id, const OpArgs& op_args, const search::Schema& schema,
307307 const std::optional<std::vector<FieldReference>>& return_fields);
308308
309+ ssize_t Defragment (PageUsage* page_usage, ssize_t quota) {
310+ if (indices_) {
311+ return indices_->Defragment (page_usage, quota);
312+ }
313+ return quota;
314+ }
315+
309316 private:
310317 // Clears internal data. Traverses all matching documents and assigns ids.
311318 void Rebuild (const OpArgs& op_args, PMR_NS::memory_resource* mr);
@@ -355,13 +362,18 @@ class ShardDocIndices {
355362
356363 size_t GetUsedMemory () const ;
357364 SearchStats GetStats () const ; // combines stats for all indices
365+
366+ ssize_t Defragment (PageUsage* page_usage, ssize_t quota);
367+
358368 private:
359369 // Clean caches that might have data from this index
360370 void DropIndexCache (const dfly::ShardDocIndex& shard_doc_index);
361371
362372 private:
363373 MiMemoryResource local_mr_;
364374 absl::flat_hash_map<std::string, std::unique_ptr<ShardDocIndex>> indices_;
375+
376+ std::string next_defrag_index_;
365377};
366378
367379} // namespace dfly
You can’t perform that action at this time.
0 commit comments