Java Code Examples for org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException

The following examples show how to use org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public static void handleHBaseException(
    Throwable t, Iterator<Record> records, ErrorRecordHandler errorRecordHandler
) throws StageException {
  Throwable cause = t;

  // Drill down to root cause
  while ((
      cause instanceof UncheckedExecutionException ||
          cause instanceof UndeclaredThrowableException ||
          cause instanceof ExecutionException
  ) && cause.getCause() != null) {
    cause = cause.getCause();
  }

  // Column is null or No such Column Family exception
  if (cause instanceof NullPointerException || cause instanceof NoSuchColumnFamilyException) {
    while (records.hasNext()) {
      Record record = records.next();
      errorRecordHandler.onError(new OnRecordErrorException(record, Errors.HBASE_37, cause));
    }
  } else {
    LOG.error(Errors.HBASE_36.getMessage(), cause.toString(), cause);
    throw new StageException(Errors.HBASE_36, cause.toString(), cause);
  }
}
 
Example 2
public static void handleHBaseException(
    RetriesExhaustedWithDetailsException rex,
    Record record,
    Map<String, Record> rowKeyToRecord,
    ErrorRecordHandler errorRecordHandler
) throws StageException {
  for (int i = 0; i < rex.getNumExceptions(); i++) {
    if (rex.getCause(i) instanceof NoSuchColumnFamilyException) {
      Row r = rex.getRow(i);
      Record errorRecord = record != null ? record : rowKeyToRecord.get(Bytes.toString(r.getRow()));
      OnRecordErrorException exception = new OnRecordErrorException(errorRecord,
          Errors.HBASE_10,
          getErrorDescription(rex.getCause(i), r, rex.getHostnamePort(i))
      );
      errorRecordHandler.onError(exception);
    } else {
      // If at least 1 non NoSuchColumnFamilyException exception,
      // consider as stage exception
      throw new StageException(Errors.HBASE_02, rex);
    }
  }
}
 
Example 3
/**
 * Check if there's an {@link NoSuchColumnFamilyException} in the caused by stacktrace.
 */
@VisibleForTesting
public static boolean isNoSuchColumnFamilyException(Throwable io) {
  if (io instanceof RemoteException) {
    io = ((RemoteException) io).unwrapRemoteException();
  }
  if (io != null && io.getMessage().contains("NoSuchColumnFamilyException")) {
    return true;
  }
  for (; io != null; io = io.getCause()) {
    if (io instanceof NoSuchColumnFamilyException) {
      return true;
    }
  }
  return false;
}
 
Example 4
Source Project: hbase   Source File: TestAsyncTableBatch.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testPartialSuccessOnSameRegion() throws InterruptedException, ExecutionException {
  AsyncTable<?> table = tableGetter.apply(TABLE_NAME);
  List<CompletableFuture<Object>> futures = table.batch(Arrays.asList(
    new Put(Bytes.toBytes("put")).addColumn(Bytes.toBytes("not-exists"), CQ,
      Bytes.toBytes("bad")),
    new Increment(Bytes.toBytes("inc")).addColumn(FAMILY, CQ, 1),
    new Put(Bytes.toBytes("put")).addColumn(FAMILY, CQ, Bytes.toBytes("good"))));
  try {
    futures.get(0).get();
    fail();
  } catch (ExecutionException e) {
    assertThat(e.getCause(), instanceOf(RetriesExhaustedException.class));
    assertThat(e.getCause().getCause(), instanceOf(NoSuchColumnFamilyException.class));
  }
  assertEquals(1, Bytes.toLong(((Result) futures.get(1).get()).getValue(FAMILY, CQ)));
  assertTrue(((Result) futures.get(2).get()).isEmpty());
  assertEquals("good",
    Bytes.toString(table.get(new Get(Bytes.toBytes("put"))).get().getValue(FAMILY, CQ)));
}
 
Example 5
Source Project: hbase   Source File: TestFromClientSide4.java    License: Apache License 2.0 6 votes vote down vote up
@Test public void testPutNoCF() throws IOException {
  final byte[] BAD_FAM = Bytes.toBytes("BAD_CF");
  final byte[] VAL = Bytes.toBytes(100);
  try (Table table = TEST_UTIL.createTable(name.getTableName(), FAMILY)) {
    boolean caughtNSCFE = false;

    try {
      Put p = new Put(ROW);
      p.addColumn(BAD_FAM, QUALIFIER, VAL);
      table.put(p);
    } catch (Exception e) {
      caughtNSCFE = e instanceof NoSuchColumnFamilyException;
    }
    assertTrue("Should throw NoSuchColumnFamilyException", caughtNSCFE);
  }
}
 
Example 6
@Override
public boolean processPutStatus(MutationStatus operationStatus) throws IOException{
    OperationStatus opStat = ((HMutationStatus)operationStatus).unwrapDelegate();
     switch (opStat.getOperationStatusCode()) {
        case NOT_RUN:
            throw new IOException("Could not acquire Lock");
        case BAD_FAMILY:
            throw new NoSuchColumnFamilyException(opStat.getExceptionMsg());
        case SANITY_CHECK_FAILURE:
            throw new IOException("Sanity Check failure:" + opStat.getExceptionMsg());
        case FAILURE:
            throw new IOException(opStat.getExceptionMsg());
        default:
            return true;
     }
}
 
