feat(xce-test-e2e-primitives): quiet wait-primary poll — suppress per-attempt joblist perror + libxce failover INFO spam
The wait-primary probe loop EXPECTS repeated failure until a primary serves, so it no longer spams the console: joblist_query gains a quiet flag (the poll passes quiet=1) and the client log threshold is raised to warn for the loop duration, restored to the user's level on every exit path. Interactive joblist + the assertions keep their diagnostics (quiet=0).
This commit is contained in:
parent
c205b5b25d
commit
2988682bd6
1 changed files with 30 additions and 6 deletions
|
|
@ -901,7 +901,8 @@ static char* job_state_str(int state)
|
|||
*
|
||||
* On error this returns the negative rc WITHOUT setting any auto-variable, so a
|
||||
* failed joblist never advertises a fake `$jobcount` (Req 3.6). */
|
||||
static int joblist_query(const char* find_jobid, int* contains, int print_table)
|
||||
static int joblist_query(const char* find_jobid, int* contains, int print_table,
|
||||
int quiet)
|
||||
{
|
||||
int rc, i;
|
||||
xce_job_t** jobs;
|
||||
|
|
@ -914,7 +915,12 @@ static int joblist_query(const char* find_jobid, int* contains, int print_table)
|
|||
|
||||
if (rc < 0) {
|
||||
SET_ERROR(-rc);
|
||||
perror("xce_joblist");
|
||||
/* `quiet` callers (e.g. the wait-primary poll, which probes repeatedly
|
||||
* and EXPECTS failure until a primary serves) suppress the per-attempt
|
||||
* error print so a normal failover wait does not spam the console. */
|
||||
if (!quiet) {
|
||||
perror("xce_joblist");
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
|
@ -957,7 +963,7 @@ int cmd_joblist(int argc, char* argv[])
|
|||
{
|
||||
int count;
|
||||
|
||||
count = joblist_query(NULL, NULL, 1);
|
||||
count = joblist_query(NULL, NULL, 1, /*quiet=*/0);
|
||||
|
||||
if (count < 0) {
|
||||
return count;
|
||||
|
|
@ -1008,7 +1014,7 @@ int cmd_expect_jobs(int argc, char* argv[])
|
|||
/* Print-free count via the shared helper. A negative rc means the query
|
||||
* itself failed (e.g. no reachable master) — that is an assertion failure,
|
||||
* not "0 jobs". */
|
||||
count = joblist_query(NULL, NULL, 0);
|
||||
count = joblist_query(NULL, NULL, 0, /*quiet=*/0);
|
||||
|
||||
if (count < 0) {
|
||||
printf("expect-jobs: could not determine job count (joblist query "
|
||||
|
|
@ -1056,7 +1062,7 @@ int cmd_expect_job(int argc, char* argv[])
|
|||
/* Print-free membership query via the shared helper. A negative rc means the
|
||||
* query itself failed (e.g. no reachable master) — that is an assertion
|
||||
* failure, distinct from "job absent". */
|
||||
rc = joblist_query(argv[1], &contains, 0);
|
||||
rc = joblist_query(argv[1], &contains, 0, /*quiet=*/0);
|
||||
|
||||
if (rc < 0) {
|
||||
printf("expect-job: could not determine membership of '%s' (joblist "
|
||||
|
|
@ -1099,6 +1105,11 @@ int cmd_expect_job(int argc, char* argv[])
|
|||
#define NS_PER_MS 1000000L
|
||||
#define US_PER_MS 1000L
|
||||
|
||||
/* The client's configured log level (set in main from -v), so wait-primary can
|
||||
* temporarily raise the threshold to silence libxce's per-attempt failover INFO
|
||||
* spam during its poll and then RESTORE the user's chosen level. */
|
||||
static char* g_active_loglevel = (char*)"info";
|
||||
|
||||
static long monotonic_ms(void)
|
||||
{
|
||||
struct timespec ts;
|
||||
|
|
@ -1135,15 +1146,23 @@ int cmd_wait_primary(int argc, char* argv[])
|
|||
|
||||
start_ms = monotonic_ms();
|
||||
|
||||
/* The poll probes repeatedly and EXPECTS failure until a primary serves, so
|
||||
* it must not spam the console: the probe suppresses its own error print
|
||||
* (quiet=1), and we raise the client log threshold for the duration of the
|
||||
* loop to silence libxce's per-attempt "xcecli failover: attempt N" INFO
|
||||
* logs — RESTORED to the user's level on every exit path. */
|
||||
mylog_setlevel((char*)"warn");
|
||||
|
||||
/* Probe, then re-check the monotonic deadline between attempts. Each probe
|
||||
* may itself take time (libxce failover has its own internal retry budget);
|
||||
* we re-read the clock after every probe returns so the overall loop honors
|
||||
* the deadline and returns failure in bounded time. */
|
||||
for (;;) {
|
||||
int rc = joblist_query(NULL, NULL, 0);
|
||||
int rc = joblist_query(NULL, NULL, 0, /*quiet=*/1);
|
||||
|
||||
if (rc >= 0) {
|
||||
elapsed_ms = monotonic_ms() - start_ms;
|
||||
mylog_setlevel(g_active_loglevel);
|
||||
printf("wait-primary: primary serving after %ld ms\n", elapsed_ms);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1151,6 +1170,7 @@ int cmd_wait_primary(int argc, char* argv[])
|
|||
elapsed_ms = monotonic_ms() - start_ms;
|
||||
|
||||
if (elapsed_ms >= timeout_ms) {
|
||||
mylog_setlevel(g_active_loglevel);
|
||||
printf("wait-primary: no primary served within %ld ms (waited "
|
||||
"%ld ms)\n",
|
||||
timeout_ms, elapsed_ms);
|
||||
|
|
@ -3079,6 +3099,10 @@ int main(int argc, char* argv[])
|
|||
loglevel = verbose_to_loglevel(arguments.verbose);
|
||||
}
|
||||
|
||||
/* Remember the user's level so wait-primary can restore it after temporarily
|
||||
* raising the threshold to silence its poll-loop failover spam. */
|
||||
g_active_loglevel = loglevel;
|
||||
|
||||
mylog_init(logfile, loglevel, logsize, logcount);
|
||||
|
||||
signal(SIGINT, sigbreak);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue