00001 // @file d_writeback.h 00002 00019 #pragma once 00020 00021 #include "../pch.h" 00022 00023 #include "../util/queue.h" 00024 00025 namespace mongo { 00026 00027 /* 00028 * The WriteBackManager keeps one queue of pending operations per mongos. The operations get here 00029 * if they were directed to a chunk that is no longer in this mongod server. The operations are 00030 * "written back" to the mongos server per its request (command 'writebacklisten'). 00031 * 00032 * The class is thread safe. 00033 */ 00034 class WriteBackManager { 00035 public: 00036 WriteBackManager(); 00037 ~WriteBackManager(); 00038 00039 /* 00040 * @param remote server ID this operation came from 00041 * @param op the operation itself 00042 * 00043 * Enqueues opeartion 'op' in server 'remote's queue. The operation will be written back to 00044 * remote at a later stager. 00045 */ 00046 void queueWriteBack( const string& remote , const BSONObj& op ); 00047 00048 /* 00049 * @param remote server ID 00050 * @return the queue for operations that came from 'remote' 00051 * 00052 * Gets access to server 'remote's queue, which is synchronized. 00053 */ 00054 BlockingQueue<BSONObj>* getWritebackQueue( const string& remote ); 00055 00056 /* 00057 * @return true if there is no operation queued for write back 00058 */ 00059 bool queuesEmpty() const; 00060 00061 private: 00062 // a map from mongos's serverIDs to queues of "rejected" operations 00063 // an operation is rejected if it targets data that does not live on this shard anymore 00064 typedef map< string , BlockingQueue<BSONObj>* > WriteBackQueuesMap; 00065 00066 // '_writebackQueueLock' protects only the map itself, since each queue is syncrhonized. 00067 mutable mongo::mutex _writebackQueueLock; 00068 WriteBackQueuesMap _writebackQueues; 00069 00070 }; 00071 00072 // TODO collect global state in a central place and init during startup 00073 extern WriteBackManager writeBackManager; 00074 00075 } // namespace mongo