Exemple #1
0
/**
 * Destroys a bloom filter
 * @arg filter The filter to destroy
 * @return 0 on success
 */
int destroy_bloom_filter(bloom_filter *filter) {
    // Close first
    bloomf_close(filter);

    // Cleanup
    free(filter->filter_name);
    free(filter->full_path);
    free(filter);
    return 0;
}
Exemple #2
0
/**
 * Invoked to cleanup a filter once we
 * have hit 0 remaining references.
 */
static void delete_filter(bloom_filter_wrapper *filt) {
    // Delete or Close the filter
    if (filt->should_delete)
        bloomf_delete(filt->filter);
    else
        bloomf_close(filt->filter);

    // Cleanup the filter
    destroy_bloom_filter(filt->filter);

    // Release any custom configs
    if (filt->custom) {
        free(filt->custom);
    }

    // Release the struct
    free(filt);
    return;
}
Exemple #3
0
/**
 * Unmaps the filter from memory, but leaves it
 * registered in the filter manager. This is rarely invoked
 * by a client, as it can be handled automatically by bloomd,
 * but particular clients with specific needs may use it as an
 * optimization.
 * @arg filter_name The name of the filter to delete
 * @return 0 on success, -1 if the filter does not exist.
 */
int filtmgr_unmap_filter(bloom_filtmgr *mgr, char *filter_name) {
    // Get the filter
    bloom_filter_wrapper *filt = take_filter(mgr, filter_name);
    if (!filt) return -1;

    // Skip if we are in memory
    if (filt->filter->filter_config.in_memory)
        goto LEAVE;

    // Acquire the write lock
    pthread_rwlock_wrlock(&filt->rwlock);

    // Close the filter
    bloomf_close(filt->filter);

    // Release the lock
    pthread_rwlock_unlock(&filt->rwlock);

LEAVE:
    return 0;
}
Exemple #4
0
/**
 * Deletes the bloom filter with
 * extreme prejudice.
 * @arg filter The filter to delete
 * @return 0 on success.
 */
int bloomf_delete(bloom_filter *filter) {
    // Close first
    bloomf_close(filter);

    // Delete the files
    struct dirent **namelist = NULL;
    int num;

    // Filter only data dirs, in sorted order
    num = scandir(filter->full_path, &namelist, filter_out_special, NULL);
    syslog(LOG_INFO, "Deleting %d files for filter %s.", num, filter->filter_name);

    // Free the memory associated with scandir
    for (int i=0; i < num; i++) {
        char *file_path = join_path(filter->full_path, namelist[i]->d_name);
        syslog(LOG_INFO, "Deleting: %s.", file_path);
        if (unlink(file_path)) {
            syslog(LOG_ERR, "Failed to delete: %s. %s", file_path, strerror(errno));
        }
        free(file_path);
    }

    // Free the memory associated with scandir
    for (int i=0; i < num; i++) {
        free(namelist[i]);
    }
    if (namelist)
        free(namelist);

    // Delete the directory
    if (rmdir(filter->full_path)) {
        syslog(LOG_ERR, "Failed to delete: %s. %s", filter->full_path, strerror(errno));
    }

    return 0;
}