类org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException源码实例Demo

下面列出了怎么用org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException的API类实例代码及写法,或者点击链接到github查看源代码。

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);
  }
}
 
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);
    }
  }
}
 
/**
 * 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;
}
 
源代码4 项目: hbase   文件: TestAsyncTableBatch.java
@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)));
}
 
源代码5 项目: hbase   文件: TestFromClientSide4.java
@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);
  }
}
 
源代码6 项目: spliceengine   文件: HOperationStatusFactory.java
@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;
     }
}
 
源代码7 项目: hbase   文件: AbstractTestAsyncTableScan.java
@Test
public void testScanWrongColumnFamily() throws Exception {
  try {
    doScan(createScan().addFamily(Bytes.toBytes("WrongColumnFamily")));
  } catch (Exception e) {
    assertTrue(e instanceof NoSuchColumnFamilyException ||
      e.getCause() instanceof NoSuchColumnFamilyException);
  }
}
 
@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();
}
 
源代码9 项目: hbase   文件: ResourceBase.java
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());
}
 
源代码10 项目: spliceengine   文件: HExceptionFactory.java
@Override
public IOException noSuchFamily(String message){
    return new NoSuchColumnFamilyException(message);
}
 
 类所在包
 类方法
 同包方法