@@ -21,41 +21,54 @@ ScrubResources::ScrubResources(
2121 , conf{config}
2222{}
2323
24+ // ------------------------- scrubbing as primary on this OSD -----------------
25+
26+ // can we increase the number of concurrent scrubs performed by Primaries
27+ // on this OSD? note that counted separately from the number of scrubs
28+ // performed by replicas.
2429bool ScrubResources::can_inc_scrubs () const
2530{
2631 std::lock_guard lck{resource_lock};
27- if (scrubs_local + granted_reservations.size () < conf->osd_max_scrubs ) {
28- return true ;
29- }
30- log_upwards (fmt::format (
31- " {}== false. {} (local) + {} (remote) >= max ({})" , __func__,
32- scrubs_local, granted_reservations.size (), conf->osd_max_scrubs ));
33- return false ;
32+ return can_inc_local_scrubs_unlocked ();
3433}
3534
3635bool ScrubResources::inc_scrubs_local ()
3736{
3837 std::lock_guard lck{resource_lock};
39- if (scrubs_local + granted_reservations. size () < conf-> osd_max_scrubs ) {
38+ if (can_inc_local_scrubs_unlocked () ) {
4039 ++scrubs_local;
40+ log_upwards (fmt::format (
41+ " {}: {} -> {} (max {}, remote {})" , __func__, (scrubs_local - 1 ),
42+ scrubs_local, conf->osd_max_scrubs , granted_reservations.size ()));
43+ return true ;
44+ }
45+ return false ;
46+ }
47+
48+ bool ScrubResources::can_inc_local_scrubs_unlocked () const
49+ {
50+ if (scrubs_local < conf->osd_max_scrubs ) {
4151 return true ;
4252 }
4353 log_upwards (fmt::format (
44- " {}: {} ( local) + {} (remote ) >= max ({})" , __func__, scrubs_local ,
45- granted_reservations. size () , conf->osd_max_scrubs ));
54+ " {}: Cannot add local scrubs. Current counter ({} ) >= max ({})" , __func__,
55+ scrubs_local , conf->osd_max_scrubs ));
4656 return false ;
4757}
4858
4959void ScrubResources::dec_scrubs_local ()
5060{
5161 std::lock_guard lck{resource_lock};
5262 log_upwards (fmt::format (
53- " {}: {} -> {} (max {}, remote {})" , __func__, scrubs_local,
54- (scrubs_local - 1 ), conf->osd_max_scrubs , granted_reservations.size ()));
63+ " {}: {} -> {} (max {}, remote {})" ,
64+ __func__, scrubs_local, (scrubs_local - 1 ), conf->osd_max_scrubs ,
65+ granted_reservations.size ()));
5566 --scrubs_local;
5667 ceph_assert (scrubs_local >= 0 );
5768}
5869
70+ // ------------------------- scrubbing on this OSD as replicas ----------------
71+
5972bool ScrubResources::inc_scrubs_remote (pg_t pgid)
6073{
6174 std::lock_guard lck{resource_lock};
@@ -67,18 +80,20 @@ bool ScrubResources::inc_scrubs_remote(pg_t pgid)
6780 return true ;
6881 }
6982
70- auto prev = granted_reservations.size ();
71- if (scrubs_local + prev < conf->osd_max_scrubs ) {
83+ auto pre_op_cnt = granted_reservations.size ();
84+ if (pre_op_cnt < conf->osd_max_scrubs ) {
7285 granted_reservations.insert (pgid);
7386 log_upwards (fmt::format (
74- " {}: pg[{}] {} -> {} (max {}, local {})" , __func__, pgid, prev,
75- granted_reservations.size (), conf->osd_max_scrubs , scrubs_local));
87+ " {}: pg[{}] reserved. Remote scrubs count changed from {} -> {} (max "
88+ " {}, local {})" ,
89+ __func__, pgid, pre_op_cnt, granted_reservations.size (),
90+ conf->osd_max_scrubs , scrubs_local));
7691 return true ;
7792 }
7893
7994 log_upwards (fmt::format (
80- " {}: pg[{}] {} (local) + {} (remote) >= max ({})" , __func__, pgid ,
81- scrubs_local, granted_reservations. size () , conf->osd_max_scrubs ));
95+ " {}: pg[{}] failed. Too many concurrent replica scrubs ( {} >= max ({})) " ,
96+ __func__, pgid, pre_op_cnt , conf->osd_max_scrubs ));
8297 return false ;
8398}
8499
0 commit comments