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.OutputStream;
23  import java.io.PrintStream;
24  import java.io.PrintWriter;
25  import java.util.Date;
26  
27  import javax.servlet.http.HttpServletRequest;
28  import javax.servlet.http.HttpServletResponse;
29  
30  import org.apache.hadoop.hbase.classification.InterfaceAudience;
31  import org.apache.hadoop.conf.Configuration;
32  import org.apache.hadoop.hbase.monitoring.LogMonitoring;
33  import org.apache.hadoop.hbase.monitoring.StateDumpServlet;
34  import org.apache.hadoop.hbase.monitoring.TaskMonitor;
35  import org.apache.hadoop.hbase.util.Threads;
36  
37  @InterfaceAudience.Private
38  public class RSDumpServlet extends StateDumpServlet {
39    private static final long serialVersionUID = 1L;
40    private static final String LINE = "===========================================================";
41  
42    @Override
43    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
44      HRegionServer hrs =
45          (HRegionServer) getServletContext().getAttribute(HRegionServer.REGIONSERVER);
46      assert hrs != null : "No RS in context!";
47  
48      response.setContentType("text/plain");
49  
50      if (!hrs.isOnline()) {
51        response.getWriter().write("The RegionServer is initializing!");
52        response.getWriter().close();
53        return;
54      }
55  
56      OutputStream os = response.getOutputStream();
57      PrintWriter out = new PrintWriter(os);
58  
59      out.println("RegionServer status for " + hrs.getServerName() + " as of " + new Date());
60  
61      out.println("\n\nVersion Info:");
62      out.println(LINE);
63      dumpVersionInfo(out);
64  
65      out.println("\n\nTasks:");
66      out.println(LINE);
67      TaskMonitor.get().dumpAsText(out);
68      
69      out.println("\n\nRowLocks:");
70      out.println(LINE);
71      dumpRowLock(hrs, out);
72  
73      out.println("\n\nExecutors:");
74      out.println(LINE);
75      dumpExecutors(hrs.getExecutorService(), out);
76  
77      out.println("\n\nStacks:");
78      out.println(LINE);
79      PrintStream ps = new PrintStream(response.getOutputStream(), false, "UTF-8");
80      Threads.printThreadInfo(ps, "");
81      ps.flush();
82  
83      out.println("\n\nRS Configuration:");
84      out.println(LINE);
85      Configuration conf = hrs.getConfiguration();
86      out.flush();
87      conf.writeXml(os);
88      os.flush();
89  
90      out.println("\n\nLogs");
91      out.println(LINE);
92      long tailKb = getTailKbParam(request);
93      LogMonitoring.dumpTailOfLogs(out, tailKb);
94  
95      out.println("\n\nRS Queue:");
96      out.println(LINE);
97      if (isShowQueueDump(conf)) {
98        dumpQueue(hrs, out);
99      }
100 
101     out.flush();
102   }
103 
104   public static void dumpRowLock(HRegionServer hrs, PrintWriter out) {
105     StringBuilder sb = new StringBuilder();
106     for (Region region : hrs.getOnlineRegionsLocalContext()) {
107       HRegion hRegion = (HRegion) region;
108       if (hRegion.getLockedRows().size() > 0) {
109         for (HRegion.RowLockContext rowLockContext : hRegion.getLockedRows().values()) {
110           sb.setLength(0);
111           sb.append(hRegion.getTableDesc().getTableName()).append(",")
112               .append(hRegion.getRegionInfo().getEncodedName()).append(",");
113           sb.append(rowLockContext.toString());
114           out.println(sb.toString());
115         }
116       }
117     }
118   }
119 
120   public static void dumpQueue(HRegionServer hrs, PrintWriter out) throws IOException {
121     if (hrs.compactSplitThread != null) {
122       // 1. Print out Compaction/Split Queue
123       out.println("Compaction/Split Queue summary: " + hrs.compactSplitThread.toString());
124       out.println(hrs.compactSplitThread.dumpQueue());
125     }
126 
127     if (hrs.cacheFlusher != null) {
128       // 2. Print out flush Queue
129       out.println("\nFlush Queue summary: " + hrs.cacheFlusher.toString());
130       out.println(hrs.cacheFlusher.dumpQueue());
131     }
132   }
133 }