static void handle_flush_cmd(bloom_conn_handler *handle, char *args, int args_len) { // If we have a specfic filter, use filt_cmd if (args) { handle_filt_cmd(handle, args, args_len, filtmgr_flush_filter); return; } // List all the filters bloom_filter_list_head *head; int res = filtmgr_list_filters(handle->mgr, NULL, &head); if (res != 0) { INTERNAL_ERROR(); return; } // Flush all, ignore errors since // filters might get deleted in the process bloom_filter_list *node = head->head; while (node) { filtmgr_flush_filter(handle->mgr, node->filter_name); node = node->next; } // Respond handle_client_resp(handle->conn, (char*)DONE_RESP, DONE_RESP_LEN); // Cleanup filtmgr_cleanup_list(head); }
END_TEST /* Flush */ START_TEST(test_mgr_flush_no_filter) { bloom_config config; int res = config_from_filename(NULL, &config); fail_unless(res == 0); bloom_filtmgr *mgr; res = init_filter_manager(&config, &mgr); fail_unless(res == 0); res = filtmgr_flush_filter(mgr, "noop1"); fail_unless(res == -1); res = destroy_filter_manager(mgr); fail_unless(res == 0); }
static void* flush_thread_main(void *in) { bloom_config *config; bloom_filtmgr *mgr; int *should_run; UNPACK_ARGS(); // Perform the initial checkpoint with the manager filtmgr_client_checkpoint(mgr); syslog(LOG_INFO, "Flush thread started. Interval: %d seconds.", config->flush_interval); unsigned int ticks = 0; while (*should_run) { sleep(1); filtmgr_client_checkpoint(mgr); if ((++ticks % config->flush_interval) == 0 && *should_run) { // List all the filters syslog(LOG_INFO, "Scheduled flush started."); bloom_filter_list_head *head; int res = filtmgr_list_filters(mgr, &head); if (res != 0) { syslog(LOG_WARNING, "Failed to list filters for flushing!"); continue; } // Flush all, ignore errors since // filters might get deleted in the process bloom_filter_list *node = head->head; while (node) { filtmgr_flush_filter(mgr, node->filter_name); node = node->next; } // Cleanup filtmgr_cleanup_list(head); } } return NULL; }
END_TEST START_TEST(test_mgr_flush) { bloom_config config; int res = config_from_filename(NULL, &config); fail_unless(res == 0); bloom_filtmgr *mgr; res = init_filter_manager(&config, &mgr); fail_unless(res == 0); res = filtmgr_create_filter(mgr, "zab3", NULL); fail_unless(res == 0); res = filtmgr_flush_filter(mgr, "zab3"); fail_unless(res == 0); res = filtmgr_drop_filter(mgr, "zab3"); fail_unless(res == 0); res = destroy_filter_manager(mgr); fail_unless(res == 0); }