forked from rethinkdb/rethinkdb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimestamps.hpp
More file actions
95 lines (74 loc) · 3 KB
/
Copy pathtimestamps.hpp
File metadata and controls
95 lines (74 loc) · 3 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2010-2012 RethinkDB, all rights reserved.
#ifndef TIMESTAMPS_HPP_
#define TIMESTAMPS_HPP_
#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif
#include <inttypes.h>
#include "repli_timestamp.hpp"
#include "rpc/serialize_macros.hpp"
class printf_buffer_t;
/* These are the timestamp types used by the clustering code.
`repli_timestamp_t`, which is used internally within the btree code, is defined
elsewhere. */
/* `state_timestamp_t` is a unique identifier of a particular point in a
timeline. `transition_timestamp_t` is the unique identifier of a transition from
one `state_timestamp_t` to the next. Databases have `state_timestamp_t`s, and
transactions have `transition_timestamp_t`s. */
class state_timestamp_t {
public:
bool operator==(state_timestamp_t t) const { return num == t.num; }
bool operator!=(state_timestamp_t t) const { return num != t.num; }
bool operator<(state_timestamp_t t) const { return num < t.num; }
bool operator>(state_timestamp_t t) const { return num > t.num; }
bool operator<=(state_timestamp_t t) const { return num <= t.num; }
bool operator>=(state_timestamp_t t) const { return num >= t.num; }
static state_timestamp_t zero() {
state_timestamp_t t;
t.num = 0;
return t;
}
// TODO get rid of this. This is only for a hack until we know what to do with timestamps
repli_timestamp_t to_repli_timestamp() const {
repli_timestamp_t ts;
ts.longtime = num;
return ts;
}
friend void debug_print(printf_buffer_t *buf, state_timestamp_t ts);
private:
friend class transition_timestamp_t;
uint64_t num;
RDB_MAKE_ME_SERIALIZABLE_1(num);
};
void debug_print(printf_buffer_t *buf, state_timestamp_t ts);
class transition_timestamp_t {
public:
bool operator==(transition_timestamp_t t) const { return before == t.before; }
bool operator!=(transition_timestamp_t t) const { return before != t.before; }
bool operator<(transition_timestamp_t t) const { return before < t.before; }
bool operator>(transition_timestamp_t t) const { return before > t.before; }
bool operator<=(transition_timestamp_t t) const { return before <= t.before; }
bool operator>=(transition_timestamp_t t) const { return before >= t.before; }
static transition_timestamp_t starting_from(state_timestamp_t before) {
transition_timestamp_t t;
t.before = before;
return t;
}
state_timestamp_t timestamp_before() const {
return before;
}
state_timestamp_t timestamp_after() const {
state_timestamp_t after;
after.num = before.num + 1;
guarantee(after > before, "timestamp counter overflowed");
return after;
}
// TODO get rid of this. This is only for a hack until we know what to do with timestamps
repli_timestamp_t to_repli_timestamp() const {
return before.to_repli_timestamp();
}
private:
state_timestamp_t before;
RDB_MAKE_ME_SERIALIZABLE_1(before);
};
#endif /* TIMESTAMPS_HPP_ */