Example 7
Source Project: hbase   Source File: AbstractTestAsyncTableScan.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testScanWrongColumnFamily() throws Exception {
  try {
    doScan(createScan().addFamily(Bytes.toBytes("WrongColumnFamily")));
  } catch (Exception e) {
    assertTrue(e instanceof NoSuchColumnFamilyException ||
      e.getCause() instanceof NoSuchColumnFamilyException);
  }
}
 
Example 8
@Test
public void testRestoreSchemaChange() throws Exception {
  Table table = TEST_UTIL.getConnection().getTable(tableName);

  // Add one column family and put some data in it
  admin.disableTable(tableName);
  admin.addColumnFamily(tableName, getTestRestoreSchemaChangeHCD());
  admin.enableTable(tableName);
  assertEquals(2, table.getDescriptor().getColumnFamilyCount());
  TableDescriptor htd = admin.getDescriptor(tableName);
  assertEquals(2, htd.getColumnFamilyCount());
  SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 500, TEST_FAMILY2);
  long snapshot2Rows = snapshot1Rows + 500L;
  assertEquals(snapshot2Rows, countRows(table));
  assertEquals(500, countRows(table, TEST_FAMILY2));
  Set<String> fsFamilies = getFamiliesFromFS(tableName);
  assertEquals(2, fsFamilies.size());

  // Take a snapshot
  admin.disableTable(tableName);
  admin.snapshot(snapshotName2, tableName);

  // Restore the snapshot (without the cf)
  admin.restoreSnapshot(snapshotName0);
  admin.enableTable(tableName);
  assertEquals(1, table.getDescriptor().getColumnFamilyCount());
  try {
    countRows(table, TEST_FAMILY2);
    fail("family '" + Bytes.toString(TEST_FAMILY2) + "' should not exists");
  } catch (NoSuchColumnFamilyException e) {
    // expected
  }
  assertEquals(snapshot0Rows, countRows(table));
  htd = admin.getDescriptor(tableName);
  assertEquals(1, htd.getColumnFamilyCount());
  fsFamilies = getFamiliesFromFS(tableName);
  assertEquals(1, fsFamilies.size());

  // Restore back the snapshot (with the cf)
  admin.disableTable(tableName);
  admin.restoreSnapshot(snapshotName2);
  admin.enableTable(tableName);
  htd = admin.getDescriptor(tableName);
  assertEquals(2, htd.getColumnFamilyCount());
  assertEquals(2, table.getDescriptor().getColumnFamilyCount());
  assertEquals(500, countRows(table, TEST_FAMILY2));
  assertEquals(snapshot2Rows, countRows(table));
  fsFamilies = getFamiliesFromFS(tableName);
  assertEquals(2, fsFamilies.size());
  table.close();
}
 
Example 9
Source Project: hbase   Source File: ResourceBase.java    License: Apache License 2.0 4 votes vote down vote up
protected Response processException(Throwable exp) {
  Throwable curr = exp;
  if(accessDeniedClazz != null) {
    //some access denied exceptions are buried
    while (curr != null) {
      if(accessDeniedClazz.isAssignableFrom(curr.getClass())) {
        throw new WebApplicationException(
            Response.status(Response.Status.FORBIDDEN)
              .type(MIMETYPE_TEXT).entity("Forbidden" + CRLF +
                 StringUtils.stringifyException(exp) + CRLF)
              .build());
      }
      curr = curr.getCause();
    }
  }
  //TableNotFound may also be buried one level deep
  if (exp instanceof TableNotFoundException ||
      exp.getCause() instanceof TableNotFoundException) {
    throw new WebApplicationException(
      Response.status(Response.Status.NOT_FOUND)
        .type(MIMETYPE_TEXT).entity("Not found" + CRLF +
           StringUtils.stringifyException(exp) + CRLF)
        .build());
  }
  if (exp instanceof NoSuchColumnFamilyException){
    throw new WebApplicationException(
      Response.status(Response.Status.NOT_FOUND)
        .type(MIMETYPE_TEXT).entity("Not found" + CRLF +
           StringUtils.stringifyException(exp) + CRLF)
        .build());
  }
  if (exp instanceof RuntimeException) {
    throw new WebApplicationException(
        Response.status(Response.Status.BAD_REQUEST)
          .type(MIMETYPE_TEXT).entity("Bad request" + CRLF +
            StringUtils.stringifyException(exp) + CRLF)
          .build());
  }
  if (exp instanceof RetriesExhaustedException) {
    RetriesExhaustedException retryException = (RetriesExhaustedException) exp;
    processException(retryException.getCause());
  }
  throw new WebApplicationException(
    Response.status(Response.Status.SERVICE_UNAVAILABLE)
      .type(MIMETYPE_TEXT).entity("Unavailable" + CRLF +
        StringUtils.stringifyException(exp) + CRLF)
      .build());
}
 
Example 10
@Override
public IOException noSuchFamily(String message){
    return new NoSuchColumnFamilyException(message);
}