Exemplo n.º 1
0
/**
 * Clears the filter from the internal data stores. This can only
 * be performed if the filter is proxied.
 * @arg filter_name The name of the filter to delete
 * @return 0 on success, -1 if the filter does not exist, -2
 * if the filter is not proxied.
 */
int filtmgr_clear_filter(bloom_filtmgr *mgr, char *filter_name) {
    int res = 0;
    pthread_mutex_lock(&mgr->write_lock);

    // Get the filter
    bloom_filter_wrapper *filt = take_filter(mgr, filter_name);
    if (!filt) {
        res = -1;
        goto LEAVE;
    }

    // Check if the filter is proxied
    if (!bloomf_is_proxied(filt->filter)) {
        res = -2;
        goto LEAVE;
    }

    // This is critical, as it prevents it from
    // being deleted. Instead, it is merely closed.
    filt->is_active = 0;
    filt->should_delete = 0;
    create_delta_update(mgr, DELETE, filt);

LEAVE:
    pthread_mutex_unlock(&mgr->write_lock);
    return res;
}
Exemplo n.º 2
0
/**
 * Called as part of the hashmap callback
 * to list cold filters. Only works if value is
 * not NULL.
 */
static int filter_map_list_cold_cb(void *data, const unsigned char *key, uint32_t key_len, void *value) {
    (void)key_len;
    // Cast the inputs
    bloom_filter_list_head *head = data;
    bloom_filter_wrapper *filt = value;

    // Check if hot, turn off and skip
    if (filt->is_hot) {
        filt->is_hot = 0;
        return 0;
    }

    // Check if proxied
    if (bloomf_is_proxied(filt->filter)) {
        return 0;
    }

    // Allocate a new entry
    bloom_filter_list *node = malloc(sizeof(bloom_filter_list));

    // Setup
    node->filter_name = strdup((char*)key);
    node->next = head->head;

    // Inject
    head->head = node;
    head->size++;
    return 0;
}
Exemplo n.º 3
0
// Callback invoked by list command to create an output
// line for each filter. We hold a filter handle which we
// can use to get some info about it
static void info_filter_cb(void *data, char *filter_name, bloom_filter *filter) {
    (void)filter_name;

    // Cast the intput
    char **out = data;

    // Get some metrics
    filter_counters *counters = bloomf_counters(filter);
    uint64_t capacity = bloomf_capacity(filter);
    uint64_t storage = bloomf_byte_size(filter);
    uint64_t size = bloomf_size(filter);
    uint64_t checks = counters->check_hits + counters->check_misses;
    uint64_t sets = counters->set_hits + counters->set_misses;

    // Generate a formatted string output
    int res;
    res = asprintf(out, "capacity %llu\n\
checks %llu\n\
check_hits %llu\n\
check_misses %llu\n\
in_memory %d\n\
page_ins %llu\n\
page_outs %llu\n\
probability %f\n\
sets %llu\n\
set_hits %llu\n\
set_misses %llu\n\
size %llu\n\
storage %llu\n",
    (unsigned long long)capacity, (unsigned long long)checks,
    (unsigned long long)counters->check_hits, (unsigned long long)counters->check_misses,
    ((bloomf_is_proxied(filter)) ? 0 : 1),
    (unsigned long long)counters->page_ins, (unsigned long long)counters->page_outs,
    filter->filter_config.default_probability,
    (unsigned long long)sets, (unsigned long long)counters->set_hits,
    (unsigned long long)counters->set_misses, (unsigned long long)size, (unsigned long long)storage);
    assert(res != -1);
}