Storage Engine API
durop.h
Go to the documentation of this file.
1 // @file durop.h class DurOp and descendants
2 
31 #pragma once
32 
33 
36 #include "mongo/util/bufreader.h"
37 
38 namespace mongo {
39 
40 class AlignedBuilder;
41 
42 namespace dur {
43 
52 class DurOp { /* copyable */
53 public:
54  // @param opcode a sentinel value near max unsigned which uniquely identifies the operation.
55  // @see dur::JEntry
56  DurOp(unsigned opcode) : _opcode(opcode) {}
57 
58  virtual ~DurOp() {}
59 
61  void serialize(AlignedBuilder& ab);
62 
66  static std::shared_ptr<DurOp> read(unsigned opcode, BufReader& br);
67 
74  virtual void replay() = 0;
75 
76  virtual std::string toString() = 0;
77 
79  virtual bool needFilesClosed() {
80  return false;
81  }
82 
83 protected:
85  virtual void _serialize(AlignedBuilder& ab) = 0;
86 
87 private:
88  const unsigned _opcode;
89 };
90 
92 class FileCreatedOp : public DurOp {
93 public:
94  FileCreatedOp(BufReader& log);
96  FileCreatedOp(const std::string& f, unsigned long long l);
97  virtual void replay();
98  virtual std::string toString();
99  virtual bool needFilesClosed();
100 
101 protected:
102  virtual void _serialize(AlignedBuilder& ab);
103 
104 private:
106  unsigned long long _len; // size of file, not length of name
107 };
108 
110 class DropDbOp : public DurOp {
111 public:
112  DropDbOp(BufReader& log);
113  DropDbOp(const std::string& db) : DurOp(JEntry::OpCode_DropDb), _db(db) {}
114  virtual void replay();
115  virtual std::string toString() {
116  return std::string("DropDbOp ") + _db;
117  }
118  virtual bool needFilesClosed() {
119  return true;
120  }
121 
122 protected:
123  virtual void _serialize(AlignedBuilder& ab);
124 
125 private:
126  std::string _db;
127 };
128 }
129 }
virtual void _serialize(AlignedBuilder &ab)=0
DurOp will have already written the opcode for you.
unsigned long long _len
Definition: durop.h:106
an individual write operation within a group commit section.
Definition: dur_journalformat.h:119
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
virtual bool needFilesClosed()
if the op requires all file to be closed before doing its work, returns true.
Definition: durop.h:79
DurOp(unsigned opcode)
Definition: durop.h:56
std::string _db
Definition: durop.h:126
virtual void replay()=0
replay the operation (during recovery) throws
DropDbOp(const std::string &db)
Definition: durop.h:113
virtual ~DurOp()
Definition: durop.h:58
DurOp - Operations we journal that aren&#39;t just basic writes.
Definition: durop.h:52
const unsigned _opcode
Definition: durop.h:88
a page-aligned BufBuilder.
Definition: aligned_builder.h:37
record drop of a database
Definition: durop.h:110
virtual std::string toString()
Definition: durop.h:115
static std::shared_ptr< DurOp > read(unsigned opcode, BufReader &br)
read a durop from journal file referenced by br.
Definition: durop.cpp:60
virtual std::string toString()=0
OperationContext Database * db
Definition: database_impl.cpp:949
virtual bool needFilesClosed()
if the op requires all file to be closed before doing its work, returns true.
Definition: durop.h:118
indicates creation of a new file
Definition: durop.h:92
RelativePath _p
Definition: durop.h:105
void serialize(AlignedBuilder &ab)
serialize the op out to a builder which will then be written (presumably) to the journal ...
Definition: durop.cpp:77
this is very much like a boost::path.
Definition: paths.h:49