MCPcopy Create free account
hub / github.com/Tencent/phxsql / ApplyToken

Method ApplyToken

phxsqlproxy/plugin/requestfilter/freqctrlconfig.cpp:34–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32}
33
34bool FreqCtrlBucket::ApplyToken(int * for_apply, int count) {
35 uint32_t last_refill_time = (unsigned int) time(NULL);
36 last_refill_time = last_refill_time - last_refill_time % (db_token_.period);
37
38 if (db_bucket_struct_.last_refill_time != last_refill_time) {
39 db_bucket_struct_.last_refill_time = last_refill_time;
40 db_bucket_struct_.read_bucket = db_token_.read_token;
41 db_bucket_struct_.write_bucket = db_token_.write_token;
42 }
43
44 bool is_apply_ok = false;
45 if (*for_apply >= count) {
46 *for_apply -= count;
47 is_apply_ok = true;
48 }
49 return is_apply_ok;
50}
51
52bool FreqCtrlBucket::ApplyReadToken(int count) {
53 return ApplyToken(&db_bucket_struct_.read_bucket, count);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected