HBASE-12518 Task 4 polish. Remove CM#{get,delete}Connection

Remove deleteConnection from everywhere except the two tests that ensure
it does the right thing and from HCM and CM themselves.

Undoes deleteConnection from tests and from the web ui
This commit is contained in:
stack 2014-11-25 17:22:09 -08:00
parent 2e9597ffb7
commit daff5e8d96
11 changed files with 86 additions and 89 deletions

View File

@ -18,7 +18,6 @@ limitations under the License.
</%doc> </%doc>
<%args> <%args>
HMaster master; HMaster master;
HBaseAdmin admin;
Map<String, Integer> frags = null; Map<String, Integer> frags = null;
ServerName metaLocation = null; ServerName metaLocation = null;
List<ServerName> servers = null; List<ServerName> servers = null;
@ -42,7 +41,7 @@ org.apache.hadoop.hbase.HConstants;
org.apache.hadoop.hbase.NamespaceDescriptor; org.apache.hadoop.hbase.NamespaceDescriptor;
org.apache.hadoop.hbase.ServerLoad; org.apache.hadoop.hbase.ServerLoad;
org.apache.hadoop.hbase.ServerName; org.apache.hadoop.hbase.ServerName;
org.apache.hadoop.hbase.client.HBaseAdmin; org.apache.hadoop.hbase.client.Admin;
org.apache.hadoop.hbase.client.HConnectionManager; org.apache.hadoop.hbase.client.HConnectionManager;
org.apache.hadoop.hbase.HTableDescriptor; org.apache.hadoop.hbase.HTableDescriptor;
org.apache.hadoop.hbase.HBaseConfiguration; org.apache.hadoop.hbase.HBaseConfiguration;
@ -307,8 +306,11 @@ AssignmentManager assignmentManager = master.getAssignmentManager();
<%def catalogTables> <%def catalogTables>
<%java> <%java>
HTableDescriptor[] sysTables = master.isInitialized() ? admin.listTableDescriptorsByNamespace( HTableDescriptor[] sysTables = null;
try (Admin admin = master.getConnection().getAdmin()) {
sysTables = master.isInitialized() ? admin.listTableDescriptorsByNamespace(
NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR) : null; NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR) : null;
}
</%java> </%java>
<%if (sysTables != null && sysTables.length > 0)%> <%if (sysTables != null && sysTables.length > 0)%>
<table class="table table-striped"> <table class="table table-striped">
@ -347,7 +349,10 @@ AssignmentManager assignmentManager = master.getAssignmentManager();
<%def userTables> <%def userTables>
<%java> <%java>
HTableDescriptor[] tables = master.isInitialized() ? admin.listTables() : null; HTableDescriptor[] tables = null;
try (Admin admin = master.getConnection().getAdmin()) {
tables = master.isInitialized() ? admin.listTables() : null;
}
</%java> </%java>
<%if (tables != null && tables.length > 0)%> <%if (tables != null && tables.length > 0)%>
<table class="table table-striped"> <table class="table table-striped">
@ -379,7 +384,10 @@ AssignmentManager assignmentManager = master.getAssignmentManager();
<%def userSnapshots> <%def userSnapshots>
<%java> <%java>
List<SnapshotDescription> snapshots = master.isInitialized() ? admin.listSnapshots() : null; List<SnapshotDescription> snapshots = null;
try (Admin admin = master.getConnection().getAdmin()) {
snapshots = master.isInitialized() ? admin.listSnapshots() : null;
}
</%java> </%java>
<%if (snapshots != null && snapshots.size() > 0)%> <%if (snapshots != null && snapshots.size() > 0)%>
<table class="table table-striped"> <table class="table table-striped">
@ -436,7 +444,4 @@ AssignmentManager assignmentManager = master.getAssignmentManager();
</tr> </tr>
</table> </table>
</%if> </%if>
<%java>
HConnectionManager.deleteConnection(admin.getConfiguration());
</%java>
</%def> </%def>

