1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
// @file durop.h class DurOp and descendants
/**
* Copyright (C) 2010 10gen Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, the copyright holders give permission to link the
* code of portions of this program with the OpenSSL library under certain
* conditions as described in each individual source file and distribute
* linked combinations including the program with the OpenSSL library. You
* must comply with the GNU Affero General Public License in all respects for
* all of the code used other than as permitted herein. If you modify file(s)
* with this exception, you may extend this exception to your version of the
* file(s), but you are not obligated to do so. If you do not wish to do so,
* delete this exception statement from your version. If you delete this
* exception statement from all source files in the program, then also delete
* it in the license file.
*/
#pragma once
#include "mongo/db/storage/mmap_v1/dur_journalformat.h"
#include "mongo/db/storage/paths.h"
#include "mongo/util/bufreader.h"
namespace mongo {
class AlignedBuilder;
namespace dur {
/** DurOp - Operations we journal that aren't just basic writes.
*
* Basic writes are logged as JEntry's, and indicated in ram temporarily as struct
* dur::WriteIntent. We don't make WriteIntent inherit from DurOp to keep it as lean as possible as
* there will be millions of them (we don't want a vtable for example there).
*
* For each op we want to journal, we define a subclass.
*/
class DurOp {/* copyable */
public:
// @param opcode a sentinel value near max unsigned which uniquely identifies the operation.
// @see dur::JEntry
DurOp(unsigned opcode) : _opcode(opcode) {}
virtual ~DurOp() {}
/** serialize the op out to a builder which will then be written (presumably) to the journal */
void serialize(AlignedBuilder& ab);
/** read a durop from journal file referenced by br.
@param opcode the opcode which has already been written from the bufreader
*/
static std::shared_ptr<DurOp> read(unsigned opcode, BufReader& br);
/** replay the operation (during recovery)
throws
For now, these are not replayed during the normal WRITETODATAFILES phase, since these
operations are handled in other parts of the code. At some point this may change.
*/
virtual void replay() = 0;
virtual std::string toString() = 0;
/** if the op requires all file to be closed before doing its work, returns true. */
virtual bool needFilesClosed() {
return false;
}
protected:
/** DurOp will have already written the opcode for you */
virtual void _serialize(AlignedBuilder& ab) = 0;
private:
const unsigned _opcode;
};
/** indicates creation of a new file */
class FileCreatedOp : public DurOp {
public:
FileCreatedOp(BufReader& log);
/** param f filename to create with path */
FileCreatedOp(const std::string& f, unsigned long long l);
virtual void replay();
virtual std::string toString();
virtual bool needFilesClosed();
protected:
virtual void _serialize(AlignedBuilder& ab);
private:
RelativePath _p;
unsigned long long _len; // size of file, not length of name
};
/** record drop of a database */
class DropDbOp : public DurOp {
public:
DropDbOp(BufReader& log);
DropDbOp(const std::string& db) : DurOp(JEntry::OpCode_DropDb), _db(db) {}
virtual void replay();
virtual std::string toString() {
return std::string("DropDbOp ") + _db;
}
virtual bool needFilesClosed() {
return true;
}
protected:
virtual void _serialize(AlignedBuilder& ab);
private:
std::string _db;
};
}
}
|