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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 package org
.apache
.hadoop
.hbase
.regionserver
;
21 import java
.io
.IOException
;
22 import java
.io
.OutputStream
;
23 import java
.io
.PrintStream
;
24 import java
.io
.PrintWriter
;
25 import java
.util
.Date
;
26 import javax
.servlet
.http
.HttpServletRequest
;
27 import javax
.servlet
.http
.HttpServletResponse
;
29 import org
.apache
.hadoop
.hbase
.classification
.InterfaceAudience
;
30 import org
.apache
.hadoop
.conf
.Configuration
;
31 import org
.apache
.hadoop
.hbase
.monitoring
.LogMonitoring
;
32 import org
.apache
.hadoop
.hbase
.monitoring
.StateDumpServlet
;
33 import org
.apache
.hadoop
.hbase
.monitoring
.TaskMonitor
;
34 import org
.apache
.hadoop
.hbase
.util
.Threads
;
36 @InterfaceAudience.Private
37 public class RSDumpServlet
extends StateDumpServlet
{
38 private static final long serialVersionUID
= 1L;
39 private static final String LINE
=
40 "===========================================================";
43 public void doGet(HttpServletRequest request
, HttpServletResponse response
)
45 HRegionServer hrs
= (HRegionServer
)getServletContext().getAttribute(
46 HRegionServer
.REGIONSERVER
);
47 assert hrs
!= null : "No RS in context!";
49 response
.setContentType("text/plain");
51 if (!hrs
.isOnline()) {
52 response
.getWriter().write("The RegionServer is initializing!");
53 response
.getWriter().close();
57 OutputStream os
= response
.getOutputStream();
58 try (PrintWriter out
= new PrintWriter(os
)) {
60 out
.println("RegionServer status for " + hrs
.getServerName()
61 + " as of " + new Date());
63 out
.println("\n\nVersion Info:");
67 out
.println("\n\nTasks:");
69 TaskMonitor
.get().dumpAsText(out
);
71 out
.println("\n\nRowLocks:");
73 dumpRowLock(hrs
, out
);
75 out
.println("\n\nExecutors:");
77 dumpExecutors(hrs
.getExecutorService(), out
);
79 out
.println("\n\nStacks:");
81 PrintStream ps
= new PrintStream(response
.getOutputStream(), false, "UTF-8");
82 Threads
.printThreadInfo(ps
, "");
85 out
.println("\n\nRS Configuration:");
87 Configuration conf
= hrs
.getConfiguration();
92 out
.println("\n\nLogs");
94 long tailKb
= getTailKbParam(request
);
95 LogMonitoring
.dumpTailOfLogs(out
, tailKb
);
97 out
.println("\n\nRS Queue:");
99 if (isShowQueueDump(conf
)) {
107 public static void dumpRowLock(HRegionServer hrs
, PrintWriter out
) {
108 StringBuilder sb
= new StringBuilder();
109 for (Region region
: hrs
.getOnlineRegions()) {
110 HRegion hRegion
= (HRegion
)region
;
111 if (hRegion
.getLockedRows().size() > 0) {
112 for (HRegion
.RowLockContext rowLockContext
: hRegion
.getLockedRows().values()) {
114 sb
.append(hRegion
.getTableDescriptor().getTableName()).append(",")
115 .append(hRegion
.getRegionInfo().getEncodedName()).append(",");
116 sb
.append(rowLockContext
.toString());
117 out
.println(sb
.toString());
123 public static void dumpQueue(HRegionServer hrs
, PrintWriter out
)
125 if (hrs
.compactSplitThread
!= null) {
126 // 1. Print out Compaction/Split Queue
127 out
.println("Compaction/Split Queue summary: "
128 + hrs
.compactSplitThread
.toString() );
129 out
.println(hrs
.compactSplitThread
.dumpQueue());
132 if (hrs
.cacheFlusher
!= null) {
133 // 2. Print out flush Queue
134 out
.println("\nFlush Queue summary: "
135 + hrs
.cacheFlusher
.toString());
136 out
.println(hrs
.cacheFlusher
.dumpQueue());