summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/replication_executor.cpp
blob: be8dbb0ba9f6f5e14abb3412af16e07fcee71b48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
/**
 *    Copyright (C) 2014 MongoDB Inc.
 *
 *    This program is free software: you can redistribute it and/or  modify
 *    it under the terms of the GNU Affero General Public License, version 3,
 *    as published by the Free Software Foundation.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU Affero General Public License for more details.
 *
 *    You should have received a copy of the GNU Affero General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *    As a special exception, the copyright holders give permission to link the
 *    code of portions of this program with the OpenSSL library under certain
 *    conditions as described in each individual source file and distribute
 *    linked combinations including the program with the OpenSSL library. You
 *    must comply with the GNU Affero General Public License in all respects for
 *    all of the code used other than as permitted herein. If you modify file(s)
 *    with this exception, you may extend this exception to your version of the
 *    file(s), but you are not obligated to do so. If you do not wish to do so,
 *    delete this exception statement from your version. If you delete this
 *    exception statement from all source files in the program, then also delete
 *    it in the license file.
 */

#include "mongo/platform/basic.h"

#include "mongo/db/repl/replication_executor.h"

#include <limits>

#include "mongo/db/repl/database_task.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/mongoutils/str.h"

namespace mongo {
namespace repl {

namespace {
    stdx::function<void ()> makeNoExcept(const stdx::function<void ()> &fn);
}  // namespace

    ReplicationExecutor::ReplicationExecutor(NetworkInterface* netInterface, int64_t prngSeed) :
        _random(prngSeed),
        _networkInterface(netInterface),
        _totalEventWaiters(0),
        _inShutdown(false),
        _dblockWorkers(threadpool::ThreadPool::DoNotStartThreadsTag(),
                       3,
                       "replCallbackWithGlobalLock-"),
        _dblockTaskRunner(
            &_dblockWorkers,
            stdx::bind(&NetworkInterface::createOperationContext, netInterface)),
        _dblockExclusiveLockTaskRunner(
            &_dblockWorkers,
            stdx::bind(&NetworkInterface::createOperationContext, netInterface)),
        _nextId(0) {
    }

    ReplicationExecutor::~ReplicationExecutor() {}

    std::string ReplicationExecutor::getDiagnosticString() {
        boost::lock_guard<boost::mutex> lk(_mutex);
        return _getDiagnosticString_inlock();
    }

    std::string ReplicationExecutor::_getDiagnosticString_inlock() const {
        str::stream output;
        output << "ReplicationExecutor";
        output << " networkInProgress:" << _networkInProgressQueue.size();
        output << " dbWorkInProgress:" << _dbWorkInProgressQueue.size();
        output << " exclusiveInProgress:" << _exclusiveLockInProgressQueue.size();
        output << " sleeperQueue:" << _sleepersQueue.size();
        output << " ready:" << _readyQueue.size();
        output << " free:" << _freeQueue.size();
        output << " unsignaledEvents:" << _unsignaledEvents.size();
        output << " eventWaiters:" << _totalEventWaiters;
        output << " shuttingDown:" << _inShutdown;
        output << " networkInterface:" << _networkInterface->getDiagnosticString();
        return output;
    }

    Date_t ReplicationExecutor::now() {
        return _networkInterface->now();
    }

    void ReplicationExecutor::run() {
        setThreadName("ReplicationExecutor");
        _networkInterface->startup();
        _dblockWorkers.startThreads();
        std::pair<WorkItem, CallbackHandle> work;
        while ((work = getWork()).first.callback) {
            {
                boost::lock_guard<boost::mutex> lk(_terribleExLockSyncMutex);
                const Status inStatus = work.first.isCanceled ?
                    Status(ErrorCodes::CallbackCanceled, "Callback canceled") :
                    Status::OK();
                makeNoExcept(stdx::bind(work.first.callback,
                                        CallbackData(this, work.second, inStatus)))();
            }
            signalEvent(work.first.finishedEvent);
        }
        finishShutdown();
        _networkInterface->shutdown();
    }

