]> git.proxmox.com Git - ceph.git/blob - ceph/src/os/bluestore/zoned_types.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / os / bluestore / zoned_types.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 #ifndef CEPH_OS_BLUESTORE_ZONED_TYPES_H
4 #define CEPH_OS_BLUESTORE_ZONED_TYPES_H
5
6 #include "include/types.h"
7 #include "kv/KeyValueDB.h"
8 #include "os/kv.h"
9
10 // Tracks two bits of information about the state of a zone: (1) number of dead
11 // bytes in a zone and (2) the write pointer. We use the existing
12 // Int64ArrayMergeOperator for merge and avoid the cost of point queries.
13 //
14 // We use the same struct for an on-disk and in-memory representation of the
15 // state.
16 struct zone_state_t {
17 uint64_t num_dead_bytes = 0; ///< dead bytes deallocated (behind the write pointer)
18 uint64_t write_pointer = 0; ///< relative offset within the zone
19
20 void encode(ceph::buffer::list &bl) const {
21 using ceph::encode;
22 encode(write_pointer, bl);
23 encode(num_dead_bytes, bl);
24 }
25 void decode(ceph::buffer::list::const_iterator &p) {
26 using ceph::decode;
27 decode(write_pointer, p);
28 decode(num_dead_bytes, p);
29 }
30
31 void reset() {
32 write_pointer = 0;
33 num_dead_bytes = 0;
34 }
35
36 uint64_t get_num_dead_bytes() const {
37 return num_dead_bytes;
38 }
39
40 uint64_t get_num_live_bytes() const {
41 return write_pointer - num_dead_bytes;
42 }
43
44 uint64_t get_write_pointer() const {
45 return write_pointer;
46 }
47
48 void increment_num_dead_bytes(uint64_t num_bytes) {
49 num_dead_bytes += num_bytes;
50 }
51
52 void increment_write_pointer(uint64_t num_bytes) {
53 write_pointer += num_bytes;
54 }
55
56 friend std::ostream& operator<<(
57 std::ostream& out,
58 const zone_state_t& zone_state) {
59 return out << std::hex
60 << " dead bytes: 0x" << zone_state.get_num_dead_bytes()
61 << " write pointer: 0x" << zone_state.get_write_pointer()
62 << " " << std::dec;
63 }
64 };
65
66 #endif