Akumuli
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
page.h
1 
23 #pragma once
24 #include "akumuli.h"
25 #include "buffer_cache.h"
26 #include "storage_engine/compression.h"
27 #include "internal_cursor.h"
28 #include "queryprocessor_framework.h"
29 #include "util.h"
30 #include <cstdint>
31 #include <functional>
32 #include <mutex>
33 #include <vector>
34 
35 const int64_t AKU_MAX_PAGE_SIZE = 0x100000000;
36 
37 namespace Akumuli {
38 
39 typedef uint64_t aku_Duration; //< Time duration
40 
43  aku_Timestamp timestamp;
44  uint32_t offset;
45 } __attribute__((packed));
46 
48  uint32_t n_elements; //< Number of elements in a chunk
49  uint32_t begin_offset; //< Data begin offset
50  uint32_t end_offset; //< Data end offset
51  uint32_t checksum; //< Checksum
52 } __attribute__((packed));
53 
54 
55 struct aku_Entry {
56  //aku_Timestamp time; //< Entry timestamp
57  aku_ParamId param_id; //< Parameter ID
58  uint32_t length; //< Entry length: constant + variable sized parts
59  uint32_t value[]; //< Data begining
60 } __attribute__((packed));
61 
63 struct PageHeader;
64 
69 struct SearchStats {
70  aku_SearchStats stats;
71  std::mutex mutex;
72 
73  SearchStats() { memset(&stats, 0, sizeof(stats)); }
74 };
75 
76 SearchStats& get_global_search_stats();
77 
78 
86 class PageHeader {
87  // metadata
88  const uint32_t version; //< format version
89  uint32_t count; //< number of elements stored
90  uint32_t next_offset; //< offset of the last added record in payload array
91  uint32_t checkpoint; //< page checkpoint index
92  uint32_t open_count; //< how many times page was open for write
93  uint32_t close_count; //< how many times page was closed for write
94  uint32_t page_id; //< page index in storage
95  uint32_t numpages; //< total number or pages
96  uint64_t length; //< payload size
97  char payload[]; //< page payload
98 
99 public:
101  uint64_t get_page_length() const;
102 
104  uint32_t get_page_id() const;
105 
107  uint32_t get_numpages() const;
108 
110  uint32_t get_open_count() const;
111 
113  uint32_t get_close_count() const;
114 
116  void set_open_count(uint32_t cnt);
117 
119  void set_close_count(uint32_t cnt);
120 
122 
124  void create_checkpoint();
125 
127  bool restore();
128 
129 
131  std::pair<aku_EntryIndexRecord, int> index_to_offset(uint32_t index) const;
132 
133  aku_EntryIndexRecord* page_index(int index);
134 
135  const aku_EntryIndexRecord* page_index(int index) const;
136 
138  PageHeader(uint32_t count, uint64_t length, uint32_t page_id, uint32_t numpages);
139 
141  void reuse();
142 
144  void close();
145 
147  uint32_t get_entries_count() const;
148 
150  size_t get_free_space() const;
151 
152  bool inside_bbox(aku_ParamId param, aku_Timestamp time) const;
153 
159  aku_Status add_entry(const aku_ParamId param, const aku_Timestamp timestamp,
160  const aku_MemRange& range);
161 
168  aku_Status add_chunk(const aku_MemRange data, const uint32_t free_space_required,
169  uint32_t* out_offset);
170 
176  aku_Status complete_chunk(const UncompressedChunk& data);
177 
183  int get_entry_length_at(int entry_index) const;
184 
190  int get_entry_length(uint32_t offset) const;
191 
200  int copy_entry_at(int index, aku_Entry* receiver) const;
201 
210  int copy_entry(uint32_t offset, aku_Entry* receiver) const;
211 
217  const aku_Entry* read_entry_at(uint32_t index) const;
218 
224  const aku_Timestamp read_timestamp_at(uint32_t index) const;
225 
231  const aku_Entry* read_entry(uint32_t offset) const;
232 
239  const void* read_entry_data(uint32_t offset) const;
240 
244  void search(std::shared_ptr<QP::IQueryProcessor> query,
245  std::shared_ptr<ChunkCache> cache = std::shared_ptr<ChunkCache>()) const;
246 
247  static void get_search_stats(aku_SearchStats* stats, bool reset = false);
248 
250  void get_stats(aku_StorageStats* rcv_stats);
251 };
252 
253 } // namespaces
uint32_t get_numpages() const
Get number of pages.
Definition: page.cpp:62
void reuse()
Clear all page conent (open_count += 1)
Definition: page.cpp:126
aku_Status add_chunk(const aku_MemRange data, const uint32_t free_space_required, uint32_t *out_offset)
Definition: page.cpp:173
Definition: page.h:47
Definition: page.h:55
Definition: page.h:69
const aku_Entry * read_entry(uint32_t offset) const
Definition: page.cpp:255
int copy_entry(uint32_t offset, aku_Entry *receiver) const
Definition: page.cpp:294
Definition: page.h:86
aku_Status add_entry(const aku_ParamId param, const aku_Timestamp timestamp, const aku_MemRange &range)
Definition: page.cpp:138
uint32_t get_close_count() const
Number of times page was closed for writing.
Definition: page.cpp:70
void set_close_count(uint32_t cnt)
Set open count.
Definition: page.cpp:78
void close()
Close page for write (close_count += 1)
Definition: page.cpp:134
uint32_t get_page_id() const
Get page ID.
Definition: page.cpp:58
std::pair< aku_EntryIndexRecord, int > index_to_offset(uint32_t index) const
Convert entry index to entry offset.
Definition: page.cpp:108
int copy_entry_at(int index, aku_Entry *receiver) const
Definition: page.cpp:281
void create_checkpoint()
Checkpoint and restore ///.
Definition: page.cpp:82
void set_open_count(uint32_t cnt)
Set open count.
Definition: page.cpp:74
PageHeader(uint32_t count, uint64_t length, uint32_t page_id, uint32_t numpages)
C-tor.
Definition: page.cpp:42
int get_entry_length(uint32_t offset) const
Definition: page.cpp:273
Entry index record.
Definition: page.h:42
bool restore()
Restore, return true if flush needed.
Definition: page.cpp:86
Definition: compression.h:39
const aku_Entry * read_entry_at(uint32_t index) const
Definition: page.cpp:247
uint32_t get_entries_count() const
Return number of entries stored in page.
Definition: page.cpp:115
const aku_Timestamp read_timestamp_at(uint32_t index) const
Definition: page.cpp:243
uint64_t get_page_length() const
Get length of the page.
Definition: page.cpp:54
void search(std::shared_ptr< QP::IQueryProcessor > query, std::shared_ptr< ChunkCache > cache=std::shared_ptr< ChunkCache >()) const
Search matches inside the volume.
Definition: page.cpp:687
aku_Status complete_chunk(const UncompressedChunk &data)
Definition: page.cpp:187
uint32_t get_open_count() const
Number of times page was opened for writing.
Definition: page.cpp:66
size_t get_free_space() const
Returns amount of free space in bytes.
Definition: page.cpp:119
void get_stats(aku_StorageStats *rcv_stats)
Get page status.
Definition: page.cpp:697
int get_entry_length_at(int entry_index) const
Definition: page.cpp:265
const void * read_entry_data(uint32_t offset) const
Definition: page.cpp:261