eolivelli commented on a change in pull request #1641: Added module to enable 
CPU affinity
URL: https://github.com/apache/bookkeeper/pull/1641#discussion_r232079643
 
 

 ##########
 File path: 
cpu-affinity/src/main/java/org/apache/bookkeeper/common/util/affinity/impl/CpuAffinityImpl.java
 ##########
 @@ -0,0 +1,210 @@
+/**
+ *
+ * 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.
+ *
+ */
+package org.apache.bookkeeper.common.util.affinity.impl;
+
+import java.io.Closeable;
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileLock;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import lombok.experimental.UtilityClass;
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * Implementation of CPU Affinity functionality.
+ */
+@UtilityClass
+@Slf4j
+public class CpuAffinityImpl {
+
+    private static final boolean SUPPORTED = checkSupported();
+
+    // Id of CPU cores acquired by this process
+    private static final SortedSet<Integer> acquiredProcessors = new 
TreeSet<>();
+
+    // Ids of processors that were isolated by Linux at boot time. This is the 
set
+    // of processors that can acquired by this or other processes.
+    private static SortedSet<Integer> isolatedProcessors = null;
+
+    private static ProcessorsInfo processorsInfo = null;
+
+    public static synchronized void acquireCore() {
+        if (!SUPPORTED) {
+            throw new RuntimeException("CPU Affinity not supported in current 
environment");
+        }
+
+        if (!CpuAffinityJni.isRoot()) {
+            throw new RuntimeException("CPU Affinity can only be set if the 
process is running as root");
 
 Review comment:
   Okay

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to