aboutsummaryrefslogtreecommitdiffstats
path: root/commit.c
blob: 3be296421dea0583abf1973a66bf05062d9eb182 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <errno.h>
#include <string.h>
#include "commit.h"

extern char *storage_dir;
extern char *storage_prefix;
const uint32_t write_blk_size = 8196;

void nfl_commit_init() {

}

void nfl_commit_worker(nflog_header_t* header, nflog_entry_t* store) {
    FILE* f;
    char filename[1024];
    uint32_t written, id = header->id;

    sprintf(filename, "%s/%s_%d", storage_dir, storage_prefix, id);
    debug("Comm worker #%u: commit to file %s\n", header->id, filename);
    ERR((f = fopen(filename, "wb")) == NULL, strerror(errno));
    
    // commit header
    written = fwrite(header, 1, sizeof(nflog_header_t), f);
    ERR(written != sizeof(nflog_header_t), strerror(errno));

    // commit store
    uint32_t store_size = sizeof(nflog_entry_t) * header->max_n_entries;
    written = fwrite(store, 1, store_size, f);
    ERR(written != store_size, strerror(errno));

    // Do fsync ?
    fclose(f);
}