Zero  0.1.0
vol.h
Go to the documentation of this file.
1 /*
2  * (c) Copyright 2011-2013, Hewlett-Packard Development Company, LP
3  */
4 
5 #ifndef __VOL_H
6 #define __VOL_H
7 
8 #include "w_defines.h"
9 #include "stnode_page.h"
10 
11 #include <list>
12 #include <cstdlib>
13 #include <chrono>
14 
16 class alloc_cache_t;
17 class stnode_cache_t;
18 class sm_options;
19 class chkpt_t;
20 
21 class vol_t {
22 public:
23  vol_t(const sm_options&);
24 
25  virtual ~vol_t();
26 
27  void shutdown();
28 
29  size_t num_used_pages() const;
30 
32  return _alloc_cache;
33  }
34 
36  return _stnode_cache;
37  }
38 
48  PageID first_page,
49  const generic_page* buf, //caller must align this buffer
50  int cnt);
51 
53  return write_many_pages(page, buf, 1);
54  }
55 
56  rc_t read_page(PageID page, generic_page* const buf);
57 
58  void read_vector(PageID first_pid, unsigned count,
59  std::vector<generic_page*>& pages, bool from_backup);
60 
62  PageID first_page,
63  generic_page* const buf, //caller must align this buffer
64  int cnt);
65 
66  void read_backup(PageID first, size_t count, void* buf);
67 
68  rc_t write_backup(PageID first, size_t count, void* buf);
69 
71  bool open_backup();
72 
73  void close_backup();
74 
76  rc_t sx_add_backup(const string& path, lsn_t backupLSN, bool redo = false);
77 
78  void list_backups(std::vector<string>& backups);
79 
80  void sync();
81 
82  rc_t alloc_a_page(PageID& pid, StoreID stid = 0);
83 
84  rc_t deallocate_page(const PageID& pid);
85 
86  bool is_allocated_page(PageID pid) const;
87 
88  bool is_valid_store(StoreID f) const;
89 
91  bool is_alloc_store(StoreID f) const;
92 
94  rc_t set_store_root(StoreID snum, PageID root);
95 
97  PageID get_store_root(StoreID f) const;
98 
100 
102 
104  void set_readonly(bool r) {
106  _readonly = r;
107  }
108 
110  rc_t take_backup(string path, bool forceArchive = false);
111 
112  unsigned num_backups() const;
113 
116 
118  void build_caches(bool truncate, chkpt_t* = nullptr);
119 
120  bool caches_ready() {
121  return _alloc_cache && _stnode_cache;
122  }
123 
124 private:
125  // variables read from volume header -- remain constant after mount
126  int _fd;
127 
128  mutable srwlock_t _mutex;
129 
136  std::chrono::high_resolution_clock::duration _fake_read_latency;
137 
138  std::chrono::high_resolution_clock::duration _fake_write_latency;
139 
141 
143 
150  bool _readonly;
151 
153 
155  std::vector<string> _backups;
156 
157  std::vector<lsn_t> _backup_lsns;
158 
161 
163 
164  unique_ptr<backup_alloc_cache_t> _backup_alloc_cache;
165 
168 
170 
173 
176 
180 
183 
186 
189 };
190 
191 inline bool vol_t::is_valid_store(StoreID f) const {
192  return (f < stnode_page::max);
193 }
194 
195 #endif // __VOL_H /*</std-footer>*/
alloc_cache_t * _alloc_cache
Definition: vol.h:140
bool _log_page_reads
Definition: vol.h:172
Definition: backup_alloc_cache.h:9
rc_t write_many_pages(PageID first_page, const generic_page *buf, int cnt)
Definition: vol.cpp:462
rc_t read_page(PageID page, generic_page *const buf)
Definition: vol.cpp:259
void build_caches(bool truncate, chkpt_t *=nullptr)
Definition: vol.cpp:114
string _backup_write_path
Definition: vol.h:169
unique_ptr< backup_alloc_cache_t > _backup_alloc_cache
Definition: vol.h:164
static constexpr size_t max
Definition: stnode_page.h:64
int _fd
Definition: vol.h:126
rc_t read_many_pages(PageID first_page, generic_page *const buf, int cnt)
Definition: vol.cpp:309
rc_t sx_add_backup(const string &path, lsn_t backupLSN, bool redo=false)
Definition: vol.cpp:177
bool _no_db_mode
Definition: vol.h:152
Definition: latches.h:461
bool _readonly
Definition: vol.h:150
Definition: vol.h:21
bool is_valid_store(StoreID f) const
Definition: vol.h:191
bool _use_o_direct
Definition: vol.h:185
uint32_t StoreID
Definition: basics.h:47
A generic page view: any Zero page can be viewed as being of this type but it only exposes fields sha...
Definition: generic_page.h:121
Definition: chkpt.h:156
unsigned num_backups() const
Definition: vol.cpp:163
std::vector< lsn_t > _backup_lsns
Definition: vol.h:157
rc_t write_page(PageID page, generic_page *buf)
Definition: vol.h:52
Start-up parameters for the storage engine. See OPTIONS.
Definition: sm_options.h:24
rc_t deallocate_page(const PageID &pid)
Definition: vol.cpp:226
vol_t(const sm_options &)
Definition: vol.cpp:52
size_t num_used_pages() const
Definition: vol.cpp:234
PageID get_store_root(StoreID f) const
Definition: vol.cpp:248
bool open_backup()
Definition: vol.cpp:128
lsn_t get_backup_lsn()
Definition: vol.cpp:158
void set_readonly(bool r)
Definition: vol.h:104
uint32_t PageID
Definition: basics.h:45
rc_t set_store_root(StoreID snum, PageID root)
Log Sequence Number. See Log Sequence Numbers (LSN).
Definition: lsn.h:243
Store creation/destroy/query interface.
Definition: stnode_page.h:137
void list_backups(std::vector< string > &backups)
Definition: vol.cpp:168
rc_t create_store(PageID &, StoreID &)
Definition: vol.cpp:238
rc_t write_backup(PageID first, size_t count, void *buf)
Definition: vol.cpp:441
void shutdown()
Definition: vol.cpp:193
Return code for most functions and methods.
Definition: w_rc.h:87
PageID get_last_allocated_pid() const
Definition: vol.cpp:499
alloc_cache_t * get_alloc_cache()
Definition: vol.h:31
Free-Page allocation/deallocation interface.
Definition: alloc_cache.h:27
stnode_cache_t * _stnode_cache
Definition: vol.h:142
bool _cluster_stores
Definition: vol.h:188
void read_vector(PageID first_pid, unsigned count, std::vector< generic_page *> &pages, bool from_backup)
Definition: vol.cpp:263
void close_backup()
Definition: vol.cpp:205
virtual ~vol_t()
Definition: vol.cpp:95
void sync()
Definition: vol.cpp:109
bool _prioritize_archive
Definition: vol.h:179
srwlock_t _mutex
Definition: vol.h:128
bool _log_page_writes
Definition: vol.h:175
int _backup_write_fd
Definition: vol.h:167
void read_backup(PageID first, size_t count, void *buf)
Definition: vol.cpp:332
bool caches_ready()
Definition: vol.h:120
rc_t take_backup(string path, bool forceArchive=false)
Definition: vol.cpp:374
bool is_alloc_store(StoreID f) const
Definition: vol.cpp:244
std::chrono::high_resolution_clock::duration _fake_write_latency
Definition: vol.h:138
bool _use_o_sync
Definition: vol.h:182
rc_t alloc_a_page(PageID &pid, StoreID stid=0)
Definition: vol.cpp:215
lsn_t _current_backup_lsn
Definition: vol.h:162
int _backup_fd
Definition: vol.h:160
std::vector< string > _backups
Definition: vol.h:155
bool is_allocated_page(PageID pid) const
Definition: vol.cpp:504
Shore read-write lock:: many-reader/one-writer spin lock.
Definition: latches.h:350
stnode_cache_t * get_stnode_cache()
Definition: vol.h:35
std::chrono::high_resolution_clock::duration _fake_read_latency
Definition: vol.h:136