1 #ifndef __LOGARCHIVE_INDEX_H 2 #define __LOGARCHIVE_INDEX_H 6 #include <unordered_map> 8 #define BOOST_FILESYSTEM_NO_DEPRECATED 10 #include <boost/filesystem.hpp> 12 namespace fs = boost::filesystem;
30 && level == other.
level;
68 return ((h1 ^ (h2 << 1)) >> 1) ^ (h3 << 1);
143 lsn_t getFirstLSN(
unsigned level);
146 rc_t openNewRun(
unsigned level);
148 rc_t append(
char* data,
size_t length,
unsigned level);
150 rc_t closeCurrentRun(
lsn_t runEndLSN,
unsigned level,
PageID maxPID = 0);
155 void closeScan(
const RunId& runid);
157 rc_t readBlock(
int fd,
char* buf,
size_t& offset,
size_t readSize = 0);
159 void listFiles(std::vector<std::string>& list,
int level = -1);
161 void listFileStats(std::list<RunId>& list,
int level = -1);
163 void deleteRuns(
unsigned replicationFactor = 0);
165 size_t getSkipLogrecSize()
const;
169 static size_t getFileSize(
int fd);
171 void newBlock(
const vector<pair<PageID, size_t>>& buckets,
unsigned level);
174 int fd, off_t offset,
unsigned level);
176 template<
class Input>
180 void getBlockCounts(
RunFile*,
size_t* indexBlocks,
size_t* dataBlocks);
184 void startNewRun(
unsigned level);
195 if (level > maxLevel) {
198 return runs[
level].size();
201 void dumpIndex(ostream& out);
203 void dumpIndex(ostream& out,
const RunId& runid);
205 template<
class OutputIter>
207 auto level = maxLevel;
213 auto index = findRun(startLSN, level);
215 while ((
int)index <= lastFinished[level]) {
216 auto& run = runs[
level][index];
217 out =
RunId{run.firstLSN, run.lastLSN, level};
218 startLSN = run.lastLSN;
228 void appendNewRun(
unsigned level);
230 size_t findRun(
lsn_t lsn,
unsigned level);
234 int from = -1,
int to = -1);
238 lsn_t roundToEndLSN(
lsn_t lsn,
unsigned level);
252 std::vector<std::vector<RunInfo>>
runs;
283 fs::path make_run_path(
lsn_t begin,
lsn_t end,
unsigned level = 1)
const;
285 fs::path make_current_run_path(
unsigned level)
const;
297 template<
class Input>
303 input.endPID = endPID;
304 unsigned level = maxLevel;
308 size_t index = findRun(startLSN, level);
310 while ((
int)index <= lastFinished[level]) {
311 auto& run = runs[
level][index];
313 startLSN = run.lastLSN;
319 if (startPID > run.maxPID) {
323 if (run.entries.size() > 0) {
324 size_t entryBegin = findEntry(&run, startPID);
327 if (bucketSize == 1 && startPID == endPID - 1 &&
328 run.entries[entryBegin].pid != startPID) {
334 input.pos = run.entries[entryBegin].offset;
336 openForScan(
RunId{run.firstLSN, run.lastLSN, level});
337 w_assert1(input.pos < input.runFile->length);
338 inputs.push_back(input);
346 #endif // __LOGARCHIVE_INDEX_H
unsigned maxLevel
Definition: logarchive_index.h:270
PageID maxPID
Definition: logarchive_index.h:122
static const string RUN_PREFIX
Definition: logarchive_index.h:288
static const string run_regex
Definition: logarchive_index.h:292
size_t getRunCount(unsigned level)
Definition: logarchive_index.h:194
size_t blockSize
Definition: logarchive_index.h:247
unsigned level
Definition: logarchive_index.h:26
RunFile()
Definition: logarchive_index.h:46
size_t length
Definition: logarchive_index.h:44
static const string current_regex
Definition: logarchive_index.h:294
#define w_assert1(x)
Level 1 should not add significant extra time.
Definition: w_base.h:198
unsigned getMaxLevel() const
Definition: logarchive_index.h:186
std::string getArchDir() const
Definition: logarchive_index.h:135
std::size_t result_type
Definition: logarchive_index.h:62
char * getOffset(off_t offset) const
Definition: logarchive_index.h:51
int fd
Definition: logarchive_index.h:38
std::vector< BlockEntry > entries
Definition: logarchive_index.h:124
Definition: latches.h:447
lsn_t lastLSN
Definition: logarchive_index.h:119
Start-up parameters for the storage engine. See OPTIONS.
Definition: sm_options.h:24
std::unordered_map< RunId, RunFile > _open_files
Cache for open files (for scans only)
Definition: logarchive_index.h:277
static const lsn_t null
Definition: lsn.h:371
lsn_t endLSN
Definition: logarchive_index.h:24
Definition: logarchive_index.cpp:20
Encapsulates all file and I/O operations on the log archive.
Definition: logarchive_index.h:94
std::string archdir
Definition: logarchive_index.h:241
lsn_t beginLSN
Definition: logarchive_index.h:22
std::vector< int > lastFinished
Definition: logarchive_index.h:258
uint32_t PageID
Definition: basics.h:45
PageID pid
Definition: logarchive_index.h:102
std::vector< off_t > appendPos
Definition: logarchive_index.h:245
void listRunsNonOverlapping(OutputIter out)
Definition: logarchive_index.h:206
RunId runid
Definition: logarchive_index.h:36
Log Sequence Number. See Log Sequence Numbers (LSN).
Definition: lsn.h:243
void probe(std::vector< Input > &, PageID, PageID, lsn_t startLSN, lsn_t endLSN=lsn_t::null)
Definition: logarchive_index.h:298
std::vector< std::vector< RunInfo > > runs
Definition: logarchive_index.h:252
size_t getBlockSize() const
Definition: logarchive_index.h:131
bool directIO
Definition: logarchive_index.h:281
lsn_t firstLSN
Definition: logarchive_index.h:111
size_t offset
Definition: logarchive_index.h:101
srwlock_t _open_file_mutex
Definition: logarchive_index.h:279
Return code for most functions and methods.
Definition: w_rc.h:87
Definition: logarchive_index.h:21
srwlock_t _mutex
Definition: logarchive_index.h:274
bool operator==(const RunId &other) const
Definition: logarchive_index.h:28
Definition: logarchive_index.h:35
std::vector< int > appendFd
Definition: logarchive_index.h:243
char * data
Definition: logarchive_index.h:42
int refcount
Definition: logarchive_index.h:40
bool operator<(const RunInfo &other) const
Definition: logarchive_index.h:126
bool is_null() const
Definition: lsn.h:357
Definition: logarchive_index.h:110
static const string CURR_RUN_PREFIX
Definition: logarchive_index.h:290
result_type operator()(argument_type const &a) const
Definition: logarchive_index.h:64
size_t bucketSize
Definition: logarchive_index.h:268
Definition: logarchive_index.h:100
fs::path archpath
Definition: logarchive_index.h:249
Shore read-write lock:: many-reader/one-writer spin lock.
Definition: latches.h:350
std::unique_ptr< RunRecycler > runRecycler
Definition: logarchive_index.h:272
const auto & parseRunFileName
Definition: scanner.cpp:13
size_t getBucketSize()
Definition: logarchive_index.h:190