summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDwight <dwight@10gen.com>2010-08-23 13:55:34 -0400
committerEliot Horowitz <eliot@10gen.com>2010-09-15 14:50:58 -0400
commit0c434ca442aec92f878d97dfb149c67de42bd5f8 (patch)
treee1d8d4807ec249996ee4d598475a5c13fb82ee9c
parent2bd429278f1a9d7bd7d54fb5e9b9094a09196952 (diff)
downloadmongo-0c434ca442aec92f878d97dfb149c67de42bd5f8.tar.gz
do not background index when applying a create index operation
-rw-r--r--db/client.cpp1
-rw-r--r--db/client.h7
-rw-r--r--db/pdfile.cpp7
-rw-r--r--db/repl.cpp1
-rw-r--r--db/repl/rs_sync.cpp1
5 files changed, 17 insertions, 0 deletions
diff --git a/db/client.cpp b/db/client.cpp
index cc13271d103..fec02544f1e 100644
--- a/db/client.cpp
+++ b/db/client.cpp
@@ -35,6 +35,7 @@
namespace mongo {
+ Client* Client::syncThread;
mongo::mutex Client::clientsMutex("clientsMutex");
set<Client*> Client::clients; // always be in clientsMutex when manipulating this
boost::thread_specific_ptr<Client> currentClient;
diff --git a/db/client.h b/db/client.h
index da97c846a3e..dfd78ca35d9 100644
--- a/db/client.h
+++ b/db/client.h
@@ -46,6 +46,13 @@ namespace mongo {
class Client : boost::noncopyable {
public:
+ static Client *syncThread;
+ void iAmSyncThread() {
+ wassert( syncThread == 0 );
+ syncThread = this;
+ }
+ bool isSyncThread() const { return this == syncThread; }
+
static mongo::mutex clientsMutex;
static set<Client*> clients; // always be in clientsMutex when manipulating this
static int recommendedYieldMicros( int * writers = 0 , int * readers = 0 );
diff --git a/db/pdfile.cpp b/db/pdfile.cpp
index 5f68fef5993..21f95f2bd18 100644
--- a/db/pdfile.cpp
+++ b/db/pdfile.cpp
@@ -1529,6 +1529,13 @@ namespace mongo {
BSONObj info = loc.obj();
bool background = info["background"].trueValue();
+ if( background && cc().isSyncThread() ) {
+ /* don't do background indexing on slaves. there are nuances. this could be added later
+ but requires more code.
+ */
+ log() << "info: indexing in foreground on this replica; was a background index build on the primary" << endl;
+ background = false;
+ }
int idxNo = tableToIndex->nIndexes;
IndexDetails& idx = tableToIndex->addIndex(tabletoidxns.c_str(), !background); // clear transient info caches so they refresh; increments nIndexes
diff --git a/db/repl.cpp b/db/repl.cpp
index 113c69e969e..085ae64d1e1 100644
--- a/db/repl.cpp
+++ b/db/repl.cpp
@@ -1687,6 +1687,7 @@ namespace mongo {
void replSlaveThread() {
sleepsecs(1);
Client::initThread("replslave");
+ cc().iAmSyncThread();
{
dblock lk;
diff --git a/db/repl/rs_sync.cpp b/db/repl/rs_sync.cpp
index 331f7f68691..81312172d86 100644
--- a/db/repl/rs_sync.cpp
+++ b/db/repl/rs_sync.cpp
@@ -28,6 +28,7 @@ namespace mongo {
void startSyncThread() {
Client::initThread("rs_sync");
+ cc().iAmSyncThread();
theReplSet->syncThread();
cc().shutdown();
}