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 2016/02/04 20:21:54 UTC
[2/3] mesos git commit: Implemented the NetClsHandleManager class.
Implemented the NetClsHandleManager class.
Review: https://reviews.apache.org/r/42587/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/9c57aa97
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/9c57aa97
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/9c57aa97
Branch: refs/heads/master
Commit: 9c57aa97cbae07f5c7c0c4b002d952b371babb0c
Parents: 5ff85e1
Author: Avinash sridharan <av...@mesosphere.io>
Authored: Thu Feb 4 10:46:21 2016 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Thu Feb 4 11:21:48 2016 -0800
----------------------------------------------------------------------
.../mesos/isolators/cgroups/net_cls.cpp | 103 ++++++++++++++++++-
.../mesos/isolators/cgroups/net_cls.hpp | 3 +-
2 files changed, 102 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/9c57aa97/src/slave/containerizer/mesos/isolators/cgroups/net_cls.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/cgroups/net_cls.cpp b/src/slave/containerizer/mesos/isolators/cgroups/net_cls.cpp
index 52a1109..740b1b4 100644
--- a/src/slave/containerizer/mesos/isolators/cgroups/net_cls.cpp
+++ b/src/slave/containerizer/mesos/isolators/cgroups/net_cls.cpp
@@ -15,6 +15,7 @@
// limitations under the License.
#include <list>
+#include <sstream>
#include <vector>
#include <process/defer.hpp>
@@ -31,9 +32,11 @@
#include "slave/containerizer/mesos/isolators/cgroups/net_cls.hpp"
+using std::bitset;
using std::list;
using std::set;
using std::string;
+using std::stringstream;
using std::vector;
using process::Failure;
@@ -51,21 +54,115 @@ namespace mesos {
namespace internal {
namespace slave {
+string NetClsHandleManager::hexify(uint32_t handle)
+{
+ stringstream stream;
+ stream << std::hex << handle;
+ return "0x" + stream.str();
+};
+
+// For each primary handle, we maintain a bitmap to keep track of
+// allocated and free secondary handles. To find a free secondary
+// handle we scan the bitmap from the first element till we find a
+// free handle.
+//
+// TODO(asridharan): Currently the bitmap search is naive, since the
+// assumption is that the number of containers running on an agent
+// will be O(100). If we start facing any performance issues, we might
+// want to revisit this logic and make the search for a free secondary
+// handle more efficient. One idea for making it more efficient would
+// be to store the last allocated handle and start the search at this
+// position and performing a circular search on the bitmap.
Try<NetClsHandle> NetClsHandleManager::alloc(uint16_t primary)
{
- return Error("Not Implemented");
+ if (!primaries.contains(primary)) {
+ return Error(
+ "Primary handle "+ hexify(primary) +
+ " not present in primary handle range");
+ }
+
+ if (!used.contains(primary)) {
+ // NOTE: We never use 0 as a secondary handle, so mark it used.
+ used[primary].set(0);
+ } else if (used[primary].all()) {
+ return Error(
+ "No free handles remaining for primary handle " +
+ hexify(primary));
+ }
+
+ // There is at least one secondary handle free for this primary handle.
+ for (size_t count = 1; count < used[primary].size(); count++) {
+ if (!used[primary].test(count)) {
+ used[primary].set(count);
+
+ NetClsHandle handle(primary, count);
+
+ return handle;
+ }
+ }
+
+ UNREACHABLE();
}
Try<Nothing> NetClsHandleManager::reserve(const NetClsHandle& handle)
{
- return Error("Not Implemented");
+ if (!primaries.contains(handle.primary)) {
+ return Error(
+ "Primary handle " + hexify(handle.primary) +
+ " not present in primary handle range");
+ }
+
+ if (handle.secondary == 0) {
+ return Error("0 is an invalid secondary handle");
+ }
+
+ if (!used.contains(handle.primary)) {
+ // NOTE: We never use 0 as a secondary handle, so mark it used.
+ used[handle.primary].set(0);
+ }
+
+ if (used[handle.primary].test(handle.secondary)) {
+ return Error(
+ "The secondary handle " + hexify(handle.secondary) +
+ ", for the primary handle " + hexify(handle.primary) +
+ " has already been allocated");
+ }
+
+ used[handle.primary].set(handle.secondary);
+
+ return Nothing();
}
+
Try<Nothing> NetClsHandleManager::free(const NetClsHandle& handle)
{
- return Error("Not Implemented");
+ if (!primaries.contains(handle.primary)) {
+ return Error(
+ "Primary handle "+ hexify(handle.primary) +
+ " not present in primary handle range");
+ }
+
+ if (handle.secondary == 0) {
+ return Error("0 is an invalid secondary handle");
+ }
+
+ if (!used.contains(handle.primary)) {
+ return Error(
+ "No secondary handles have been allocated from this primary handle " +
+ hexify(handle.primary));
+ }
+
+ if (!used[handle.primary].test(handle.secondary)) {
+ return Error(
+ "Secondary handle " + hexify(handle.secondary) +
+ " is not allocated for primary handle " + hexify(handle.primary));
+ }
+
+ used[handle.primary].reset(handle.secondary);
+
+ return Nothing();
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/9c57aa97/src/slave/containerizer/mesos/isolators/cgroups/net_cls.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/cgroups/net_cls.hpp b/src/slave/containerizer/mesos/isolators/cgroups/net_cls.hpp
index 6de2056..8e3259e 100644
--- a/src/slave/containerizer/mesos/isolators/cgroups/net_cls.hpp
+++ b/src/slave/containerizer/mesos/isolators/cgroups/net_cls.hpp
@@ -21,7 +21,6 @@
#include <bitset>
#include <iostream>
-#include <sstream>
#include <string>
#include <stout/hashmap.hpp>
@@ -70,6 +69,8 @@ struct NetClsHandle
class NetClsHandleManager
{
public:
+ static std::string hexify(uint32_t handle);
+
NetClsHandleManager(const IntervalSet<uint16_t>& _primaries)
: primaries(_primaries) {};