blob: 20d7513ee8f0787f933ce243814633314bf0fb5c (
plain)
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
|
#pragma once
#include "types.hpp"
#include "Key.hpp"
#include "DataView.hpp"
#include <opendht/dhtrunner.h>
#include <vector>
#include <ntp/NtpClient.hpp>
namespace odhtdb
{
class Group;
struct StagedCreateObject
{
Key key;
Group *primaryAdminGroup;
u64 timestamp; // In microseconds
};
struct StagedAddObject
{
Key key;
DataView data;
u64 timestamp; // In microseconds
};
class Database
{
public:
Database(const char *bootstrapNodeAddr, u16 port);
~Database();
void create(const Key &key, Group *primaryAdminGroup);
void add(const Key &key, DataView data);
void commit();
private:
void commitStagedCreateObject(const StagedCreateObject &stagedObject);
void commitStagedAddObject(const StagedAddObject &stagedObject);
ntp::NtpTimestamp getSyncedTimestampUtc() const;
private:
dht::DhtRunner node;
std::vector<StagedCreateObject> stagedCreateObjects;
std::vector<StagedAddObject> stagedAddObjects;
};
}
|