Skip to content

HBASE-28999 Return HTTP 503 when stateless scan REST endpoint is invoked on disabled table #6520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.hadoop.hbase.rest;

import java.io.IOException;
import org.apache.hadoop.hbase.TableNotEnabledException;
import org.apache.hadoop.hbase.TableNotFoundException;
import org.apache.hadoop.hbase.client.RetriesExhaustedException;
import org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException;
Expand Down Expand Up @@ -74,6 +75,15 @@ protected Response processException(Throwable exp) {
RetriesExhaustedException retryException = (RetriesExhaustedException) exp;
processException(retryException.getCause());
}
if (exp instanceof TableNotEnabledException) {
throwServiceUnavailableException(exp);
}

throwServiceUnavailableException(exp);
return null;
}

private static void throwServiceUnavailableException(Throwable exp) {
throw new WebApplicationException(
Response.status(Response.Status.SERVICE_UNAVAILABLE).type(MIMETYPE_TEXT)
.entity("Unavailable" + CRLF + StringUtils.stringifyException(exp) + CRLF).build());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hbase.rest;

import java.io.IOException;
import org.apache.yetus.audience.InterfaceAudience;

@InterfaceAudience.Private
public class ServiceUnavailableException extends IOException {
public ServiceUnavailableException(final String msg) {
super(msg);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
@InterfaceAudience.Private
public class TableResource extends ResourceBase {

String table;
private final String table;
private static final Logger LOG = LoggerFactory.getLogger(TableResource.class);

private static final Decoder base64Urldecoder = java.util.Base64.getUrlDecoder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,36 +63,43 @@ public CellSetModelStream get(final @Context UriInfo uriInfo) {
LOG.trace("GET " + uriInfo.getAbsolutePath());
}
servlet.getMetrics().incrementRequests(1);
final int rowsToSend = userRequestedLimit;
servlet.getMetrics().incrementSucessfulScanRequests(1);
final Iterator<Result> itr = results.iterator();
return new CellSetModelStream(new ArrayList<RowModel>() {
@Override
public Iterator<RowModel> iterator() {
return new Iterator<RowModel>() {
int count = rowsToSend;

@Override
public boolean hasNext() {
return count > 0 && itr.hasNext();
}
try {
final int rowsToSend = userRequestedLimit;
servlet.getMetrics().incrementSucessfulScanRequests(1);
final Iterator<Result> itr = results.iterator();
return new CellSetModelStream(new ArrayList<RowModel>() {
@Override
public Iterator<RowModel> iterator() {
return new Iterator<RowModel>() {
int count = rowsToSend;

@Override
public RowModel next() {
Result rs = itr.next();
if ((rs == null) || (count <= 0)) {
return null;
@Override
public boolean hasNext() {
return count > 0 && itr.hasNext();
}
RowModel rModel = RestUtil.createRowModelFromResult(rs);
count--;
if (count == 0) {
results.close();

@Override
public RowModel next() {
Result rs = itr.next();
if ((rs == null) || (count <= 0)) {
return null;
}
RowModel rModel = RestUtil.createRowModelFromResult(rs);
count--;
if (count == 0) {
results.close();
}
return rModel;
}
return rModel;
}
};
}
});
};
}
});
} catch (Exception exp) {
servlet.getMetrics().incrementFailedScanRequests(1);
processException(exp);
LOG.warn(exp.toString(), exp);
return null;
}
}

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public class TestTableResource {
private static final String COLUMN_FAMILY = "test";
private static final String COLUMN = COLUMN_FAMILY + ":qualifier";
private static final int NUM_REGIONS = 4;
private static final String DISABLED_TABLE_NAME = "disabled";
private static final TableName DISABLED_TABLE = TableName.valueOf(DISABLED_TABLE_NAME);
private static List<HRegionLocation> regionMap;

private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();
Expand Down Expand Up @@ -117,6 +119,10 @@ public static void setUpBeforeClass() throws Exception {
regionMap = m;
LOG.error("regions: " + regionMap);
regionLocator.close();

TEST_UTIL.createTable(DISABLED_TABLE, "cf");
TEST_UTIL.getAdmin().disableTable(DISABLED_TABLE);
TEST_UTIL.waitTableDisabled(DISABLED_TABLE, 30);
}

@AfterClass
Expand Down Expand Up @@ -262,4 +268,10 @@ public void testTableNotFound() throws IOException {
assertEquals(404, response2.getCode());
}

@Test
public void testDisabledTableScan() throws IOException {
Response response = client.get("/" + DISABLED_TABLE_NAME + "/*", Constants.MIMETYPE_JSON);
assertEquals(503, response.getCode());
assertTrue(Bytes.toString(response.getBody()).contains("Table disabled."));
}
}