    void ReplicationExecutor::shutdown() {
        // Correct shutdown needs to:
        // * Disable future work queueing.
        // * drain all of the unsignaled events, sleepers, and ready queue, by running those
        //   callbacks with a "shutdown" or "canceled" status.
        // * Signal all threads blocked in waitForEvent, and wait for them to return from that method.
        boost::lock_guard<boost::mutex> lk(_mutex);
        _inShutdown = true;

        _readyQueue.splice(_readyQueue.end(), _dbWorkInProgressQueue);
        _readyQueue.splice(_readyQueue.end(), _exclusiveLockInProgressQueue);
        _readyQueue.splice(_readyQueue.end(), _networkInProgressQueue);
        _readyQueue.splice(_readyQueue.end(), _sleepersQueue);
        for (EventList::iterator event = _unsignaledEvents.begin();
             event != _unsignaledEvents.end();
             ++event) {

            _readyQueue.splice(_readyQueue.end(), event->waiters);
        }
        for (WorkQueue::iterator readyWork = _readyQueue.begin();
             readyWork != _readyQueue.end();
             ++readyWork) {

            readyWork->isCanceled = true;
        }
        _networkInterface->signalWorkAvailable();
    }

    void ReplicationExecutor::finishShutdown() {
        _dblockExclusiveLockTaskRunner.cancel();
        _dblockTaskRunner.cancel();
        _dblockWorkers.join();
        boost::unique_lock<boost::mutex> lk(_mutex);
        invariant(_inShutdown);
        invariant(_dbWorkInProgressQueue.empty());
        invariant(_exclusiveLockInProgressQueue.empty());
        invariant(_readyQueue.empty());
        invariant(_sleepersQueue.empty());

        while (!_unsignaledEvents.empty()) {
            EventList::iterator event = _unsignaledEvents.begin();
            invariant(event->waiters.empty());
            signalEvent_inlock(EventHandle(event, ++_nextId));
        }

        while (_totalEventWaiters > 0)
            _noMoreWaitingThreads.wait(lk);

        invariant(_dbWorkInProgressQueue.empty());
        invariant(_exclusiveLockInProgressQueue.empty());
        invariant(_readyQueue.empty());
        invariant(_sleepersQueue.empty());
        invariant(_unsignaledEvents.empty());
    }

    void ReplicationExecutor::maybeNotifyShutdownComplete_inlock() {
        if (_totalEventWaiters == 0)
            _noMoreWaitingThreads.notify_all();
    }

    StatusWith<ReplicationExecutor::EventHandle> ReplicationExecutor::makeEvent() {
        boost::lock_guard<boost::mutex> lk(_mutex);
        return makeEvent_inlock();
    }

    StatusWith<ReplicationExecutor::EventHandle> ReplicationExecutor::makeEvent_inlock() {
        if (_inShutdown)
            return StatusWith<EventHandle>(ErrorCodes::ShutdownInProgress, "Shutdown in progress");

        if (_signaledEvents.empty())
            _signaledEvents.push_back(Event());
        const EventList::iterator iter = _signaledEvents.begin();
        invariant(iter->waiters.empty());
        iter->generation++;
        iter->isSignaled = false;
        _unsignaledEvents.splice(_unsignaledEvents.end(), _signaledEvents, iter);
        return StatusWith<EventHandle>(EventHandle(iter, ++_nextId));
    }

    void ReplicationExecutor::signalEvent(const EventHandle& event) {
        boost::lock_guard<boost::mutex> lk(_mutex);
        signalEvent_inlock(event);
    }

    void ReplicationExecutor::signalEvent_inlock(const EventHandle& event) {
        invariant(!event._iter->isSignaled);
        invariant(event._iter->generation == event._generation);
        event._iter->isSignaled = true;
        _signaledEvents.splice(_signaledEvents.end(), _unsignaledEvents, event._iter);
        if (!event._iter->waiters.empty()) {
            _readyQueue.splice(_readyQueue.end(), event._iter->waiters);
            _networkInterface->signalWorkAvailable();
        }
        event._iter->isSignaledCondition->notify_all();
    }

    StatusWith<ReplicationExecutor::CallbackHandle> ReplicationExecutor::onEvent(
            const EventHandle& event,
            const CallbackFn& work) {
        boost::lock_guard<boost::mutex> lk(_mutex);
        invariant(event.isValid());
        invariant(event._generation <= event._iter->generation);
        WorkQueue* queue = &_readyQueue;
        if (event._generation == event._iter->generation && !event._iter->isSignaled) {
            queue = &event._iter->waiters;
        }
        else {
            queue = &_readyQueue;
        }
        return enqueueWork_inlock(queue, work);
    }

    void ReplicationExecutor::waitForEvent(const EventHandle& event) {
        boost::unique_lock<boost::mutex> lk(_mutex);
        invariant(event.isValid());
        ++_totalEventWaiters;
        while ((event._generation == event._iter->generation) && !event._iter->isSignaled) {
            event._iter->isSignaledCondition->wait(lk);
        }
        --_totalEventWaiters;
        maybeNotifyShutdownComplete_inlock();
    }

