summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorAndy Schwerin <schwerin@mongodb.com>2016-05-09 16:27:06 -0400
committerAndy Schwerin <schwerin@mongodb.com>2016-05-17 11:11:57 -0400
commit76de5323b88080f852ca4c2f42593502d26c5620 (patch)
treeed2757f12d12670a25f29529c78b327bb308263d /src/mongo
parent73a042328a539b51b3bf35efc16ec3245381dc40 (diff)
downloadmongo-76de5323b88080f852ca4c2f42593502d26c5620.tar.gz
SERVER-24104 Replace stdx::duration with mongo::Duration.
The mongo::Duration type does overflow checking on casts and arithmetic. This patch also moves DESTRUCTOR_GUARD out of assert_util.h into destructor_guard.h in order to break an include cycle with duration.h.
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/SConscript1
-rw-r--r--src/mongo/base/data_builder.h1
-rw-r--r--src/mongo/client/dbclientcursor.cpp1
-rw-r--r--src/mongo/client/fetcher.cpp1
-rw-r--r--src/mongo/client/remote_command_retry_scheduler.cpp1
-rw-r--r--src/mongo/client/replica_set_monitor.cpp4
-rw-r--r--src/mongo/client/replica_set_monitor.h2
-rw-r--r--src/mongo/client/replica_set_monitor_internal.h1
-rw-r--r--src/mongo/db/auth/authz_manager_external_state_local.h1
-rw-r--r--src/mongo/db/auth/impersonation_session.cpp1
-rw-r--r--src/mongo/db/auth/role_name.h1
-rw-r--r--src/mongo/db/auth/user_cache_invalidator_job.cpp7
-rw-r--r--src/mongo/db/background.cpp1
-rw-r--r--src/mongo/db/catalog/collection.cpp2
-rw-r--r--src/mongo/db/catalog/database_holder.h1
-rw-r--r--src/mongo/db/client.cpp2
-rw-r--r--src/mongo/db/commands/getmore_cmd.cpp2
-rw-r--r--src/mongo/db/commands/parameters.cpp1
-rw-r--r--src/mongo/db/concurrency/lock_state.cpp4
-rw-r--r--src/mongo/db/exec/and_hash.h1
-rw-r--r--src/mongo/db/ftdc/config.h2
-rw-r--r--src/mongo/db/ftdc/ftdc_mongod.cpp2
-rw-r--r--src/mongo/db/ftdc/util.cpp2
-rw-r--r--src/mongo/db/hasher.h3
-rw-r--r--src/mongo/db/pipeline/document_source_out.cpp1
-rw-r--r--src/mongo/db/pipeline/field_path.h5
-rw-r--r--src/mongo/db/query/plan_enumerator.h1
-rw-r--r--src/mongo/db/query/plan_yield_policy.cpp7
-rw-r--r--src/mongo/db/range_deleter.cpp3
-rw-r--r--src/mongo/db/range_deleter_test.cpp6
-rw-r--r--src/mongo/db/repl/applier.cpp1
-rw-r--r--src/mongo/db/repl/collection_cloner.cpp1
-rw-r--r--src/mongo/db/repl/data_replicator.cpp1
-rw-r--r--src/mongo/db/repl/database_cloner.cpp1
-rw-r--r--src/mongo/db/repl/multiapplier.cpp1
-rw-r--r--src/mongo/db/repl/oplog_fetcher.cpp6
-rw-r--r--src/mongo/db/repl/oplogreader.cpp3
-rw-r--r--src/mongo/db/repl/replication_coordinator_external_state_mock.h1
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl.cpp24
-rw-r--r--src/mongo/db/repl/reporter.cpp1
-rw-r--r--src/mongo/db/repl/sync_source_feedback.cpp3
-rw-r--r--src/mongo/db/repl/sync_source_resolver.h1
-rw-r--r--src/mongo/db/repl/sync_tail.cpp2
-rw-r--r--src/mongo/db/repl/task_runner.cpp1
-rw-r--r--src/mongo/db/repl/topology_coordinator_impl.cpp12
-rw-r--r--src/mongo/db/repl/topology_coordinator_impl_test.cpp1
-rw-r--r--src/mongo/db/repl/topology_coordinator_impl_v1_test.cpp1
-rw-r--r--src/mongo/db/s/collection_sharding_state.h1
-rw-r--r--src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp6
-rw-r--r--src/mongo/db/s/migration_destination_manager.cpp5
-rw-r--r--src/mongo/db/s/migration_source_manager.cpp5
-rw-r--r--src/mongo/db/s/operation_sharding_state.cpp5
-rw-r--r--src/mongo/db/s/sharding_state.cpp2
-rw-r--r--src/mongo/db/service_context.h1
-rw-r--r--src/mongo/db/sorter/sorter.cpp1
-rw-r--r--src/mongo/db/sorter/sorter.h1
-rw-r--r--src/mongo/db/stats/snapshots.h2
-rw-r--r--src/mongo/db/storage/mmap_v1/dur.cpp4
-rw-r--r--src/mongo/db/storage/mmap_v1/dur_journalimpl.h1
-rw-r--r--src/mongo/db/storage/mmap_v1/dur_recover.cpp1
-rw-r--r--src/mongo/db/storage/mmap_v1/dur_recover.h2
-rw-r--r--src/mongo/db/storage/mmap_v1/file_allocator.h6
-rw-r--r--src/mongo/db/storage/mmap_v1/record_access_tracker.cpp2
-rw-r--r--src/mongo/db/storage/mmap_v1/record_access_tracker.h2
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_options_init.cpp5
-rw-r--r--src/mongo/dbtests/framework_options_init.cpp1
-rw-r--r--src/mongo/executor/async_timer_asio.cpp2
-rw-r--r--src/mongo/executor/connection_pool.cpp1
-rw-r--r--src/mongo/executor/connection_pool.h1
-rw-r--r--src/mongo/executor/connection_pool_asio.cpp2
-rw-r--r--src/mongo/executor/network_interface_asio.cpp2
-rw-r--r--src/mongo/executor/network_interface_thread_pool.cpp1
-rw-r--r--src/mongo/executor/network_test_env.h6
-rw-r--r--src/mongo/logger/logstream_builder.h9
-rw-r--r--src/mongo/s/balancer/balancer.cpp3
-rw-r--r--src/mongo/s/catalog/dist_lock_manager.h1
-rw-r--r--src/mongo/s/catalog/replset/replset_dist_lock_manager.cpp2
-rw-r--r--src/mongo/s/catalog/replset/replset_dist_lock_manager_test.cpp18
-rw-r--r--src/mongo/s/client/shard_remote.cpp8
-rw-r--r--src/mongo/s/grid.h1
-rw-r--r--src/mongo/s/mongos_options_init.cpp1
-rw-r--r--src/mongo/s/query/cluster_cursor_cleanup_job.cpp3
-rw-r--r--src/mongo/scripting/deadline_monitor.h3
-rw-r--r--src/mongo/scripting/mozjs/PosixNSPR.cpp2
-rw-r--r--src/mongo/scripting/mozjs/global.cpp1
-rw-r--r--src/mongo/scripting/mozjs/proxyscope.cpp1
-rw-r--r--src/mongo/shell/shell_options.cpp3
-rw-r--r--src/mongo/shell/shell_options_init.cpp1
-rw-r--r--src/mongo/shell/shell_utils_launcher.cpp1
-rw-r--r--src/mongo/shell/shell_utils_launcher.h1
-rw-r--r--src/mongo/tools/mongobridge_options_init.cpp1
-rw-r--r--src/mongo/util/SConscript2
-rw-r--r--src/mongo/util/assert_util.h21
-rw-r--r--src/mongo/util/background.cpp7
-rw-r--r--src/mongo/util/background_thread_clock_source.cpp3
-rw-r--r--src/mongo/util/base64.cpp2
-rw-r--r--src/mongo/util/base64.h3
-rw-r--r--src/mongo/util/bufreader.h1
-rw-r--r--src/mongo/util/concurrency/synchronization.h2
-rw-r--r--src/mongo/util/destructor_guard.h50
-rw-r--r--src/mongo/util/duration.cpp2
-rw-r--r--src/mongo/util/duration.h49
-rw-r--r--src/mongo/util/duration_test.cpp30
-rw-r--r--src/mongo/util/net/sock.h1
-rw-r--r--src/mongo/util/ntservice.cpp2
-rw-r--r--src/mongo/util/processinfo.h1
-rw-r--r--src/mongo/util/text.cpp3
-rw-r--r--src/mongo/util/time_support.cpp63
-rw-r--r--src/mongo/util/time_support.h42
-rw-r--r--src/mongo/util/time_support_test.cpp4
110 files changed, 306 insertions, 239 deletions
diff --git a/src/mongo/SConscript b/src/mongo/SConscript
index 77c190b5814..398d34de72d 100644
--- a/src/mongo/SConscript
+++ b/src/mongo/SConscript
@@ -93,6 +93,7 @@ baseSource=[
'util/assert_util.cpp',
'util/base64.cpp',
'util/concurrency/thread_name.cpp',
+ 'util/duration.cpp',
'util/exception_filter_win32.cpp',
'util/exit.cpp',
'util/hex.cpp',
diff --git a/src/mongo/base/data_builder.h b/src/mongo/base/data_builder.h
index 28736de35da..53b09263403 100644
--- a/src/mongo/base/data_builder.h
+++ b/src/mongo/base/data_builder.h
@@ -31,6 +31,7 @@
#include <cstddef>
#include <cstring>
#include <limits>
+#include <memory>
#include "mongo/base/data_range_cursor.h"
#include "mongo/util/allocator.h"
diff --git a/src/mongo/client/dbclientcursor.cpp b/src/mongo/client/dbclientcursor.cpp
index ca06f27aa43..b1c1faef87f 100644
--- a/src/mongo/client/dbclientcursor.cpp
+++ b/src/mongo/client/dbclientcursor.cpp
@@ -43,6 +43,7 @@
#include "mongo/s/stale_exception.h"
#include "mongo/stdx/memory.h"
#include "mongo/util/debug_util.h"
+#include "mongo/util/destructor_guard.h"
#include "mongo/util/exit.h"
#include "mongo/util/log.h"
#include "mongo/util/scopeguard.h"
diff --git a/src/mongo/client/fetcher.cpp b/src/mongo/client/fetcher.cpp
index acc446298b5..c25202da605 100644
--- a/src/mongo/client/fetcher.cpp
+++ b/src/mongo/client/fetcher.cpp
@@ -35,6 +35,7 @@
#include "mongo/db/namespace_string.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/util/assert_util.h"
+#include "mongo/util/destructor_guard.h"
#include "mongo/util/log.h"
#include "mongo/util/mongoutils/str.h"
diff --git a/src/mongo/client/remote_command_retry_scheduler.cpp b/src/mongo/client/remote_command_retry_scheduler.cpp
index f290a85484f..8c20d0af925 100644
--- a/src/mongo/client/remote_command_retry_scheduler.cpp
+++ b/src/mongo/client/remote_command_retry_scheduler.cpp
@@ -36,6 +36,7 @@
#include "mongo/client/remote_command_retry_scheduler.h"
#include "mongo/stdx/memory.h"
#include "mongo/util/assert_util.h"
+#include "mongo/util/destructor_guard.h"
#include "mongo/util/log.h"
namespace mongo {
diff --git a/src/mongo/client/replica_set_monitor.cpp b/src/mongo/client/replica_set_monitor.cpp
index d8fb071c6c6..970d2ca3818 100644
--- a/src/mongo/client/replica_set_monitor.cpp
+++ b/src/mongo/client/replica_set_monitor.cpp
@@ -133,7 +133,7 @@ protected:
// using it.
if (!inShutdown() && !StaticObserver::_destroyingStatics) {
stdx::unique_lock<stdx::mutex> sl(_monitorMutex);
- _stopRequestedCV.wait_for(sl, Seconds(10));
+ _stopRequestedCV.wait_for(sl, Seconds(10).toSystemDuration());
}
while (!inShutdown() && !StaticObserver::_destroyingStatics) {
@@ -157,7 +157,7 @@ protected:
break;
}
- _stopRequestedCV.wait_for(sl, Seconds(10));
+ _stopRequestedCV.wait_for(sl, Seconds(10).toSystemDuration());
}
}
diff --git a/src/mongo/client/replica_set_monitor.h b/src/mongo/client/replica_set_monitor.h
index 10f9558d6a2..5847a6af6cd 100644
--- a/src/mongo/client/replica_set_monitor.h
+++ b/src/mongo/client/replica_set_monitor.h
@@ -28,6 +28,7 @@
#pragma once
#include <atomic>
+#include <memory>
#include <set>
#include <string>
@@ -35,6 +36,7 @@
#include "mongo/base/string_data.h"
#include "mongo/stdx/functional.h"
#include "mongo/util/net/hostandport.h"
+#include "mongo/util/time_support.h"
namespace mongo {
diff --git a/src/mongo/client/replica_set_monitor_internal.h b/src/mongo/client/replica_set_monitor_internal.h
index 1b669f1ab9b..6dda1935d29 100644
--- a/src/mongo/client/replica_set_monitor_internal.h
+++ b/src/mongo/client/replica_set_monitor_internal.h
@@ -44,6 +44,7 @@
#include "mongo/client/replica_set_monitor.h"
#include "mongo/db/jsobj.h"
#include "mongo/platform/random.h"
+#include "mongo/stdx/mutex.h"
#include "mongo/stdx/condition_variable.h"
#include "mongo/util/net/hostandport.h"
diff --git a/src/mongo/db/auth/authz_manager_external_state_local.h b/src/mongo/db/auth/authz_manager_external_state_local.h
index 883d9d261e7..c9646686b03 100644
--- a/src/mongo/db/auth/authz_manager_external_state_local.h
+++ b/src/mongo/db/auth/authz_manager_external_state_local.h
@@ -37,6 +37,7 @@
#include "mongo/db/auth/role_name.h"
#include "mongo/db/auth/user_name.h"
#include "mongo/stdx/functional.h"
+#include "mongo/stdx/mutex.h"
namespace mongo {
diff --git a/src/mongo/db/auth/impersonation_session.cpp b/src/mongo/db/auth/impersonation_session.cpp
index 228d5567807..791e3c56a0b 100644
--- a/src/mongo/db/auth/impersonation_session.cpp
+++ b/src/mongo/db/auth/impersonation_session.cpp
@@ -41,6 +41,7 @@
#include "mongo/db/operation_context.h"
#include "mongo/rpc/metadata/audit_metadata.h"
#include "mongo/util/assert_util.h"
+#include "mongo/util/destructor_guard.h"
namespace mongo {
diff --git a/src/mongo/db/auth/role_name.h b/src/mongo/db/auth/role_name.h
index 30ef4d50412..7606b216c02 100644
--- a/src/mongo/db/auth/role_name.h
+++ b/src/mongo/db/auth/role_name.h
@@ -29,6 +29,7 @@
#pragma once
#include <iosfwd>
+#include <memory>
#include <string>
#include <vector>
diff --git a/src/mongo/db/auth/user_cache_invalidator_job.cpp b/src/mongo/db/auth/user_cache_invalidator_job.cpp
index cda52569f1f..ef64311cbe6 100644
--- a/src/mongo/db/auth/user_cache_invalidator_job.cpp
+++ b/src/mongo/db/auth/user_cache_invalidator_job.cpp
@@ -141,11 +141,12 @@ void UserCacheInvalidator::run() {
while (true) {
stdx::unique_lock<stdx::mutex> lock(invalidationIntervalMutex);
- Date_t sleepUntil = lastInvalidationTime + Seconds(userCacheInvalidationIntervalSecs);
+ Date_t sleepUntil =
+ lastInvalidationTime + Seconds(userCacheInvalidationIntervalSecs.load());
Date_t now = Date_t::now();
while (now < sleepUntil) {
- invalidationIntervalChangedCondition.wait_for(lock, sleepUntil - now);
- sleepUntil = lastInvalidationTime + Seconds(userCacheInvalidationIntervalSecs);
+ invalidationIntervalChangedCondition.wait_until(lock, sleepUntil.toSystemTimePoint());
+ sleepUntil = lastInvalidationTime + Seconds(userCacheInvalidationIntervalSecs.load());
now = Date_t::now();
}
lastInvalidationTime = now;
diff --git a/src/mongo/db/background.cpp b/src/mongo/db/background.cpp
index 306d966a01b..e3869b1bd6b 100644
--- a/src/mongo/db/background.cpp
+++ b/src/mongo/db/background.cpp
@@ -37,6 +37,7 @@
#include "mongo/base/disallow_copying.h"
#include "mongo/stdx/condition_variable.h"
+#include "mongo/stdx/mutex.h"
#include "mongo/stdx/thread.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/map_util.h"
diff --git a/src/mongo/db/catalog/collection.cpp b/src/mongo/db/catalog/collection.cpp
index 84c596c25ef..2805c3d3b05 100644
--- a/src/mongo/db/catalog/collection.cpp
+++ b/src/mongo/db/catalog/collection.cpp
@@ -152,7 +152,7 @@ void CappedInsertNotifier::_wait(stdx::unique_lock<stdx::mutex>& lk,
while (!_dead && prevVersion == _version) {
if (timeout == Microseconds::max()) {
_notifier.wait(lk);
- } else if (stdx::cv_status::timeout == _notifier.wait_for(lk, timeout)) {
+ } else if (stdx::cv_status::timeout == _notifier.wait_for(lk, timeout.toSystemDuration())) {
return;
}
}
diff --git a/src/mongo/db/catalog/database_holder.h b/src/mongo/db/catalog/database_holder.h
index ce99747937b..ba8b5c673fa 100644
--- a/src/mongo/db/catalog/database_holder.h
+++ b/src/mongo/db/catalog/database_holder.h
@@ -32,6 +32,7 @@
#include "mongo/base/string_data.h"
#include "mongo/db/namespace_string.h"
+#include "mongo/stdx/mutex.h"
#include "mongo/util/concurrency/mutex.h"
#include "mongo/util/string_map.h"
diff --git a/src/mongo/db/client.cpp b/src/mongo/db/client.cpp
index e72553d1fbe..807a7650aa5 100644
--- a/src/mongo/db/client.cpp
+++ b/src/mongo/db/client.cpp
@@ -50,8 +50,6 @@
namespace mongo {
-using logger::LogComponent;
-
TSP_DECLARE(ServiceContext::UniqueClient, currentClient)
TSP_DEFINE(ServiceContext::UniqueClient, currentClient)
diff --git a/src/mongo/db/commands/getmore_cmd.cpp b/src/mongo/db/commands/getmore_cmd.cpp
index 577c53b2d13..341bc67b8ed 100644
--- a/src/mongo/db/commands/getmore_cmd.cpp
+++ b/src/mongo/db/commands/getmore_cmd.cpp
@@ -357,7 +357,7 @@ public:
ctx.reset();
// Block waiting for data.
- Microseconds timeout(curOp->getRemainingMaxTimeMicros());
+ Microseconds timeout(static_cast<int64_t>(curOp->getRemainingMaxTimeMicros()));
notifier->wait(notifierVersion, timeout);
notifier.reset();
diff --git a/src/mongo/db/commands/parameters.cpp b/src/mongo/db/commands/parameters.cpp
index c9bc974e040..c2a5bf23d91 100644
--- a/src/mongo/db/commands/parameters.cpp
+++ b/src/mongo/db/commands/parameters.cpp
@@ -42,6 +42,7 @@
#include "mongo/db/commands.h"
#include "mongo/db/server_parameters.h"
#include "mongo/db/storage/storage_options.h"
+#include "mongo/logger/logger.h"
#include "mongo/logger/parse_log_component_settings.h"
#include "mongo/util/mongoutils/str.h"
#include "mongo/util/net/ssl_manager.h"
diff --git a/src/mongo/db/concurrency/lock_state.cpp b/src/mongo/db/concurrency/lock_state.cpp
index a1da8b0075e..ff77d6021c3 100644
--- a/src/mongo/db/concurrency/lock_state.cpp
+++ b/src/mongo/db/concurrency/lock_state.cpp
@@ -228,7 +228,9 @@ void CondVarLockGrantNotification::clear() {
LockResult CondVarLockGrantNotification::wait(unsigned timeoutMs) {
stdx::unique_lock<stdx::mutex> lock(_mutex);
while (_result == LOCK_INVALID) {
- if (stdx::cv_status::timeout == _cond.wait_for(lock, Milliseconds(timeoutMs))) {
+ if (stdx::cv_status::timeout ==
+ _cond.wait_for(lock,
+ Milliseconds(static_cast<int64_t>(timeoutMs)).toSystemDuration())) {
// Timeout
return LOCK_TIMEOUT;
}
diff --git a/src/mongo/db/exec/and_hash.h b/src/mongo/db/exec/and_hash.h
index ba57866ac28..b984f390590 100644
--- a/src/mongo/db/exec/and_hash.h
+++ b/src/mongo/db/exec/and_hash.h
@@ -34,6 +34,7 @@
#include "mongo/db/exec/plan_stage.h"
#include "mongo/db/matcher/expression.h"
#include "mongo/db/record_id.h"
+#include "mongo/platform/unordered_map.h"
#include "mongo/platform/unordered_set.h"
namespace mongo {
diff --git a/src/mongo/db/ftdc/config.h b/src/mongo/db/ftdc/config.h
index ef7ee8b9143..08e9be0b6df 100644
--- a/src/mongo/db/ftdc/config.h
+++ b/src/mongo/db/ftdc/config.h
@@ -85,7 +85,7 @@ struct FTDCConfig {
static const bool kEnabledDefault = true;
- static const std::uint64_t kPeriodMillisDefault;
+ static const std::int64_t kPeriodMillisDefault;
static const std::uint64_t kMaxDirectorySizeBytesDefault = 100 * 1024 * 1024;
static const std::uint64_t kMaxFileSizeBytesDefault = 10 * 1024 * 1024;
diff --git a/src/mongo/db/ftdc/ftdc_mongod.cpp b/src/mongo/db/ftdc/ftdc_mongod.cpp
index e328dbd3dff..73813248b45 100644
--- a/src/mongo/db/ftdc/ftdc_mongod.cpp
+++ b/src/mongo/db/ftdc/ftdc_mongod.cpp
@@ -299,7 +299,7 @@ void startFTDC() {
FTDCConfig config;
- config.period = Milliseconds(localPeriodMillis);
+ config.period = Milliseconds(localPeriodMillis.load());
config.enabled = localEnabledFlag;
config.maxFileSizeBytes = localMaxFileSizeMB * 1024 * 1024;
config.maxDirectorySizeBytes = localMaxDirectorySizeMB * 1024 * 1024;
diff --git a/src/mongo/db/ftdc/util.cpp b/src/mongo/db/ftdc/util.cpp
index 0cc96d35a50..ea87e6b58e5 100644
--- a/src/mongo/db/ftdc/util.cpp
+++ b/src/mongo/db/ftdc/util.cpp
@@ -63,7 +63,7 @@ const char kFTDCDocsField[] = "docs";
const char kFTDCCollectStartField[] = "start";
const char kFTDCCollectEndField[] = "end";
-const std::uint64_t FTDCConfig::kPeriodMillisDefault = 1000;
+const std::int64_t FTDCConfig::kPeriodMillisDefault = 1000;
const std::size_t kMaxRecursion = 10;
diff --git a/src/mongo/db/hasher.h b/src/mongo/db/hasher.h
index fd634b69ba5..15fd27d2696 100644
--- a/src/mongo/db/hasher.h
+++ b/src/mongo/db/hasher.h
@@ -34,8 +34,7 @@
#pragma once
-#include "mongo/platform/basic.h"
-
+#include "mongo/base/disallow_copying.h"
#include "mongo/bson/bsonelement.h"
#include "mongo/util/md5.hpp"
diff --git a/src/mongo/db/pipeline/document_source_out.cpp b/src/mongo/db/pipeline/document_source_out.cpp
index 8a8863486a0..148f7f4fc7e 100644
--- a/src/mongo/db/pipeline/document_source_out.cpp
+++ b/src/mongo/db/pipeline/document_source_out.cpp
@@ -29,6 +29,7 @@
#include "mongo/platform/basic.h"
#include "mongo/db/pipeline/document_source.h"
+#include "mongo/util/destructor_guard.h"
namespace mongo {
diff --git a/src/mongo/db/pipeline/field_path.h b/src/mongo/db/pipeline/field_path.h
index 84dca905fdb..6cec754815c 100644
--- a/src/mongo/db/pipeline/field_path.h
+++ b/src/mongo/db/pipeline/field_path.h
@@ -28,7 +28,10 @@
#pragma once
-#include "mongo/platform/basic.h"
+#include <iosfwd>
+#include <string>
+#include <vector>
+
#include "mongo/util/assert_util.h"
namespace mongo {
diff --git a/src/mongo/db/query/plan_enumerator.h b/src/mongo/db/query/plan_enumerator.h
index 20994eedba7..a74889fce64 100644
--- a/src/mongo/db/query/plan_enumerator.h
+++ b/src/mongo/db/query/plan_enumerator.h
@@ -36,6 +36,7 @@
#include "mongo/db/query/index_entry.h"
#include "mongo/db/query/index_tag.h"
#include "mongo/db/query/query_knobs.h"
+#include "mongo/platform/unordered_map.h"
namespace mongo {
diff --git a/src/mongo/db/query/plan_yield_policy.cpp b/src/mongo/db/query/plan_yield_policy.cpp
index 575ebf664b8..76705aafb93 100644
--- a/src/mongo/db/query/plan_yield_policy.cpp
+++ b/src/mongo/db/query/plan_yield_policy.cpp
@@ -46,15 +46,16 @@ PlanYieldPolicy::PlanYieldPolicy(PlanExecutor* exec, PlanExecutor::YieldPolicy p
_forceYield(false),
_elapsedTracker(exec->getOpCtx()->getServiceContext()->getFastClockSource(),
internalQueryExecYieldIterations,
- Milliseconds(internalQueryExecYieldPeriodMS)),
+ Milliseconds(internalQueryExecYieldPeriodMS.load())),
_planYielding(exec) {}
PlanYieldPolicy::PlanYieldPolicy(PlanExecutor::YieldPolicy policy, ClockSource* cs)
: _policy(policy),
_forceYield(false),
- _elapsedTracker(
- cs, internalQueryExecYieldIterations, Milliseconds(internalQueryExecYieldPeriodMS)),
+ _elapsedTracker(cs,
+ internalQueryExecYieldIterations,
+ Milliseconds(internalQueryExecYieldPeriodMS.load())),
_planYielding(nullptr) {}
bool PlanYieldPolicy::shouldYield() {
diff --git a/src/mongo/db/range_deleter.cpp b/src/mongo/db/range_deleter.cpp
index 2d9e9c04bd5..8d05a926991 100644
--- a/src/mongo/db/range_deleter.cpp
+++ b/src/mongo/db/range_deleter.cpp
@@ -423,7 +423,8 @@ void RangeDeleter::doWork() {
{
stdx::unique_lock<stdx::mutex> sl(_queueMutex);
while (_taskQueue.empty()) {
- _taskQueueNotEmptyCV.wait_for(sl, Milliseconds(kNotEmptyTimeoutMillis));
+ _taskQueueNotEmptyCV.wait_for(
+ sl, Milliseconds(kNotEmptyTimeoutMillis).toSystemDuration());
if (stopRequested()) {
log() << "stopping range deleter worker" << endl;
diff --git a/src/mongo/db/range_deleter_test.cpp b/src/mongo/db/range_deleter_test.cpp
index 240925c1c2f..a2fc38dc6c6 100644
--- a/src/mongo/db/range_deleter_test.cpp
+++ b/src/mongo/db/range_deleter_test.cpp
@@ -199,7 +199,8 @@ TEST(ImmediateDelete, ShouldWaitCursor) {
env->addCursorId(ns, 200);
env->removeCursorId(ns, 345);
- ASSERT_TRUE(stdx::future_status::ready == deleterFuture.wait_for(MAX_IMMEDIATE_DELETE_WAIT));
+ ASSERT_TRUE(stdx::future_status::ready ==
+ deleterFuture.wait_for(MAX_IMMEDIATE_DELETE_WAIT.toSystemDuration()));
ASSERT_TRUE(deleterFuture.get());
ASSERT_TRUE(env->deleteOccured());
@@ -250,7 +251,8 @@ TEST(ImmediateDelete, StopWhileWaitingCursor) {
stop_deleter_guard.Execute();
- ASSERT_TRUE(stdx::future_status::ready == deleterFuture.wait_for(MAX_IMMEDIATE_DELETE_WAIT));
+ ASSERT_TRUE(stdx::future_status::ready ==
+ deleterFuture.wait_for(MAX_IMMEDIATE_DELETE_WAIT.toSystemDuration()));
ASSERT_FALSE(deleterFuture.get());
ASSERT_FALSE(env->deleteOccured());
}
diff --git a/src/mongo/db/repl/applier.cpp b/src/mongo/db/repl/applier.cpp
index ef7e37debde..4eda40c6ab1 100644
--- a/src/mongo/db/repl/applier.cpp
+++ b/src/mongo/db/repl/applier.cpp
@@ -35,6 +35,7 @@
#include "mongo/db/operation_context.h"
#include "mongo/db/repl/replication_executor.h"
#include "mongo/util/assert_util.h"
+#include "mongo/util/destructor_guard.h"
#include "mongo/util/mongoutils/str.h"
namespace mongo {
diff --git a/src/mongo/db/repl/collection_cloner.cpp b/src/mongo/db/repl/collection_cloner.cpp
index 1f71fe762e7..95c2fd66baf 100644
--- a/src/mongo/db/repl/collection_cloner.cpp
+++ b/src/mongo/db/repl/collection_cloner.cpp
@@ -33,6 +33,7 @@
#include "mongo/db/repl/collection_cloner.h"
#include "mongo/util/assert_util.h"
+#include "mongo/util/destructor_guard.h"
#include "mongo/util/log.h"
#include "mongo/util/mongoutils/str.h"
diff --git a/src/mongo/db/repl/data_replicator.cpp b/src/mongo/db/repl/data_replicator.cpp
index b8f2d7f3a3a..c72427f3d40 100644
--- a/src/mongo/db/repl/data_replicator.cpp
+++ b/src/mongo/db/repl/data_replicator.cpp
@@ -52,6 +52,7 @@
#include "mongo/stdx/memory.h"
#include "mongo/stdx/thread.h"
#include "mongo/util/assert_util.h"
+#include "mongo/util/destructor_guard.h"
#include "mongo/util/fail_point_service.h"
#include "mongo/util/log.h"
#include "mongo/util/mongoutils/str.h"
diff --git a/src/mongo/db/repl/database_cloner.cpp b/src/mongo/db/repl/database_cloner.cpp
index b0c0bddcd01..da4d3c33887 100644
--- a/src/mongo/db/repl/database_cloner.cpp
+++ b/src/mongo/db/repl/database_cloner.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/catalog/collection_options.h"
#include "mongo/stdx/functional.h"
#include "mongo/util/assert_util.h"
+#include "mongo/util/destructor_guard.h"
#include "mongo/util/log.h"
#include "mongo/util/mongoutils/str.h"
diff --git a/src/mongo/db/repl/multiapplier.cpp b/src/mongo/db/repl/multiapplier.cpp
index 8db87b5e1f5..0fe05fa48bb 100644
--- a/src/mongo/db/repl/multiapplier.cpp
+++ b/src/mongo/db/repl/multiapplier.cpp
@@ -37,6 +37,7 @@
#include "mongo/db/operation_context.h"
#include "mongo/db/repl/optime.h"
#include "mongo/db/repl/replication_executor.h"
+#include "mongo/util/destructor_guard.h"
namespace mongo {
namespace repl {
diff --git a/src/mongo/db/repl/oplog_fetcher.cpp b/src/mongo/db/repl/oplog_fetcher.cpp
index fcb41bdca51..1655a717210 100644
--- a/src/mongo/db/repl/oplog_fetcher.cpp
+++ b/src/mongo/db/repl/oplog_fetcher.cpp
@@ -53,8 +53,10 @@ Milliseconds calculateAwaitDataTimeout(const ReplicaSetConfig& config) {
// Under protocol version 1, make the awaitData timeout (maxTimeMS) dependent on the election
// timeout. This enables the sync source to communicate liveness of the primary to secondaries.
// Under protocol version 0, use a default timeout of 2 seconds for awaitData.
- return config.getProtocolVersion() == 1LL ? config.getElectionTimeoutPeriod() / 2
- : OplogFetcher::kDefaultProtocolZeroAwaitDataTimeout;
+ if (config.getProtocolVersion() == 1LL) {
+ return config.getElectionTimeoutPeriod() / 2;
+ }
+ return OplogFetcher::kDefaultProtocolZeroAwaitDataTimeout;
}
/**
diff --git a/src/mongo/db/repl/oplogreader.cpp b/src/mongo/db/repl/oplogreader.cpp
index e1823bad682..e9e7b79c261 100644
--- a/src/mongo/db/repl/oplogreader.cpp
+++ b/src/mongo/db/repl/oplogreader.cpp
@@ -138,7 +138,8 @@ HostAndPort OplogReader::getHost() const {
void OplogReader::connectToSyncSource(OperationContext* txn,
const OpTime& lastOpTimeFetched,
ReplicationCoordinator* replCoord) {
- const Timestamp sentinelTimestamp(duration_cast<Seconds>(Milliseconds(curTimeMillis64())), 0);
+ const Timestamp sentinelTimestamp(duration_cast<Seconds>(Date_t::now().toDurationSinceEpoch()),
+ 0);
const OpTime sentinel(sentinelTimestamp, std::numeric_limits<long long>::max());
OpTime oldestOpTimeSeen = sentinel;
diff --git a/src/mongo/db/repl/replication_coordinator_external_state_mock.h b/src/mongo/db/repl/replication_coordinator_external_state_mock.h
index 311de9c5e58..77d883df480 100644
--- a/src/mongo/db/repl/replication_coordinator_external_state_mock.h
+++ b/src/mongo/db/repl/replication_coordinator_external_state_mock.h
@@ -38,6 +38,7 @@
#include "mongo/db/repl/last_vote.h"
#include "mongo/db/repl/replication_coordinator_external_state.h"
#include "mongo/stdx/condition_variable.h"
+#include "mongo/stdx/mutex.h"
#include "mongo/stdx/thread.h"
#include "mongo/util/net/hostandport.h"
diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp
index 36e0ea67444..f086e293cfa 100644
--- a/src/mongo/db/repl/replication_coordinator_impl.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl.cpp
@@ -604,7 +604,7 @@ Status ReplicationCoordinatorImpl::waitForMemberState(MemberState expectedState,
stdx::unique_lock<stdx::mutex> lk(_mutex);
auto pred = [this, expectedState]() { return _memberState == expectedState; };
- if (!_memberStateChange.wait_for(lk, timeout, pred)) {
+ if (!_memberStateChange.wait_for(lk, timeout.toSystemDuration(), pred)) {
return Status(ErrorCodes::ExceededTimeLimit,
str::stream() << "Timed out waiting for state to become "
<< expectedState.toString() << ". Current state is "
@@ -779,7 +779,7 @@ Status ReplicationCoordinatorImpl::waitForDrainFinish(Milliseconds timeout) {
stdx::unique_lock<stdx::mutex> lk(_mutex);
auto pred = [this]() { return !_isWaitingForDrainToComplete; };
- if (!_drainFinishedCond.wait_for(lk, timeout, pred)) {
+ if (!_drainFinishedCond.wait_for(lk, timeout.toSystemDuration(), pred)) {
return Status(ErrorCodes::ExceededTimeLimit,
"Timed out waiting to finish draining applier buffer");
}
@@ -1096,13 +1096,13 @@ ReadConcernResponse ReplicationCoordinatorImpl::waitUntilOpTime(OperationContext
if (isMajorityReadConcern) {
// Wait for a snapshot that meets our needs (< targetOpTime).
const auto waitTime = CurOp::get(txn)->isMaxTimeSet()
- ? Microseconds(txn->getRemainingMaxTimeMicros())
+ ? Microseconds(static_cast<int64_t>(txn->getRemainingMaxTimeMicros()))
: Microseconds{0};
const auto waitForever = waitTime == Microseconds{0};
LOG(2) << "waitUntilOpTime: waiting for a new snapshot to occur for micros: "
<< waitTime;
if (!waitForever) {
- _currentCommittedSnapshotCond.wait_for(lock, waitTime);
+ _currentCommittedSnapshotCond.wait_for(lock, waitTime.toSystemDuration());
} else {
_currentCommittedSnapshotCond.wait(lock);
}
@@ -1117,7 +1117,9 @@ ReadConcernResponse ReplicationCoordinatorImpl::waitUntilOpTime(OperationContext
LOG(3) << "Waiting for OpTime: " << waitInfo;
if (CurOp::get(txn)->isMaxTimeSet()) {
- condVar.wait_for(lock, Microseconds(txn->getRemainingMaxTimeMicros()));
+ condVar.wait_for(lock,
+ Microseconds(static_cast<int64_t>(txn->getRemainingMaxTimeMicros()))
+ .toSystemDuration());
} else {
condVar.wait(lock);
}
@@ -1543,7 +1545,8 @@ ReplicationCoordinator::StatusAndDuration ReplicationCoordinatorImpl::_awaitRepl
Status(ErrorCodes::ShutdownInProgress, "Replication is being shut down"), elapsed);
}
- const Microseconds maxTimeMicrosRemaining{txn->getRemainingMaxTimeMicros()};
+ const Microseconds maxTimeMicrosRemaining{
+ static_cast<int64_t>(txn->getRemainingMaxTimeMicros())};
Microseconds waitTime = Microseconds::max();
if (maxTimeMicrosRemaining != Microseconds::zero()) {
waitTime = maxTimeMicrosRemaining;
@@ -1557,7 +1560,7 @@ ReplicationCoordinator::StatusAndDuration ReplicationCoordinatorImpl::_awaitRepl
if (waitForever) {
condVar.wait(*lock);
} else {
- condVar.wait_for(*lock, waitTime);
+ condVar.wait_for(*lock, waitTime.toSystemDuration());
}
}
@@ -2937,7 +2940,8 @@ bool ReplicationCoordinatorImpl::shouldChangeSyncSource(const HostAndPort& curre
SyncSourceResolverResponse ReplicationCoordinatorImpl::selectSyncSource(
OperationContext* txn, const OpTime& lastOpTimeFetched) {
- const Timestamp sentinelTimestamp(duration_cast<Seconds>(Milliseconds(curTimeMillis64())), 0);
+ const Timestamp sentinelTimestamp(duration_cast<Seconds>(Date_t::now().toDurationSinceEpoch()),
+ 0);
const OpTime sentinel(sentinelTimestamp, std::numeric_limits<long long>::max());
OpTime earliestOpTimeSeen = sentinel;
SyncSourceResolverResponse resp;
@@ -3336,11 +3340,11 @@ void ReplicationCoordinatorImpl::waitUntilSnapshotCommitted(OperationContext* tx
stdx::unique_lock<stdx::mutex> lock(_mutex);
while (!_currentCommittedSnapshot || _currentCommittedSnapshot->name < untilSnapshot) {
- Microseconds waitTime(txn->getRemainingMaxTimeMicros());
+ Microseconds waitTime(static_cast<int64_t>(txn->getRemainingMaxTimeMicros()));
if (waitTime == Microseconds(0)) {
_currentCommittedSnapshotCond.wait(lock);
} else {
- _currentCommittedSnapshotCond.wait_for(lock, waitTime);
+ _currentCommittedSnapshotCond.wait_for(lock, waitTime.toSystemDuration());
}
txn->checkForInterrupt();
}
diff --git a/src/mongo/db/repl/reporter.cpp b/src/mongo/db/repl/reporter.cpp
index b9e9d9cb8e8..f7f0dca3873 100644
--- a/src/mongo/db/repl/reporter.cpp
+++ b/src/mongo/db/repl/reporter.cpp
@@ -37,6 +37,7 @@
#include "mongo/db/repl/update_position_args.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/util/assert_util.h"
+#include "mongo/util/destructor_guard.h"
#include "mongo/util/log.h"
namespace mongo {
diff --git a/src/mongo/db/repl/sync_source_feedback.cpp b/src/mongo/db/repl/sync_source_feedback.cpp
index 136978df15b..411b3fb0133 100644
--- a/src/mongo/db/repl/sync_source_feedback.cpp
+++ b/src/mongo/db/repl/sync_source_feedback.cpp
@@ -191,7 +191,8 @@ void SyncSourceFeedback::run() {
// this class.
stdx::unique_lock<stdx::mutex> lock(_mtx);
while (!_positionChanged && !_shutdownSignaled) {
- if (_cond.wait_for(lock, keepAliveInterval) == stdx::cv_status::timeout) {
+ if (_cond.wait_for(lock, keepAliveInterval.toSystemDuration()) ==
+ stdx::cv_status::timeout) {
MemberState state = ReplicationCoordinator::get(txn.get())->getMemberState();
if (!(state.primary() || state.startup())) {
break;
diff --git a/src/mongo/db/repl/sync_source_resolver.h b/src/mongo/db/repl/sync_source_resolver.h
index be46c78c3b1..fd098374882 100644
--- a/src/mongo/db/repl/sync_source_resolver.h
+++ b/src/mongo/db/repl/sync_source_resolver.h
@@ -30,6 +30,7 @@
#include "mongo/base/status_with.h"
#include "mongo/db/repl/optime.h"
+#include "mongo/stdx/mutex.h"
#include "mongo/util/net/hostandport.h"
namespace mongo {
diff --git a/src/mongo/db/repl/sync_tail.cpp b/src/mongo/db/repl/sync_tail.cpp
index 1341b2c16e3..313da81150c 100644
--- a/src/mongo/db/repl/sync_tail.cpp
+++ b/src/mongo/db/repl/sync_tail.cpp
@@ -601,7 +601,7 @@ public:
if (_ops.empty()) {
// We intentionally don't care about whether this returns due to signaling or timeout
// since we do the same thing either way: return whatever is in _ops.
- (void)_cv.wait_for(lk, maxWaitTime);
+ (void)_cv.wait_for(lk, maxWaitTime.toSystemDuration());
}
OpQueue ops = std::move(_ops);
diff --git a/src/mongo/db/repl/task_runner.cpp b/src/mongo/db/repl/task_runner.cpp
index 37d05af51a6..1558e88929a 100644
--- a/src/mongo/db/repl/task_runner.cpp
+++ b/src/mongo/db/repl/task_runner.cpp
@@ -42,6 +42,7 @@
#include "mongo/util/assert_util.h"
#include "mongo/util/concurrency/old_thread_pool.h"
#include "mongo/util/concurrency/thread_name.h"
+#include "mongo/util/destructor_guard.h"
#include "mongo/util/mongoutils/str.h"
#include "mongo/util/log.h"
diff --git a/src/mongo/db/repl/topology_coordinator_impl.cpp b/src/mongo/db/repl/topology_coordinator_impl.cpp
index e2cf990a13f..45f8e6280ad 100644
--- a/src/mongo/db/repl/topology_coordinator_impl.cpp
+++ b/src/mongo/db/repl/topology_coordinator_impl.cpp
@@ -857,9 +857,9 @@ std::pair<ReplSetHeartbeatArgs, Milliseconds> TopologyCoordinatorImpl::prepareHe
hbArgs.setConfigVersion(-2);
}
- const Milliseconds timeoutPeriod(_rsConfig.isInitialized()
- ? _rsConfig.getHeartbeatTimeoutPeriodMillis()
- : ReplicaSetConfig::kDefaultHeartbeatTimeoutPeriod);
+ const Milliseconds timeoutPeriod(
+ _rsConfig.isInitialized() ? _rsConfig.getHeartbeatTimeoutPeriodMillis()
+ : Milliseconds{ReplicaSetConfig::kDefaultHeartbeatTimeoutPeriod});
const Milliseconds timeout = timeoutPeriod - alreadyElapsed;
return std::make_pair(hbArgs, timeout);
}
@@ -893,9 +893,9 @@ std::pair<ReplSetHeartbeatArgsV1, Milliseconds> TopologyCoordinatorImpl::prepare
hbArgs.setTerm(OpTime::kInitialTerm);
}
- const Milliseconds timeoutPeriod(_rsConfig.isInitialized()
- ? _rsConfig.getHeartbeatTimeoutPeriodMillis()
- : ReplicaSetConfig::kDefaultHeartbeatTimeoutPeriod);
+ const Milliseconds timeoutPeriod(
+ _rsConfig.isInitialized() ? _rsConfig.getHeartbeatTimeoutPeriodMillis()
+ : Milliseconds{ReplicaSetConfig::kDefaultHeartbeatTimeoutPeriod});
const Milliseconds timeout(timeoutPeriod - alreadyElapsed);
return std::make_pair(hbArgs, timeout);
}
diff --git a/src/mongo/db/repl/topology_coordinator_impl_test.cpp b/src/mongo/db/repl/topology_coordinator_impl_test.cpp
index b1ff5db42cf..b0e41018c32 100644
--- a/src/mongo/db/repl/topology_coordinator_impl_test.cpp
+++ b/src/mongo/db/repl/topology_coordinator_impl_test.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/repl/topology_coordinator.h"
#include "mongo/db/repl/topology_coordinator_impl.h"
#include "mongo/db/server_options.h"
+#include "mongo/logger/logger.h"
#include "mongo/s/catalog/catalog_manager.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/assert_util.h"
diff --git a/src/mongo/db/repl/topology_coordinator_impl_v1_test.cpp b/src/mongo/db/repl/topology_coordinator_impl_v1_test.cpp
index e68d84e9d6d..79d6f7e6727 100644
--- a/src/mongo/db/repl/topology_coordinator_impl_v1_test.cpp
+++ b/src/mongo/db/repl/topology_coordinator_impl_v1_test.cpp
@@ -40,6 +40,7 @@
#include "mongo/db/repl/topology_coordinator.h"
#include "mongo/db/repl/topology_coordinator_impl.h"
#include "mongo/db/server_options.h"
+#include "mongo/logger/logger.h"
#include "mongo/s/catalog/catalog_manager.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/assert_util.h"
diff --git a/src/mongo/db/s/collection_sharding_state.h b/src/mongo/db/s/collection_sharding_state.h
index 62d8358c998..449c8b4ba6b 100644
--- a/src/mongo/db/s/collection_sharding_state.h
+++ b/src/mongo/db/s/collection_sharding_state.h
@@ -28,6 +28,7 @@
#pragma once
+#include <memory>
#include <string>
#include "mongo/base/disallow_copying.h"
diff --git a/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp b/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp
index 31af3138035..79517b5b193 100644
--- a/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp
+++ b/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp
@@ -231,10 +231,10 @@ Status MigrationChunkClonerSourceLegacy::awaitUntilCriticalSectionIsAppropriate(
invariant(!txn->lockState()->isLocked());
auto scopedGuard = MakeGuard([&] { cancelClone(txn); });
- const Milliseconds startTime(curTimeMillis64());
+ const auto startTime = Date_t::now();
int iteration = 0;
- while ((Milliseconds(curTimeMillis64()) - startTime) < maxTimeToWait) {
+ while ((Date_t::now() - startTime) < maxTimeToWait) {
// Exponential sleep backoff, up to 1024ms. Don't sleep much on the first few iterations,
// since we want empty chunk migrations to be fast.
sleepmillis(1 << std::min(iteration, 10));
@@ -400,7 +400,7 @@ Status MigrationChunkClonerSourceLegacy::nextCloneBatch(OperationContext* txn,
ElapsedTracker tracker(txn->getServiceContext()->getFastClockSource(),
internalQueryExecYieldIterations,
- Milliseconds(internalQueryExecYieldPeriodMS));
+ Milliseconds(internalQueryExecYieldPeriodMS.load()));
stdx::lock_guard<stdx::mutex> sl(_mutex);
diff --git a/src/mongo/db/s/migration_destination_manager.cpp b/src/mongo/db/s/migration_destination_manager.cpp
index 9d8153e7a53..36592d6bd2e 100644
--- a/src/mongo/db/s/migration_destination_manager.cpp
+++ b/src/mongo/db/s/migration_destination_manager.cpp
@@ -326,10 +326,11 @@ bool MigrationDestinationManager::startCommit(const MigrationSessionId& sessionI
_state = COMMIT_START;
- const auto deadline = stdx::chrono::system_clock::now() + Seconds(30);
+ const auto deadline = Date_t::now() + Seconds(30);
while (_sessionId) {
- if (stdx::cv_status::timeout == _isActiveCV.wait_until(lock, deadline)) {
+ if (stdx::cv_status::timeout ==
+ _isActiveCV.wait_until(lock, deadline.toSystemTimePoint())) {
_state = FAIL;
log() << "startCommit never finished!" << migrateLog;
return false;
diff --git a/src/mongo/db/s/migration_source_manager.cpp b/src/mongo/db/s/migration_source_manager.cpp
index 242201ed57d..6c097090960 100644
--- a/src/mongo/db/s/migration_source_manager.cpp
+++ b/src/mongo/db/s/migration_source_manager.cpp
@@ -453,11 +453,12 @@ MigrationSourceManager::CriticalSectionState::CriticalSectionState() = default;
bool MigrationSourceManager::CriticalSectionState::waitUntilOutOfCriticalSection(
Microseconds waitTimeout) {
- const auto waitDeadline = stdx::chrono::system_clock::now() + waitTimeout;
+ const auto waitDeadline = Date_t::now() + waitTimeout;
stdx::unique_lock<stdx::mutex> sl(_criticalSectionMutex);
while (_inCriticalSection) {
- if (stdx::cv_status::timeout == _criticalSectionCV.wait_until(sl, waitDeadline)) {
+ if (stdx::cv_status::timeout ==
+ _criticalSectionCV.wait_until(sl, waitDeadline.toSystemTimePoint())) {
return false;
}
}
diff --git a/src/mongo/db/s/operation_sharding_state.cpp b/src/mongo/db/s/operation_sharding_state.cpp
index 40617c08138..01a0132df07 100644
--- a/src/mongo/db/s/operation_sharding_state.cpp
+++ b/src/mongo/db/s/operation_sharding_state.cpp
@@ -101,11 +101,12 @@ bool OperationShardingState::waitForMigrationCriticalSection(OperationContext* t
invariant(!txn->lockState()->isLocked());
if (_migrationCriticalSection) {
- const Microseconds operationRemainingTime(Microseconds(txn->getRemainingMaxTimeMicros()));
+ const Microseconds operationRemainingTime(
+ Microseconds(static_cast<int64_t>(txn->getRemainingMaxTimeMicros())));
_migrationCriticalSection->waitUntilOutOfCriticalSection(
durationCount<Microseconds>(operationRemainingTime)
? operationRemainingTime
- : kMaxWaitForMigrationCriticalSection);
+ : Microseconds{kMaxWaitForMigrationCriticalSection});
_migrationCriticalSection = nullptr;
return true;
}
diff --git a/src/mongo/db/s/sharding_state.cpp b/src/mongo/db/s/sharding_state.cpp
index 16061c2cf9b..85c8916b4d0 100644
--- a/src/mongo/db/s/sharding_state.cpp
+++ b/src/mongo/db/s/sharding_state.cpp
@@ -133,7 +133,7 @@ Date_t getDeadlineFromMaxTimeMS(OperationContext* txn) {
return Date_t::now();
}
- return Date_t::now() + Microseconds(remainingTime);
+ return Date_t::now() + Microseconds(static_cast<int64_t>(remainingTime));
}
/**
diff --git a/src/mongo/db/service_context.h b/src/mongo/db/service_context.h
index cd9d0de93b8..1cba9bdb05d 100644
--- a/src/mongo/db/service_context.h
+++ b/src/mongo/db/service_context.h
@@ -35,6 +35,7 @@
#include "mongo/db/storage/storage_engine.h"
#include "mongo/platform/unordered_set.h"
#include "mongo/stdx/functional.h"
+#include "mongo/stdx/mutex.h"
#include "mongo/util/clock_source.h"
#include "mongo/util/decorable.h"
#include "mongo/util/tick_source.h"
diff --git a/src/mongo/db/sorter/sorter.cpp b/src/mongo/db/sorter/sorter.cpp
index 9193c64f8c9..fda8ee146ed 100644
--- a/src/mongo/db/sorter/sorter.cpp
+++ b/src/mongo/db/sorter/sorter.cpp
@@ -61,6 +61,7 @@
#include "mongo/s/mongos_options.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/bufreader.h"
+#include "mongo/util/destructor_guard.h"
#include "mongo/util/mongoutils/str.h"
#include "mongo/util/print.h"
#include "mongo/util/unowned_ptr.h"
diff --git a/src/mongo/db/sorter/sorter.h b/src/mongo/db/sorter/sorter.h
index 5d19aef8c2d..ba6f3e3192f 100644
--- a/src/mongo/db/sorter/sorter.h
+++ b/src/mongo/db/sorter/sorter.h
@@ -30,6 +30,7 @@
#include <deque>
#include <fstream>
+#include <memory>
#include <string>
#include <utility>
#include <vector>
diff --git a/src/mongo/db/stats/snapshots.h b/src/mongo/db/stats/snapshots.h
index 32ac1c6efbb..5013275265b 100644
--- a/src/mongo/db/stats/snapshots.h
+++ b/src/mongo/db/stats/snapshots.h
@@ -33,7 +33,7 @@
#include "mongo/base/status_with.h"
#include "mongo/db/jsobj.h"
#include "mongo/db/stats/top.h"
-#include "mongo/platform/basic.h"
+#include "mongo/stdx/mutex.h"
#include "mongo/util/background.h"
/**
diff --git a/src/mongo/db/storage/mmap_v1/dur.cpp b/src/mongo/db/storage/mmap_v1/dur.cpp
index d7037b87b19..db74bd99ea8 100644
--- a/src/mongo/db/storage/mmap_v1/dur.cpp
+++ b/src/mongo/db/storage/mmap_v1/dur.cpp
@@ -687,7 +687,7 @@ static void durThread(ClockSource* cs, int64_t serverStartMs) {
}
// +1 so it never goes down to zero
- const unsigned oneThird = (ms / 3) + 1;
+ const int64_t oneThird = (ms / 3) + 1;
// Reset the stats based on the reset interval
if (stats.curr()->getCurrentDurationMillis() > DurStatsResetIntervalMillis) {
@@ -699,7 +699,7 @@ static void durThread(ClockSource* cs, int64_t serverStartMs) {
for (unsigned i = 0; i <= 2; i++) {
if (stdx::cv_status::no_timeout ==
- flushRequested.wait_for(lock, Milliseconds(oneThird))) {
+ flushRequested.wait_for(lock, Milliseconds(oneThird).toSystemDuration())) {
// Someone forced a flush
break;
}
diff --git a/src/mongo/db/storage/mmap_v1/dur_journalimpl.h b/src/mongo/db/storage/mmap_v1/dur_journalimpl.h
index 5a7a6a63e7f..9a4d22fa826 100644
--- a/src/mongo/db/storage/mmap_v1/dur_journalimpl.h
+++ b/src/mongo/db/storage/mmap_v1/dur_journalimpl.h
@@ -36,6 +36,7 @@
#include "mongo/db/storage/mmap_v1/dur_journalformat.h"
#include "mongo/db/storage/mmap_v1/logfile.h"
#include "mongo/platform/atomic_word.h"
+#include "mongo/stdx/mutex.h"
#include "mongo/util/concurrency/mutex.h"
namespace mongo {
diff --git a/src/mongo/db/storage/mmap_v1/dur_recover.cpp b/src/mongo/db/storage/mmap_v1/dur_recover.cpp
index 69e700bc187..dfd429d0713 100644
--- a/src/mongo/db/storage/mmap_v1/dur_recover.cpp
+++ b/src/mongo/db/storage/mmap_v1/dur_recover.cpp
@@ -53,6 +53,7 @@
#include "mongo/platform/strnlen.h"
#include "mongo/util/bufreader.h"
#include "mongo/util/checksum.h"
+#include "mongo/util/destructor_guard.h"
#include "mongo/util/exit.h"
#include "mongo/util/hex.h"
#include "mongo/util/log.h"
diff --git a/src/mongo/db/storage/mmap_v1/dur_recover.h b/src/mongo/db/storage/mmap_v1/dur_recover.h
index 39925f9063f..b9b7c5ddfdb 100644
--- a/src/mongo/db/storage/mmap_v1/dur_recover.h
+++ b/src/mongo/db/storage/mmap_v1/dur_recover.h
@@ -32,8 +32,10 @@
#include <boost/filesystem/operations.hpp>
#include <list>
+#include <memory>
#include "mongo/db/storage/mmap_v1/dur_journalformat.h"
+#include "mongo/stdx/mutex.h"
#include "mongo/util/concurrency/mutex.h"
namespace mongo {
diff --git a/src/mongo/db/storage/mmap_v1/file_allocator.h b/src/mongo/db/storage/mmap_v1/file_allocator.h
index e3e4ad55881..988277dfe6d 100644
--- a/src/mongo/db/storage/mmap_v1/file_allocator.h
+++ b/src/mongo/db/storage/mmap_v1/file_allocator.h
@@ -27,12 +27,12 @@
* then also delete it in the license file.
*/
-#include "mongo/platform/basic.h"
-
-#include <list>
#include <boost/filesystem/path.hpp>
+#include <list>
+#include <map>
#include "mongo/stdx/condition_variable.h"
+#include "mongo/stdx/mutex.h"
#include "mongo/util/concurrency/mutex.h"
namespace mongo {
diff --git a/src/mongo/db/storage/mmap_v1/record_access_tracker.cpp b/src/mongo/db/storage/mmap_v1/record_access_tracker.cpp
index 22fa4cb2bce..535bc3fc447 100644
--- a/src/mongo/db/storage/mmap_v1/record_access_tracker.cpp
+++ b/src/mongo/db/storage/mmap_v1/record_access_tracker.cpp
@@ -231,7 +231,7 @@ bool RecordAccessTracker::Rolling::access(size_t region,
if (rarelyCount++ % (2048 / BigHashSize) == 0) {
Date_t now = cs->now();
- if (now - _lastRotate > Seconds(RotateTimeSecs)) {
+ if (now - _lastRotate > Seconds(static_cast<int64_t>(RotateTimeSecs))) {
_rotate(cs);
}
}
diff --git a/src/mongo/db/storage/mmap_v1/record_access_tracker.h b/src/mongo/db/storage/mmap_v1/record_access_tracker.h
index e88a6b280ae..c4ec579c720 100644
--- a/src/mongo/db/storage/mmap_v1/record_access_tracker.h
+++ b/src/mongo/db/storage/mmap_v1/record_access_tracker.h
@@ -28,8 +28,10 @@
#pragma once
+#include <memory>
#include "mongo/util/concurrency/mutex.h"
+#include "mongo/util/time_support.h"
namespace mongo {
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_options_init.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_options_init.cpp
index 589706daed4..2ad2b519ec2 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_options_init.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_options_init.cpp
@@ -28,12 +28,15 @@
* it in the license file.
*/
+#include "mongo/platform/basic.h"
+
#include "mongo/util/options_parser/startup_option_init.h"
#include <iostream>
-#include "mongo/util/options_parser/startup_options.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_global_options.h"
+#include "mongo/util/exit_code.h"
+#include "mongo/util/options_parser/startup_options.h"
namespace mongo {
diff --git a/src/mongo/dbtests/framework_options_init.cpp b/src/mongo/dbtests/framework_options_init.cpp
index d6f0771d5dc..7e3689ae5e9 100644
--- a/src/mongo/dbtests/framework_options_init.cpp
+++ b/src/mongo/dbtests/framework_options_init.cpp
@@ -33,6 +33,7 @@
#include "mongo/dbtests/framework_options.h"
#include "mongo/util/options_parser/startup_option_init.h"
#include "mongo/util/options_parser/startup_options.h"
+#include "mongo/util/exit_code.h"
#include "mongo/util/quick_exit.h"
namespace mongo {
diff --git a/src/mongo/executor/async_timer_asio.cpp b/src/mongo/executor/async_timer_asio.cpp
index 293ab3e137a..d8951d22d43 100644
--- a/src/mongo/executor/async_timer_asio.cpp
+++ b/src/mongo/executor/async_timer_asio.cpp
@@ -34,7 +34,7 @@ namespace mongo {
namespace executor {
AsyncTimerASIO::AsyncTimerASIO(asio::io_service::strand* strand, Milliseconds expiration)
- : _strand(strand), _timer(_strand->get_io_service(), expiration) {}
+ : _strand(strand), _timer(_strand->get_io_service(), expiration.toSystemDuration()) {}
void AsyncTimerASIO::cancel() {
_timer.cancel();
diff --git a/src/mongo/executor/connection_pool.cpp b/src/mongo/executor/connection_pool.cpp
index fb88bef8577..e6c0d150694 100644
--- a/src/mongo/executor/connection_pool.cpp
+++ b/src/mongo/executor/connection_pool.cpp
@@ -36,6 +36,7 @@
#include "mongo/executor/remote_command_request.h"
#include "mongo/stdx/memory.h"
#include "mongo/util/assert_util.h"
+#include "mongo/util/destructor_guard.h"
#include "mongo/util/log.h"
#include "mongo/util/scopeguard.h"
diff --git a/src/mongo/executor/connection_pool.h b/src/mongo/executor/connection_pool.h
index a5bcc1c3925..1ac0b7194ee 100644
--- a/src/mongo/executor/connection_pool.h
+++ b/src/mongo/executor/connection_pool.h
@@ -36,6 +36,7 @@
#include "mongo/stdx/functional.h"
#include "mongo/stdx/mutex.h"
#include "mongo/util/net/hostandport.h"
+#include "mongo/util/time_support.h"
namespace mongo {
diff --git a/src/mongo/executor/connection_pool_asio.cpp b/src/mongo/executor/connection_pool_asio.cpp
index e5ebcb2edc2..7be1874e7b3 100644
--- a/src/mongo/executor/connection_pool_asio.cpp
+++ b/src/mongo/executor/connection_pool_asio.cpp
@@ -59,7 +59,7 @@ void ASIOTimer::setTimeout(Milliseconds timeout, TimeoutCallback cb) {
_cb = std::move(cb);
cancelTimeout();
- _impl.expires_after(std::min(kMaxTimerDuration, timeout));
+ _impl.expires_after(std::min(kMaxTimerDuration, timeout).toSystemDuration());
decltype(_callbackSharedState->id) id;
decltype(_callbackSharedState) sharedState;
diff --git a/src/mongo/executor/network_interface_asio.cpp b/src/mongo/executor/network_interface_asio.cpp
index 4198fb8a0e3..ca54f813e37 100644
--- a/src/mongo/executor/network_interface_asio.cpp
+++ b/src/mongo/executor/network_interface_asio.cpp
@@ -189,7 +189,7 @@ void NetworkInterfaceASIO::waitForWorkUntil(Date_t when) {
if (waitTime <= Milliseconds(0)) {
break;
}
- _isExecutorRunnableCondition.wait_for(lk, waitTime);
+ _isExecutorRunnableCondition.wait_for(lk, waitTime.toSystemDuration());
}
_isExecutorRunnable = false;
}
diff --git a/src/mongo/executor/network_interface_thread_pool.cpp b/src/mongo/executor/network_interface_thread_pool.cpp
index d8ec2335fa3..b678a9486d1 100644
--- a/src/mongo/executor/network_interface_thread_pool.cpp
+++ b/src/mongo/executor/network_interface_thread_pool.cpp
@@ -33,6 +33,7 @@
#include "mongo/executor/network_interface_thread_pool.h"
#include "mongo/executor/network_interface.h"
+#include "mongo/util/destructor_guard.h"
#include "mongo/util/log.h"
#include "mongo/util/scopeguard.h"
diff --git a/src/mongo/executor/network_test_env.h b/src/mongo/executor/network_test_env.h
index 9fe53f07e2c..e83311b7bc4 100644
--- a/src/mongo/executor/network_test_env.h
+++ b/src/mongo/executor/network_test_env.h
@@ -38,6 +38,7 @@
#include "mongo/stdx/future.h"
#include "mongo/stdx/thread.h"
#include "mongo/unittest/unittest.h"
+#include "mongo/util/time_support.h"
namespace mongo {
@@ -99,6 +100,11 @@ public:
return _future.get();
}
+ template <class Period>
+ T timed_get(const Duration<Period>& timeout_duration) {
+ return timed_get(timeout_duration.toSystemDuration());
+ }
+
private:
stdx::future<T> _future;
executor::TaskExecutor* _executor;
diff --git a/src/mongo/logger/logstream_builder.h b/src/mongo/logger/logstream_builder.h
index a8a6890fe38..04e1583073c 100644
--- a/src/mongo/logger/logstream_builder.h
+++ b/src/mongo/logger/logstream_builder.h
@@ -183,12 +183,9 @@ public:
return *this;
}
- template <typename Rep, typename Period>
- LogstreamBuilder& operator<<(stdx::chrono::duration<Rep, Period> d) {
- // We can't rely on ADL to find our custom stream out class,
- // since neither the class (ostream) nor the argument are in
- // our namespace. Just manually invoke
- mongo::operator<<(stream(), d);
+ template <typename Period>
+ LogstreamBuilder& operator<<(const Duration<Period>& d) {
+ stream() << d;
return *this;
}
diff --git a/src/mongo/s/balancer/balancer.cpp b/src/mongo/s/balancer/balancer.cpp
index f92d3f615ef..203e3e5ce3d 100644
--- a/src/mongo/s/balancer/balancer.cpp
+++ b/src/mongo/s/balancer/balancer.cpp
@@ -179,7 +179,8 @@ Status executeSingleMigration(OperationContext* txn,
secondaryThrottle,
waitForDelete);
builder.append(LiteParsedQuery::cmdOptionMaxTimeMS,
- durationCount<Milliseconds>(Microseconds(txn->getRemainingMaxTimeMicros())));
+ durationCount<Milliseconds>(
+ Microseconds(static_cast<int64_t>(txn->getRemainingMaxTimeMicros()))));
BSONObj cmdObj = builder.obj();
diff --git a/src/mongo/s/catalog/dist_lock_manager.h b/src/mongo/s/catalog/dist_lock_manager.h
index f97b186e2de..23f815c63cc 100644
--- a/src/mongo/s/catalog/dist_lock_manager.h
+++ b/src/mongo/s/catalog/dist_lock_manager.h
@@ -28,6 +28,7 @@
#pragma once
+#include "mongo/base/disallow_copying.h"
#include "mongo/base/string_data.h"
#include "mongo/bson/oid.h"
#include "mongo/stdx/chrono.h"
diff --git a/src/mongo/s/catalog/replset/replset_dist_lock_manager.cpp b/src/mongo/s/catalog/replset/replset_dist_lock_manager.cpp
index a7b693fe5c4..8fcd79fc6cd 100644
--- a/src/mongo/s/catalog/replset/replset_dist_lock_manager.cpp
+++ b/src/mongo/s/catalog/replset/replset_dist_lock_manager.cpp
@@ -164,7 +164,7 @@ void ReplSetDistLockManager::doTask() {
}
stdx::unique_lock<stdx::mutex> lk(_mutex);
- _shutDownCV.wait_for(lk, _pingInterval);
+ _shutDownCV.wait_for(lk, _pingInterval.toSystemDuration());
}
}
diff --git a/src/mongo/s/catalog/replset/replset_dist_lock_manager_test.cpp b/src/mongo/s/catalog/replset/replset_dist_lock_manager_test.cpp
index a52aa8f1bc3..792bb3ca9d8 100644
--- a/src/mongo/s/catalog/replset/replset_dist_lock_manager_test.cpp
+++ b/src/mongo/s/catalog/replset/replset_dist_lock_manager_test.cpp
@@ -517,7 +517,8 @@ TEST_F(RSDistLockMgrWithMockTickSource, LockFailsAfterRetry) {
{
stdx::unique_lock<stdx::mutex> lk(unlockMutex);
if (unlockCallCount == 0) {
- didTimeout = unlockCV.wait_for(lk, kJoinTimeout) == stdx::cv_status::timeout;
+ didTimeout =
+ unlockCV.wait_for(lk, kJoinTimeout.toSystemDuration()) == stdx::cv_status::timeout;
}
}
@@ -660,7 +661,8 @@ TEST_F(ReplSetDistLockManagerFixture, MustUnlockOnLockError) {
{
stdx::unique_lock<stdx::mutex> lk(unlockMutex);
if (unlockCallCount == 0) {
- didTimeout = unlockCV.wait_for(lk, kJoinTimeout) == stdx::cv_status::timeout;
+ didTimeout =
+ unlockCV.wait_for(lk, kJoinTimeout.toSystemDuration()) == stdx::cv_status::timeout;
}
}
@@ -705,7 +707,8 @@ TEST_F(ReplSetDistLockManagerFixture, LockPinging) {
{
stdx::unique_lock<stdx::mutex> lk(testMutex);
if (processIDList.size() < 3) {
- didTimeout = ping3TimesCV.wait_for(lk, kJoinTimeout) == stdx::cv_status::timeout;
+ didTimeout = ping3TimesCV.wait_for(lk, kJoinTimeout.toSystemDuration()) ==
+ stdx::cv_status::timeout;
}
}
@@ -783,7 +786,8 @@ TEST_F(ReplSetDistLockManagerFixture, UnlockUntilNoError) {
{
stdx::unique_lock<stdx::mutex> lk(unlockMutex);
if (lockSessionIDPassed.size() < kUnlockErrorCount) {
- didTimeout = unlockCV.wait_for(lk, kJoinTimeout) == stdx::cv_status::timeout;
+ didTimeout =
+ unlockCV.wait_for(lk, kJoinTimeout.toSystemDuration()) == stdx::cv_status::timeout;
}
}
@@ -879,7 +883,8 @@ TEST_F(ReplSetDistLockManagerFixture, MultipleQueuedUnlock) {
stdx::unique_lock<stdx::mutex> lk(testMutex);
if (unlockIDMap.size() < 2 || !mapEntriesGreaterThanTwo(unlockIDMap)) {
- didTimeout = unlockCV.wait_for(lk, kJoinTimeout) == stdx::cv_status::timeout;
+ didTimeout =
+ unlockCV.wait_for(lk, kJoinTimeout.toSystemDuration()) == stdx::cv_status::timeout;
}
}
@@ -1747,7 +1752,8 @@ TEST_F(ReplSetDistLockManagerFixture, LockOvertakingResultsInError) {
{
stdx::unique_lock<stdx::mutex> lk(unlockMutex);
if (!unlockSessionIDPassed.isSet()) {
- didTimeout = unlockCV.wait_for(lk, kJoinTimeout) == stdx::cv_status::timeout;
+ didTimeout =
+ unlockCV.wait_for(lk, kJoinTimeout.toSystemDuration()) == stdx::cv_status::timeout;
}
}
diff --git a/src/mongo/s/client/shard_remote.cpp b/src/mongo/s/client/shard_remote.cpp
index 8f7322ef307..a5e21e9becd 100644
--- a/src/mongo/s/client/shard_remote.cpp
+++ b/src/mongo/s/client/shard_remote.cpp
@@ -66,7 +66,7 @@ namespace {
const Status kInternalErrorStatus{ErrorCodes::InternalError,
"Invalid to check for write concern error if command failed"};
-const Seconds kConfigCommandTimeout{30};
+const Milliseconds kConfigCommandTimeout = Seconds{30};
const BSONObj kNoMetadata(rpc::makeEmptyMetadata());
@@ -332,10 +332,10 @@ StatusWith<Shard::QueryResponse> ShardRemote::_exhaustiveFindOnConfig(
BSONObjBuilder findCmdBuilder;
lpq->asFindCommand(&findCmdBuilder);
- Seconds maxTime = kConfigCommandTimeout;
- Microseconds remainingTxnMaxTime(txn->getRemainingMaxTimeMicros());
+ Milliseconds maxTime = kConfigCommandTimeout;
+ Microseconds remainingTxnMaxTime(static_cast<int64_t>(txn->getRemainingMaxTimeMicros()));
if (remainingTxnMaxTime != Microseconds::zero()) {
- maxTime = duration_cast<Seconds>(remainingTxnMaxTime);
+ maxTime = duration_cast<Milliseconds>(remainingTxnMaxTime);
}
findCmdBuilder.append(LiteParsedQuery::cmdOptionMaxTimeMS,
diff --git a/src/mongo/s/grid.h b/src/mongo/s/grid.h
index a990143a4c1..3059ce733b4 100644
--- a/src/mongo/s/grid.h
+++ b/src/mongo/s/grid.h
@@ -31,6 +31,7 @@
#include <memory>
#include "mongo/db/repl/optime.h"
+#include "mongo/stdx/mutex.h"
namespace mongo {
diff --git a/src/mongo/s/mongos_options_init.cpp b/src/mongo/s/mongos_options_init.cpp
index 85528114de4..d26bdb039f7 100644
--- a/src/mongo/s/mongos_options_init.cpp
+++ b/src/mongo/s/mongos_options_init.cpp
@@ -32,6 +32,7 @@
#include "mongo/util/options_parser/startup_option_init.h"
#include "mongo/util/options_parser/startup_options.h"
+#include "mongo/util/exit_code.h"
#include "mongo/util/quick_exit.h"
namespace mongo {
diff --git a/src/mongo/s/query/cluster_cursor_cleanup_job.cpp b/src/mongo/s/query/cluster_cursor_cleanup_job.cpp
index cdc7f2f0972..a7e4159c9b5 100644
--- a/src/mongo/s/query/cluster_cursor_cleanup_job.cpp
+++ b/src/mongo/s/query/cluster_cursor_cleanup_job.cpp
@@ -65,7 +65,8 @@ void ClusterCursorCleanupJob::run() {
invariant(manager);
while (!inShutdown()) {
- manager->killMortalCursorsInactiveSince(Date_t::now() - Milliseconds(cursorTimeoutMillis));
+ manager->killMortalCursorsInactiveSince(Date_t::now() -
+ Milliseconds(cursorTimeoutMillis.load()));
manager->reapZombieCursors();
sleepFor(Seconds(4));
}
diff --git a/src/mongo/scripting/deadline_monitor.h b/src/mongo/scripting/deadline_monitor.h
index 89f7e9d1b84..d3c30f4b2e8 100644
--- a/src/mongo/scripting/deadline_monitor.h
+++ b/src/mongo/scripting/deadline_monitor.h
@@ -32,6 +32,7 @@
#include "mongo/base/disallow_copying.h"
#include "mongo/platform/unordered_map.h"
#include "mongo/stdx/condition_variable.h"
+#include "mongo/stdx/mutex.h"
#include "mongo/stdx/thread.h"
#include "mongo/util/concurrency/mutex.h"
#include "mongo/util/time_support.h"
@@ -91,7 +92,7 @@ public:
* @param task the task to kill()
* @param timeoutMs number of milliseconds before the deadline expires
*/
- void startDeadline(_Task* const task, uint64_t timeoutMs) {
+ void startDeadline(_Task* const task, int64_t timeoutMs) {
const auto deadline = Date_t::now() + Milliseconds(timeoutMs);
stdx::lock_guard<stdx::mutex> lk(_deadlineMutex);
diff --git a/src/mongo/scripting/mozjs/PosixNSPR.cpp b/src/mongo/scripting/mozjs/PosixNSPR.cpp
index 9800990ac04..ed1a3d5a49d 100644
--- a/src/mongo/scripting/mozjs/PosixNSPR.cpp
+++ b/src/mongo/scripting/mozjs/PosixNSPR.cpp
@@ -276,7 +276,7 @@ PRStatus PR_WaitCondVar(PRCondVar* cvar, uint32_t timeout) {
mongo::stdx::unique_lock<mongo::stdx::mutex> lk(cvar->lock()->mutex(),
mongo::stdx::adopt_lock_t());
- cvar->cond().wait_for(lk, mongo::Microseconds(timeout));
+ cvar->cond().wait_for(lk, mongo::Microseconds(timeout).toSystemDuration());
lk.release();
return PR_SUCCESS;
diff --git a/src/mongo/scripting/mozjs/global.cpp b/src/mongo/scripting/mozjs/global.cpp
index 127dbdc3352..d56cdba7dec 100644
--- a/src/mongo/scripting/mozjs/global.cpp
+++ b/src/mongo/scripting/mozjs/global.cpp
@@ -33,6 +33,7 @@
#include <js/Conversions.h>
#include "mongo/base/init.h"
+#include "mongo/logger/logger.h"
#include "mongo/logger/logstream_builder.h"
#include "mongo/scripting/mozjs/implscope.h"
#include "mongo/scripting/mozjs/jsstringwrapper.h"
diff --git a/src/mongo/scripting/mozjs/proxyscope.cpp b/src/mongo/scripting/mozjs/proxyscope.cpp
index 5e48aabf9cf..7c360302d31 100644
--- a/src/mongo/scripting/mozjs/proxyscope.cpp
+++ b/src/mongo/scripting/mozjs/proxyscope.cpp
@@ -35,6 +35,7 @@
#include "mongo/db/service_context.h"
#include "mongo/platform/decimal128.h"
#include "mongo/scripting/mozjs/implscope.h"
+#include "mongo/util/destructor_guard.h"
#include "mongo/util/quick_exit.h"
namespace mongo {
diff --git a/src/mongo/shell/shell_options.cpp b/src/mongo/shell/shell_options.cpp
index 87e558ebace..63ab20931dc 100644
--- a/src/mongo/shell/shell_options.cpp
+++ b/src/mongo/shell/shell_options.cpp
@@ -26,6 +26,8 @@
* then also delete it in the license file.
*/
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault;
+
#include "mongo/platform/basic.h"
#include "mongo/shell/shell_options.h"
@@ -42,6 +44,7 @@
#include "mongo/db/server_options.h"
#include "mongo/rpc/protocol.h"
#include "mongo/shell/shell_utils.h"
+#include "mongo/util/log.h"
#include "mongo/util/mongoutils/str.h"
#include "mongo/util/net/ssl_options.h"
#include "mongo/util/options_parser/startup_options.h"
diff --git a/src/mongo/shell/shell_options_init.cpp b/src/mongo/shell/shell_options_init.cpp
index e1374ec4691..ba662ff75e0 100644
--- a/src/mongo/shell/shell_options_init.cpp
+++ b/src/mongo/shell/shell_options_init.cpp
@@ -30,6 +30,7 @@
#include <iostream>
+#include "mongo/util/exit_code.h"
#include "mongo/util/options_parser/startup_option_init.h"
#include "mongo/util/options_parser/startup_options.h"
#include "mongo/util/quick_exit.h"
diff --git a/src/mongo/shell/shell_utils_launcher.cpp b/src/mongo/shell/shell_utils_launcher.cpp
index dc3aa068ace..b71f7a8ebc6 100644
--- a/src/mongo/shell/shell_utils_launcher.cpp
+++ b/src/mongo/shell/shell_utils_launcher.cpp
@@ -55,6 +55,7 @@
#include "mongo/shell/shell_utils.h"
#include "mongo/stdx/memory.h"
#include "mongo/stdx/thread.h"
+#include "mongo/util/destructor_guard.h"
#include "mongo/util/exit.h"
#include "mongo/util/log.h"
#include "mongo/util/net/hostandport.h"
diff --git a/src/mongo/shell/shell_utils_launcher.h b/src/mongo/shell/shell_utils_launcher.h
index 860bf241e8c..7ecb8e95384 100644
--- a/src/mongo/shell/shell_utils_launcher.h
+++ b/src/mongo/shell/shell_utils_launcher.h
@@ -38,6 +38,7 @@
#include "mongo/bson/bsonobj.h"
#include "mongo/platform/process_id.h"
+#include "mongo/platform/unordered_map.h"
#include "mongo/stdx/mutex.h"
namespace mongo {
diff --git a/src/mongo/tools/mongobridge_options_init.cpp b/src/mongo/tools/mongobridge_options_init.cpp
index 9878ce9568b..4dbf03ce479 100644
--- a/src/mongo/tools/mongobridge_options_init.cpp
+++ b/src/mongo/tools/mongobridge_options_init.cpp
@@ -32,6 +32,7 @@
#include "mongo/util/options_parser/startup_option_init.h"
#include "mongo/util/options_parser/startup_options.h"
+#include "mongo/util/exit_code.h"
#include "mongo/util/quick_exit.h"
namespace mongo {
diff --git a/src/mongo/util/SConscript b/src/mongo/util/SConscript
index f2d3763c858..d1716c98713 100644
--- a/src/mongo/util/SConscript
+++ b/src/mongo/util/SConscript
@@ -494,7 +494,7 @@ env.CppUnitTest(
target='duration_test',
source=[
'duration_test.cpp',
- 'duration.cpp',
],
LIBDEPS=[
+ '$BUILD_DIR/mongo/base',
])
diff --git a/src/mongo/util/assert_util.h b/src/mongo/util/assert_util.h
index 82369810174..1d72c045764 100644
--- a/src/mongo/util/assert_util.h
+++ b/src/mongo/util/assert_util.h
@@ -31,10 +31,8 @@
#include <string>
#include "mongo/base/status.h" // NOTE: This is safe as utils depend on base
+#include "mongo/base/status_with.h"
#include "mongo/platform/compiler.h"
-#include "mongo/logger/log_severity.h"
-#include "mongo/logger/logger.h"
-#include "mongo/logger/logstream_builder.h"
#include "mongo/util/concurrency/thread_name.h"
#include "mongo/util/debug_util.h"
@@ -380,23 +378,6 @@ Status exceptionToStatus();
msgasserted(14044, std::string("unknown exception") + msg); \
}
-#define DESTRUCTOR_GUARD MONGO_DESTRUCTOR_GUARD
-#define MONGO_DESTRUCTOR_GUARD(expression) \
- try { \
- expression; \
- } catch (const std::exception& e) { \
- ::mongo::logger::LogstreamBuilder(::mongo::logger::globalLogDomain(), \
- ::mongo::getThreadName(), \
- ::mongo::logger::LogSeverity::Log()) \
- << "caught exception (" << e.what() << ") in destructor (" << __FUNCTION__ << ")" \
- << std::endl; \
- } catch (...) { \
- ::mongo::logger::LogstreamBuilder(::mongo::logger::globalLogDomain(), \
- ::mongo::getThreadName(), \
- ::mongo::logger::LogSeverity::Log()) \
- << "caught unknown exception in destructor (" << __FUNCTION__ << ")" << std::endl; \
- }
-
/**
* The purpose of this macro is to instruct the compiler that a line of code will never be reached.
*
diff --git a/src/mongo/util/background.cpp b/src/mongo/util/background.cpp
index 11eab0e06d1..bc6c293b1bb 100644
--- a/src/mongo/util/background.cpp
+++ b/src/mongo/util/background.cpp
@@ -200,11 +200,12 @@ Status BackgroundJob::cancel() {
bool BackgroundJob::wait(unsigned msTimeOut) {
verify(!_selfDelete); // you cannot call wait on a self-deleting job
- const auto deadline = stdx::chrono::system_clock::now() + Milliseconds(msTimeOut);
+ const auto deadline = Date_t::now() + Milliseconds(msTimeOut);
stdx::unique_lock<stdx::mutex> l(_status->mutex);
while (_status->state != Done) {
if (msTimeOut) {
- if (stdx::cv_status::timeout == _status->done.wait_until(l, deadline))
+ if (stdx::cv_status::timeout ==
+ _status->done.wait_until(l, deadline.toSystemTimePoint()))
return false;
} else {
_status->done.wait(l);
@@ -308,7 +309,7 @@ void PeriodicTaskRunner::run() {
stdx::unique_lock<stdx::mutex> lock(_mutex);
while (!_shutdownRequested) {
- if (stdx::cv_status::timeout == _cond.wait_for(lock, waitTime))
+ if (stdx::cv_status::timeout == _cond.wait_for(lock, waitTime.toSystemDuration()))
_runTasks();
}
}
diff --git a/src/mongo/util/background_thread_clock_source.cpp b/src/mongo/util/background_thread_clock_source.cpp
index 3a2d43c1f82..81b4666760b 100644
--- a/src/mongo/util/background_thread_clock_source.cpp
+++ b/src/mongo/util/background_thread_clock_source.cpp
@@ -70,7 +70,8 @@ void BackgroundThreadClockSource::_startTimerThread() {
_timer = stdx::thread([&]() {
stdx::unique_lock<stdx::mutex> lock(_mutex);
while (!_shutdownTimer) {
- if (_condition.wait_for(lock, _granularity) == stdx::cv_status::timeout) {
+ if (_condition.wait_for(lock, _granularity.toSystemDuration()) ==
+ stdx::cv_status::timeout) {
_updateCurrent();
}
}
diff --git a/src/mongo/util/base64.cpp b/src/mongo/util/base64.cpp
index 6938b318148..59fdfb63872 100644
--- a/src/mongo/util/base64.cpp
+++ b/src/mongo/util/base64.cpp
@@ -32,6 +32,8 @@
#include "mongo/util/base64.h"
+#include <sstream>
+
namespace mongo {
using std::string;
diff --git a/src/mongo/util/base64.h b/src/mongo/util/base64.h
index 388e0f9cf1d..d5cf3a71f55 100644
--- a/src/mongo/util/base64.h
+++ b/src/mongo/util/base64.h
@@ -29,6 +29,9 @@
#pragma once
+#include <memory>
+#include <iosfwd>
+#include <string>
#include "mongo/util/assert_util.h"
diff --git a/src/mongo/util/bufreader.h b/src/mongo/util/bufreader.h
index 58e7c5d2816..ae7f2a469e3 100644
--- a/src/mongo/util/bufreader.h
+++ b/src/mongo/util/bufreader.h
@@ -33,6 +33,7 @@
#include "mongo/base/data_range.h"
#include "mongo/base/data_range_cursor.h"
#include "mongo/base/data_type_terminated.h"
+#include "mongo/base/disallow_copying.h"
#include "mongo/bson/util/builder.h"
#include "mongo/platform/strnlen.h"
#include "mongo/util/assert_util.h"
diff --git a/src/mongo/util/concurrency/synchronization.h b/src/mongo/util/concurrency/synchronization.h
index 655ddfb149d..aa611e981f1 100644
--- a/src/mongo/util/concurrency/synchronization.h
+++ b/src/mongo/util/concurrency/synchronization.h
@@ -30,7 +30,7 @@
#pragma once
#include "mongo/stdx/condition_variable.h"
-
+#include "mongo/stdx/mutex.h"
#include "mongo/util/concurrency/mutex.h"
namespace mongo {
diff --git a/src/mongo/util/destructor_guard.h b/src/mongo/util/destructor_guard.h
new file mode 100644
index 00000000000..388cdb45668
--- /dev/null
+++ b/src/mongo/util/destructor_guard.h
@@ -0,0 +1,50 @@
+/** Copyright 2009 10gen 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.
+ */
+
+#pragma once
+
+#include "mongo/logger/log_severity.h"
+#include "mongo/logger/logger.h"
+#include "mongo/logger/logstream_builder.h"
+#include "mongo/util/assert_util.h"
+
+#define DESTRUCTOR_GUARD MONGO_DESTRUCTOR_GUARD
+#define MONGO_DESTRUCTOR_GUARD(expression) \
+ try { \
+ expression; \
+ } catch (const std::exception& e) { \
+ ::mongo::logger::LogstreamBuilder(::mongo::logger::globalLogDomain(), \
+ ::mongo::getThreadName(), \
+ ::mongo::logger::LogSeverity::Log()) \
+ << "caught exception (" << e.what() << ") in destructor (" << __FUNCTION__ << ")" \
+ << std::endl; \
+ } catch (...) { \
+ ::mongo::logger::LogstreamBuilder(::mongo::logger::globalLogDomain(), \
+ ::mongo::getThreadName(), \
+ ::mongo::logger::LogSeverity::Log()) \
+ << "caught unknown exception in destructor (" << __FUNCTION__ << ")" << std::endl; \
+ }
diff --git a/src/mongo/util/duration.cpp b/src/mongo/util/duration.cpp
index ac0faf19394..e3a29e858dc 100644
--- a/src/mongo/util/duration.cpp
+++ b/src/mongo/util/duration.cpp
@@ -34,7 +34,6 @@
#include "mongo/bson/util/builder.h"
namespace mongo {
-namespace x {
namespace {
template <typename Stream>
Stream& streamPut(Stream& os, Nanoseconds ns) {
@@ -142,5 +141,4 @@ template StringBuilderImpl<TrivialAllocator>& operator<<(StringBuilderImpl<Trivi
Minutes);
template StringBuilderImpl<TrivialAllocator>& operator<<(StringBuilderImpl<TrivialAllocator>&,
Hours);
-} // namespace x
} // namespace mongo
diff --git a/src/mongo/util/duration.h b/src/mongo/util/duration.h
index ba4f15ec44e..6cf26b06421 100644
--- a/src/mongo/util/duration.h
+++ b/src/mongo/util/duration.h
@@ -27,13 +27,13 @@
#pragma once
-#include <chrono>
#include <cstdint>
#include <iosfwd>
#include <limits>
#include <ratio>
#include "mongo/platform/overflow_arithmetic.h"
+#include "mongo/stdx/chrono.h"
#include "mongo/stdx/type_traits.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/mongoutils/str.h"
@@ -43,8 +43,6 @@ namespace mongo {
template <typename Allocator>
class StringBuilderImpl;
-namespace x {
-
template <typename Period>
class Duration;
@@ -103,7 +101,7 @@ using HigherPrecisionDuration =
* so attempting to cast that value to Milliseconds will throw an exception.
*/
template <typename ToDuration, typename FromPeriod>
-ToDuration durationCast(const Duration<FromPeriod>& from) {
+ToDuration duration_cast(const Duration<FromPeriod>& from) {
using FromOverTo = std::ratio_divide<FromPeriod, typename ToDuration::period>;
if (ToDuration::template isHigherPrecisionThan<Duration<FromPeriod>>()) {
typename ToDuration::rep toCount;
@@ -115,6 +113,29 @@ ToDuration durationCast(const Duration<FromPeriod>& from) {
return ToDuration{from.count() / FromOverTo::den};
}
+template <typename ToDuration, typename FromRep, typename FromPeriod>
+inline ToDuration duration_cast(const stdx::chrono::duration<FromRep, FromPeriod>& d) {
+ return duration_cast<ToDuration>(Duration<FromPeriod>{d.count()});
+}
+
+/**
+ * Convenience method for reading the count of a duration with specified units.
+ *
+ * Use when logging or comparing to integers, to ensure that you're using
+ * the units you intend.
+ *
+ * E.g., log() << durationCount<Seconds>(some duration) << " seconds";
+ */
+template <typename DOut, typename DIn>
+inline long long durationCount(DIn d) {
+ return duration_cast<DOut>(d).count();
+}
+
+template <typename DOut, typename RepIn, typename PeriodIn>
+inline long long durationCount(const stdx::chrono::duration<RepIn, PeriodIn>& d) {
+ return durationCount<DOut>(Duration<PeriodIn>{d.count()});
+}
+
/**
* Type representing a duration using a 64-bit counter.
*
@@ -197,12 +218,14 @@ public:
template <typename Rep2>
constexpr explicit Duration(const Rep2& r)
: _count(r) {
- static_assert(std::is_integral<Rep2>::value && std::is_signed<Rep2>::value,
- "Durations must be constructed from values of signed integral type");
+ static_assert(std::is_integral<Rep2>::value &&
+ (std::is_signed<Rep2>::value || sizeof(Rep2) < sizeof(rep)),
+ "Durations must be constructed from values of integral type that are "
+ "representable as 64-bit signed integers");
}
/**
- * Constructs a higher-precision duration from a lower-precision one, as by durationCast.
+ * Constructs a higher-precision duration from a lower-precision one, as by duration_cast.
*
* Throws a UserException if "from" is out of the range of this duration type.
*
@@ -210,18 +233,23 @@ public:
* this constructor.
*/
template <typename FromPeriod>
- /*implicit*/ Duration(const Duration<FromPeriod>& from) : Duration(durationCast<Duration>(from)) {
+ /*implicit*/ Duration(const Duration<FromPeriod>& from)
+ : Duration(duration_cast<Duration>(from)) {
static_assert(!isLowerPrecisionThan<Duration<FromPeriod>>(),
"Use duration_cast to convert from higher precision Duration types to lower "
"precision ones");
}
- constexpr operator stdx::chrono::duration<int64_t, period>() const {
- return stdx::chrono::duration<int64_t, period>{_count};
+ stdx::chrono::system_clock::duration toSystemDuration() const {
+ using SystemDuration = stdx::chrono::system_clock::duration;
+ return SystemDuration{duration_cast<Duration<SystemDuration::period>>(*this).count()};
}
/**
* Returns the number of periods represented by this duration.
+ *
+ * It is better to use durationCount<DesiredDurationType>(value), since it makes the unit of the
+ * count clear at the call site.
*/
constexpr rep count() const {
return _count;
@@ -411,5 +439,4 @@ Duration<Period> operator/(Duration<Period> d, const Rep2& scale) {
return d;
}
-} // namespace x
} // namespace mongo
diff --git a/src/mongo/util/duration_test.cpp b/src/mongo/util/duration_test.cpp
index 8e463bcee76..0a5f8c95c2a 100644
--- a/src/mongo/util/duration_test.cpp
+++ b/src/mongo/util/duration_test.cpp
@@ -25,11 +25,11 @@
* then also delete it in the license file.
*/
+#include "mongo/stdx/chrono.h"
#include "mongo/util/duration.h"
#include "mongo/unittest/unittest.h"
namespace mongo {
-namespace x {
namespace {
// The DurationTestSameType Compare* tests server to check the implementation of the comparison
@@ -114,30 +114,35 @@ TEST(DurationComparisonDifferentTypes, CompareAtLimits) {
ASSERT_LT(Seconds::min(), Milliseconds::min());
ASSERT_LT(Milliseconds::min(),
- durationCast<Milliseconds>(durationCast<Seconds>(Milliseconds::min())));
+ duration_cast<Milliseconds>(duration_cast<Seconds>(Milliseconds::min())));
ASSERT_GT(Milliseconds::max(),
- durationCast<Milliseconds>(durationCast<Seconds>(Milliseconds::max())));
+ duration_cast<Milliseconds>(duration_cast<Seconds>(Milliseconds::max())));
}
TEST(DurationCast, NonTruncatingDurationCasts) {
- ASSERT_EQ(1, durationCast<Seconds>(Milliseconds{1000}).count());
- ASSERT_EQ(1000, durationCast<Milliseconds>(Seconds{1}).count());
+ ASSERT_EQ(1, duration_cast<Seconds>(Milliseconds{1000}).count());
+ ASSERT_EQ(1000, duration_cast<Milliseconds>(Seconds{1}).count());
ASSERT_EQ(1000, Milliseconds{Seconds{1}}.count());
- ASSERT_EQ(1053, durationCast<Milliseconds>(Milliseconds{1053}).count());
+ ASSERT_EQ(1053, duration_cast<Milliseconds>(Milliseconds{1053}).count());
}
TEST(DurationCast, TruncatingDurationCasts) {
- ASSERT_EQ(1, durationCast<Seconds>(Milliseconds{1600}).count());
- ASSERT_EQ(0, durationCast<Seconds>(Milliseconds{999}).count());
- ASSERT_EQ(-1, durationCast<Seconds>(Milliseconds{-1600}).count());
- ASSERT_EQ(0, durationCast<Seconds>(Milliseconds{-999}).count());
+ ASSERT_EQ(1, duration_cast<Seconds>(Milliseconds{1600}).count());
+ ASSERT_EQ(0, duration_cast<Seconds>(Milliseconds{999}).count());
+ ASSERT_EQ(-1, duration_cast<Seconds>(Milliseconds{-1600}).count());
+ ASSERT_EQ(0, duration_cast<Seconds>(Milliseconds{-999}).count());
}
TEST(DurationCast, OverflowingCastsThrow) {
ASSERT_THROWS_CODE(
- durationCast<Milliseconds>(Seconds::max()), UserException, ErrorCodes::DurationOverflow);
+ duration_cast<Milliseconds>(Seconds::max()), UserException, ErrorCodes::DurationOverflow);
ASSERT_THROWS_CODE(
- durationCast<Milliseconds>(Seconds::min()), UserException, ErrorCodes::DurationOverflow);
+ duration_cast<Milliseconds>(Seconds::min()), UserException, ErrorCodes::DurationOverflow);
+}
+
+TEST(DurationCast, ImplicitConversionToStdxDuration) {
+ auto standardMillis = Milliseconds{10}.toSystemDuration();
+ ASSERT_EQUALS(Milliseconds{10}, duration_cast<Milliseconds>(standardMillis));
}
TEST(DurationAssignment, DurationAssignment) {
@@ -215,5 +220,4 @@ TEST(DurationArithmetic, DivideOverflowThrows) {
}
} // namespace
-} // namespace x
} // namespace mongo
diff --git a/src/mongo/util/net/sock.h b/src/mongo/util/net/sock.h
index 6a815100561..1ef0381c1c8 100644
--- a/src/mongo/util/net/sock.h
+++ b/src/mongo/util/net/sock.h
@@ -45,6 +45,7 @@
#endif // not _WIN32
#include <cstdint>
+#include <memory>
#include <string>
#include <utility>
#include <vector>
diff --git a/src/mongo/util/ntservice.cpp b/src/mongo/util/ntservice.cpp
index 571614a14c9..43028bf50e0 100644
--- a/src/mongo/util/ntservice.cpp
+++ b/src/mongo/util/ntservice.cpp
@@ -547,7 +547,7 @@ static void serviceStop() {
const auto timeout = Milliseconds(kStopWaitHintMillis / 2);
// We periodically check if we are done exiting by polling at half of each wait interval
- while (exitedCleanly.wait_for(timeout) != stdx::future_status::ready) {
+ while (exitedCleanly.wait_for(timeout.toSystemDuration()) != stdx::future_status::ready) {
reportStatus(SERVICE_STOP_PENDING, kStopWaitHintMillis);
log() << "Service Stop is waiting for storage engine to finish shutdown";
}
diff --git a/src/mongo/util/processinfo.h b/src/mongo/util/processinfo.h
index 7d48fe31aea..b2e6fcf2852 100644
--- a/src/mongo/util/processinfo.h
+++ b/src/mongo/util/processinfo.h
@@ -35,6 +35,7 @@
#include "mongo/db/jsobj.h"
#include "mongo/platform/process_id.h"
+#include "mongo/stdx/mutex.h"
#include "mongo/util/concurrency/mutex.h"
namespace mongo {
diff --git a/src/mongo/util/text.cpp b/src/mongo/util/text.cpp
index 24bc71cf059..edb5c1a50b9 100644
--- a/src/mongo/util/text.cpp
+++ b/src/mongo/util/text.cpp
@@ -27,11 +27,14 @@
* then also delete it in the license file.
*/
+#include "mongo/platform/basic.h"
+
#include "mongo/util/text.h"
#include <boost/integer_traits.hpp>
#include <errno.h>
#include <iostream>
+#include <memory>
#include <sstream>
#ifdef _WIN32
diff --git a/src/mongo/util/time_support.cpp b/src/mongo/util/time_support.cpp
index f443db0f3b4..b26e0a07361 100644
--- a/src/mongo/util/time_support.cpp
+++ b/src/mongo/util/time_support.cpp
@@ -57,61 +57,6 @@ extern "C" time_t timegm(struct tm* const tmp);
namespace mongo {
-namespace {
-template <typename Stream>
-Stream& streamPut(Stream& os, Microseconds us) {
- return os << us.count() << "\xce\xbcs";
-}
-
-template <typename Stream>
-Stream& streamPut(Stream& os, Milliseconds ms) {
- return os << ms.count() << "ms";
-}
-
-template <typename Stream>
-Stream& streamPut(Stream& os, Seconds s) {
- return os << s.count() << 's';
-}
-} // namespace
-
-std::ostream& operator<<(std::ostream& os, Microseconds us) {
- return streamPut(os, us);
-}
-
-std::ostream& operator<<(std::ostream& os, Milliseconds ms) {
- return streamPut(os, ms);
-}
-std::ostream& operator<<(std::ostream& os, Seconds s) {
- return streamPut(os, s);
-}
-
-template <typename Allocator>
-StringBuilderImpl<Allocator>& operator<<(StringBuilderImpl<Allocator>& os, Microseconds us) {
- return streamPut(os, us);
-}
-
-template <typename Allocator>
-StringBuilderImpl<Allocator>& operator<<(StringBuilderImpl<Allocator>& os, Milliseconds ms) {
- return streamPut(os, ms);
-}
-
-template <typename Allocator>
-StringBuilderImpl<Allocator>& operator<<(StringBuilderImpl<Allocator>& os, Seconds s) {
- return streamPut(os, s);
-}
-
-template StringBuilderImpl<StackAllocator>& operator<<(StringBuilderImpl<StackAllocator>&,
- Microseconds);
-template StringBuilderImpl<StackAllocator>& operator<<(StringBuilderImpl<StackAllocator>&,
- Milliseconds);
-template StringBuilderImpl<StackAllocator>& operator<<(StringBuilderImpl<StackAllocator>&, Seconds);
-template StringBuilderImpl<TrivialAllocator>& operator<<(StringBuilderImpl<TrivialAllocator>&,
- Microseconds);
-template StringBuilderImpl<TrivialAllocator>& operator<<(StringBuilderImpl<TrivialAllocator>&,
- Milliseconds);
-template StringBuilderImpl<TrivialAllocator>& operator<<(StringBuilderImpl<TrivialAllocator>&,
- Seconds);
-
Date_t Date_t::max() {
return fromMillisSinceEpoch(std::numeric_limits<long long>::max());
}
@@ -124,7 +69,7 @@ Date_t::Date_t(stdx::chrono::system_clock::time_point tp)
: millis(durationCount<Milliseconds>(tp - stdx::chrono::system_clock::from_time_t(0))) {}
stdx::chrono::system_clock::time_point Date_t::toSystemTimePoint() const {
- return stdx::chrono::system_clock::from_time_t(0) + toDurationSinceEpoch();
+ return stdx::chrono::system_clock::from_time_t(0) + toDurationSinceEpoch().toSystemDuration();
}
bool Date_t::isFormattable() const {
@@ -773,14 +718,14 @@ bool toPointInTime(const string& str, boost::posix_time::ptime* timeOfDay) {
}
void sleepsecs(int s) {
- stdx::this_thread::sleep_for(Seconds(s));
+ stdx::this_thread::sleep_for(Seconds(s).toSystemDuration());
}
void sleepmillis(long long s) {
- stdx::this_thread::sleep_for(Milliseconds(s));
+ stdx::this_thread::sleep_for(Milliseconds(s).toSystemDuration());
}
void sleepmicros(long long s) {
- stdx::this_thread::sleep_for(Microseconds(s));
+ stdx::this_thread::sleep_for(Microseconds(s).toSystemDuration());
}
void Backoff::nextSleepMillis() {
diff --git a/src/mongo/util/time_support.h b/src/mongo/util/time_support.h
index 6f20025d832..a445e9b6f47 100644
--- a/src/mongo/util/time_support.h
+++ b/src/mongo/util/time_support.h
@@ -37,55 +37,17 @@
#include "mongo/base/status_with.h"
#include "mongo/stdx/chrono.h"
+#include "mongo/stdx/mutex.h"
+#include "mongo/util/duration.h"
namespace mongo {
template <typename Allocator>
class StringBuilderImpl;
-using Microseconds = stdx::chrono::microseconds;
-using Milliseconds = stdx::chrono::milliseconds;
-using Seconds = stdx::chrono::seconds;
-using Minutes = stdx::chrono::minutes;
-using Hours = stdx::chrono::hours;
-using stdx::chrono::duration_cast;
-
void time_t_to_Struct(time_t t, struct tm* buf, bool local = false);
std::string time_t_to_String_short(time_t t);
-//
-// Operators for putting durations to streams. Note that these will
-// *not* normally be found by ADL since the duration types are
-// typedefs, but see the handling of chrono::duration in
-// logstream_builder.h for why they are useful.
-//
-
-std::ostream& operator<<(std::ostream& os, Microseconds us);
-std::ostream& operator<<(std::ostream& os, Milliseconds ms);
-std::ostream& operator<<(std::ostream& os, Seconds s);
-
-template <typename Allocator>
-StringBuilderImpl<Allocator>& operator<<(StringBuilderImpl<Allocator>& os, Microseconds us);
-
-template <typename Allocator>
-StringBuilderImpl<Allocator>& operator<<(StringBuilderImpl<Allocator>& os, Milliseconds ms);
-
-template <typename Allocator>
-StringBuilderImpl<Allocator>& operator<<(StringBuilderImpl<Allocator>& os, Seconds s);
-
-/**
- * Convenience method for reading the count of a duration with specified units.
- *
- * Use when logging or comparing to integers, to ensure that you're using
- * the units you intend.
- *
- * E.g., log() << durationCount<Seconds>(some duration) << " seconds";
- */
-template <typename DOut, typename DIn>
-long long durationCount(DIn d) {
- return duration_cast<DOut>(d).count();
-}
-
/**
* Representation of a point in time, with millisecond resolution and capable
* of representing all times representable by the BSON Date type.
diff --git a/src/mongo/util/time_support_test.cpp b/src/mongo/util/time_support_test.cpp
index 64a6b3b16bf..24052f3f147 100644
--- a/src/mongo/util/time_support_test.cpp
+++ b/src/mongo/util/time_support_test.cpp
@@ -825,8 +825,8 @@ TEST(SystemTime, ConvertDateToSystemTime) {
const Date_t aDate = unittest::assertGet(dateFromISOString(isoTimeString));
const auto aTimePoint = aDate.toSystemTimePoint();
const auto actual = aTimePoint - stdx::chrono::system_clock::from_time_t(0);
- ASSERT(aDate.toDurationSinceEpoch() == actual) << "Expected " << aDate << "; but found "
- << Date_t::fromDurationSinceEpoch(actual);
+ ASSERT(aDate.toDurationSinceEpoch().toSystemDuration() == actual)
+ << "Expected " << aDate << "; but found " << Date_t::fromDurationSinceEpoch(actual);
ASSERT_EQUALS(aDate, Date_t(aTimePoint));
}