View File

@ -53,7 +53,6 @@ public class MasterStatusServlet extends HttpServlet {
response.setContentType("text/html"); response.setContentType("text/html");
Configuration conf = master.getConfiguration(); Configuration conf = master.getConfiguration();
HBaseAdmin admin = new HBaseAdmin(conf);
Map<String, Integer> frags = getFragmentationInfo(master, conf); Map<String, Integer> frags = getFragmentationInfo(master, conf);
ServerName metaLocation = null; ServerName metaLocation = null;
@ -80,8 +79,7 @@ public class MasterStatusServlet extends HttpServlet {
tmpl.setFilter(request.getParameter("filter")); tmpl.setFilter(request.getParameter("filter"));
if (request.getParameter("format") != null) if (request.getParameter("format") != null)
tmpl.setFormat(request.getParameter("format")); tmpl.setFormat(request.getParameter("format"));
tmpl.render(response.getWriter(), tmpl.render(response.getWriter(), master);
master, admin);
} }
private ServerName getMetaLocationOrNull(HMaster master) { private ServerName getMetaLocationOrNull(HMaster master) {

View File

@ -34,10 +34,8 @@ public class RSStatusServlet extends HttpServlet {
@Override @Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException throws ServletException, IOException {
{ HRegionServer hrs = (HRegionServer)getServletContext().getAttribute(HRegionServer.REGIONSERVER);
HRegionServer hrs = (HRegionServer)getServletContext().getAttribute(
HRegionServer.REGIONSERVER);
assert hrs != null : "No RS in context!"; assert hrs != null : "No RS in context!";
resp.setContentType("text/html"); resp.setContentType("text/html");

View File

@ -20,7 +20,7 @@
<%@ page contentType="text/html;charset=UTF-8" <%@ page contentType="text/html;charset=UTF-8"
import="java.util.Date" import="java.util.Date"
import="org.apache.hadoop.conf.Configuration" import="org.apache.hadoop.conf.Configuration"
import="org.apache.hadoop.hbase.client.HBaseAdmin" import="org.apache.hadoop.hbase.client.Admin"
import="org.apache.hadoop.hbase.client.HConnectionManager" import="org.apache.hadoop.hbase.client.HConnectionManager"
import="org.apache.hadoop.hbase.master.HMaster" import="org.apache.hadoop.hbase.master.HMaster"
import="org.apache.hadoop.hbase.snapshot.SnapshotInfo" import="org.apache.hadoop.hbase.snapshot.SnapshotInfo"
@ -31,13 +31,13 @@
<% <%
HMaster master = (HMaster)getServletContext().getAttribute(HMaster.MASTER); HMaster master = (HMaster)getServletContext().getAttribute(HMaster.MASTER);
Configuration conf = master.getConfiguration(); Configuration conf = master.getConfiguration();
HBaseAdmin hbadmin = new HBaseAdmin(conf);
boolean readOnly = conf.getBoolean("hbase.master.ui.readonly", false); boolean readOnly = conf.getBoolean("hbase.master.ui.readonly", false);
String snapshotName = request.getParameter("name"); String snapshotName = request.getParameter("name");
SnapshotDescription snapshot = null; SnapshotDescription snapshot = null;
SnapshotInfo.SnapshotStats stats = null; SnapshotInfo.SnapshotStats stats = null;
TableName snapshotTable = null; TableName snapshotTable = null;
for (SnapshotDescription snapshotDesc: hbadmin.listSnapshots()) { try (Admin admin = master.getConnection().getAdmin()) {
for (SnapshotDescription snapshotDesc: admin.listSnapshots()) {
if (snapshotName.equals(snapshotDesc.getName())) { if (snapshotName.equals(snapshotDesc.getName())) {
snapshot = snapshotDesc; snapshot = snapshotDesc;
stats = SnapshotInfo.getSnapshotStats(conf, snapshot); stats = SnapshotInfo.getSnapshotStats(conf, snapshot);
@ -45,6 +45,7 @@
break; break;
} }
} }
}
String action = request.getParameter("action"); String action = request.getParameter("action");
String cloneName = request.getParameter("cloneName"); String cloneName = request.getParameter("cloneName");
@ -112,17 +113,19 @@
</div> </div>
<p><hr><p> <p><hr><p>
<% <%
try (Admin admin = master.getConnection().getAdmin()) {
if (action.equals("restore")) { if (action.equals("restore")) {
hbadmin.restoreSnapshot(snapshotName); admin.restoreSnapshot(snapshotName);
%> Restore Snapshot request accepted. <% %> Restore Snapshot request accepted. <%
} else if (action.equals("clone")) { } else if (action.equals("clone")) {
if (cloneName != null && cloneName.length() > 0) { if (cloneName != null && cloneName.length() > 0) {
hbadmin.cloneSnapshot(snapshotName, cloneName); admin.cloneSnapshot(snapshotName, TableName.valueOf(cloneName));
%> Clone from Snapshot request accepted. <% %> Clone from Snapshot request accepted. <%
} else { } else {
%> Clone from Snapshot request failed, No table name specified. <% %> Clone from Snapshot request failed, No table name specified. <%
} }
} }
}
%> %>
<p>Go <a href="javascript:history.back()">Back</a>, or wait for the redirect. <p>Go <a href="javascript:history.back()">Back</a>, or wait for the redirect.
</div> </div>
@ -189,8 +192,6 @@
<% } %> <% } %>
<% <%
} // end else } // end else
HConnectionManager.deleteConnection(hbadmin.getConfiguration());
%> %>

View File

@ -23,7 +23,7 @@
import="java.util.Map" import="java.util.Map"
import="org.apache.hadoop.conf.Configuration" import="org.apache.hadoop.conf.Configuration"
import="org.apache.hadoop.hbase.client.HTable" import="org.apache.hadoop.hbase.client.HTable"
import="org.apache.hadoop.hbase.client.HBaseAdmin" import="org.apache.hadoop.hbase.client.Admin"
import="org.apache.hadoop.hbase.client.HConnectionManager" import="org.apache.hadoop.hbase.client.HConnectionManager"
import="org.apache.hadoop.hbase.HRegionInfo" import="org.apache.hadoop.hbase.HRegionInfo"
import="org.apache.hadoop.hbase.ServerName" import="org.apache.hadoop.hbase.ServerName"
@ -41,7 +41,6 @@
<% <%
HMaster master = (HMaster)getServletContext().getAttribute(HMaster.MASTER); HMaster master = (HMaster)getServletContext().getAttribute(HMaster.MASTER);
Configuration conf = master.getConfiguration(); Configuration conf = master.getConfiguration();
HBaseAdmin hbadmin = new HBaseAdmin(conf);
MetaTableLocator metaTableLocator = new MetaTableLocator(); MetaTableLocator metaTableLocator = new MetaTableLocator();
String fqtn = request.getParameter("name"); String fqtn = request.getParameter("name");
HTable table = new HTable(conf, fqtn); HTable table = new HTable(conf, fqtn);
@ -125,22 +124,24 @@
</div> </div>
<p><hr><p> <p><hr><p>
<% <%
try (Admin admin = master.getConnection().getAdmin()) {
if (action.equals("split")) { if (action.equals("split")) {
if (key != null && key.length() > 0) { if (key != null && key.length() > 0) {
hbadmin.split(key); admin.splitRegion(Bytes.toBytes(key));
} else { } else {
hbadmin.split(fqtn); admin.split(TableName.valueOf(fqtn));
} }
%> Split request accepted. <% %> Split request accepted. <%
} else if (action.equals("compact")) { } else if (action.equals("compact")) {
if (key != null && key.length() > 0) { if (key != null && key.length() > 0) {
hbadmin.compact(key); admin.compactRegion(Bytes.toBytes(key));
} else { } else {
hbadmin.compact(fqtn); admin.compact(TableName.valueOf(fqtn));
} }
%> Compact request accepted. <% %> Compact request accepted. <%
} }
}
%> %>
<p>Go <a href="javascript:history.back()">Back</a>, or wait for the redirect. <p>Go <a href="javascript:history.back()">Back</a>, or wait for the redirect.
</div> </div>
@ -220,6 +221,7 @@
<% } %> <% } %>
</table> </table>
<%} else { <%} else {
Admin admin = master.getConnection().getAdmin();
try { %> try { %>
<h2>Table Attributes</h2> <h2>Table Attributes</h2>
<table class="table table-striped"> <table class="table table-striped">
@ -230,7 +232,7 @@
</tr> </tr>
<tr> <tr>
<td>Enabled</td> <td>Enabled</td>
<td><%= hbadmin.isTableEnabled(table.getTableName()) %></td> <td><%= admin.isTableEnabled(table.getName()) %></td>
<td>Is the table enabled</td> <td>Is the table enabled</td>
</tr> </tr>
<tr> <tr>
@ -238,7 +240,7 @@
<td> <td>
<% <%
try { try {
CompactionState compactionState = hbadmin.getCompactionState(table.getTableName()); CompactionState compactionState = admin.getCompactionState(table.getName());
%> %>
<%= compactionState %> <%= compactionState %>
<% <%
@ -332,10 +334,10 @@
<% } <% }
} catch(Exception ex) { } catch(Exception ex) {
ex.printStackTrace(System.err); ex.printStackTrace(System.err);
} finally {
admin.close();
} }
} // end else } // end else
HConnectionManager.deleteConnection(hbadmin.getConfiguration());
%> %>

