Skip to content

Commit a61874a

Browse files
author
matt dannenberg
committed
SERVER-14503 move replHasDatabases to heartbeat.* from instance.*
1 parent 46a25fd commit a61874a

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

src/mongo/db/instance.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -903,29 +903,6 @@ namespace mongo {
903903
wunit.commit();
904904
}
905905

906-
/* returns true if there is data on this server. useful when starting replication.
907-
local database does NOT count except for rsoplog collection.
908-
used to set the hasData field on replset heartbeat command response
909-
*/
910-
bool replHasDatabases(OperationContext* txn) {
911-
vector<string> names;
912-
globalStorageEngine->listDatabases( &names );
913-
914-
if( names.size() >= 2 ) return true;
915-
if( names.size() == 1 ) {
916-
if( names[0] != "local" )
917-
return true;
918-
// we have a local database. return true if oplog isn't empty
919-
{
920-
Lock::DBRead lk(txn->lockState(), repl::rsoplog);
921-
BSONObj o;
922-
if( Helpers::getFirst(txn, repl::rsoplog, o) )
923-
return true;
924-
}
925-
}
926-
return false;
927-
}
928-
929906
DBDirectClient::DBDirectClient()
930907
: _txnOwned(new OperationContextImpl),
931908
_txn(_txnOwned.get())

src/mongo/db/instance.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ namespace mongo {
7373
DbResponse& dbresponse,
7474
const HostAndPort &client );
7575

76-
/* returns true if there is no data on this server. useful when starting replication.
77-
local database does NOT count.
78-
*/
79-
bool replHasDatabases(OperationContext* txn);
80-
8176
/**
8277
* Embedded calls to the local server using the DBClientBase API without going over the network.
8378
*

src/mongo/db/repl/heartbeat.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,17 @@
3131
#include <boost/thread/thread.hpp>
3232

3333
#include "mongo/db/commands.h"
34-
#include "mongo/db/instance.h"
34+
#include "mongo/db/dbhelpers.h"
3535
#include "mongo/db/repl/bgsync.h"
3636
#include "mongo/db/repl/connections.h"
3737
#include "mongo/db/repl/heartbeat_info.h"
38+
#include "mongo/db/repl/oplog.h"
3839
#include "mongo/db/repl/repl_coordinator_global.h"
3940
#include "mongo/db/repl/repl_set_health_poll_task.h"
4041
#include "mongo/db/repl/replset_commands.h"
4142
#include "mongo/db/repl/rs.h"
4243
#include "mongo/db/repl/server.h"
44+
#include "mongo/db/storage/storage_engine.h"
4345
#include "mongo/util/background.h"
4446
#include "mongo/util/concurrency/task.h"
4547
#include "mongo/util/fail_point_service.h"
@@ -53,6 +55,32 @@ namespace repl {
5355

5456
using namespace bson;
5557

58+
namespace {
59+
/**
60+
* Returns true if there is no data on this server. Useful when starting replication.
61+
* The "local" database does NOT count except for "rs.oplog" collection.
62+
* Used to set the hasData field on replset heartbeat command response.
63+
*/
64+
bool replHasDatabases(OperationContext* txn) {
65+
vector<string> names;
66+
globalStorageEngine->listDatabases( &names );
67+
68+
if( names.size() >= 2 ) return true;
69+
if( names.size() == 1 ) {
70+
if( names[0] != "local" )
71+
return true;
72+
// we have a local database. return true if oplog isn't empty
73+
{
74+
Lock::DBRead lk(txn->lockState(), repl::rsoplog);
75+
BSONObj o;
76+
if( Helpers::getFirst(txn, repl::rsoplog, o) )
77+
return true;
78+
}
79+
}
80+
return false;
81+
}
82+
} // namespace
83+
5684
/* { replSetHeartbeat : <setname> } */
5785
class CmdReplSetHeartbeat : public ReplSetCommand {
5886
public:

0 commit comments

Comments
 (0)