コード例 #1
0
ファイル: filter_manager.c プロジェクト: armon/bloomd
/**
 * 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;
}
コード例 #2
0
ファイル: filter_manager.c プロジェクト: armon/bloomd
/**
 * Creates a new filter and adds it to the filter map.
 * @arg mgr The manager to add to
 * @arg filter_name The name of the filter
 * @arg config The configuration for the filter
 * @arg is_hot Is the filter hot. False for existing.
 * @arg delta Is this a delta update or should the map be updated
 * @return 0 on success, -1 on error
 */
static int add_filter(bloom_filtmgr *mgr, char *filter_name, bloom_config *config, int is_hot, int delta) {
    // Create the filter
    bloom_filter_wrapper *filt = calloc(1, sizeof(bloom_filter_wrapper));
    filt->is_active = 1;
    filt->is_hot = is_hot;
    filt->should_delete = 0;
    pthread_rwlock_init(&filt->rwlock, NULL);

    // Set the custom filter if its not the same
    if (mgr->config != config) {
        filt->custom = config;
    }

    // Try to create the underlying filter. Only discover if it is hot.
    int res = init_bloom_filter(config, filter_name, is_hot, &filt->filter);
    if (res != 0) {
        free(filt);
        return -1;
    }

    // Check if we are adding a delta value or directly updating ART tree
    if (delta)
        create_delta_update(mgr, CREATE, filt);
    else
        art_insert(mgr->filter_map, (unsigned char*)filter_name, strlen(filter_name)+1, filt);
    return 0;
}
コード例 #3
0
ファイル: set_manager.c プロジェクト: geetarista/hlld
/**
 * Creates a new set and adds it to the set set.
 * @arg mgr The manager to add to
 * @arg set_name The name of the set
 * @arg config The configuration for the set
 * @arg is_hot Is the set hot. False for existing.
 * @arg delta Should a delta entry be added, or the primary tree updated.
 * This is usually 0, except during initialization when it is safe to update
 * the primary tree.
 * @return 0 on success, -1 on error
 */
static int add_set(hlld_setmgr *mgr, char *set_name, hlld_config *config, int is_hot, int delta) {
    // Create the set
    hlld_set_wrapper *set = calloc(1, sizeof(hlld_set_wrapper));
    set->is_active = 1;
    set->is_hot = is_hot;
    set->should_delete = 0;
    pthread_rwlock_init(&set->rwlock, NULL);

    // Set the custom set if its not the same
    if (mgr->config != config) {
        set->custom = config;
    }

    // Try to create the underlying set. Only discover if it is hot.
    int res = init_set(config, set_name, is_hot, &set->set);
    if (res != 0) {
        free(set);
        return -1;
    }

    // Check if we are adding a delta value or directly updating ART tree
    if (delta)
        create_delta_update(mgr, CREATE, set);
    else
        art_insert(mgr->set_map, set_name, strlen(set_name)+1, set);

    return 0;
}
コード例 #4
0
ファイル: set_manager.c プロジェクト: geetarista/hlld
/**
 * Clears the set from the internal data stores. This can only
 * be performed if the set is proxied.
 * @arg set_name The name of the set to delete
 * @return 0 on success, -1 if the set does not exist, -2
 * if the set is not proxied.
 */
int setmgr_clear_set(hlld_setmgr *mgr, char *set_name) {
    int res = 0;
    pthread_mutex_lock(&mgr->write_lock);

    // Get the set
    hlld_set_wrapper *set = take_set(mgr, set_name);
    if (!set) {
        res = -1;
        goto LEAVE;
    }

    // Check if the set is proxied
    if (!hset_is_proxied(set->set)) {
        res = -2;
        goto LEAVE;
    }

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

LEAVE:
    pthread_mutex_unlock(&mgr->write_lock);
    return res;
}
コード例 #5
0
ファイル: filter_manager.c プロジェクト: armon/bloomd
/**
 * Creates a barrier that is implicit by adding a
 * new version, and waiting for all clients to reach
 * that version. This can be used as a non-locking
 * syncronization mechanism.
 */
static void version_barrier(bloom_filtmgr *mgr) {
    // Create a new delta
    pthread_mutex_lock(&mgr->write_lock);
    unsigned long long vsn = create_delta_update(mgr, BARRIER, NULL);
    pthread_mutex_unlock(&mgr->write_lock);

    // Wait until we converge on the version
    while (mgr->should_run && client_min_vsn(mgr) < vsn)
        usleep(VACUUM_POLL_USEC);
}
コード例 #6
0
ファイル: filter_manager.c プロジェクト: armon/bloomd
/**
 * Deletes the filter entirely. This removes it from the filter
 * manager and deletes it from disk. This is a permanent operation.
 * @arg filter_name The name of the filter to delete
 * @return 0 on success, -1 if the filter does not exist.
 */
int filtmgr_drop_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;
    }

    // Set the filter to be non-active and mark for deletion
    filt->is_active = 0;
    filt->should_delete = 1;
    create_delta_update(mgr, DELETE, filt);

LEAVE:
    pthread_mutex_unlock(&mgr->write_lock);
    return res;
}
コード例 #7
0
ファイル: set_manager.c プロジェクト: geetarista/hlld
/**
 * Deletes the set entirely. This removes it from the set
 * manager and deletes it from disk. This is a permanent operation.
 * @arg set_name The name of the set to delete
 * @return 0 on success, -1 if the set does not exist.
 */
int setmgr_drop_set(hlld_setmgr *mgr, char *set_name) {
    // Lock the deletion
    int res = 0;
    pthread_mutex_lock(&mgr->write_lock);

    // Get the set
    hlld_set_wrapper *set = take_set(mgr, set_name);
    if (!set) {
        res = -1;
        goto LEAVE;
    }

    // Set the set to be non-active and mark for deletion
    set->is_active = 0;
    set->should_delete = 1;
    create_delta_update(mgr, DELETE, set);

LEAVE:
    pthread_mutex_unlock(&mgr->write_lock);
    return res;
}