]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/cephfs/JournalScanner.h
update sources to v12.1.3
[ceph.git] / ceph / src / tools / cephfs / JournalScanner.h
1 // -*- mode:c++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * ceph - scalable distributed file system
5 *
6 * copyright (c) 2014 john spray <john.spray@inktank.com>
7 *
8 * this is free software; you can redistribute it and/or
9 * modify it under the terms of the gnu lesser general public
10 * license version 2.1, as published by the free software
11 * foundation. see file copying.
12 */
13
14 #ifndef JOURNAL_SCANNER_H
15 #define JOURNAL_SCANNER_H
16
17 // For Journaler::Header, can't forward-declare nested classes
18 #include <osdc/Journaler.h>
19
20 namespace librados {
21 class IoCtx;
22 }
23
24 #include "JournalFilter.h"
25
26 /**
27 * A simple sequential reader for metadata journals. Unlike
28 * the MDS Journaler class, this is written to detect, record,
29 * and read past corruptions and missing objects. It is also
30 * less efficient but more plainly written.
31 */
32 class JournalScanner
33 {
34 private:
35 librados::IoCtx &io;
36
37 // Input constraints
38 const int rank;
39 JournalFilter const filter;
40
41 void gap_advance();
42
43 public:
44 JournalScanner(
45 librados::IoCtx &io_,
46 int rank_,
47 JournalFilter const &filter_) :
48 io(io_),
49 rank(rank_),
50 filter(filter_),
51 pointer_present(false),
52 pointer_valid(false),
53 header_present(false),
54 header_valid(false),
55 header(NULL) {};
56
57 JournalScanner(
58 librados::IoCtx &io_,
59 int rank_) :
60 io(io_),
61 rank(rank_),
62 pointer_present(false),
63 pointer_valid(false),
64 header_present(false),
65 header_valid(false),
66 header(NULL) {};
67
68 ~JournalScanner();
69
70 int scan(bool const full=true);
71 int scan_pointer();
72 int scan_header();
73 int scan_events();
74 void report(std::ostream &out) const;
75
76 std::string obj_name(uint64_t offset) const;
77 std::string obj_name(inodeno_t ino, uint64_t offset) const;
78
79 // The results of the scan
80 inodeno_t ino; // Corresponds to JournalPointer.front
81 class EventRecord {
82 public:
83 EventRecord() : log_event(NULL), raw_size(0) {}
84 EventRecord(LogEvent *le, uint32_t rs) : log_event(le), raw_size(rs) {}
85 LogEvent *log_event;
86 uint32_t raw_size; //< Size from start offset including all encoding overhead
87 };
88
89 class EventError {
90 public:
91 int r;
92 std::string description;
93 EventError(int r_, const std::string &desc_)
94 : r(r_), description(desc_) {}
95 };
96
97 typedef std::map<uint64_t, EventRecord> EventMap;
98 typedef std::map<uint64_t, EventError> ErrorMap;
99 typedef std::pair<uint64_t, uint64_t> Range;
100 bool pointer_present;
101 bool pointer_valid;
102 bool header_present;
103 bool header_valid;
104 Journaler::Header *header;
105
106 bool is_healthy() const;
107 bool is_readable() const;
108 std::vector<std::string> objects_valid;
109 std::vector<uint64_t> objects_missing;
110 std::vector<Range> ranges_invalid;
111 std::vector<uint64_t> events_valid;
112 EventMap events;
113
114 // For events present in ::events (i.e. scanned successfully),
115 // any subsequent errors handling them (e.g. replaying)
116 ErrorMap errors;
117
118
119 private:
120 // Forbid copy construction because I have ptr members
121 JournalScanner(const JournalScanner &rhs);
122 };
123
124 #endif // JOURNAL_SCANNER_H
125