You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2016/03/12 03:55:31 UTC

[3/7] mesos git commit: Avoided external linkage for master constants.

Avoided external linkage for master constants.

We were only using external linkage to workaround bugs in ancient
(4.1.x) of GCC. We can also mark most of these constants `constexpr`
to bring this up-to-date with the latest style guidelines.

Review: https://reviews.apache.org/r/44191/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/83001de3
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/83001de3
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/83001de3

Branch: refs/heads/master
Commit: 83001de38e7d08cae7baef3b63f80ec7688db875
Parents: 6ce23f8
Author: Neil Conway <ne...@gmail.com>
Authored: Fri Mar 11 18:11:48 2016 -0800
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Fri Mar 11 18:15:22 2016 -0800

----------------------------------------------------------------------
 src/CMakeLists.txt       |  1 -
 src/Makefile.am          |  1 -
 src/master/constants.cpp | 55 -------------------------------------------
 src/master/constants.hpp | 51 +++++++++++++++++----------------------
 4 files changed, 22 insertions(+), 86 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/83001de3/src/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index bfd2141..a41d3cc 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -197,7 +197,6 @@ set(LOGGING_SRC
 
 set(MASTER_SRC
   master/contender.cpp
-  master/constants.cpp
   master/detector.cpp
   master/flags.cpp
   master/http.cpp

http://git-wip-us.apache.org/repos/asf/mesos/blob/83001de3/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index 70c32f0..5157b15 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -621,7 +621,6 @@ libmesos_no_3rdparty_la_SOURCES +=					\
   local/local.cpp							\
   logging/flags.cpp							\
   logging/logging.cpp							\
-  master/constants.cpp							\
   master/contender.cpp							\
   master/detector.cpp							\
   master/flags.cpp							\

http://git-wip-us.apache.org/repos/asf/mesos/blob/83001de3/src/master/constants.cpp
----------------------------------------------------------------------
diff --git a/src/master/constants.cpp b/src/master/constants.cpp
deleted file mode 100644
index e316f97..0000000
--- a/src/master/constants.cpp
+++ /dev/null
@@ -1,55 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include <stdint.h>
-
-#include <string>
-
-#include <stout/bytes.hpp>
-
-#include "master/constants.hpp"
-
-namespace mesos {
-namespace internal {
-namespace master {
-
-const int MAX_OFFERS_PER_FRAMEWORK = 50;
-const double MIN_CPUS = 0.01;
-const Bytes MIN_MEM = Megabytes(32);
-const Duration DEFAULT_HEARTBEAT_INTERVAL = Seconds(15);
-const Duration DEFAULT_SLAVE_PING_TIMEOUT = Seconds(15);
-const size_t DEFAULT_MAX_SLAVE_PING_TIMEOUTS = 5;
-const Duration MIN_SLAVE_REREGISTER_TIMEOUT = Minutes(10);
-const double RECOVERY_SLAVE_REMOVAL_PERCENT_LIMIT = 1.0; // 100%.
-const size_t MAX_REMOVED_SLAVES = 100000;
-const size_t DEFAULT_MAX_COMPLETED_FRAMEWORKS = 50;
-const size_t DEFAULT_MAX_COMPLETED_TASKS_PER_FRAMEWORK = 1000;
-const Duration WHITELIST_WATCH_INTERVAL = Seconds(5);
-const uint32_t TASK_LIMIT = 100;
-const std::string MASTER_INFO_LABEL = "info";
-const std::string MASTER_INFO_JSON_LABEL = "json.info";
-
-const Duration ZOOKEEPER_SESSION_TIMEOUT = Seconds(10);
-const std::string DEFAULT_AUTHENTICATOR = "crammd5";
-const std::string DEFAULT_ALLOCATOR = "HierarchicalDRF";
-const Duration DEFAULT_ALLOCATION_INTERVAL = Seconds(1);
-const std::string DEFAULT_AUTHORIZER = "local";
-const std::string DEFAULT_HTTP_AUTHENTICATOR = "basic";
-const std::string DEFAULT_HTTP_AUTHENTICATION_REALM = "mesos";
-
-} // namespace master {
-} // namespace internal {
-} // namespace mesos {

http://git-wip-us.apache.org/repos/asf/mesos/blob/83001de3/src/master/constants.hpp
----------------------------------------------------------------------
diff --git a/src/master/constants.hpp b/src/master/constants.hpp
index 2c3299b..f87c2d5 100644
--- a/src/master/constants.hpp
+++ b/src/master/constants.hpp
@@ -31,12 +31,6 @@ namespace master {
 // TODO(benh): Add units after constants.
 // TODO(benh): Also make configuration options be constants.
 
-// TODO(bmahler): It appears there may be a bug with gcc-4.1.2 in which the
-// duration constants were not being initialized when having static linkage.
-// This issue did not manifest in newer gcc's. Specifically, 4.2.1 was ok.
-// So we've moved these to have external linkage but perhaps in the future
-// we can revert this.
-
 // TODO(vinod): Move constants that are only used in flags to
 // 'master/flags.hpp'.
 
@@ -44,18 +38,17 @@ namespace master {
 // details in MESOS-1023.
 
 // Maximum number of slot offers to have outstanding for each framework.
-extern const int MAX_OFFERS_PER_FRAMEWORK;
+constexpr int MAX_OFFERS_PER_FRAMEWORK = 50;
 
 // Minimum number of cpus per offer.
-extern const double MIN_CPUS;
+constexpr double MIN_CPUS = 0.01;
 
 // Minimum amount of memory per offer.
-extern const Bytes MIN_MEM;
-
+constexpr Bytes MIN_MEM = Megabytes(32);
 
 // Default interval the master uses to send heartbeats to an HTTP
 // scheduler.
-extern const Duration DEFAULT_HEARTBEAT_INTERVAL;
+constexpr Duration DEFAULT_HEARTBEAT_INTERVAL = Seconds(15);
 
 // Amount of time within which a slave PING should be received.
 // NOTE: The slave uses these PING constants to determine when
@@ -63,15 +56,15 @@ extern const Duration DEFAULT_HEARTBEAT_INTERVAL;
 // configurable, then we'll need to rely on upper/lower bounds
 // to ensure that the slave is not unnecessarily triggering
 // re-registrations.
-extern const Duration DEFAULT_SLAVE_PING_TIMEOUT;
+constexpr Duration DEFAULT_SLAVE_PING_TIMEOUT = Seconds(15);
 
 // Maximum number of ping timeouts until slave is considered failed.
-extern const size_t DEFAULT_MAX_SLAVE_PING_TIMEOUTS;
+constexpr size_t DEFAULT_MAX_SLAVE_PING_TIMEOUTS = 5;
 
 // The minimum timeout that can be used by a newly elected leader to
 // allow re-registration of slaves. Any slaves that do not re-register
 // within this timeout will be shutdown.
-extern const Duration MIN_SLAVE_REREGISTER_TIMEOUT;
+constexpr Duration MIN_SLAVE_REREGISTER_TIMEOUT = Minutes(10);
 
 // Default limit on the percentage of slaves that will be removed
 // after recovering if no re-registration attempts were made.
@@ -82,59 +75,59 @@ extern const Duration MIN_SLAVE_REREGISTER_TIMEOUT;
 // production clusters. This TODO is to provide a --production flag
 // which would allow flag defaults that are more appropriate for
 // production use-cases.
-extern const double RECOVERY_SLAVE_REMOVAL_PERCENT_LIMIT;
+constexpr double RECOVERY_SLAVE_REMOVAL_PERCENT_LIMIT = 1.0; // 100%.
 
 // Maximum number of removed slaves to store in the cache.
-extern const size_t MAX_REMOVED_SLAVES;
+constexpr size_t MAX_REMOVED_SLAVES = 100000;
 
 // Default maximum number of completed frameworks to store in the cache.
-extern const size_t DEFAULT_MAX_COMPLETED_FRAMEWORKS;
+constexpr size_t DEFAULT_MAX_COMPLETED_FRAMEWORKS = 50;
 
 // Default maximum number of completed tasks per framework
 // to store in the cache.
-extern const size_t DEFAULT_MAX_COMPLETED_TASKS_PER_FRAMEWORK;
+constexpr size_t DEFAULT_MAX_COMPLETED_TASKS_PER_FRAMEWORK = 1000;
 
 // Time interval to check for updated watchers list.
-extern const Duration WHITELIST_WATCH_INTERVAL;
+constexpr Duration WHITELIST_WATCH_INTERVAL = Seconds(5);
 
 // Default number of tasks (limit) for /master/tasks endpoint.
-extern const uint32_t TASK_LIMIT;
+constexpr uint32_t TASK_LIMIT = 100;
 
 /**
  * Label used by the Leader Contender and Detector.
  *
  * \deprecated Will be deprecated as of Mesos 0.24: see MESOS-2340.
  */
-extern const std::string MASTER_INFO_LABEL;
+const std::string MASTER_INFO_LABEL = "info";
 
 /**
  * Label used by the Leader Contender and Detector, for JSON content.
  *
  * \since Mesos 0.23 (see MESOS-2340).
  */
-extern const std::string MASTER_INFO_JSON_LABEL;
+const std::string MASTER_INFO_JSON_LABEL = "json.info";
 
 // Timeout used for ZooKeeper related operations.
 // TODO(vinod): Master detector/contender should use this timeout.
-extern const Duration ZOOKEEPER_SESSION_TIMEOUT;
+constexpr Duration ZOOKEEPER_SESSION_TIMEOUT = Seconds(10);
 
 // Name of the default, CRAM-MD5 authenticator.
-extern const std::string DEFAULT_AUTHENTICATOR;
+const std::string DEFAULT_AUTHENTICATOR = "crammd5";
 
 // Name of the default, HierarchicalDRF authenticator.
-extern const std::string DEFAULT_ALLOCATOR;
+const std::string DEFAULT_ALLOCATOR = "HierarchicalDRF";
 
 // The default interval between allocations.
-extern const Duration DEFAULT_ALLOCATION_INTERVAL;
+constexpr Duration DEFAULT_ALLOCATION_INTERVAL = Seconds(1);
 
 // Name of the default, local authorizer.
-extern const std::string DEFAULT_AUTHORIZER;
+const std::string DEFAULT_AUTHORIZER = "local";
 
 // Name of the default, basic authenticator.
-extern const std::string DEFAULT_HTTP_AUTHENTICATOR;
+const std::string DEFAULT_HTTP_AUTHENTICATOR = "basic";
 
 // Name of the default, "mesos" HTTP authentication realm.
-extern const std::string DEFAULT_HTTP_AUTHENTICATION_REALM;
+const std::string DEFAULT_HTTP_AUTHENTICATION_REALM = "mesos";
 
 } // namespace master {
 } // namespace internal {