Exemplo n.º 1
0
int scaling_bloom_flush(scaling_bloom_t *bloom)
{
    if (bitmap_flush(bloom->bitmap) != 0) {
        return -1;
    }
    // all changes written to disk before disk_seqnum set
    if (bloom->header->disk_seqnum == 0) {
        bloom->header->disk_seqnum = bloom->header->mem_seqnum;
        return bitmap_flush(bloom->bitmap);
    }
    return 0;
}
Exemplo n.º 2
0
/**
 * Flushes the filter, and updates the metadata.
 * @return 0 on success, negative on failure.
 */
int bf_flush(bloom_bloomfilter *filter) {
    // Flush the bitmap if we have one
    if (filter == NULL or filter->map == NULL) {
        return -1;
    }
    return bitmap_flush(filter->map);
}
Exemplo n.º 3
0
END_TEST

START_TEST(flush_bitmap_file)
{
    bloom_bitmap map;
    int res = bitmap_from_filename("/tmp/mmap_flush_bitmap", 8196, 1, 1, SHARED, &map);
    fail_unless(res == 0);
    fail_unless(bitmap_flush(&map) == 0);
    unlink("/tmp/mmap_flush_bitmap");
}
Exemplo n.º 4
0
END_TEST

START_TEST(flush_bitmap_file_persistent)
{
    bloom_bitmap map;
    int res = bitmap_from_filename("/tmp/mmap_flush_bitmap_persist", 8196,
            1, 1, PERSISTENT, &map);
    fail_unless(res == 0);
    fail_unless(bitmap_flush(&map) == 0);
    unlink("/tmp/mmap_flush_bitmap_persist");
}
Exemplo n.º 5
0
END_TEST


/*
 * int bitmap_flush(bloom_bitmap *map) {
 */
START_TEST(flush_bitmap_anonymous)
{
    bloom_bitmap map;
    int res = bitmap_from_file(-1, 4096, ANONYMOUS, &map);
    fail_unless(res == 0);
    fail_unless(bitmap_flush(&map) == 0);
}
Exemplo n.º 6
0
uint64_t scaling_bloom_clear_seqnums(scaling_bloom_t *bloom)
{
    uint64_t seqnum;

    if (bloom->header->disk_seqnum != 0) {
        // disk_seqnum cleared on disk before any other changes
        bloom->header->disk_seqnum = 0;
        bitmap_flush(bloom->bitmap);
    }
    seqnum = bloom->header->mem_seqnum;
    bloom->header->mem_seqnum = 0;
    return seqnum;
}
Exemplo n.º 7
0
END_TEST

START_TEST(flush_does_write_persist) {
    bloom_bitmap map;
    int res = bitmap_from_filename("/tmp/persist_flush_write", 4096, 1, 1, PERSISTENT, &map);
    fchmod(map.fileno, 0777);
    fail_unless(res == 0);
    for (int idx = 0; idx < 4096*8 ; idx++) {
        bitmap_setbit((&map), idx);
    }
    bitmap_flush(&map);

    bloom_bitmap map2;
    res = bitmap_from_filename("/tmp/persist_flush_write", 4096, 0, 0,
            PERSISTENT, &map2);
    fail_unless(res == 0);
    for (int idx = 0; idx < 4096; idx++) {
        fail_unless(map2.mmap[idx] == 255);
    }
    unlink("/tmp/persist_flush_write");
}
Exemplo n.º 8
0
END_TEST


/**
 * Test that flush does indeed write to disk
 */
START_TEST(flush_does_write) {
    bloom_bitmap map;
    int res = bitmap_from_filename("/tmp/mmap_flush_write", 4096, 1, 1, SHARED, &map);
    fchmod(map.fileno, 0777);
    fail_unless(res == 0);
    for (int idx = 0; idx < 4096*8 ; idx++) {
        bitmap_setbit((&map), idx);
    }
    bitmap_flush(&map);

    bloom_bitmap map2;
    res = bitmap_from_filename("/tmp/mmap_flush_write", 4096, 0, 0, SHARED, &map2);
    fail_unless(res == 0);
    for (int idx = 0; idx < 4096; idx++) {
        fail_unless(map2.mmap[idx] == 255);
    }
    unlink("/tmp/mmap_flush_write");
}
Exemplo n.º 9
0
END_TEST

START_TEST(flush_bitmap_null)
{
    fail_unless(bitmap_flush(NULL) == -EINVAL);
}
Exemplo n.º 10
0
int test_scaling_remove_reopen(const char *bloom_file, const char *words_file)
{
    FILE *fp;
    char word[256];
    scaling_bloom_t *bloom;
    int i, key_removed;
    struct stats results = { 0 };
    
    printf("\n* test scaling remove & reopen\n");
    
    if ((fp = fopen(bloom_file, "r"))) {
        fclose(fp);
        remove(bloom_file);
    }
    
    if (!(bloom = new_scaling_bloom(CAPACITY, ERROR_RATE, bloom_file))) {
        fprintf(stderr, "ERROR: Could not create bloom filter\n");
        return TEST_FAIL;
    }
    
    if (!(fp = fopen(words_file, "r"))) {
        fprintf(stderr, "ERROR: Could not open words file\n");
        return TEST_FAIL;
    }
    
    for (i = 0; fgets(word, sizeof(word), fp); i++) {
        chomp_line(word);
        scaling_bloom_add(bloom, word, strlen(word), i);
    }
    
    fseek(fp, 0, SEEK_SET);
    for (i = 0; fgets(word, sizeof(word), fp); i++) {
        if (i % 5 == 0) {
            chomp_line(word);
            scaling_bloom_remove(bloom, word, strlen(word), i);
        }
    }
    
    bitmap_flush(bloom->bitmap);
    free_scaling_bloom(bloom);
    
    bloom = new_scaling_bloom_from_file(CAPACITY, ERROR_RATE, bloom_file);
    
    fseek(fp, 0, SEEK_SET);
    for (i = 0; fgets(word, sizeof(word), fp); i++) {
        chomp_line(word);
        key_removed = (i % 5 == 0);
        bloom_score(scaling_bloom_check(bloom, word, strlen(word)), !key_removed, &results, word);
    }
    fclose(fp);
    
    printf("Elements added:   %6d" "\n"
           "Elements removed: %6d" "\n"
           "Total size: %d KiB"  "\n\n",
           i, i / 5,
           (int) bloom->num_bytes / 1024);
           
    free_scaling_bloom(bloom);
    
    return print_results(&results);
}