maxWaitTime(wait_time_in_secs * 1000 * 1000),
totalSleepTime(0) {}
- void incrementAndAbortIfLimitReached(const useconds_t sleep_time)
+ void incrementAndAbortIfLimitReached(T last_value,
+ const useconds_t sleep_time)
{
totalSleepTime += sleep_time;
if (totalSleepTime >= maxWaitTime) {
if (statKey != NULL) {
std::cerr << "(" << statKey << ")";
}
- std::cerr << "' " << compareName << " " << final << " - aborting."
+ std::cerr << "' " << compareName << " " << final
+ << " (last value:" << last_value << ") - aborting."
<< std::endl;
abort();
}
void wait_for_stat_change(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
const char *stat, int initial,
- const char *statkey,
+ const char *stat_key,
const time_t max_wait_time_in_secs) {
useconds_t sleepTime = 128;
- WaitTimeAccumulator<int> accumulator("to change from", stat, statkey,
+ WaitTimeAccumulator<int> accumulator("to change from", stat, stat_key,
initial, max_wait_time_in_secs);
- while (get_int_stat(h, h1, stat, statkey) == initial) {
- accumulator.incrementAndAbortIfLimitReached(sleepTime);
+ for (;;) {
+ auto current = get_int_stat(h, h1, stat, stat_key);
+ if (current != initial) {
+ break;
+ }
+ accumulator.incrementAndAbortIfLimitReached(current, sleepTime);
decayingSleep(&sleepTime);
}
}
useconds_t sleepTime = 128;
WaitTimeAccumulator<int> accumulator("to be", stat, stat_key, final,
max_wait_time_in_secs);
- while (get_int_stat(h, h1, stat, stat_key) != final) {
- accumulator.incrementAndAbortIfLimitReached(sleepTime);
+ for (;;) {
+ auto current = get_int_stat(h, h1, stat, stat_key);
+ if (current == final) {
+ break;
+ }
+ accumulator.incrementAndAbortIfLimitReached(current, sleepTime);
decayingSleep(&sleepTime);
}
}
WaitTimeAccumulator<int> accumulator("to be greater or equal than", stat,
stat_key, final,
max_wait_time_in_secs);
- while (get_int_stat(h, h1, stat, stat_key) < final) {
- accumulator.incrementAndAbortIfLimitReached(sleepTime);
+ for (;;) {
+ auto current = get_int_stat(h, h1, stat, stat_key);
+ if (current >= final) {
+ break;
+ }
+ accumulator.incrementAndAbortIfLimitReached(current, sleepTime);
decayingSleep(&sleepTime);
}
}
WaitTimeAccumulator<int> accumulator("to be less than or equal to", stat,
stat_key, final,
max_wait_time_in_secs);
- while (get_int_stat(h, h1, stat, stat_key) > final) {
- accumulator.incrementAndAbortIfLimitReached(sleepTime);
+ for (;;) {
+ auto current = get_int_stat(h, h1, stat, stat_key);
+ if (current <= final) {
+ break;
+ }
+ accumulator.incrementAndAbortIfLimitReached(current, sleepTime);
decayingSleep(&sleepTime);
}
}
WaitTimeAccumulator<int> accumulator("to be", "expired items",
NULL, final,
max_wait_time_in_secs);
- while(get_int_stat(h, h1, "ep_expired_access") +
- get_int_stat(h, h1, "ep_expired_compactor") +
- get_int_stat(h, h1, "ep_expired_pager") != final) {
- accumulator.incrementAndAbortIfLimitReached(sleepTime);
+ for (;;) {
+ auto current = get_int_stat(h, h1, "ep_expired_access") +
+ get_int_stat(h, h1, "ep_expired_compactor") +
+ get_int_stat(h, h1, "ep_expired_pager");
+ if (current == final) {
+ break;
+ }
+ accumulator.incrementAndAbortIfLimitReached(current, sleepTime);
decayingSleep(&sleepTime);
}
}
WaitTimeAccumulator<const char*> accumulator("to be", stat, stat_key,
final,
max_wait_time_in_secs);
- while (get_str_stat(h, h1, stat, stat_key).compare(final) != 0) {
- accumulator.incrementAndAbortIfLimitReached(sleepTime);
+ for (;;) {
+ auto current = get_str_stat(h, h1, stat, stat_key);
+ if (current == final) {
+ break;
+ }
+ accumulator.incrementAndAbortIfLimitReached(current.c_str(),
+ sleepTime);
decayingSleep(&sleepTime);
}
}
WaitTimeAccumulator<int> accumulator("to be below", "mem_used", NULL,
mem_threshold,
max_wait_time_in_secs);
- while (get_int_stat(h, h1, "mem_used") > mem_threshold) {
- accumulator.incrementAndAbortIfLimitReached(sleepTime);
+ for (;;) {
+ auto current = get_int_stat(h, h1, "mem_used");
+ if (current <= mem_threshold) {
+ break;
+ }
+ accumulator.incrementAndAbortIfLimitReached(current, sleepTime);
decayingSleep(&sleepTime);
}
}