-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathshard_manager.hpp
More file actions
64 lines (52 loc) · 2.07 KB
/
shard_manager.hpp
File metadata and controls
64 lines (52 loc) · 2.07 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
#pragma once
#include <compare>
#include <list>
#include <optional>
#include <sisl/utility/enum.hpp>
#include "common.hpp"
namespace homeobject {
ENUM(ShardErrorCode, uint16_t, UNKNOWN = 1, TIMEOUT, INVALID_ARG, NOT_LEADER, UNSUPPORTED_OP, UNKNOWN_PG, UNKNOWN_SHARD,
PG_NOT_READY, CRC_MISMATCH, NO_SPACE_LEFT, RETRY_REQUEST, SHUTTING_DOWN);
struct ShardError {
ShardErrorCode code;
// set when we are not the current leader of the PG.
std::optional< peer_id_t > current_leader{std::nullopt};
ShardError(ShardErrorCode _code) { code = _code; }
ShardError(ShardErrorCode _code, peer_id_t _leader) {
code = _code;
current_leader = _leader;
}
ShardErrorCode getCode() const { return code; }
};
struct ShardInfo {
static constexpr uint64_t meta_length = 1024 + 1;
enum class State : uint8_t {
OPEN = 0,
SEALED = 1,
DELETED = 2,
};
shard_id_t id;
pg_id_t placement_group;
State state;
uint64_t lsn; // created_lsn
uint64_t created_time;
uint64_t last_modified_time;
uint64_t available_capacity_bytes;
uint64_t total_capacity_bytes;
std::optional< peer_id_t > current_leader{std::nullopt};
uint8_t meta[meta_length]{};
auto operator<=>(ShardInfo const& rhs) const { return id <=> rhs.id; }
auto operator==(ShardInfo const& rhs) const { return id == rhs.id; }
bool is_open() const { return state == State::OPEN; }
};
using InfoList = std::list< ShardInfo >;
class ShardManager : public Manager< ShardError > {
public:
static uint64_t max_shard_size(); // Static function forces runtime evaluation.
static uint64_t max_shard_num_in_pg();
virtual AsyncResult< ShardInfo > get_shard(shard_id_t id, trace_id_t tid = 0) const = 0;
virtual AsyncResult< InfoList > list_shards(pg_id_t id, trace_id_t tid = 0) const = 0;
virtual AsyncResult< ShardInfo > create_shard(pg_id_t pg_owner, uint64_t size_bytes, std::string meta, trace_id_t tid = 0) = 0;
virtual AsyncResult< ShardInfo > seal_shard(shard_id_t id, trace_id_t tid = 0) = 0;
};
} // namespace homeobject