You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2017/12/21 19:31:13 UTC
[2/4] mesos git commit: Removed the usage of `Bytes::kilobytes()` and
`Bytes::megabytes()`.
Removed the usage of `Bytes::kilobytes()` and `Bytes::megabytes()`.
Review: https://reviews.apache.org/r/64755/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/866d4c8d
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/866d4c8d
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/866d4c8d
Branch: refs/heads/master
Commit: 866d4c8da0794b1d45ba0e57e857bf06dabdc295
Parents: e3b8c1a
Author: Chun-Hung Hsiao <ch...@mesosphere.io>
Authored: Thu Dec 21 11:03:25 2017 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Thu Dec 21 11:03:25 2017 -0800
----------------------------------------------------------------------
src/examples/balloon_executor.cpp | 2 +-
src/examples/balloon_framework.cpp | 5 +++--
src/examples/disk_full_framework.cpp | 5 +++--
src/master/validation.cpp | 4 ++--
src/resource_provider/storage/provider.cpp | 9 +++++----
src/slave/containerizer/containerizer.cpp | 8 ++++++--
.../mesos/isolators/cgroups/subsystems/memory.cpp | 3 ++-
src/slave/slave.cpp | 5 ++++-
src/tests/container_logger_tests.cpp | 16 ++++++++--------
.../containerizer/docker_containerizer_tests.cpp | 4 ++--
src/tests/hierarchical_allocator_tests.cpp | 14 +++++++++-----
src/tests/mesos.hpp | 6 ++++--
src/tests/persistent_volume_tests.cpp | 6 +++---
13 files changed, 52 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/866d4c8d/src/examples/balloon_executor.cpp
----------------------------------------------------------------------
diff --git a/src/examples/balloon_executor.cpp b/src/examples/balloon_executor.cpp
index 7343ee7..941cbe7 100644
--- a/src/examples/balloon_executor.cpp
+++ b/src/examples/balloon_executor.cpp
@@ -59,7 +59,7 @@ void run(ExecutorDriver* driver, const TaskInfo& task)
// Get the balloon limit (in MB).
Try<Bytes> _limit = Bytes::parse(task.data());
CHECK(_limit.isSome());
- const size_t limit = _limit->megabytes();
+ const size_t limit = _limit->bytes() / Bytes::MEGABYTES;
const size_t chunk = BALLOON_STEP_MB * 1024 * 1024;
for (size_t i = 0; i < limit / BALLOON_STEP_MB; i++) {
http://git-wip-us.apache.org/repos/asf/mesos/blob/866d4c8d/src/examples/balloon_framework.cpp
----------------------------------------------------------------------
diff --git a/src/examples/balloon_framework.cpp b/src/examples/balloon_framework.cpp
index a36e04b..410966e 100644
--- a/src/examples/balloon_framework.cpp
+++ b/src/examples/balloon_framework.cpp
@@ -91,7 +91,7 @@ public:
"The task will attempt to occupy memory up until this limit.",
static_cast<const Bytes*>(nullptr),
[](const Bytes& value) -> Option<Error> {
- if (value.megabytes() < MEM_PER_EXECUTOR) {
+ if (value < Bytes(MEM_PER_EXECUTOR, Bytes::MEGABYTES)) {
return Error(
"Please use a --task_memory_usage_limit greater than " +
stringify(MEM_PER_EXECUTOR) + " MB");
@@ -211,7 +211,8 @@ public:
{
Resources taskResources = Resources::parse(
"cpus:" + stringify(CPUS_PER_TASK) +
- ";mem:" + stringify(flags.task_memory.megabytes())).get();
+ ";mem:" + stringify(
+ (double) flags.task_memory.bytes() / Bytes::MEGABYTES)).get();
taskResources.allocate(role);
Resources executorResources = Resources(executor.resources());
http://git-wip-us.apache.org/repos/asf/mesos/blob/866d4c8d/src/examples/disk_full_framework.cpp
----------------------------------------------------------------------
diff --git a/src/examples/disk_full_framework.cpp b/src/examples/disk_full_framework.cpp
index d9d2d35..d75f769 100644
--- a/src/examples/disk_full_framework.cpp
+++ b/src/examples/disk_full_framework.cpp
@@ -149,7 +149,8 @@ public:
Resources taskResources = Resources::parse(
"cpus:" + stringify(CPUS_PER_TASK) +
";mem:" + stringify(MEMORY_PER_TASK) +
- ";disk:" + stringify(DISK_PER_TASK.megabytes())).get();
+ ";disk:" + stringify(
+ (double) DISK_PER_TASK.bytes() / Bytes::MEGABYTES)).get();
taskResources.allocate(role);
foreach (const Offer& offer, offers) {
@@ -182,7 +183,7 @@ public:
static const string command =
"sleep " + stringify(flags.pre_sleep_duration.secs()) +
" && dd if=/dev/zero of=file bs=1K count=" +
- stringify(flags.disk_use_limit.kilobytes()) +
+ stringify(flags.disk_use_limit.bytes() / Bytes::KILOBYTES) +
" && sleep " + stringify(flags.post_sleep_duration.secs());
TaskInfo task;
http://git-wip-us.apache.org/repos/asf/mesos/blob/866d4c8d/src/master/validation.cpp
----------------------------------------------------------------------
diff --git a/src/master/validation.cpp b/src/master/validation.cpp
index 1e1e754..44d7a57 100644
--- a/src/master/validation.cpp
+++ b/src/master/validation.cpp
@@ -1399,7 +1399,7 @@ Option<Error> validateExecutor(
<< "Executor '" << task.executor().executor_id()
<< "' for task '" << task.task_id()
<< "' uses less memory ("
- << (mem.isSome() ? stringify(mem.get().megabytes()) : "None")
+ << (mem.isSome() ? stringify(mem.get()) : "None")
<< ") than the minimum required (" << MIN_MEM
<< "). Please update your executor, as this will be mandatory "
<< "in future releases.";
@@ -1582,7 +1582,7 @@ Option<Error> validateExecutor(
return Error(
"Executor '" + stringify(executor.executor_id()) +
"' uses less memory (" +
- (mem.isSome() ? stringify(mem.get().megabytes()) : "None") +
+ (mem.isSome() ? stringify(mem.get()) : "None") +
") than the minimum required (" + stringify(MIN_MEM) + ")");
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/866d4c8d/src/resource_provider/storage/provider.cpp
----------------------------------------------------------------------
diff --git a/src/resource_provider/storage/provider.cpp b/src/resource_provider/storage/provider.cpp
index b6781d6..34c413e 100644
--- a/src/resource_provider/storage/provider.cpp
+++ b/src/resource_provider/storage/provider.cpp
@@ -253,7 +253,8 @@ static inline Resource createRawDiskResource(
Resource resource;
resource.set_name("disk");
resource.set_type(Value::SCALAR);
- resource.mutable_scalar()->set_value(capacity.megabytes());
+ resource.mutable_scalar()
+ ->set_value((double) capacity.bytes() / Bytes::MEGABYTES);
resource.mutable_provider_id()->CopyFrom(info.id()),
resource.mutable_reservations()->CopyFrom(info.default_reservations());
resource.mutable_disk()->mutable_source()
@@ -1195,7 +1196,7 @@ ResourceConversion StorageLocalResourceProviderProcess::reconcileResources(
foreach (const Resource& resource, checkpointed) {
Resource unconverted = createRawDiskResource(
info,
- Bytes(resource.scalar().value(), Bytes::MEGABYTES),
+ Bytes(resource.scalar().value() * Bytes::MEGABYTES),
resource.disk().source().has_profile()
? resource.disk().source().profile() : Option<string>::none(),
resource.disk().source().has_id()
@@ -2743,7 +2744,7 @@ StorageLocalResourceProviderProcess::applyCreateVolumeOrBlock(
// RAW profiled resources afterward.
created = createVolume(
operationUuid.toString(),
- Bytes(resource.scalar().value(), Bytes::MEGABYTES),
+ Bytes(resource.scalar().value() * Bytes::MEGABYTES),
profileInfos.at(resource.disk().source().profile()));
} else {
const string& volumeId = resource.disk().source().id();
@@ -2786,7 +2787,7 @@ StorageLocalResourceProviderProcess::applyCreateVolumeOrBlock(
// RAW profiled resources afterward.
created = createVolume(
operationUuid.toString(),
- Bytes(resource.scalar().value(), Bytes::MEGABYTES),
+ Bytes(resource.scalar().value() * Bytes::MEGABYTES),
profileInfos.at(resource.disk().source().profile()));
} else {
const string& volumeId = resource.disk().source().id();
http://git-wip-us.apache.org/repos/asf/mesos/blob/866d4c8d/src/slave/containerizer/containerizer.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/containerizer.cpp b/src/slave/containerizer/containerizer.cpp
index 935dfc9..fa1d24a 100644
--- a/src/slave/containerizer/containerizer.cpp
+++ b/src/slave/containerizer/containerizer.cpp
@@ -156,9 +156,11 @@ Try<Resources> Containerizer::resources(const Flags& flags)
}
}
+ // NOTE: The size is truncated here to preserve the existing
+ // behavior for backward compatibility.
resources += Resources::parse(
"mem",
- stringify(mem.megabytes()),
+ stringify(mem.bytes() / Bytes::MEGABYTES),
flags.default_role).get();
}
@@ -184,9 +186,11 @@ Try<Resources> Containerizer::resources(const Flags& flags)
}
}
+ // NOTE: The size is truncated here to preserve the existing
+ // behavior for backward compatibility.
resources += Resources::parse(
"disk",
- stringify(disk.megabytes()),
+ stringify(disk.bytes() / Bytes::MEGABYTES),
flags.default_role).get();
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/866d4c8d/src/slave/containerizer/mesos/isolators/cgroups/subsystems/memory.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/cgroups/subsystems/memory.cpp b/src/slave/containerizer/mesos/isolators/cgroups/subsystems/memory.cpp
index 113e908..99e824a 100644
--- a/src/slave/containerizer/mesos/isolators/cgroups/subsystems/memory.cpp
+++ b/src/slave/containerizer/mesos/isolators/cgroups/subsystems/memory.cpp
@@ -560,7 +560,8 @@ void MemorySubsystem::oomWaited(
// we should save the resources passed in and report it here.
Resources mem = Resources::parse(
"mem",
- stringify(usage.isSome() ? usage.get().megabytes() : 0),
+ stringify(usage.isSome()
+ ? (double) usage->bytes() / Bytes::MEGABYTES : 0),
"*").get();
infos[containerId]->limitation.set(
http://git-wip-us.apache.org/repos/asf/mesos/blob/866d4c8d/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index e091d82..47d5632 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -5602,6 +5602,8 @@ ExecutorInfo Slave::getExecutorInfo(
// Add an allowance for the command executor. This does lead to a
// small overcommit of resources.
//
+ // NOTE: The size of the memory is truncated here to preserve the
+ // existing behavior for backward compatibility.
// TODO(vinod): If a task is using revocable resources, mark the
// corresponding executor resource (e.g., cpus) to be also
// revocable. Currently, it is OK because the containerizer is
@@ -5609,7 +5611,8 @@ ExecutorInfo Slave::getExecutorInfo(
// the container being correctly marked as revocable.
Resources executorOverhead = Resources::parse(
"cpus:" + stringify(DEFAULT_EXECUTOR_CPUS) + ";" +
- "mem:" + stringify(DEFAULT_EXECUTOR_MEM.megabytes())).get();
+ "mem:" + stringify(
+ DEFAULT_EXECUTOR_MEM.bytes() / Bytes::MEGABYTES)).get();
// If the task has an allocation role, we inject it into
// the executor as well. Note that old masters will not
http://git-wip-us.apache.org/repos/asf/mesos/blob/866d4c8d/src/tests/container_logger_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/container_logger_tests.cpp b/src/tests/container_logger_tests.cpp
index b65cf6a..2d5e7de 100644
--- a/src/tests/container_logger_tests.cpp
+++ b/src/tests/container_logger_tests.cpp
@@ -370,8 +370,8 @@ TEST_F(ContainerLoggerTest, LOGROTATE_RotateInSandbox)
// one MB since there is also the executor's output besides the task's stdout.
Try<Bytes> stdoutSize = os::stat::size(stdoutPath);
ASSERT_SOME(stdoutSize);
- EXPECT_LE(1024u, stdoutSize->kilobytes());
- EXPECT_GE(1050u, stdoutSize->kilobytes());
+ EXPECT_LE(1024u, stdoutSize->bytes() / Bytes::KILOBYTES);
+ EXPECT_GE(1050u, stdoutSize->bytes() / Bytes::KILOBYTES);
// We should only have files up to "stdout.4".
stdoutPath = path::join(sandboxDirectory, "stdout.5");
@@ -385,8 +385,8 @@ TEST_F(ContainerLoggerTest, LOGROTATE_RotateInSandbox)
// NOTE: The rotated files are written in contiguous blocks, meaning that
// each file may be less than the maximum allowed size.
stdoutSize = os::stat::size(stdoutPath);
- EXPECT_LE(2040u, stdoutSize->kilobytes());
- EXPECT_GE(2048u, stdoutSize->kilobytes());
+ EXPECT_LE(2040u, stdoutSize->bytes() / Bytes::KILOBYTES);
+ EXPECT_GE(2048u, stdoutSize->bytes() / Bytes::KILOBYTES);
}
}
@@ -783,8 +783,8 @@ TEST_P(UserContainerLoggerTest, ROOT_LOGROTATE_RotateWithSwitchUserTrueOrFalse)
// one MB since there is also the executor's output besides the task's stdout.
Try<Bytes> stdoutSize = os::stat::size(stdoutPath);
ASSERT_SOME(stdoutSize);
- EXPECT_LE(1024u, stdoutSize->kilobytes());
- EXPECT_GE(1050u, stdoutSize->kilobytes());
+ EXPECT_LE(1024u, stdoutSize->bytes() / Bytes::KILOBYTES);
+ EXPECT_GE(1050u, stdoutSize->bytes() / Bytes::KILOBYTES);
// We should only have files up to "stdout.1".
stdoutPath = path::join(sandboxDirectory, "stdout.2");
@@ -798,8 +798,8 @@ TEST_P(UserContainerLoggerTest, ROOT_LOGROTATE_RotateWithSwitchUserTrueOrFalse)
// each file may be less than the maximum allowed size.
stdoutSize = os::stat::size(stdoutPath);
ASSERT_SOME(stdoutSize);
- EXPECT_LE(2040u, stdoutSize->kilobytes());
- EXPECT_GE(2048u, stdoutSize->kilobytes());
+ EXPECT_LE(2040u, stdoutSize->bytes() / Bytes::KILOBYTES);
+ EXPECT_GE(2048u, stdoutSize->bytes() / Bytes::KILOBYTES);
}
#endif // __WINDOWS__
http://git-wip-us.apache.org/repos/asf/mesos/blob/866d4c8d/src/tests/containerizer/docker_containerizer_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/docker_containerizer_tests.cpp b/src/tests/containerizer/docker_containerizer_tests.cpp
index 630bb2e..d1e6570 100644
--- a/src/tests/containerizer/docker_containerizer_tests.cpp
+++ b/src/tests/containerizer/docker_containerizer_tests.cpp
@@ -1131,7 +1131,7 @@ TEST_F(DockerContainerizerTest, ROOT_DOCKER_Update)
ASSERT_SOME(mem);
EXPECT_EQ(1024u, cpu.get());
- EXPECT_EQ(128u, mem->megabytes());
+ EXPECT_EQ(128u, mem->bytes() / Bytes::MEGABYTES);
newResources = Resources::parse("cpus:1;mem:144");
@@ -1151,7 +1151,7 @@ TEST_F(DockerContainerizerTest, ROOT_DOCKER_Update)
ASSERT_SOME(mem);
EXPECT_EQ(1024u, cpu.get());
- EXPECT_EQ(144u, mem->megabytes());
+ EXPECT_EQ(144u, mem->bytes() / Bytes::MEGABYTES);
driver.stop();
driver.join();
http://git-wip-us.apache.org/repos/asf/mesos/blob/866d4c8d/src/tests/hierarchical_allocator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/hierarchical_allocator_tests.cpp b/src/tests/hierarchical_allocator_tests.cpp
index c98bebb..ad9d556 100644
--- a/src/tests/hierarchical_allocator_tests.cpp
+++ b/src/tests/hierarchical_allocator_tests.cpp
@@ -2069,7 +2069,8 @@ TEST_F(HierarchicalAllocatorTest, Allocatable)
// Not enough memory or cpu to be considered allocatable.
SlaveInfo slave1 = createSlaveInfo(
"cpus:" + stringify(MIN_CPUS / 2u) + ";"
- "mem:" + stringify((MIN_MEM / 2u).megabytes()) + ";"
+ "mem:" + stringify(
+ (double) (MIN_MEM / 2u).bytes() / Bytes::MEGABYTES) + ";"
"disk:128");
allocator->addSlave(
slave1.id(),
@@ -2082,7 +2083,8 @@ TEST_F(HierarchicalAllocatorTest, Allocatable)
// Enough cpus to be considered allocatable.
SlaveInfo slave2 = createSlaveInfo(
"cpus:" + stringify(MIN_CPUS) + ";"
- "mem:" + stringify((MIN_MEM / 2u).megabytes()) + ";"
+ "mem:" + stringify(
+ (double) (MIN_MEM / 2u).bytes() / Bytes::MEGABYTES) + ";"
"disk:128");
allocator->addSlave(
slave2.id(),
@@ -2101,7 +2103,7 @@ TEST_F(HierarchicalAllocatorTest, Allocatable)
// Enough memory to be considered allocatable.
SlaveInfo slave3 = createSlaveInfo(
"cpus:" + stringify(MIN_CPUS / 2u) + ";"
- "mem:" + stringify((MIN_MEM).megabytes()) + ";"
+ "mem:" + stringify((double) (MIN_MEM).bytes() / Bytes::MEGABYTES) + ";"
"disk:128");
allocator->addSlave(
slave3.id(),
@@ -2121,9 +2123,11 @@ TEST_F(HierarchicalAllocatorTest, Allocatable)
// but it lies across unreserved and reserved resources!
SlaveInfo slave4 = createSlaveInfo(
"cpus:" + stringify(MIN_CPUS * 3u / 2u) + ";"
- "mem:" + stringify((MIN_MEM / 2u).megabytes()) + ";"
+ "mem:" + stringify(
+ (double) (MIN_MEM / 2u).bytes() / Bytes::MEGABYTES) + ";"
"cpus(role1):" + stringify(MIN_CPUS * 3u / 2u) + ";"
- "mem(role1):" + stringify((MIN_MEM / 2u).megabytes()) + ";"
+ "mem(role1):" + stringify(
+ (double) (MIN_MEM / 2u).bytes() / Bytes::MEGABYTES) + ";"
"disk:128");
allocator->addSlave(
slave4.id(),
http://git-wip-us.apache.org/repos/asf/mesos/blob/866d4c8d/src/tests/mesos.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp
index 5e833a1..93913f2 100644
--- a/src/tests/mesos.hpp
+++ b/src/tests/mesos.hpp
@@ -1138,8 +1138,10 @@ inline TResource createPersistentVolume(
const Option<std::string>& creatorPrincipal = None(),
bool isShared = false)
{
- TResource volume =
- TResources::parse("disk", stringify(size.megabytes()), role).get();
+ TResource volume = TResources::parse(
+ "disk",
+ stringify((double) size.bytes() / Bytes::MEGABYTES),
+ role).get();
volume.mutable_disk()->CopyFrom(
createDiskInfo<TResource, TVolume>(
http://git-wip-us.apache.org/repos/asf/mesos/blob/866d4c8d/src/tests/persistent_volume_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/persistent_volume_tests.cpp b/src/tests/persistent_volume_tests.cpp
index 5962dd1..372037f 100644
--- a/src/tests/persistent_volume_tests.cpp
+++ b/src/tests/persistent_volume_tests.cpp
@@ -260,7 +260,7 @@ protected:
switch (::testing::get<0>(GetParam())) {
case NONE: {
diskResource = createDiskResource(
- stringify(mb.megabytes()),
+ stringify((double) mb.bytes() / Bytes::MEGABYTES),
DEFAULT_TEST_ROLE,
None(),
None());
@@ -269,7 +269,7 @@ protected:
}
case PATH: {
diskResource = createDiskResource(
- stringify(mb.megabytes()),
+ stringify((double) mb.bytes() / Bytes::MEGABYTES),
DEFAULT_TEST_ROLE,
None(),
None(),
@@ -279,7 +279,7 @@ protected:
}
case MOUNT: {
diskResource = createDiskResource(
- stringify(mb.megabytes()),
+ stringify((double) mb.bytes() / Bytes::MEGABYTES),
DEFAULT_TEST_ROLE,
None(),
None(),