    static void remoteCommandFinished(
            const ReplicationExecutor::CallbackData& cbData,
            const ReplicationExecutor::RemoteCommandCallbackFn& cb,
            const RemoteCommandRequest& request,
            const ResponseStatus& response) {

        if (cbData.status.isOK()) {
            cb(ReplicationExecutor::RemoteCommandCallbackData(
                       cbData.executor, cbData.myHandle, request, response));
        }
        else {
            cb(ReplicationExecutor::RemoteCommandCallbackData(
                       cbData.executor,
                       cbData.myHandle,
                       request,
                       ResponseStatus(cbData.status)));
        }
    }

    static void remoteCommandFailedEarly(
            const ReplicationExecutor::CallbackData& cbData,
            const ReplicationExecutor::RemoteCommandCallbackFn& cb,
            const RemoteCommandRequest& request) {

        invariant(!cbData.status.isOK());
        cb(ReplicationExecutor::RemoteCommandCallbackData(
                   cbData.executor,
                   cbData.myHandle,
                   request,
                   ResponseStatus(cbData.status)));
    }

    void ReplicationExecutor::_finishRemoteCommand(
            const RemoteCommandRequest& request,
            const ResponseStatus& response,
            const CallbackHandle& cbHandle,
            const uint64_t expectedHandleGeneration,
            const RemoteCommandCallbackFn& cb) {

        const WorkQueue::iterator iter = cbHandle._iter;
        boost::lock_guard<boost::mutex> lk(_mutex);
        if (_inShutdown) {
            return;
        }
        if (expectedHandleGeneration != iter->generation) {
            return;
        }
        iter->callback = stdx::bind(remoteCommandFinished,
                                    stdx::placeholders::_1,
                                    cb,
                                    request,
                                    response);
        _readyQueue.splice(_readyQueue.end(), _networkInProgressQueue, iter);
    }

    StatusWith<ReplicationExecutor::CallbackHandle> ReplicationExecutor::scheduleRemoteCommand(
            const RemoteCommandRequest& request,
            const RemoteCommandCallbackFn& cb) {
        RemoteCommandRequest scheduledRequest = request;
        if (request.timeout == kNoTimeout) {
            scheduledRequest.expirationDate = kNoExpirationDate;
        }
        else {
            scheduledRequest.expirationDate =
                _networkInterface->now() + scheduledRequest.timeout.total_milliseconds();
        }
        boost::lock_guard<boost::mutex> lk(_mutex);
        StatusWith<CallbackHandle> handle = enqueueWork_inlock(
                &_networkInProgressQueue,
                stdx::bind(remoteCommandFailedEarly,
                           stdx::placeholders::_1,
                           cb,
                           scheduledRequest));
        if (handle.isOK()) {
            handle.getValue()._iter->isNetworkOperation = true;
            _networkInterface->startCommand(
                    handle.getValue(),
                    scheduledRequest,
                    stdx::bind(&ReplicationExecutor::_finishRemoteCommand,
                               this,
                               scheduledRequest,
                               stdx::placeholders::_1,
                               handle.getValue(),
                               handle.getValue()._iter->generation,
                               cb));
        }
        return handle;
    }

    StatusWith<ReplicationExecutor::CallbackHandle> ReplicationExecutor::scheduleWork(
            const CallbackFn& work) {
        boost::lock_guard<boost::mutex> lk(_mutex);
        _networkInterface->signalWorkAvailable();
        return enqueueWork_inlock(&_readyQueue, work);
    }

    StatusWith<ReplicationExecutor::CallbackHandle> ReplicationExecutor::scheduleWorkAt(
            Date_t when,
            const CallbackFn& work) {

        boost::lock_guard<boost::mutex> lk(_mutex);
        WorkQueue temp;
        StatusWith<CallbackHandle> cbHandle = enqueueWork_inlock(&temp, work);
        if (!cbHandle.isOK())
            return cbHandle;
        cbHandle.getValue()._iter->readyDate = when;
        WorkQueue::iterator insertBefore = _sleepersQueue.begin();
        while (insertBefore != _sleepersQueue.end() && insertBefore->readyDate <= when)
            ++insertBefore;
        _sleepersQueue.splice(insertBefore, temp, temp.begin());
        return cbHandle;
    }

    StatusWith<ReplicationExecutor::CallbackHandle>
    ReplicationExecutor::scheduleDBWork(const CallbackFn& work) {
        return scheduleDBWork(work, NamespaceString(), MODE_NONE);
    }

