@@ -69,6 +69,7 @@ namespace mongo {
69
69
ServerStatusMetricField<Counter64> ttlDeletedDocumentsDisplay (" ttl.deletedDocuments" , &ttlDeletedDocuments);
70
70
71
71
MONGO_EXPORT_SERVER_PARAMETER ( ttlMonitorEnabled, bool , true );
72
+ MONGO_EXPORT_SERVER_PARAMETER ( ttlMonitorSleepSecs, int , 60 ); // used for testing
72
73
73
74
class TTLMonitor : public BackgroundJob {
74
75
public:
@@ -84,7 +85,7 @@ namespace mongo {
84
85
cc ().getAuthorizationSession ()->grantInternalAuthorization ();
85
86
86
87
while ( ! inShutdown () ) {
87
- sleepsecs ( 60 );
88
+ sleepsecs ( ttlMonitorSleepSecs );
88
89
89
90
LOG (3 ) << " TTLMonitor thread awake" << endl;
90
91
@@ -123,8 +124,16 @@ namespace mongo {
123
124
for ( vector<BSONObj>::const_iterator it = indexes.begin ();
124
125
it != indexes.end (); ++it ) {
125
126
126
- if ( !doTTLForIndex ( &txn, db, *it ) ) {
127
- break ; // stop processing TTL indexes on this database
127
+ BSONObj idx = *it;
128
+ try {
129
+ if ( !doTTLForIndex ( &txn, db, idx ) ) {
130
+ break ; // stop processing TTL indexes on this database
131
+ }
132
+ } catch (const DBException& dbex) {
133
+ error () << " Error processing ttl index: " << idx
134
+ << " -- " << dbex.toString ();
135
+ // continue on to the next index
136
+ continue ;
128
137
}
129
138
}
130
139
}
@@ -191,6 +200,7 @@ namespace mongo {
191
200
*/
192
201
bool doTTLForIndex ( OperationContext* txn, const string& dbName, const BSONObj& idx ) {
193
202
BSONObj key = idx[" key" ].Obj ();
203
+ const string ns = idx[" ns" ].String ();
194
204
if ( key.nFields () != 1 ) {
195
205
error () << " key for ttl index can only have 1 field" << endl;
196
206
return true ;
@@ -210,13 +220,11 @@ namespace mongo {
210
220
query = BSON ( key.firstElement ().fieldName () << b.obj () );
211
221
}
212
222
213
- LOG (1 ) << " TTL: " << key << " \t " << query << endl;
223
+ LOG (1 ) << " TTL -- ns : " << ns << " key: " << key << " query: " << query << endl;
214
224
215
225
long long numDeleted = 0 ;
216
226
int attempt = 1 ;
217
227
while (1 ) {
218
- const string ns = idx[" ns" ].String ();
219
-
220
228
ScopedTransaction scopedXact (txn, MODE_IX);
221
229
AutoGetDb autoDb (txn, dbName, MODE_IX);
222
230
Database* db = autoDb.getDb ();
0 commit comments