View File

@ -30,8 +30,6 @@ import java.util.NavigableMap;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.client.ClusterConnection; import org.apache.hadoop.hbase.client.ClusterConnection;
import org.apache.hadoop.hbase.client.HConnection;
import org.apache.hadoop.hbase.client.HConnectionManager;
import org.apache.hadoop.hbase.client.HConnectionTestingUtility; import org.apache.hadoop.hbase.client.HConnectionTestingUtility;
import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.ipc.PayloadCarryingRpcController; import org.apache.hadoop.hbase.ipc.PayloadCarryingRpcController;
@ -128,7 +126,7 @@ public class TestMetaTableAccessorNoCluster {
// This is a servername we use in a few places below. // This is a servername we use in a few places below.
ServerName sn = ServerName.valueOf("example.com", 1234, System.currentTimeMillis()); ServerName sn = ServerName.valueOf("example.com", 1234, System.currentTimeMillis());
HConnection connection; ClusterConnection connection = null;
try { try {
// Mock an ClientProtocol. Our mock implementation will fail a few // Mock an ClientProtocol. Our mock implementation will fail a few
// times when we go to open a scanner. // times when we go to open a scanner.
@ -204,7 +202,7 @@ public class TestMetaTableAccessorNoCluster {
Mockito.verify(implementation, Mockito.times(6)). Mockito.verify(implementation, Mockito.times(6)).
scan((RpcController)Mockito.any(), (ScanRequest)Mockito.any()); scan((RpcController)Mockito.any(), (ScanRequest)Mockito.any());
} finally { } finally {
HConnectionManager.deleteConnection(UTIL.getConfiguration()); if (connection != null && !connection.isClosed()) connection.close();
zkw.close(); zkw.close();
} }
} }

