|
| 1 | +/** |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +package org.apache.hadoop.hdfs.server.federation.fairness; |
| 20 | + |
| 21 | +import org.apache.hadoop.conf.Configuration; |
| 22 | +import org.apache.hadoop.hdfs.server.federation.router.FederationUtil; |
| 23 | +import org.slf4j.Logger; |
| 24 | +import org.slf4j.LoggerFactory; |
| 25 | + |
| 26 | +import java.util.Set; |
| 27 | + |
| 28 | +import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys. |
| 29 | + DFS_ROUTER_ASYNC_RPC_MAX_ASYNCCALL_PERMIT_KEY; |
| 30 | +import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys. |
| 31 | + DFS_ROUTER_ASYNC_RPC_MAX_ASYNC_CALL_PERMIT_DEFAULT; |
| 32 | + |
| 33 | +public class RouterAsyncRpcFairnessPolicyController extends |
| 34 | + AbstractRouterRpcFairnessPolicyController { |
| 35 | + |
| 36 | + private static final Logger LOG = |
| 37 | + LoggerFactory.getLogger(RouterAsyncRpcFairnessPolicyController.class); |
| 38 | + |
| 39 | + public RouterAsyncRpcFairnessPolicyController(Configuration conf) { |
| 40 | + init(conf); |
| 41 | + } |
| 42 | + |
| 43 | + public void init(Configuration conf) throws IllegalArgumentException { |
| 44 | + super.init(conf); |
| 45 | + |
| 46 | + int maxAsyncCallPermit = conf.getInt(DFS_ROUTER_ASYNC_RPC_MAX_ASYNCCALL_PERMIT_KEY, |
| 47 | + DFS_ROUTER_ASYNC_RPC_MAX_ASYNC_CALL_PERMIT_DEFAULT); |
| 48 | + if (maxAsyncCallPermit <= 0) { |
| 49 | + maxAsyncCallPermit = DFS_ROUTER_ASYNC_RPC_MAX_ASYNC_CALL_PERMIT_DEFAULT; |
| 50 | + } |
| 51 | + LOG.info("Max async call permits per nameservice: {}", maxAsyncCallPermit); |
| 52 | + |
| 53 | + // Get all name services configured |
| 54 | + Set<String> allConfiguredNS = FederationUtil.getAllConfiguredNS(conf); |
| 55 | + |
| 56 | + for (String nsId : allConfiguredNS) { |
| 57 | + LOG.info("Dedicated permits {} for ns {} ", maxAsyncCallPermit, nsId); |
| 58 | + insertNameServiceWithPermits(nsId, maxAsyncCallPermit); |
| 59 | + logAssignment(nsId, maxAsyncCallPermit); |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + private static void logAssignment(String nsId, int count) { |
| 64 | + LOG.info("Assigned {} permits to nsId {} ", count, nsId); |
| 65 | + } |
| 66 | +} |
0 commit comments