Example #1
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 list_filter_cb(void *data, char *filter_name, bloom_filter *filter) {
    char **out = data;
    int res;
    res = asprintf(out, "%s %f %llu %llu %llu\n",
            filter_name,
            filter->filter_config.default_probability,
            (unsigned long long)bloomf_byte_size(filter),
            (unsigned long long)bloomf_capacity(filter),
            (unsigned long long)bloomf_size(filter));
    assert(res != -1);
}
Example #2
0
/**
 * Flushes the filter. Idempotent if the
 * filter is proxied or not dirty.
 * @arg filter The filter to close
 * @return 0 on success.
 */
int bloomf_flush(bloom_filter *filter) {
    // Only do things if we are non-proxied
    if (filter->sbf) {
        // Time how long this takes
        struct timeval start, end;
        gettimeofday(&start, NULL);

        // If our size has not changed, there is no need to flush
        uint64_t new_size = bloomf_size(filter);
        if (new_size == filter->filter_config.size && filter->filter_config.bytes != 0) {
            return 0;
        }

        // Store our properties for a future unmap
        filter->filter_config.size = new_size;
        filter->filter_config.capacity = bloomf_capacity(filter);
        filter->filter_config.bytes = bloomf_byte_size(filter);

        // Write out filter_config
        char *config_name = join_path(filter->full_path, (char*)CONFIG_FILENAME);
        int res = update_filename_from_filter_config(config_name, &filter->filter_config);
        free(config_name);
        if (res) {
            syslog(LOG_ERR, "Failed to write filter '%s' configuration. Err: %d.",
                    filter->filter_name, res);
        }

        // Flush the filter
        res = 0;
        if (!filter->filter_config.in_memory) {
            res = sbf_flush((bloom_sbf*)filter->sbf);
        }

        // Compute the elapsed time
        gettimeofday(&end, NULL);
        syslog(LOG_INFO, "Flushed filter '%s'. Total time: %d msec.",
                filter->filter_name, timediff_msec(&start, &end));
        return res;
    }
    return 0;
}
Example #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);
}