View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  package org.apache.hadoop.hbase.regionserver;
20  
21  import java.io.IOException;
22  import java.io.PrintWriter;
23  import java.io.StringWriter;
24  import java.util.ArrayList;
25  import java.util.Iterator;
26  import java.util.List;
27  import java.util.concurrent.BlockingQueue;
28  import java.util.concurrent.Executors;
29  import java.util.concurrent.RejectedExecutionException;
30  import java.util.concurrent.RejectedExecutionHandler;
31  import java.util.concurrent.ThreadFactory;
32  import java.util.concurrent.ThreadPoolExecutor;
33  import java.util.concurrent.TimeUnit;
34  import java.util.concurrent.atomic.AtomicInteger;
35  
36  import org.apache.commons.logging.Log;
37  import org.apache.commons.logging.LogFactory;
38  import org.apache.hadoop.conf.Configuration;
39  import org.apache.hadoop.hbase.RemoteExceptionHandler;
40  import org.apache.hadoop.hbase.classification.InterfaceAudience;
41  import org.apache.hadoop.hbase.conf.ConfigurationManager;
42  import org.apache.hadoop.hbase.conf.PropagatingConfigurationObserver;
43  import org.apache.hadoop.hbase.regionserver.compactions.CompactionContext;
44  import org.apache.hadoop.hbase.regionserver.compactions.CompactionRequest;
45  import org.apache.hadoop.hbase.regionserver.throttle.CompactionThroughputControllerFactory;
46  import org.apache.hadoop.hbase.regionserver.throttle.ThroughputController;
47  import org.apache.hadoop.hbase.security.User;
48  import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
49  import org.apache.hadoop.hbase.util.Pair;
50  import org.apache.hadoop.hbase.util.StealJobQueue;
51  import org.apache.hadoop.util.StringUtils;
52  
53  import com.google.common.annotations.VisibleForTesting;
54  import com.google.common.base.Preconditions;
55  
56  /**
57   * Compact region on request and then run split if appropriate
58   */
59  @InterfaceAudience.Private
60  public class CompactSplitThread implements CompactionRequestor, PropagatingConfigurationObserver {
61    private static final Log LOG = LogFactory.getLog(CompactSplitThread.class);
62  
63    // Configuration key for the large compaction threads.
64    public final static String LARGE_COMPACTION_THREADS =
65        "hbase.regionserver.thread.compaction.large";
66    public final static int LARGE_COMPACTION_THREADS_DEFAULT = 1;
67    
68    // Configuration key for the small compaction threads.
69    public final static String SMALL_COMPACTION_THREADS =
70        "hbase.regionserver.thread.compaction.small";
71    public final static int SMALL_COMPACTION_THREADS_DEFAULT = 1;
72    
73    // Configuration key for split threads
74    public final static String SPLIT_THREADS = "hbase.regionserver.thread.split";
75    public final static int SPLIT_THREADS_DEFAULT = 1;
76    
77    // Configuration keys for merge threads
78    public final static String MERGE_THREADS = "hbase.regionserver.thread.merge";
79    public final static int MERGE_THREADS_DEFAULT = 1;
80  
81    public static final String REGION_SERVER_REGION_SPLIT_LIMIT =
82        "hbase.regionserver.regionSplitLimit";
83    public static final int DEFAULT_REGION_SERVER_REGION_SPLIT_LIMIT= 1000;
84    
85    private final HRegionServer server;
86    private final Configuration conf;
87  
88    private final ThreadPoolExecutor longCompactions;
89    private final ThreadPoolExecutor shortCompactions;
90    private final ThreadPoolExecutor splits;
91    private final ThreadPoolExecutor mergePool;
92  
93    private volatile ThroughputController compactionThroughputController;
94  
95    /**
96     * Splitting should not take place if the total number of regions exceed this.
97     * This is not a hard limit to the number of regions but it is a guideline to
98     * stop splitting after number of online regions is greater than this.
99     */
100   private int regionSplitLimit;
101 
102   /** @param server */
103   CompactSplitThread(HRegionServer server) {
104     super();
105     this.server = server;
106     this.conf = server.getConfiguration();
107     this.regionSplitLimit = conf.getInt(REGION_SERVER_REGION_SPLIT_LIMIT,
108         DEFAULT_REGION_SERVER_REGION_SPLIT_LIMIT);
109 
110     int largeThreads = Math.max(1, conf.getInt(
111         LARGE_COMPACTION_THREADS, LARGE_COMPACTION_THREADS_DEFAULT));
112     int smallThreads = conf.getInt(
113         SMALL_COMPACTION_THREADS, SMALL_COMPACTION_THREADS_DEFAULT);
114 
115     int splitThreads = conf.getInt(SPLIT_THREADS, SPLIT_THREADS_DEFAULT);
116 
117     // if we have throttle threads, make sure the user also specified size
118     Preconditions.checkArgument(largeThreads > 0 && smallThreads > 0);
119 
120     final String n = Thread.currentThread().getName();
121 
122     StealJobQueue<Runnable> stealJobQueue = new StealJobQueue<Runnable>();
123     this.longCompactions = new ThreadPoolExecutor(largeThreads, largeThreads, 60, TimeUnit.SECONDS,
124         stealJobQueue, new ThreadFactory() {
125           AtomicInteger longCompactionThreadCounter = new AtomicInteger(0);
126 
127           @Override
128           public Thread newThread(Runnable r) {
129             String name = n + "-longCompactions-" + longCompactionThreadCounter.getAndIncrement();
130             return new Thread(r, name);
131           }
132       });
133     this.longCompactions.setRejectedExecutionHandler(new Rejection());
134     this.longCompactions.prestartAllCoreThreads();
135     this.shortCompactions = new ThreadPoolExecutor(smallThreads, smallThreads, 60, TimeUnit.SECONDS,
136         stealJobQueue.getStealFromQueue(), new ThreadFactory() {
137           AtomicInteger shortCompactionThreadCounter = new AtomicInteger(0);
138 
139           @Override
140           public Thread newThread(Runnable r) {
141             String name = n + "-shortCompactions-" + shortCompactionThreadCounter.getAndIncrement();
142             return new Thread(r, name);
143           }
144       });
145     this.shortCompactions
146         .setRejectedExecutionHandler(new Rejection());
147     this.splits = (ThreadPoolExecutor)
148         Executors.newFixedThreadPool(splitThreads, new ThreadFactory() {
149           AtomicInteger splitThreadCounter = new AtomicInteger(0);
150 
151           @Override
152           public Thread newThread(Runnable r) {
153             String name = n + "-splits-" + splitThreadCounter.getAndIncrement();
154             return new Thread(r, name);
155           }
156       });
157     int mergeThreads = conf.getInt(MERGE_THREADS, MERGE_THREADS_DEFAULT);
158     this.mergePool = (ThreadPoolExecutor) Executors.newFixedThreadPool(
159         mergeThreads, new ThreadFactory() {
160           @Override
161           public Thread newThread(Runnable r) {
162             String name = n + "-merges-" + System.currentTimeMillis();
163             return new Thread(r, name);
164           }
165         });
166 
167     // compaction throughput controller
168     this.compactionThroughputController =
169         CompactionThroughputControllerFactory.create(server, conf);
170   }
171 
172   @Override
173   public String toString() {
174     return "compaction_queue=("
175         + longCompactions.getQueue().size() + ":"
176         + shortCompactions.getQueue().size() + ")"
177         + ", split_queue=" + splits.getQueue().size()
178         + ", merge_queue=" + mergePool.getQueue().size();
179   }
180   
181   public String dumpQueue() {
182     StringBuffer queueLists = new StringBuffer();
183     queueLists.append("Compaction/Split Queue dump:\n");
184     queueLists.append("  LargeCompation Queue:\n");
185     BlockingQueue<Runnable> lq = longCompactions.getQueue();
186     Iterator<Runnable> it = lq.iterator();
187     while (it.hasNext()) {
188       queueLists.append("    " + it.next().toString());
189       queueLists.append("\n");
190     }
191 
192     if (shortCompactions != null) {
193       queueLists.append("\n");
194       queueLists.append("  SmallCompation Queue:\n");
195       lq = shortCompactions.getQueue();
196       it = lq.iterator();
197       while (it.hasNext()) {
198         queueLists.append("    " + it.next().toString());
199         queueLists.append("\n");
200       }
201     }
202 
203     queueLists.append("\n");
204     queueLists.append("  Split Queue:\n");
205     lq = splits.getQueue();
206     it = lq.iterator();
207     while (it.hasNext()) {
208       queueLists.append("    " + it.next().toString());
209       queueLists.append("\n");
210     }
211 
212     queueLists.append("\n");
213     queueLists.append("  Region Merge Queue:\n");
214     lq = mergePool.getQueue();
215     it = lq.iterator();
216     while (it.hasNext()) {
217       queueLists.append("    " + it.next().toString());
218       queueLists.append("\n");
219     }
220 
221     return queueLists.toString();
222   }
223 
224   public synchronized void requestRegionsMerge(final Region a,
225       final Region b, final boolean forcible, long masterSystemTime, User user) {
226     try {
227       mergePool.execute(new RegionMergeRequest(a, b, this.server, forcible, masterSystemTime,user));
228       if (LOG.isDebugEnabled()) {
229         LOG.debug("Region merge requested for " + a + "," + b + ", forcible="
230             + forcible + ".  " + this);
231       }
232     } catch (RejectedExecutionException ree) {
233       LOG.warn("Could not execute merge for " + a + "," + b + ", forcible="
234           + forcible, ree);
235     }
236   }
237 
238   public synchronized boolean requestSplit(final Region r) {
239     // don't split regions that are blocking
240     if (shouldSplitRegion() && ((HRegion)r).getCompactPriority() >= Store.PRIORITY_USER) {
241       byte[] midKey = ((HRegion)r).checkSplit();
242       if (midKey != null) {
243         requestSplit(r, midKey);
244         return true;
245       }
246     }
247     return false;
248   }
249 
250   public synchronized void requestSplit(final Region r, byte[] midKey) {
251     requestSplit(r, midKey, null);
252   }
253 
254   /*
255    * The User parameter allows the split thread to assume the correct user identity
256    */
257   public synchronized void requestSplit(final Region r, byte[] midKey, User user) {
258     if (midKey == null) {
259       LOG.debug("Region " + r.getRegionInfo().getRegionNameAsString() +
260         " not splittable because midkey=null");
261       if (((HRegion)r).shouldForceSplit()) {
262         ((HRegion)r).clearSplit();
263       }
264       return;
265     }
266     try {
267       this.splits.execute(new SplitRequest(r, midKey, this.server, user));
268       if (LOG.isDebugEnabled()) {
269         LOG.debug("Split requested for " + r + ".  " + this);
270       }
271     } catch (RejectedExecutionException ree) {
272       LOG.info("Could not execute split for " + r, ree);
273     }
274   }
275 
276   @Override
277   public synchronized List<CompactionRequest> requestCompaction(final Region r, final String why)
278       throws IOException {
279     return requestCompaction(r, why, null);
280   }
281 
282   @Override
283   public synchronized List<CompactionRequest> requestCompaction(final Region r, final String why,
284       List<Pair<CompactionRequest, Store>> requests) throws IOException {
285     return requestCompaction(r, why, Store.NO_PRIORITY, requests, null);
286   }
287 
288   @Override
289   public synchronized CompactionRequest requestCompaction(final Region r, final Store s,
290       final String why, CompactionRequest request) throws IOException {
291     return requestCompaction(r, s, why, Store.NO_PRIORITY, request, null);
292   }
293 
294   @Override
295   public synchronized List<CompactionRequest> requestCompaction(final Region r, final String why,
296       int p, List<Pair<CompactionRequest, Store>> requests, User user) throws IOException {
297     return requestCompactionInternal(r, why, p, requests, true, user);
298   }
299 
300   private List<CompactionRequest> requestCompactionInternal(final Region r, final String why,
301       int p, List<Pair<CompactionRequest, Store>> requests, boolean selectNow, User user)
302           throws IOException {
303     // not a special compaction request, so make our own list
304     List<CompactionRequest> ret = null;
305     if (requests == null) {
306       ret = selectNow ? new ArrayList<CompactionRequest>(r.getStores().size()) : null;
307       for (Store s : r.getStores()) {
308         CompactionRequest cr = requestCompactionInternal(r, s, why, p, null, selectNow, user);
309         if (selectNow) ret.add(cr);
310       }
311     } else {
312       Preconditions.checkArgument(selectNow); // only system requests have selectNow == false
313       ret = new ArrayList<CompactionRequest>(requests.size());
314       for (Pair<CompactionRequest, Store> pair : requests) {
315         ret.add(requestCompaction(r, pair.getSecond(), why, p, pair.getFirst(), user));
316       }
317     }
318     return ret;
319   }
320 
321   public CompactionRequest requestCompaction(final Region r, final Store s,
322       final String why, int priority, CompactionRequest request, User user) throws IOException {
323     return requestCompactionInternal(r, s, why, priority, request, true, user);
324   }
325 
326   public synchronized void requestSystemCompaction(
327       final Region r, final String why) throws IOException {
328     requestCompactionInternal(r, why, Store.NO_PRIORITY, null, false, null);
329   }
330 
331   public void requestSystemCompaction(
332       final Region r, final Store s, final String why) throws IOException {
333     requestCompactionInternal(r, s, why, Store.NO_PRIORITY, null, false, null);
334   }
335 
336   /**
337    * @param r region store belongs to
338    * @param s Store to request compaction on
339    * @param why Why compaction requested -- used in debug messages
340    * @param priority override the default priority (NO_PRIORITY == decide)
341    * @param request custom compaction request. Can be <tt>null</tt> in which case a simple
342    *          compaction will be used.
343    */
344   private synchronized CompactionRequest requestCompactionInternal(final Region r, final Store s,
345       final String why, int priority, CompactionRequest request, boolean selectNow, User user)
346           throws IOException {
347     if (this.server.isStopped()
348         || (r.getTableDesc() != null && !r.getTableDesc().isCompactionEnabled())) {
349       return null;
350     }
351 
352     CompactionContext compaction = null;
353     if (selectNow) {
354       compaction = selectCompaction(r, s, priority, request, user);
355       if (compaction == null) return null; // message logged inside
356     }
357 
358     // We assume that most compactions are small. So, put system compactions into small
359     // pool; we will do selection there, and move to large pool if necessary.
360     ThreadPoolExecutor pool = (selectNow && s.throttleCompaction(compaction.getRequest().getSize()))
361       ? longCompactions : shortCompactions;
362     pool.execute(new CompactionRunner(s, r, compaction, pool, user));
363     ((HRegion)r).incrementCompactionsQueuedCount();
364     if (LOG.isDebugEnabled()) {
365       String type = (pool == shortCompactions) ? "Small " : "Large ";
366       LOG.debug(type + "Compaction requested: " + (selectNow ? compaction.toString() : "system")
367           + (why != null && !why.isEmpty() ? "; Because: " + why : "") + "; " + this);
368     }
369     return selectNow ? compaction.getRequest() : null;
370   }
371 
372   private CompactionContext selectCompaction(final Region r, final Store s,
373       int priority, CompactionRequest request, User user) throws IOException {
374     CompactionContext compaction = s.requestCompaction(priority, request, user);
375     if (compaction == null) {
376       if(LOG.isDebugEnabled() && r.getRegionInfo() != null) {
377         LOG.debug("Not compacting " + r.getRegionInfo().getRegionNameAsString() +
378             " because compaction request was cancelled");
379       }
380       return null;
381     }
382     assert compaction.hasSelection();
383     if (priority != Store.NO_PRIORITY) {
384       compaction.getRequest().setPriority(priority);
385     }
386     return compaction;
387   }
388 
389   /**
390    * Only interrupt once it's done with a run through the work loop.
391    */
392   void interruptIfNecessary() {
393     splits.shutdown();
394     mergePool.shutdown();
395     longCompactions.shutdown();
396     shortCompactions.shutdown();
397   }
398 
399   private void waitFor(ThreadPoolExecutor t, String name) {
400     boolean done = false;
401     while (!done) {
402       try {
403         done = t.awaitTermination(60, TimeUnit.SECONDS);
404         LOG.info("Waiting for " + name + " to finish...");
405         if (!done) {
406           t.shutdownNow();
407         }
408       } catch (InterruptedException ie) {
409         LOG.warn("Interrupted waiting for " + name + " to finish...");
410       }
411     }
412   }
413 
414   void join() {
415     waitFor(splits, "Split Thread");
416     waitFor(mergePool, "Merge Thread");
417     waitFor(longCompactions, "Large Compaction Thread");
418     waitFor(shortCompactions, "Small Compaction Thread");
419   }
420 
421   /**
422    * Returns the current size of the queue containing regions that are
423    * processed.
424    *
425    * @return The current size of the regions queue.
426    */
427   public int getCompactionQueueSize() {
428     return longCompactions.getQueue().size() + shortCompactions.getQueue().size();
429   }
430 
431   public int getLargeCompactionQueueSize() {
432     return longCompactions.getQueue().size();
433   }
434 
435 
436   public int getSmallCompactionQueueSize() {
437     return shortCompactions.getQueue().size();
438   }
439 
440   public int getSplitQueueSize() {
441     return splits.getQueue().size();
442   }
443 
444   private boolean shouldSplitRegion() {
445     if(server.getNumberOfOnlineRegions() > 0.9*regionSplitLimit) {
446       LOG.warn("Total number of regions is approaching the upper limit " + regionSplitLimit + ". "
447           + "Please consider taking a look at http://hbase.apache.org/book.html#ops.regionmgt");
448     }
449     return (regionSplitLimit > server.getNumberOfOnlineRegions());
450   }
451 
452   /**
453    * @return the regionSplitLimit
454    */
455   public int getRegionSplitLimit() {
456     return this.regionSplitLimit;
457   }
458 
459   @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="EQ_COMPARETO_USE_OBJECT_EQUALS",
460       justification="Contrived use of compareTo")
461   private class CompactionRunner implements Runnable, Comparable<CompactionRunner> {
462     private final Store store;
463     private final HRegion region;
464     private CompactionContext compaction;
465     private int queuedPriority;
466     private ThreadPoolExecutor parent;
467     private User user;
468     private long time;
469 
470     public CompactionRunner(Store store, Region region,
471         CompactionContext compaction, ThreadPoolExecutor parent, User user) {
472       super();
473       this.store = store;
474       this.region = (HRegion)region;
475       this.compaction = compaction;
476       this.queuedPriority = (this.compaction == null)
477           ? store.getCompactPriority() : compaction.getRequest().getPriority();
478       this.parent = parent;
479       this.user = user;
480       this.time =  System.currentTimeMillis();
481     }
482 
483     @Override
484     public String toString() {
485       return (this.compaction != null) ? ("Request = " + compaction.getRequest())
486           : ("regionName = " + region.toString() + ", storeName = " + store.toString() +
487              ", priority = " + queuedPriority + ", time = " + time);
488     }
489 
490     private void doCompaction(User user) {
491       // Common case - system compaction without a file selection. Select now.
492       if (this.compaction == null) {
493         int oldPriority = this.queuedPriority;
494         this.queuedPriority = this.store.getCompactPriority();
495         if (this.queuedPriority > oldPriority) {
496           // Store priority decreased while we were in queue (due to some other compaction?),
497           // requeue with new priority to avoid blocking potential higher priorities.
498           this.parent.execute(this);
499           return;
500         }
501         try {
502           this.compaction = selectCompaction(this.region, this.store, queuedPriority, null, user);
503         } catch (IOException ex) {
504           LOG.error("Compaction selection failed " + this, ex);
505           server.checkFileSystem();
506           region.decrementCompactionsQueuedCount();
507           return;
508         }
509         if (this.compaction == null) {
510           region.decrementCompactionsQueuedCount();
511           return; // nothing to do
512         }
513         // Now see if we are in correct pool for the size; if not, go to the correct one.
514         // We might end up waiting for a while, so cancel the selection.
515         assert this.compaction.hasSelection();
516         ThreadPoolExecutor pool = store.throttleCompaction(
517             compaction.getRequest().getSize()) ? longCompactions : shortCompactions;
518 
519         // Long compaction pool can process small job
520         // Short compaction pool should not process large job
521         if (this.parent == shortCompactions && pool == longCompactions) {
522           this.store.cancelRequestedCompaction(this.compaction);
523           this.compaction = null;
524           this.parent = pool;
525           this.parent.execute(this);
526           return;
527         }
528       }
529       // Finally we can compact something.
530       assert this.compaction != null;
531 
532       this.compaction.getRequest().beforeExecute();
533       try {
534         // Note: please don't put single-compaction logic here;
535         //       put it into region/store/etc. This is CST logic.
536         long start = EnvironmentEdgeManager.currentTime();
537         boolean completed =
538             region.compact(compaction, store, compactionThroughputController, user);
539         long now = EnvironmentEdgeManager.currentTime();
540         LOG.info(((completed) ? "Completed" : "Aborted") + " compaction: " +
541               this + "; duration=" + StringUtils.formatTimeDiff(now, start));
542         if (completed) {
543           // degenerate case: blocked regions require recursive enqueues
544           if (store.getCompactPriority() <= 0) {
545             requestSystemCompaction(region, store, "Recursive enqueue");
546           } else {
547             // see if the compaction has caused us to exceed max region size
548             requestSplit(region);
549           }
550         }
551       } catch (IOException ex) {
552         IOException remoteEx = RemoteExceptionHandler.checkIOException(ex);
553         LOG.error("Compaction failed " + this, remoteEx);
554         if (remoteEx != ex) {
555           LOG.info("Compaction failed at original callstack: " + formatStackTrace(ex));
556         }
557         region.reportCompactionRequestFailure();
558         server.checkFileSystem();
559       } catch (Exception ex) {
560         LOG.error("Compaction failed " + this, ex);
561         region.reportCompactionRequestFailure();
562         server.checkFileSystem();
563       } finally {
564         region.decrementCompactionsQueuedCount();
565         LOG.debug("CompactSplitThread Status: " + CompactSplitThread.this);
566       }
567       this.compaction.getRequest().afterExecute();
568     }
569 
570     @Override
571     public void run() {
572       Preconditions.checkNotNull(server);
573       if (server.isStopped()
574           || (region.getTableDesc() != null && !region.getTableDesc().isCompactionEnabled())) {
575         region.decrementCompactionsQueuedCount();
576         return;
577       }
578       doCompaction(user);
579     }
580 
581     private String formatStackTrace(Exception ex) {
582       StringWriter sw = new StringWriter();
583       PrintWriter pw = new PrintWriter(sw);
584       ex.printStackTrace(pw);
585       pw.flush();
586       return sw.toString();
587     }
588 
589     @Override
590     public int compareTo(CompactionRunner o) {
591       // Only compare the underlying request (if any), for queue sorting purposes.
592       int compareVal = queuedPriority - o.queuedPriority; // compare priority
593       if (compareVal != 0) return compareVal;
594       CompactionContext tc = this.compaction, oc = o.compaction;
595       // Sort pre-selected (user?) compactions before system ones with equal priority.
596       return (tc == null) ? ((oc == null) ? 0 : 1)
597           : ((oc == null) ? -1 : tc.getRequest().compareTo(oc.getRequest()));
598     }
599   }
600 
601   /**
602    * Cleanup class to use when rejecting a compaction request from the queue.
603    */
604   private static class Rejection implements RejectedExecutionHandler {
605     @Override
606     public void rejectedExecution(Runnable runnable, ThreadPoolExecutor pool) {
607       if (runnable instanceof CompactionRunner) {
608         CompactionRunner runner = (CompactionRunner)runnable;
609         LOG.debug("Compaction Rejected: " + runner);
610         runner.store.cancelRequestedCompaction(runner.compaction);
611       }
612     }
613   }
614 
615   /**
616    * {@inheritDoc}
617    */
618   @Override
619   public void onConfigurationChange(Configuration newConf) {
620     // Check if number of large / small compaction threads has changed, and then
621     // adjust the core pool size of the thread pools, by using the
622     // setCorePoolSize() method. According to the javadocs, it is safe to
623     // change the core pool size on-the-fly. We need to reset the maximum
624     // pool size, as well.
625     int largeThreads = Math.max(1, newConf.getInt(
626             LARGE_COMPACTION_THREADS,
627             LARGE_COMPACTION_THREADS_DEFAULT));
628     if (this.longCompactions.getCorePoolSize() != largeThreads) {
629       LOG.info("Changing the value of " + LARGE_COMPACTION_THREADS +
630               " from " + this.longCompactions.getCorePoolSize() + " to " +
631               largeThreads);
632       if(this.longCompactions.getCorePoolSize() < largeThreads) {
633         this.longCompactions.setMaximumPoolSize(largeThreads);
634         this.longCompactions.setCorePoolSize(largeThreads);
635       } else {
636         this.longCompactions.setCorePoolSize(largeThreads);
637         this.longCompactions.setMaximumPoolSize(largeThreads);
638       }
639     }
640 
641     int smallThreads = newConf.getInt(SMALL_COMPACTION_THREADS,
642             SMALL_COMPACTION_THREADS_DEFAULT);
643     if (this.shortCompactions.getCorePoolSize() != smallThreads) {
644       LOG.info("Changing the value of " + SMALL_COMPACTION_THREADS +
645                 " from " + this.shortCompactions.getCorePoolSize() + " to " +
646                 smallThreads);
647       if(this.shortCompactions.getCorePoolSize() < smallThreads) {
648         this.shortCompactions.setMaximumPoolSize(smallThreads);
649         this.shortCompactions.setCorePoolSize(smallThreads);
650       } else {
651         this.shortCompactions.setCorePoolSize(smallThreads);
652         this.shortCompactions.setMaximumPoolSize(smallThreads);
653       }
654     }
655 
656     int splitThreads = newConf.getInt(SPLIT_THREADS,
657             SPLIT_THREADS_DEFAULT);
658     if (this.splits.getCorePoolSize() != splitThreads) {
659       LOG.info("Changing the value of " + SPLIT_THREADS +
660                 " from " + this.splits.getCorePoolSize() + " to " +
661                 splitThreads);
662       if(this.splits.getCorePoolSize() < splitThreads) {
663         this.splits.setMaximumPoolSize(splitThreads);
664         this.splits.setCorePoolSize(splitThreads);
665       } else {
666         this.splits.setCorePoolSize(splitThreads);
667         this.splits.setMaximumPoolSize(splitThreads);
668       }
669     }
670 
671     int mergeThreads = newConf.getInt(MERGE_THREADS,
672             MERGE_THREADS_DEFAULT);
673     if (this.mergePool.getCorePoolSize() != mergeThreads) {
674       LOG.info("Changing the value of " + MERGE_THREADS +
675                 " from " + this.mergePool.getCorePoolSize() + " to " +
676                 mergeThreads);
677       if(this.mergePool.getCorePoolSize() < mergeThreads) {
678         this.mergePool.setMaximumPoolSize(mergeThreads);
679         this.mergePool.setCorePoolSize(mergeThreads);
680       } else {
681         this.mergePool.setCorePoolSize(mergeThreads);
682         this.mergePool.setMaximumPoolSize(mergeThreads);
683       }
684     }
685 
686     ThroughputController old = this.compactionThroughputController;
687     if (old != null) {
688       old.stop("configuration change");
689     }
690     this.compactionThroughputController =
691         CompactionThroughputControllerFactory.create(server, newConf);
692 
693     // We change this atomically here instead of reloading the config in order that upstream
694     // would be the only one with the flexibility to reload the config.
695     this.conf.reloadConfiguration();
696   }
697 
698   protected int getSmallCompactionThreadNum() {
699     return this.shortCompactions.getCorePoolSize();
700   }
701 
702   protected int getLargeCompactionThreadNum() {
703     return this.longCompactions.getCorePoolSize();
704   }
705 
706   protected int getSplitThreadNum() {
707     return this.splits.getCorePoolSize();
708   }
709 
710   protected int getMergeThreadNum() {
711     return this.mergePool.getCorePoolSize();
712   }
713 
714   /**
715    * {@inheritDoc}
716    */
717   @Override
718   public void registerChildren(ConfigurationManager manager) {
719     // No children to register.
720   }
721 
722   /**
723    * {@inheritDoc}
724    */
725   @Override
726   public void deregisterChildren(ConfigurationManager manager) {
727     // No children to register
728   }
729 
730   @VisibleForTesting
731   public ThroughputController getCompactionThroughputController() {
732     return compactionThroughputController;
733   }
734 
735   @VisibleForTesting
736   /**
737    * Shutdown the long compaction thread pool.
738    * Should only be used in unit test to prevent long compaction thread pool from stealing job
739    * from short compaction queue
740    */
741   void shutdownLongCompactions(){
742     this.longCompactions.shutdown();
743   }
744 }