benchmark silo added
[c11concurrency-benchmarks.git] / silo / masstree / checkpoint.hh
1 /* Masstree
2  * Eddie Kohler, Yandong Mao, Robert Morris
3  * Copyright (c) 2012-2013 President and Fellows of Harvard College
4  * Copyright (c) 2012-2013 Massachusetts Institute of Technology
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, subject to the conditions
9  * listed in the Masstree LICENSE file. These conditions include: you must
10  * preserve this copyright notice, and you cannot mention the copyright
11  * holders in advertising related to the Software without their permission.
12  * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
13  * notice is a summary of the Masstree LICENSE file; the license in that file
14  * is legally binding.
15  */
16 #ifndef MASSTREE_CHECKPOINT_HH
17 #define MASSTREE_CHECKPOINT_HH
18 #include "kvrow.hh"
19 #include "kvio.hh"
20 #include "msgpack.hh"
21
22 struct ckstate {
23     kvout *vals; // key, val, timestamp in msgpack
24     uint64_t count; // total nodes written
25     uint64_t bytes;
26     pthread_cond_t state_cond;
27     volatile int state;
28     threadinfo *ti;
29     Str startkey;
30     Str endkey;
31
32     template <typename SS, typename K>
33     void visit_leaf(const SS&, const K&, threadinfo&) {
34     }
35     bool visit_value(Str key, const row_type* value, threadinfo& ti);
36
37     template <typename T>
38     static void insert(T& table, msgpack::parser& par, threadinfo& ti);
39 };
40
41 template <typename T>
42 void ckstate::insert(T& table, msgpack::parser& par, threadinfo& ti) {
43     Str key;
44     kvtimestamp_t ts{};
45     par >> key >> ts;
46     row_type* row = row_type::checkpoint_read(par, ts, ti);
47
48     typename T::cursor_type lp(table, key);
49     bool found = lp.find_insert(ti);
50     masstree_invariant(!found); (void) found;
51     ti.advance_timestamp(lp.node_timestamp());
52     lp.value() = row;
53     lp.finish(1, ti);
54 }
55
56 #endif