summaryrefslogtreecommitdiff
path: root/s/d_writeback.cpp
diff options
context:
space:
mode:
authorAlberto Lerner <alerner@10gen.com>2010-09-20 13:20:25 -0400
committerAlberto Lerner <alerner@10gen.com>2010-09-20 13:20:25 -0400
commit090d0d09ae94145427a8813ff56c11299b4f065a (patch)
tree636a9a525c4fe4a8f4cdcc135717fa6b9a3192c1 /s/d_writeback.cpp
parentfe529143dd554fb01ea0401ae88eb5b8700a5627 (diff)
downloadmongo-090d0d09ae94145427a8813ff56c11299b4f065a.tar.gz
SERVER-1713 checks wheather writebacks queues' are empty
Diffstat (limited to 's/d_writeback.cpp')
-rw-r--r--s/d_writeback.cpp45
1 files changed, 40 insertions, 5 deletions
diff --git a/s/d_writeback.cpp b/s/d_writeback.cpp
index 96971306fc3..4e8230dd0c6 100644
--- a/s/d_writeback.cpp
+++ b/s/d_writeback.cpp
@@ -32,13 +32,15 @@
using namespace std;
namespace mongo {
+ typedef map< string , BlockingQueue<BSONObj>* > WriteBackQueuesMap;
- map< string , BlockingQueue<BSONObj>* > writebackQueue;
- mongo::mutex writebackQueueLock("sharding:writebackQueueLock");
+ // 'writebackQueueLock' protects only the map itself, since each queue is syncrhonized.
+ static mongo::mutex writebackQueueLock("sharding:writebackQueueLock");
+ static WriteBackQueuesMap writebackQueues;
BlockingQueue<BSONObj>* getWritebackQueue( const string& remote ){
scoped_lock lk (writebackQueueLock );
- BlockingQueue<BSONObj>*& q = writebackQueue[remote];
+ BlockingQueue<BSONObj>*& q = writebackQueues[remote];
if ( ! q )
q = new BlockingQueue<BSONObj>();
return q;
@@ -69,7 +71,8 @@ namespace mongo {
const OID id = e.__oid();
- // we want to do something every 5 minutes so sockets don't timeout
+ // the command issuer is blocked awaiting a response
+ // we want to do return at least at every 5 minutes so sockets don't timeout
BSONObj z;
if ( getWritebackQueue(id.str())->blockingPop( z, 5 * 60 /* 5 minutes */ ) ) {
log(1) << "WriteBackCommand got : " << z << endl;
@@ -83,4 +86,36 @@ namespace mongo {
}
} writeBackCommand;
-}
+ class WriteBacksQueuedCommand : public Command {
+ public:
+ virtual LockType locktype() const { return NONE; }
+ virtual bool slaveOk() const { return true; }
+ virtual bool adminOnly() const { return true; }
+
+ WriteBacksQueuedCommand() : Command( "writeBackQueued" ){}
+
+ void help(stringstream& help) const {
+ help << "Returns whether there are operations in the writeback queue at the time the command was called. "
+ << "This is an internal comand";
+ }
+
+ bool run(const string& , BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool){
+ bool hasOpsQueued = false;
+ {
+ scoped_lock lk(writebackQueueLock );
+ for ( WriteBackQueuesMap::const_iterator it = writebackQueues.begin(); it != writebackQueues.end(); ++it ){
+ const BlockingQueue<BSONObj>* queue = it->second;
+ if (! queue->empty() ){
+ hasOpsQueued = true;
+ break;
+ }
+ }
+ }
+
+ result.appendBool( "hasOpsQueued" , hasOpsQueued );
+ return true;
+ }
+
+ } writeBacksQueuedCommand;
+
+} // namespace mongo