    StatusWith<ReplicationExecutor::CallbackHandle>
    ReplicationExecutor::scheduleDBWork(const CallbackFn& work,
                                        const NamespaceString& nss,
                                        LockMode mode) {

        boost::lock_guard<boost::mutex> lk(_mutex);
        StatusWith<CallbackHandle> handle = enqueueWork_inlock(&_dbWorkInProgressQueue,
                                                               work);
        if (handle.isOK()) {
            auto doOp = stdx::bind(
                    &ReplicationExecutor::_doOperation,
                    this,
                    stdx::placeholders::_1,
                    stdx::placeholders::_2,
                    handle.getValue(),
                    &_dbWorkInProgressQueue,
                    nullptr);
            auto task = [doOp](OperationContext* txn, const Status& status) {
                makeNoExcept(stdx::bind(doOp, txn, status))();
                return TaskRunner::NextAction::kDisposeOperationContext;
            };
            if (mode == MODE_NONE && nss.ns().empty()) {
                _dblockTaskRunner.schedule(task);
            }
            else {
                _dblockTaskRunner.schedule(DatabaseTask::makeCollectionLockTask(task, nss, mode));
            }
        }
        return handle;
    }

    void ReplicationExecutor::_doOperation(OperationContext* txn,
                                           const Status& taskRunnerStatus,
                                           const CallbackHandle& cbHandle,
                                           WorkQueue* workQueue,
                                           boost::mutex* terribleExLockSyncMutex) {
        boost::unique_lock<boost::mutex> lk(_mutex);
        if (_inShutdown)
            return;
        const WorkQueue::iterator iter = cbHandle._iter;
        const uint64_t generation = iter->generation;
        invariant(generation == cbHandle._generation);
        WorkItem work = *iter;
        iter->callback = CallbackFn();
        _freeQueue.splice(_freeQueue.begin(), *workQueue, iter);
        lk.unlock();
        {
            std::unique_ptr<boost::lock_guard<boost::mutex> > terribleLock(
                terribleExLockSyncMutex ?
                new boost::lock_guard<boost::mutex>(*terribleExLockSyncMutex) :
                nullptr);
            // Only possible task runner error status is CallbackCanceled.
            work.callback(CallbackData(this,
                                       cbHandle,
                                       (work.isCanceled || !taskRunnerStatus.isOK() ?
                                        Status(ErrorCodes::CallbackCanceled, "Callback canceled") :
                                        Status::OK()),
                                       txn));
        }
        lk.lock();
        signalEvent_inlock(work.finishedEvent);
    }

    StatusWith<ReplicationExecutor::CallbackHandle>
    ReplicationExecutor::scheduleWorkWithGlobalExclusiveLock(
            const CallbackFn& work) {

        boost::lock_guard<boost::mutex> lk(_mutex);
        StatusWith<CallbackHandle> handle = enqueueWork_inlock(&_exclusiveLockInProgressQueue,
                                                               work);
        if (handle.isOK()) {
            auto doOp = stdx::bind(
                    &ReplicationExecutor::_doOperation,
                    this,
                    stdx::placeholders::_1,
                    stdx::placeholders::_2,
                    handle.getValue(),
                    &_exclusiveLockInProgressQueue,
                    &_terribleExLockSyncMutex);
            _dblockExclusiveLockTaskRunner.schedule(
                DatabaseTask::makeGlobalExclusiveLockTask(
                    [doOp](OperationContext* txn, const Status& status) {
                makeNoExcept(stdx::bind(doOp, txn, status))();
                return TaskRunner::NextAction::kDisposeOperationContext;
            }));
        }
        return handle;
    }

    void ReplicationExecutor::cancel(const CallbackHandle& cbHandle) {
        boost::unique_lock<boost::mutex> lk(_mutex);
        if (cbHandle._iter->generation  != cbHandle._generation) {
            return;
        }
        cbHandle._iter->isCanceled = true;
        if (cbHandle._iter->isNetworkOperation) {
            lk.unlock();
            _networkInterface->cancelCommand(cbHandle);
        }
    }

    void ReplicationExecutor::wait(const CallbackHandle& cbHandle) {
        waitForEvent(cbHandle._finishedEvent);
    }

