summaryrefslogtreecommitdiff
path: root/db/oplogreader.h
diff options
context:
space:
mode:
authorAntonin Kral <a.kral@bobek.cz>2011-09-14 17:08:06 +0200
committerAntonin Kral <a.kral@bobek.cz>2011-09-14 17:08:06 +0200
commit5d342a758c6095b4d30aba0750b54f13b8916f51 (patch)
tree762e9aa84781f5e3b96db2c02d356c29cf0217c0 /db/oplogreader.h
parentcbe2d992e9cd1ea66af9fa91df006106775d3073 (diff)
downloadmongodb-5d342a758c6095b4d30aba0750b54f13b8916f51.tar.gz
Imported Upstream version 2.0.0
Diffstat (limited to 'db/oplogreader.h')
-rw-r--r--db/oplogreader.h51
1 files changed, 34 insertions, 17 deletions
diff --git a/db/oplogreader.h b/db/oplogreader.h
index 54c90d9..01f76f4 100644
--- a/db/oplogreader.h
+++ b/db/oplogreader.h
@@ -12,8 +12,8 @@ namespace mongo {
still fairly awkward but a start.
*/
class OplogReader {
- auto_ptr<DBClientConnection> _conn;
- auto_ptr<DBClientCursor> cursor;
+ shared_ptr<DBClientConnection> _conn;
+ shared_ptr<DBClientCursor> cursor;
public:
OplogReader() {
@@ -40,6 +40,9 @@ namespace mongo {
/* ok to call if already connected */
bool connect(string hostname);
+ bool connect(const BSONObj& rid, const int from, const string& to);
+
+
void tailCheck() {
if( cursor.get() && cursor->isDead() ) {
log() << "repl: old cursor isDead, will initiate a new one" << endl;
@@ -51,25 +54,39 @@ namespace mongo {
void query(const char *ns, const BSONObj& query) {
assert( !haveCursor() );
- cursor = _conn->query(ns, query, 0, 0, 0, QueryOption_SlaveOk);
+ cursor.reset( _conn->query(ns, query, 0, 0, 0, QueryOption_SlaveOk).release() );
+ }
+
+ void queryGTE(const char *ns, OpTime t) {
+ BSONObjBuilder q;
+ q.appendDate("$gte", t.asDate());
+ BSONObjBuilder q2;
+ q2.append("ts", q.done());
+ query(ns, q2.done());
}
- void tailingQuery(const char *ns, const BSONObj& query) {
+ void tailingQuery(const char *ns, const BSONObj& query, const BSONObj* fields=0) {
assert( !haveCursor() );
log(2) << "repl: " << ns << ".find(" << query.toString() << ')' << endl;
- cursor = _conn->query( ns, query, 0, 0, 0,
- QueryOption_CursorTailable | QueryOption_SlaveOk | QueryOption_OplogReplay |
- /* TODO: slaveok maybe shouldn't use? */
- QueryOption_AwaitData
- );
+ cursor.reset( _conn->query( ns, query, 0, 0, fields,
+ QueryOption_CursorTailable | QueryOption_SlaveOk | QueryOption_OplogReplay |
+ /* TODO: slaveok maybe shouldn't use? */
+ QueryOption_AwaitData
+ ).release() );
}
- void tailingQueryGTE(const char *ns, OpTime t) {
+ void tailingQueryGTE(const char *ns, OpTime t, const BSONObj* fields=0) {
BSONObjBuilder q;
q.appendDate("$gte", t.asDate());
BSONObjBuilder query;
query.append("ts", q.done());
- tailingQuery(ns, query.done());
+ tailingQuery(ns, query.done(), fields);
+ }
+
+ /* Do a tailing query, but only send the ts field back. */
+ void ghostQueryGTE(const char *ns, OpTime t) {
+ const BSONObj fields = BSON("ts" << 1 << "_id" << 0);
+ return tailingQueryGTE(ns, t, &fields);
}
bool more() {
@@ -93,13 +110,13 @@ namespace mongo {
BSONObj nextSafe() { return cursor->nextSafe(); }
- BSONObj next() {
- return cursor->next();
- }
+ BSONObj next() { return cursor->next(); }
- void putBack(BSONObj op) {
- cursor->putBack(op);
- }
+ void putBack(BSONObj op) { cursor->putBack(op); }
+
+ private:
+ bool commonConnect(const string& hostName);
+ bool passthroughHandshake(const BSONObj& rid, const int f);
};
}