0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00
mongodb/db/durop.h

112 lines
3.9 KiB
C
Raw Normal View History

2010-11-27 00:18:24 +01:00
// @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/>.
*/
#pragma once
#include "dur_journalformat.h"
2010-12-20 03:16:37 +01:00
#include "../util/bufreader.h"
#include "../util/paths.h"
2010-11-27 00:18:24 +01:00
namespace mongo {
2010-12-20 15:28:19 +01:00
class AlignedBuilder;
2010-11-27 00:18:24 +01:00
namespace dur {
const unsigned Alignment = 8192;
2011-01-04 06:40:41 +01:00
/** DurOp - Operations we journal that aren't just basic writes.
2010-11-27 00:18:24 +01:00
*
* Basic writes are logged as JEntry's, and indicated in ram temporarily as struct dur::WriteIntent.
2011-01-04 06:40:41 +01:00
* We don't make WriteIntent inherit from DurOp to keep it as lean as possible as there will be millions of
2010-11-27 00:18:24 +01:00
* them (we don't want a vtable for example there).
2011-01-04 06:40:41 +01:00
*
2010-11-27 00:18:24 +01:00
* For each op we want to journal, we define a subclass.
*/
2011-01-04 06:40:41 +01:00
class DurOp { /* copyable */
2010-11-27 00:18:24 +01:00
public:
2010-12-06 22:00:15 +01:00
// @param opcode a sentinel value near max unsigned which uniquely identifies the operation.
2010-11-27 00:18:24 +01:00
// @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 */
2010-12-20 15:28:19 +01:00
void serialize(AlignedBuilder& ab);
2010-11-27 00:18:24 +01:00
2010-12-06 22:00:15 +01:00
/** read a durop from journal file referenced by br.
2010-11-27 00:18:24 +01:00
@param opcode the opcode which has already been written from the bufreader
*/
static shared_ptr<DurOp> read(unsigned opcode, BufReader& br);
2011-01-04 06:40:41 +01:00
/** replay the operation (during recovery)
2010-11-27 00:18:24 +01:00
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.
2010-11-27 00:18:24 +01:00
*/
virtual void replay() = 0;
virtual string toString() = 0;
2010-12-13 01:47:10 +01:00
/** if the op requires all file to be closed before doing its work, returns true. */
virtual bool needFilesClosed() { return false; }
2010-11-27 00:18:24 +01:00
protected:
/** DurOp will have already written the opcode for you */
2010-12-20 15:28:19 +01:00
virtual void _serialize(AlignedBuilder& ab) = 0;
2010-11-27 00:18:24 +01:00
private:
const unsigned _opcode;
};
/** indicates creation of a new file */
2011-01-04 06:40:41 +01:00
class FileCreatedOp : public DurOp {
2010-11-27 00:18:24 +01:00
public:
FileCreatedOp(BufReader& log);
/** param f filename to create with path */
FileCreatedOp(string f, unsigned long long l);
2010-11-27 00:18:24 +01:00
virtual void replay();
virtual string toString();
2010-12-13 01:47:10 +01:00
virtual bool needFilesClosed();
2010-11-27 00:18:24 +01:00
protected:
2010-12-20 15:28:19 +01:00
virtual void _serialize(AlignedBuilder& ab);
2010-11-27 00:18:24 +01:00
private:
RelativePath _p;
unsigned long long _len; // size of file, not length of name
2010-11-27 00:18:24 +01:00
};
2010-12-13 01:47:10 +01:00
/** record drop of a database */
2011-01-04 06:40:41 +01:00
class DropDbOp : public DurOp {
2010-12-13 01:47:10 +01:00
public:
DropDbOp(BufReader& log);
2011-01-04 06:40:41 +01:00
DropDbOp(string db) :
DurOp(JEntry::OpCode_DropDb), _db(db) { }
2010-12-13 01:47:10 +01:00
virtual void replay();
virtual string toString() { return string("DropDbOp ") + _db; }
virtual bool needFilesClosed() { return true; }
protected:
2010-12-20 15:28:19 +01:00
virtual void _serialize(AlignedBuilder& ab);
2010-12-13 01:47:10 +01:00
private:
string _db;
};
2010-11-27 00:18:24 +01:00
}
}