    std::pair<ReplicationExecutor::WorkItem, ReplicationExecutor::CallbackHandle>
    ReplicationExecutor::getWork() {
        boost::unique_lock<boost::mutex> lk(_mutex);
        while (true) {
            const Date_t now = _networkInterface->now();
            Date_t nextWakeupDate = scheduleReadySleepers_inlock(now);
            if (!_readyQueue.empty()) {
                break;
            }
            else if (_inShutdown) {
                return std::make_pair(WorkItem(), CallbackHandle());
            }
            lk.unlock();
            if (nextWakeupDate == Date_t(~0ULL)) {
                _networkInterface->waitForWork();
            }
            else {
                _networkInterface->waitForWorkUntil(nextWakeupDate);
            }
            lk.lock();
        }
        const CallbackHandle cbHandle(_readyQueue.begin());
        const WorkItem work = *cbHandle._iter;
        _readyQueue.begin()->callback = CallbackFn();
        _freeQueue.splice(_freeQueue.begin(), _readyQueue, _readyQueue.begin());
        return std::make_pair(work, cbHandle);
    }

    int64_t ReplicationExecutor::nextRandomInt64(int64_t limit) {
        return _random.nextInt64(limit);
    }

    Date_t ReplicationExecutor::scheduleReadySleepers_inlock(const Date_t now) {
        WorkQueue::iterator iter = _sleepersQueue.begin();
        while ((iter != _sleepersQueue.end()) && (iter->readyDate <= now)) {
            ++iter;
        }
        _readyQueue.splice(_readyQueue.end(), _sleepersQueue, _sleepersQueue.begin(), iter);
        if (iter == _sleepersQueue.end()) {
            // indicate no sleeper to wait for
            return Date_t(~0ULL);
        }
        return iter->readyDate;
    }

    StatusWith<ReplicationExecutor::CallbackHandle> ReplicationExecutor::enqueueWork_inlock(
            WorkQueue* queue, const CallbackFn& callback) {

        invariant(callback);
        StatusWith<EventHandle> event = makeEvent_inlock();
        if (!event.isOK())
            return StatusWith<CallbackHandle>(event.getStatus());

        if (_freeQueue.empty())
            _freeQueue.push_front(WorkItem());
        const WorkQueue::iterator iter = _freeQueue.begin();
        iter->generation++;
        iter->callback = callback;
        iter->finishedEvent = event.getValue();
        iter->readyDate = Date_t();
        iter->isCanceled = false;
        queue->splice(queue->end(), _freeQueue, iter);
        return StatusWith<CallbackHandle>(CallbackHandle(iter));
    }

    ReplicationExecutor::EventHandle::EventHandle(const EventList::iterator& iter, uint64_t id) :
        _iter(iter),
        _generation(iter->generation),
        _id(id) {
    }

    ReplicationExecutor::CallbackHandle::CallbackHandle(const WorkQueue::iterator& iter) :
        _iter(iter),
        _generation(iter->generation),
        _finishedEvent(iter->finishedEvent) {
    }

    ReplicationExecutor::CallbackData::CallbackData(ReplicationExecutor* theExecutor,
                                                    const CallbackHandle& theHandle,
                                                    const Status& theStatus,
                                                    OperationContext* theTxn) :
        executor(theExecutor),
        myHandle(theHandle),
        status(theStatus),
        txn(theTxn) {
    }


    ReplicationExecutor::RemoteCommandCallbackData::RemoteCommandCallbackData(
            ReplicationExecutor* theExecutor,
            const CallbackHandle& theHandle,
            const RemoteCommandRequest& theRequest,
            const ResponseStatus& theResponse) :
        executor(theExecutor),
        myHandle(theHandle),
        request(theRequest),
        response(theResponse) {
    }

    ReplicationExecutor::WorkItem::WorkItem() : generation(0U),
                                                isNetworkOperation(false),
                                                isCanceled(false) {}

    ReplicationExecutor::Event::Event() :
        generation(0),
        isSignaled(false),
        isSignaledCondition(new boost::condition_variable) {
    }

    // This is a bitmask with the first bit set. It's used to mark connections that should be kept
    // open during stepdowns.
#ifndef _MSC_EXTENSIONS
    const unsigned int ReplicationExecutor::NetworkInterface::kMessagingPortKeepOpen;
#endif // _MSC_EXTENSIONS

    ReplicationExecutor::NetworkInterface::NetworkInterface() {}
    ReplicationExecutor::NetworkInterface::~NetworkInterface() {}

namespace {

    void callNoExcept(const stdx::function<void ()>& fn) {
        try {
            fn();
        }
        catch (...) {
            std::terminate();
        }
    }

    stdx::function<void ()> makeNoExcept(const stdx::function<void ()> &fn) {
        return stdx::bind(callNoExcept, fn);
    }

}  // namespace

}  // namespace repl
}  // namespace mongo