View File

@ -29,8 +29,7 @@ import java.net.ConnectException;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.HConnection; import org.apache.hadoop.hbase.client.ClusterConnection;
import org.apache.hadoop.hbase.client.HConnectionManager;
import org.apache.hadoop.hbase.client.HConnectionTestingUtility; import org.apache.hadoop.hbase.client.HConnectionTestingUtility;
import org.apache.hadoop.hbase.ipc.ServerNotRunningYetException; import org.apache.hadoop.hbase.ipc.ServerNotRunningYetException;
import org.apache.hadoop.hbase.master.RegionState; import org.apache.hadoop.hbase.master.RegionState;
@ -101,9 +100,6 @@ public class TestMetaTableLocator {
LOG.warn("Unable to delete hbase:meta location", e); LOG.warn("Unable to delete hbase:meta location", e);
} }
// Clear out our doctored connection or could mess up subsequent tests.
HConnectionManager.deleteConnection(UTIL.getConfiguration());
this.watcher.close(); this.watcher.close();
} }
@ -182,7 +178,8 @@ public class TestMetaTableLocator {
// Mock an ClientProtocol. // Mock an ClientProtocol.
final ClientProtos.ClientService.BlockingInterface implementation = final ClientProtos.ClientService.BlockingInterface implementation =
Mockito.mock(ClientProtos.ClientService.BlockingInterface.class); Mockito.mock(ClientProtos.ClientService.BlockingInterface.class);
HConnection connection = mockConnection(null, implementation);
ClusterConnection connection = mockConnection(null, implementation);
// If a 'get' is called on mocked interface, throw connection refused. // If a 'get' is called on mocked interface, throw connection refused.
Mockito.when(implementation.get((RpcController) Mockito.any(), (GetRequest) Mockito.any())). Mockito.when(implementation.get((RpcController) Mockito.any(), (GetRequest) Mockito.any())).
@ -242,14 +239,14 @@ public class TestMetaTableLocator {
@Test @Test
public void testVerifyMetaRegionLocationFails() public void testVerifyMetaRegionLocationFails()
throws IOException, InterruptedException, KeeperException, ServiceException { throws IOException, InterruptedException, KeeperException, ServiceException {
HConnection connection = Mockito.mock(HConnection.class); ClusterConnection connection = Mockito.mock(ClusterConnection.class);
ServiceException connectException = ServiceException connectException =
new ServiceException(new ConnectException("Connection refused")); new ServiceException(new ConnectException("Connection refused"));
final AdminProtos.AdminService.BlockingInterface implementation = final AdminProtos.AdminService.BlockingInterface implementation =
Mockito.mock(AdminProtos.AdminService.BlockingInterface.class); Mockito.mock(AdminProtos.AdminService.BlockingInterface.class);
Mockito.when(implementation.getRegionInfo((RpcController)Mockito.any(), Mockito.when(implementation.getRegionInfo((RpcController)Mockito.any(),
(GetRegionInfoRequest)Mockito.any())).thenThrow(connectException); (GetRegionInfoRequest)Mockito.any())).thenThrow(connectException);
Mockito.when(connection.getAdmin(Mockito.any(ServerName.class), Mockito.anyBoolean())). Mockito.when(connection.getAdmin(Mockito.any(ServerName.class))).
thenReturn(implementation); thenReturn(implementation);
ServerName sn = ServerName.valueOf("example.com", 1234, System.currentTimeMillis()); ServerName sn = ServerName.valueOf("example.com", 1234, System.currentTimeMillis());
@ -301,20 +298,17 @@ public class TestMetaTableLocator {
* and that returns the passed {@link AdminProtos.AdminService.BlockingInterface} instance when * and that returns the passed {@link AdminProtos.AdminService.BlockingInterface} instance when
* {@link HConnection#getAdmin(ServerName)} is called, returns the passed * {@link HConnection#getAdmin(ServerName)} is called, returns the passed
* {@link ClientProtos.ClientService.BlockingInterface} instance when * {@link ClientProtos.ClientService.BlockingInterface} instance when
* {@link HConnection#getClient(ServerName)} is called (Be sure to call * {@link HConnection#getClient(ServerName)} is called.
* {@link HConnectionManager#deleteConnection(org.apache.hadoop.conf.Configuration)}
* when done with this mocked Connection.
* @throws IOException * @throws IOException
*/ */
private HConnection mockConnection(final AdminProtos.AdminService.BlockingInterface admin, private ClusterConnection mockConnection(final AdminProtos.AdminService.BlockingInterface admin,
final ClientProtos.ClientService.BlockingInterface client) final ClientProtos.ClientService.BlockingInterface client)
throws IOException { throws IOException {
HConnection connection = ClusterConnection connection =
HConnectionTestingUtility.getMockedConnection(UTIL.getConfiguration()); HConnectionTestingUtility.getMockedConnection(UTIL.getConfiguration());
Mockito.doNothing().when(connection).close(); Mockito.doNothing().when(connection).close();
// Make it so we return any old location when asked. // Make it so we return any old location when asked.
final HRegionLocation anyLocation = final HRegionLocation anyLocation = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, SN);
new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, SN);
Mockito.when(connection.getRegionLocation((TableName) Mockito.any(), Mockito.when(connection.getRegionLocation((TableName) Mockito.any(),
(byte[]) Mockito.any(), Mockito.anyBoolean())). (byte[]) Mockito.any(), Mockito.anyBoolean())).
thenReturn(anyLocation); thenReturn(anyLocation);

View File

@ -292,6 +292,11 @@ public class TestFromClientSide {
table.close(); table.close();
} }
/**
* @deprecated Tests deprecated functionality. Remove when we are past 1.0.
* @throws Exception
*/
@Deprecated
@Test @Test
public void testSharedZooKeeper() throws Exception { public void testSharedZooKeeper() throws Exception {
Configuration newConfig = new Configuration(TEST_UTIL.getConfiguration()); Configuration newConfig = new Configuration(TEST_UTIL.getConfiguration());

View File

@ -874,7 +874,9 @@ public class TestHCM {
* Makes sure that there is no leaking of * Makes sure that there is no leaking of
* {@link ConnectionManager.HConnectionImplementation} in the {@link HConnectionManager} * {@link ConnectionManager.HConnectionImplementation} in the {@link HConnectionManager}
* class. * class.
* @deprecated Tests deprecated functionality. Remove in 1.0.
*/ */
@Deprecated
@Test @Test
public void testConnectionUniqueness() throws Exception { public void testConnectionUniqueness() throws Exception {
int zkmaxconnections = TEST_UTIL.getConfiguration(). int zkmaxconnections = TEST_UTIL.getConfiguration().

View File

@ -195,9 +195,6 @@ public class TestCatalogJanitor {
@Override @Override
public void stop(String why) { public void stop(String why) {
if (this.connection != null) {
HConnectionManager.deleteConnection(this.connection.getConfiguration());
}
} }
} }

View File

@ -121,8 +121,7 @@ public class TestMasterStatusServlet {
@Test @Test
public void testStatusTemplateNoTables() throws IOException { public void testStatusTemplateNoTables() throws IOException {
new MasterStatusTmpl().render(new StringWriter(), new MasterStatusTmpl().render(new StringWriter(), master);
master, admin);
} }
@Test @Test
@ -131,8 +130,7 @@ public class TestMasterStatusServlet {
new MasterStatusTmpl() new MasterStatusTmpl()
.setMetaLocation(ServerName.valueOf("metaserver:123,12345")) .setMetaLocation(ServerName.valueOf("metaserver:123,12345"))
.render(new StringWriter(), .render(new StringWriter(), master);
master, admin);
} }
@Test @Test
@ -152,8 +150,7 @@ public class TestMasterStatusServlet {
.setMetaLocation(ServerName.valueOf("metaserver:123,12345")) .setMetaLocation(ServerName.valueOf("metaserver:123,12345"))
.setServers(servers) .setServers(servers)
.setDeadServers(deadServers) .setDeadServers(deadServers)
.render(new StringWriter(), .render(new StringWriter(), master);
master, admin);
} }
@Test @Test