| 5313 | } |
| 5314 | |
| 5315 | void *watcher_thread(void *arg) |
| 5316 | { |
| 5317 | bdb_state_type *bdb_state; |
| 5318 | extern int gbl_rep_lock_time_ms; |
| 5319 | extern int gbl_truncating_log; |
| 5320 | char *master_host = db_eid_invalid; |
| 5321 | int stopped_count = 0; |
| 5322 | int i; |
| 5323 | int j; |
| 5324 | int time_now, time_then; |
| 5325 | int rc; |
| 5326 | int master_is_bad = 0; |
| 5327 | int done = 0; |
| 5328 | char *rep_master = 0; |
| 5329 | int list_start; |
| 5330 | |
| 5331 | gbl_watcher_thread_ran = comdb2_time_epoch(); |
| 5332 | |
| 5333 | thrman_register(THRTYPE_WATCHDOG); |
| 5334 | thread_started("bdb watcher"); |
| 5335 | |
| 5336 | /* hold off on "watching" for a little bit during startup */ |
| 5337 | sleep(5); |
| 5338 | |
| 5339 | bdb_state = (bdb_state_type *)arg; |
| 5340 | bdb_thread_event(bdb_state, BDBTHR_EVENT_START_RDONLY); |
| 5341 | |
| 5342 | /* if we were passed a child, find his parent */ |
| 5343 | if (bdb_state->parent) |
| 5344 | bdb_state = bdb_state->parent; |
| 5345 | |
| 5346 | print(bdb_state, "watcher_thread started as 0x%"PRIxPTR"\n", |
| 5347 | (intptr_t)pthread_self()); |
| 5348 | |
| 5349 | poll(NULL, 0, (rand() % 100) + 1000); |
| 5350 | |
| 5351 | i = 0; |
| 5352 | j = 0; |
| 5353 | |
| 5354 | bdb_state->repinfo->disable_watcher = 0; |
| 5355 | |
| 5356 | while (!db_is_stopped()) { |
| 5357 | time_now = comdb2_time_epoch(); |
| 5358 | time_then = bdb_state->repinfo->disable_watcher; |
| 5359 | |
| 5360 | if (time_now < time_then) { |
| 5361 | int diff; |
| 5362 | diff = time_then - time_now; |
| 5363 | |
| 5364 | /* safeguard - no way are we gonna pause more than a minute here */ |
| 5365 | if (diff > 60) |
| 5366 | diff = 60; |
| 5367 | logmsg(LOGMSG_WARN, "watcher thread pausing for %d second\n", diff); |
| 5368 | sleep(diff); |
| 5369 | } |
| 5370 | |
| 5371 | if (gbl_truncating_log) { |
| 5372 | stopped_count++; |
nothing calls this directly
no test coverage detected