@@ -787,63 +787,56 @@ void DbSlice::Del(Context cntx, Iterator it) {
787
787
}
788
788
789
789
void DbSlice::FlushSlotsFb (const cluster::SlotSet& slot_ids) {
790
+ VLOG (1 ) << " Start FlushSlotsFb" ;
790
791
// Slot deletion can take time as it traverses all the database, hence it runs in fiber.
791
792
// We want to flush all the data of a slot that was added till the time the call to FlushSlotsFb
792
793
// was made. Therefore we delete slots entries with version < next_version
793
794
uint64_t next_version = 0 ;
795
+ uint64_t del_count = 0 ;
794
796
795
797
std::string tmp;
796
- auto del_entry_cb = [&](PrimeTable::iterator it) {
797
- std::string_view key = it->first .GetSlice (&tmp);
798
- SlotId sid = KeySlot (key);
799
- if (slot_ids.Contains (sid) && it.GetVersion () < next_version) {
800
- PerformDeletion (Iterator::FromPrime (it), db_arr_[0 ].get ());
798
+ auto iterate_bucket = [&](PrimeTable::bucket_iterator it) {
799
+ it.AdvanceIfNotOccupied ();
800
+ while (!it.is_done ()) {
801
+ std::string_view key = it->first .GetSlice (&tmp);
802
+ SlotId sid = KeySlot (key);
803
+ if (slot_ids.Contains (sid) && it.GetVersion () < next_version) {
804
+ PerformDeletion (Iterator::FromPrime (it), db_arr_[0 ].get ());
805
+ ++del_count;
806
+ }
807
+ ++it;
801
808
}
802
- return true ;
803
809
};
804
810
805
811
auto on_change = [&](DbIndex db_index, const ChangeReq& req) {
806
812
FiberAtomicGuard fg;
807
813
PrimeTable* table = GetTables (db_index).first ;
808
814
809
- auto iterate_bucket = [&](DbIndex db_index, PrimeTable::bucket_iterator it) {
810
- it.AdvanceIfNotOccupied ();
811
- while (!it.is_done ()) {
812
- del_entry_cb (it);
813
- ++it;
814
- }
815
- };
816
-
817
815
if (const PrimeTable::bucket_iterator* bit = req.update ()) {
818
816
if (!bit->is_done () && bit->GetVersion () < next_version) {
819
- iterate_bucket (db_index, *bit);
817
+ iterate_bucket (*bit);
820
818
}
821
819
} else {
822
820
string_view key = get<string_view>(req.change );
823
- table->CVCUponInsert (
824
- next_version, key,
825
- [db_index, next_version, iterate_bucket](PrimeTable::bucket_iterator it) {
826
- DCHECK_LT (it.GetVersion (), next_version);
827
- iterate_bucket (db_index, it);
828
- });
821
+ table->CVCUponInsert (next_version, key,
822
+ [next_version, iterate_bucket](PrimeTable::bucket_iterator it) {
823
+ DCHECK_LT (it.GetVersion (), next_version);
824
+ iterate_bucket (it);
825
+ });
829
826
}
830
827
};
831
828
next_version = RegisterOnChange (std::move (on_change));
832
829
833
830
ServerState& etl = *ServerState::tlocal ();
834
831
PrimeTable* pt = &db_arr_[0 ]->prime ;
835
832
PrimeTable::Cursor cursor;
836
- uint64_t i = 0 ;
833
+
837
834
do {
838
- PrimeTable::Cursor next = pt->Traverse (cursor, del_entry_cb);
839
- ++i;
835
+ PrimeTable::Cursor next = pt->TraverseBuckets (cursor, iterate_bucket);
840
836
cursor = next;
841
- if (i % 100 == 0 ) {
842
- ThisFiber::Yield ();
843
- }
844
-
837
+ ThisFiber::Yield ();
845
838
} while (cursor && etl.gstate () != GlobalState::SHUTTING_DOWN);
846
-
839
+ VLOG ( 1 ) << " FlushSlotsFb del count is: " << del_count;
847
840
UnregisterOnChange (next_version);
848
841
849
842
etl.DecommitMemory (ServerState::kDataHeap );
0 commit comments