Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 118 lines (97 sloc) 3.588 kb
0f09595 @erh move oplog code into db/oplog.*
erh authored
1 // oplog.h - writing to and reading from oplog
2
3 /**
4 * Copyright (C) 2008 10gen Inc.
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License, version 3,
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
b828d21 @erh ran astyle SERVER-2304
erh authored
19 /*
0f09595 @erh move oplog code into db/oplog.*
erh authored
20
21 local.oplog.$main is the default
22 */
23
24 #pragma once
25
26 #include "pdfile.h"
27 #include "db.h"
28 #include "dbhelpers.h"
29 #include "query.h"
30 #include "../client/dbclient.h"
31 #include "../util/optime.h"
5f7500b Pull timer.h and time_support.h out of goodies.h
Alberto Lerner authored
32 #include "../util/timer.h"
0f09595 @erh move oplog code into db/oplog.*
erh authored
33
34 namespace mongo {
35
36 void createOplog();
37
fe1d205 @dwight rs
dwight authored
38 void _logOpObjRS(const BSONObj& op);
39
f36becf @dwight repl cleaning
dwight authored
40 /** Write operation to the log (local.oplog.$main)
b828d21 @erh ran astyle SERVER-2304
erh authored
41
f36becf @dwight repl cleaning
dwight authored
42 @param opstr
43 "i" insert
44 "u" update
45 "d" delete
46 "c" db cmd
47 "n" no-op
48 "db" declares presence of a database (ns is set to the db name + '.')
49
b828d21 @erh ran astyle SERVER-2304
erh authored
50 See _logOp() in oplog.cpp for more details.
0f09595 @erh move oplog code into db/oplog.*
erh authored
51 */
52 void logOp(const char *opstr, const char *ns, const BSONObj& obj, BSONObj *patt = 0, bool *b = 0);
53
54 void logKeepalive();
6e8fafa @dwight rs
dwight authored
55
b828d21 @erh ran astyle SERVER-2304
erh authored
56 /** puts obj in the oplog as a comment (a no-op). Just for diags.
57 convention is
6e8fafa @dwight rs
dwight authored
58 { msg : "text", ... }
59 */
60 void logOpComment(const BSONObj& obj);
61
0f09595 @erh move oplog code into db/oplog.*
erh authored
62 void oplogCheckCloseDatabase( Database * db );
b828d21 @erh ran astyle SERVER-2304
erh authored
63
64 extern int __findingStartInitialTimeout; // configurable for testing
0f09595 @erh move oplog code into db/oplog.*
erh authored
65
2df2fe8 @astaple reduce queryutil dependencies a bit
astaple authored
66 class QueryPlan;
67
0f09595 @erh move oplog code into db/oplog.*
erh authored
68 class FindingStartCursor {
69 public:
2df2fe8 @astaple reduce queryutil dependencies a bit
astaple authored
70 FindingStartCursor( const QueryPlan & qp );
0f09595 @erh move oplog code into db/oplog.*
erh authored
71 bool done() const { return !_findingStart; }
740cc13 @erh auto_ptr -> shared_ptr for Cursor objects
erh authored
72 shared_ptr<Cursor> cRelease() { return _c; }
2df2fe8 @astaple reduce queryutil dependencies a bit
astaple authored
73 void next();
e6ad6ec @astaple SERVER-1453 yield during geo query
astaple authored
74 bool prepareToYield() {
f17aefd @astaple SERVER-1376 yield in query set runner for query,count,update,delete
astaple authored
75 if ( _findingStartCursor ) {
e6ad6ec @astaple SERVER-1453 yield during geo query
astaple authored
76 return _findingStartCursor->prepareToYield( _yieldData );
f17aefd @astaple SERVER-1376 yield in query set runner for query,count,update,delete
astaple authored
77 }
e6ad6ec @astaple SERVER-1453 yield during geo query
astaple authored
78 return true;
f17aefd @astaple SERVER-1376 yield in query set runner for query,count,update,delete
astaple authored
79 }
80 void recoverFromYield() {
81 if ( _findingStartCursor ) {
82 if ( !ClientCursor::recoverFromYield( _yieldData ) ) {
5ede773 @astaple SERVER-2558 don't orphan client cursors in FindingStartCursor
astaple authored
83 _findingStartCursor.reset( 0 );
f17aefd @astaple SERVER-1376 yield in query set runner for query,count,update,delete
astaple authored
84 }
85 }
b828d21 @erh ran astyle SERVER-2304
erh authored
86 }
0f09595 @erh move oplog code into db/oplog.*
erh authored
87 private:
88 enum FindingStartMode { Initial, FindExtent, InExtent };
89 const QueryPlan &_qp;
90 bool _findingStart;
91 FindingStartMode _findingStartMode;
92 auto_ptr< CoveredIndexMatcher > _matcher;
93 Timer _findingStartTimer;
5ede773 @astaple SERVER-2558 don't orphan client cursors in FindingStartCursor
astaple authored
94 ClientCursor::CleanupPointer _findingStartCursor;
740cc13 @erh auto_ptr -> shared_ptr for Cursor objects
erh authored
95 shared_ptr<Cursor> _c;
f17aefd @astaple SERVER-1376 yield in query set runner for query,count,update,delete
astaple authored
96 ClientCursor::YieldData _yieldData;
2df2fe8 @astaple reduce queryutil dependencies a bit
astaple authored
97 DiskLoc startLoc( const DiskLoc &rec );
b828d21 @erh ran astyle SERVER-2304
erh authored
98
0eec36a @astaple SERVER-1113
astaple authored
99 // should never have an empty extent in the oplog, so don't worry about that case
2df2fe8 @astaple reduce queryutil dependencies a bit
astaple authored
100 DiskLoc prevLoc( const DiskLoc &rec );
101 void createClientCursor( const DiskLoc &startLoc = DiskLoc() );
0f09595 @erh move oplog code into db/oplog.*
erh authored
102 void destroyClientCursor() {
5ede773 @astaple SERVER-2558 don't orphan client cursors in FindingStartCursor
astaple authored
103 _findingStartCursor.reset( 0 );
0f09595 @erh move oplog code into db/oplog.*
erh authored
104 }
2df2fe8 @astaple reduce queryutil dependencies a bit
astaple authored
105 void init();
0f09595 @erh move oplog code into db/oplog.*
erh authored
106 };
107
082a592 @dwight pretouch experiment
dwight authored
108 void pretouchOperation(const BSONObj& op);
39dbe97 @dwight --pretouch
dwight authored
109 void pretouchN(vector<BSONObj>&, unsigned a, unsigned b);
082a592 @dwight pretouch experiment
dwight authored
110
7cc161c @erh track replicated ops SERVER-1565
erh authored
111 /**
112 * take an op and apply locally
113 * used for applying from an oplog
114 * @param fromRepl really from replication or for testing/internal/command/etc...
115 */
116 void applyOperation_inlock(const BSONObj& op , bool fromRepl = true );
0f09595 @erh move oplog code into db/oplog.*
erh authored
117 }
Something went wrong with that request. Please try again.