org.apache.hadoop.hbase.HBaseIOException Java Examples

The following examples show how to use org.apache.hadoop.hbase.HBaseIOException. 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
Source File: TableReporter.java    From hbase-operator-tools with Apache License 2.0 6 votes vote down vote up
/**
 * @return First <code>fraction</code> of Table's regions.
 */
private static List<RegionInfo> getRegions(Connection connection, TableName tableName,
    double fraction, String encodedRegionName) throws IOException {
  try (Admin admin = connection.getAdmin()) {
    // Use deprecated API because running against old hbase.
    List<RegionInfo> regions = admin.getRegions(tableName);
    if (regions.size() <= 0) {
      throw new HBaseIOException("No regions found in " + tableName);
    }
    if (encodedRegionName != null) {
      return regions.stream().filter(ri -> ri.getEncodedName().equals(encodedRegionName)).
          collect(Collectors.toCollection(ArrayList::new));
    }
    return regions.subList(0, (int)(regions.size() * fraction)); // Rounds down.
  }
}
 
Example #2
Source File: RSGroupBasedLoadBalancer.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void generateGroupMaps(List<RegionInfo> regions, List<ServerName> servers,
  ListMultimap<String, RegionInfo> regionMap, ListMultimap<String, ServerName> serverMap)
  throws HBaseIOException {
  try {
    RSGroupInfo defaultInfo = rsGroupInfoManager.getRSGroup(RSGroupInfo.DEFAULT_GROUP);
    for (RegionInfo region : regions) {
      String groupName =
          RSGroupUtil.getRSGroupInfo(masterServices, rsGroupInfoManager, region.getTable())
              .orElse(defaultInfo).getName();
      regionMap.put(groupName, region);
    }
    for (String groupKey : regionMap.keySet()) {
      RSGroupInfo info = rsGroupInfoManager.getRSGroup(groupKey);
      serverMap.putAll(groupKey, filterOfflineServers(info, servers));
      if (fallbackEnabled && serverMap.get(groupKey).isEmpty()) {
        serverMap.putAll(groupKey, getFallBackCandidates(servers));
      }
      if (serverMap.get(groupKey).isEmpty()) {
        serverMap.put(groupKey, LoadBalancer.BOGUS_SERVER_NAME);
      }
    }
  } catch(IOException e) {
    throw new HBaseIOException("Failed to generate group maps", e);
  }
}
 
Example #3
Source File: TestAccessController.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testTruncatePerms() throws Exception {
  try {
    List<UserPermission> existingPerms = AccessControlClient.getUserPermissions(
        systemUserConnection, TEST_TABLE.getNameAsString());
    assertTrue(existingPerms != null);
    assertTrue(existingPerms.size() > 1);
    TEST_UTIL.getAdmin().disableTable(TEST_TABLE);
    TEST_UTIL.truncateTable(TEST_TABLE);
    TEST_UTIL.waitTableAvailable(TEST_TABLE);
    List<UserPermission> perms = AccessControlClient.getUserPermissions(
        systemUserConnection, TEST_TABLE.getNameAsString());
    assertTrue(perms != null);
    assertEquals(existingPerms.size(), perms.size());
  } catch (Throwable e) {
    throw new HBaseIOException(e);
  }
}
 
Example #4
Source File: TestEntityLocks.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Test that abort is called when lockHeartbeat fails with IOException.
 */
@Test
public void testHeartbeatException() throws Exception {
  final long workerSleepTime = 100;  // in ms
  Abortable abortable = Mockito.mock(Abortable.class);
  EntityLock lock = admin.namespaceLock("namespace", "description", abortable);
  lock.setTestingSleepTime(workerSleepTime);

  when(master.requestLock(any(), any()))
      .thenReturn(LockResponse.newBuilder().setProcId(procId).build());
  when(master.lockHeartbeat(any(), any()))
      .thenReturn(LOCKED_RESPONSE)
      .thenThrow(new ServiceException("Failed heartbeat!"));

  lock.requestLock();
  lock.await();
  assertTrue(waitLockTimeOut(lock, 100 * workerSleepTime));
  while (lock.getWorker().isAlive()) {
    TimeUnit.MILLISECONDS.sleep(100);
  }
  verify(abortable, times(1)).abort(any(), isA(HBaseIOException.class));
  assertFalse(lock.getWorker().isAlive());
}
 
Example #5
Source File: TestAssignmentManagerUtil.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateUnassignProceduresForMergeFail() throws IOException {
  List<RegionInfo> regions = getPrimaryRegions();
  RegionInfo regionA = regions.get(0);
  RegionInfo regionB = regions.get(1);
  AM.getRegionStates().getRegionStateNode(regionB)
    .setProcedure(TransitRegionStateProcedure.unassign(ENV, regionB));
  try {
    AssignmentManagerUtil.createUnassignProceduresForSplitOrMerge(ENV,
      Stream.of(regionA, regionB), REGION_REPLICATION);
    fail("Should fail as the region is in transition");
  } catch (HBaseIOException e) {
    // expected
  }
  IntStream.range(0, REGION_REPLICATION)
    .mapToObj(i -> RegionReplicaUtil.getRegionInfoForReplica(regionA, i))
    .map(AM.getRegionStates()::getRegionStateNode).forEachOrdered(
      rn -> assertFalse("Should have unset the proc for " + rn, rn.isInTransition()));
}
 
Example #6
Source File: RestoreSnapshotProcedure.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor
 * @param env MasterProcedureEnv
 * @param tableDescriptor the table to operate on
 * @param snapshot snapshot to restore from
 * @throws IOException
 */
public RestoreSnapshotProcedure(
    final MasterProcedureEnv env,
    final TableDescriptor tableDescriptor,
    final SnapshotDescription snapshot,
    final boolean restoreAcl)
throws HBaseIOException {
  super(env);
  // This is the new schema we are going to write out as this modification.
  this.modifiedTableDescriptor = tableDescriptor;
  preflightChecks(env, null/*Table can be online when restore is called?*/);
  // Snapshot information
  this.snapshot = snapshot;
  this.restoreAcl = restoreAcl;

  // Monitor
  getMonitorStatus();
}
 
Example #7
Source File: AssignmentManager.java    From hbase with Apache License 2.0 6 votes vote down vote up
public TransitRegionStateProcedure createMoveRegionProcedure(RegionInfo regionInfo,
    ServerName targetServer) throws HBaseIOException {
  RegionStateNode regionNode = this.regionStates.getRegionStateNode(regionInfo);
  if (regionNode == null) {
    throw new UnknownRegionException("No RegionStateNode found for " +
        regionInfo.getEncodedName() + "(Closed/Deleted?)");
  }
  TransitRegionStateProcedure proc;
  regionNode.lock();
  try {
    preTransitCheck(regionNode, STATES_EXPECTED_ON_UNASSIGN_OR_MOVE);
    regionNode.checkOnline();
    proc = TransitRegionStateProcedure.move(getProcedureEnvironment(), regionInfo, targetServer);
    regionNode.setProcedure(proc);
  } finally {
    regionNode.unlock();
  }
  return proc;
}
 
Example #8
Source File: RegionReplicaReplicationEndpoint.java    From hbase with Apache License 2.0 6 votes vote down vote up
private CompletableFuture<Long> replicate(TableDescriptor tableDesc, byte[] encodedRegionName,
    List<Entry> entries) {
  if (disabledTableCache.getIfPresent(tableDesc.getTableName()) != null) {
    logSkipped(tableDesc.getTableName(), entries, "cached as a disabled table");
    return CompletableFuture.completedFuture(Long.valueOf(entries.size()));
  }
  byte[] row = CellUtil.cloneRow(entries.get(0).getEdit().getCells().get(0));
  CompletableFuture<RegionLocations> locateFuture = new CompletableFuture<>();
  getRegionLocations(locateFuture, tableDesc, encodedRegionName, row, false);
  CompletableFuture<Long> future = new CompletableFuture<>();
  FutureUtils.addListener(locateFuture, (locs, error) -> {
    if (error != null) {
      future.completeExceptionally(error);
    } else if (locs.getDefaultRegionLocation() == null) {
      future.completeExceptionally(
        new HBaseIOException("No location found for default replica of table=" +
          tableDesc.getTableName() + " row='" + Bytes.toStringBinary(row) + "'"));
    } else {
      replicate(future, locs, tableDesc, encodedRegionName, row, entries);
    }
  });
  return future;
}
 
Example #9
Source File: FavoredNodeAssignmentHelper.java    From hbase with Apache License 2.0 6 votes vote down vote up
public Map<RegionInfo, List<ServerName>> generateFavoredNodesRoundRobin(
    Map<ServerName, List<RegionInfo>> assignmentMap, List<RegionInfo> regions)
    throws IOException {

  if (regions.size() > 0) {
    if (canPlaceFavoredNodes()) {
      Map<RegionInfo, ServerName> primaryRSMap = new HashMap<>();
      // Lets try to have an equal distribution for primary favored node
      placePrimaryRSAsRoundRobin(assignmentMap, primaryRSMap, regions);
      return generateFavoredNodes(primaryRSMap);

    } else {
      throw new HBaseIOException("Not enough nodes to generate favored nodes");
    }
  }
  return null;
}
 
Example #10
Source File: FavoredNodeAssignmentHelper.java    From hbase with Apache License 2.0 6 votes vote down vote up
public List<ServerName> generateFavoredNodes(RegionInfo hri) throws IOException {

    List<ServerName> favoredNodesForRegion = new ArrayList<>(FAVORED_NODES_NUM);
    ServerName primary = servers.get(random.nextInt(servers.size()));
    favoredNodesForRegion.add(ServerName.valueOf(primary.getAddress(), ServerName.NON_STARTCODE));

    Map<RegionInfo, ServerName> primaryRSMap = new HashMap<>(1);
    primaryRSMap.put(hri, primary);
    Map<RegionInfo, ServerName[]> secondaryAndTertiaryRSMap =
        placeSecondaryAndTertiaryRS(primaryRSMap);
    ServerName[] secondaryAndTertiaryNodes = secondaryAndTertiaryRSMap.get(hri);
    if (secondaryAndTertiaryNodes != null && secondaryAndTertiaryNodes.length == 2) {
      for (ServerName sn : secondaryAndTertiaryNodes) {
        favoredNodesForRegion.add(ServerName.valueOf(sn.getAddress(), ServerName.NON_STARTCODE));
      }
      return favoredNodesForRegion;
    } else {
      throw new HBaseIOException("Unable to generate secondary and tertiary favored nodes.");
    }
  }
 
Example #11
Source File: TestFutureUtils.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testRecordStackTrace() throws IOException {
  CompletableFuture<Void> future = new CompletableFuture<>();
  executor.execute(() -> future.completeExceptionally(new HBaseIOException("Inject error!")));
  try {
    FutureUtils.get(future);
    fail("The future should have been completed exceptionally");
  } catch (HBaseIOException e) {
    assertEquals("Inject error!", e.getMessage());
    StackTraceElement[] elements = e.getStackTrace();
    assertThat(elements[0].toString(), containsString("java.lang.Thread.getStackTrace"));
    assertThat(elements[1].toString(),
      startsWith("org.apache.hadoop.hbase.util.FutureUtils.setStackTrace"));
    assertThat(elements[2].toString(),
      startsWith("org.apache.hadoop.hbase.util.FutureUtils.rethrow"));
    assertThat(elements[3].toString(),
      startsWith("org.apache.hadoop.hbase.util.FutureUtils.get"));
    assertThat(elements[4].toString(),
      startsWith("org.apache.hadoop.hbase.util.TestFutureUtils.testRecordStackTrace"));
    assertTrue(Stream.of(elements)
      .anyMatch(element -> element.toString().contains("--------Future.get--------")));
  } catch (Throwable t) {
    throw new AssertionError("Caught unexpected Throwable", t);
  }
}
 
Example #12
Source File: IndexLoadBalancer.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Override
public ServerName randomAssignment(HRegionInfo regionInfo, List<ServerName> servers)
        throws HBaseIOException {
    if (!isTableColocated(regionInfo.getTable())) {
        return this.delegator.randomAssignment(regionInfo, servers);
    }
    ServerName sn = getServerNameFromMap(regionInfo, servers);
    if (sn == null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("No server found for region " + regionInfo.getRegionNameAsString() + '.');
        }
        sn = getRandomServer(regionInfo, servers);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Destination server for region " + regionInfo.getRegionNameAsString()
                + " is " + ((sn == null) ? "null" : sn.toString()) + '.');
    }
    return sn;
}
 
Example #13
Source File: ConcurrentMutationsExtendedIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Override public void preBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c,
        MiniBatchOperationInProgress<Mutation> miniBatchOp) throws HBaseIOException {
    try {
        String tableName = c.getEnvironment().getRegionInfo().getTable().getNameAsString();
        if (tableName.startsWith(LOCK_TEST_TABLE_PREFIX)) {
            if (lockedTableRow) {
                throw new DoNotRetryIOException(
                        "Expected lock in preBatchMutate to be exclusive, but it wasn't for row "
                                + Bytes
                                .toStringBinary(miniBatchOp.getOperation(0).getRow()));
            }
            lockedTableRow = true;
            Thread.sleep(ROW_LOCK_WAIT_TIME + 2000);
        }
        Thread.sleep(Math.abs(RAND.nextInt()) % 10);
    } catch (InterruptedException e) {
    } finally {
        lockedTableRow = false;
    }

}
 
Example #14
Source File: IndexLoadBalancer.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Override
public Map<ServerName, List<HRegionInfo>> retainAssignment(
        Map<HRegionInfo, ServerName> regions, List<ServerName> servers) throws HBaseIOException {
    Map<HRegionInfo, ServerName> userRegionsMap =
            new ConcurrentHashMap<HRegionInfo, ServerName>();
    List<HRegionInfo> indexRegions = new ArrayList<HRegionInfo>();
    for (Entry<HRegionInfo, ServerName> e : regions.entrySet()) {
        seperateUserAndIndexRegion(e, userRegionsMap, indexRegions, servers);
    }
    Map<ServerName, List<HRegionInfo>> bulkPlan = null;
    if (!userRegionsMap.isEmpty()) {
        bulkPlan = this.delegator.retainAssignment(userRegionsMap, servers);
        if (bulkPlan == null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Empty region plan for user regions.");
            }
            return null;
        }
        savePlan(bulkPlan);
    }
    bulkPlan = prepareIndexRegionsPlan(indexRegions, bulkPlan, servers);
    return bulkPlan;
}
 
Example #15
Source File: MasterRegion.java    From hbase with Apache License 2.0 6 votes vote down vote up
private static WAL createWAL(WALFactory walFactory, MasterRegionWALRoller walRoller,
  String serverName, FileSystem walFs, Path walRootDir, RegionInfo regionInfo)
  throws IOException {
  String logName = AbstractFSWALProvider.getWALDirectoryName(serverName);
  Path walDir = new Path(walRootDir, logName);
  LOG.debug("WALDir={}", walDir);
  if (walFs.exists(walDir)) {
    throw new HBaseIOException(
      "Already created wal directory at " + walDir + " for local region " + regionInfo);
  }
  if (!walFs.mkdirs(walDir)) {
    throw new IOException(
      "Can not create wal directory " + walDir + " for local region " + regionInfo);
  }
  WAL wal = walFactory.getWAL(regionInfo);
  walRoller.addWAL(wal);
  return wal;
}
 
Example #16
Source File: IndexLoadBalancer.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Override
public Map<ServerName, List<HRegionInfo>> roundRobinAssignment(List<HRegionInfo> regions,
        List<ServerName> servers) throws HBaseIOException {
    List<HRegionInfo> userRegions = new ArrayList<HRegionInfo>();
    List<HRegionInfo> indexRegions = new ArrayList<HRegionInfo>();
    for (HRegionInfo hri : regions) {
        seperateUserAndIndexRegion(hri, userRegions, indexRegions);
    }
    Map<ServerName, List<HRegionInfo>> bulkPlan = null;
    if (!userRegions.isEmpty()) {
        bulkPlan = this.delegator.roundRobinAssignment(userRegions, servers);
        // This should not happen.
        if (null == bulkPlan) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("No region plans selected for user regions in roundRobinAssignment.");
            }
            return null;
        }
        savePlan(bulkPlan);
    }
    bulkPlan = prepareIndexRegionsPlan(indexRegions, bulkPlan, servers);
    return bulkPlan;
}
 
Example #17
Source File: TestRegionProcedureStoreMigration.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testMigrateWithUnsupportedProcedures() throws IOException {
  AssignProcedure assignProc = new AssignProcedure();
  assignProc.setProcId(1L);
  assignProc.setRegionInfo(RegionInfoBuilder.newBuilder(TableName.valueOf("table")).build());
  walStore.insert(assignProc, null);
  walStore.stop(true);

  try {
    store = RegionProcedureStoreTestHelper.createStore(server, region, new LoadCounter());
    fail("Should fail since AssignProcedure is not supported");
  } catch (HBaseIOException e) {
    assertThat(e.getMessage(), startsWith("Unsupported"));
  }
}
 
Example #18
Source File: ModifyTableProcedure.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
protected void preflightChecks(MasterProcedureEnv env, Boolean enabled) throws HBaseIOException {
  super.preflightChecks(env, enabled);
  if (this.modifiedTableDescriptor.isMetaTable()) {
    // If we are modifying the hbase:meta table, make sure we are not deleting critical
    // column families else we'll damage the cluster.
    Set<byte []> cfs = this.modifiedTableDescriptor.getColumnFamilyNames();
    for (byte[] family : UNDELETABLE_META_COLUMNFAMILIES) {
      if (!cfs.contains(family)) {
        throw new HBaseIOException("Delete of hbase:meta column family " +
          Bytes.toString(family));
      }
    }
  }
}
 
Example #19
Source File: SimpleRpcServerResponder.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Process the response for this call. You need to have the lock on
 * {@link org.apache.hadoop.hbase.ipc.SimpleServerRpcConnection#responseWriteLock}
 * @return true if we proceed the call fully, false otherwise.
 * @throws IOException
 */
private boolean processResponse(SimpleServerRpcConnection conn, RpcResponse resp)
    throws IOException {
  boolean error = true;
  BufferChain buf = resp.getResponse();
  try {
    // Send as much data as we can in the non-blocking fashion
    long numBytes =
        this.simpleRpcServer.channelWrite(conn.channel, buf);
    if (numBytes < 0) {
      throw new HBaseIOException("Error writing on the socket " + conn);
    }
    error = false;
  } finally {
    if (error) {
      SimpleRpcServer.LOG.debug(conn + ": output error -- closing");
      // We will be closing this connection itself. Mark this call as done so that all the
      // buffer(s) it got from pool can get released
      resp.done();
      this.simpleRpcServer.closeConnection(conn);
    }
  }

  if (!buf.hasRemaining()) {
    resp.done();
    return true;
  } else {
    // set the serve time when the response has to be sent later
    conn.lastSentTime = System.currentTimeMillis();
    return false; // Socket can't take more, we will have to come back.
  }
}
 
Example #20
Source File: NamespaceAuditor.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void checkTableTypeAndThrowException(TableName name) throws IOException {
  if (name.isSystemTable()) {
    LOG.debug("Namespace auditor checks not performed for table " + name.getNameAsString());
  } else {
    throw new HBaseIOException(
      name + " is being created even before namespace auditor has been initialized.");
  }
}
 
Example #21
Source File: HMaster.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Remove decommission marker (previously called 'draining') from a region server to allow regions
 * assignments. Load regions onto the server asynchronously if a list of regions is given
 * @param server Region server to remove decommission marker from.
 */
public void recommissionRegionServer(final ServerName server,
    final List<byte[]> encodedRegionNames) throws IOException {
  // Remove the server from decommissioned (draining) server list.
  String parentZnode = getZooKeeper().getZNodePaths().drainingZNode;
  String node = ZNodePaths.joinZNode(parentZnode, server.getServerName());
  try {
    ZKUtil.deleteNodeFailSilent(getZooKeeper(), node);
  } catch (KeeperException ke) {
    throw new HBaseIOException(
      this.zooKeeper.prefix("Unable to recommission '" + server.getServerName() + "'."), ke);
  }
  this.serverManager.removeServerFromDrainList(server);

  // Load the regions onto the server if we are given a list of regions.
  if (encodedRegionNames == null || encodedRegionNames.isEmpty()) {
    return;
  }
  if (!this.serverManager.isServerOnline(server)) {
    return;
  }
  for (byte[] encodedRegionName : encodedRegionNames) {
    RegionState regionState =
      assignmentManager.getRegionStates().getRegionState(Bytes.toString(encodedRegionName));
    if (regionState == null) {
      LOG.warn("Unknown region " + Bytes.toStringBinary(encodedRegionName));
      continue;
    }
    RegionInfo hri = regionState.getRegion();
    if (server.equals(regionState.getServerName())) {
      LOG.info("Skipping move of region " + hri.getRegionNameAsString() +
        " because region already assigned to the same server " + server + ".");
      continue;
    }
    RegionPlan rp = new RegionPlan(hri, regionState.getServerName(), server);
    this.assignmentManager.moveAsync(rp);
  }
}
 
Example #22
Source File: ProtobufUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
private static IOException makeIOExceptionOfException(Throwable e) {
  Throwable t = e;
  if (e instanceof ServiceException) {
    t = e.getCause();
  }
  if (ExceptionUtil.isInterrupt(t)) {
    return ExceptionUtil.asInterrupt(t);
  }
  if (t instanceof RemoteException) {
    t = ((RemoteException)t).unwrapRemoteException();
  }
  return t instanceof IOException? (IOException)t: new HBaseIOException(t);
}
 
Example #23
Source File: AsyncNonMetaRegionLocator.java    From hbase with Apache License 2.0 5 votes vote down vote up
private boolean onScanNext(TableName tableName, LocateRequest req, Result result) {
  RegionLocations locs = CatalogFamilyFormat.getRegionLocations(result);
  if (LOG.isDebugEnabled()) {
    LOG.debug("The fetched location of '{}', row='{}', locateType={} is {}", tableName,
      Bytes.toStringBinary(req.row), req.locateType, locs);
  }
  // remove HRegionLocation with null location, i.e, getServerName returns null.
  if (locs != null) {
    locs = locs.removeElementsWithNullLocation();
  }

  // the default region location should always be presented when fetching from meta, otherwise
  // let's fail the request.
  if (locs == null || locs.getDefaultRegionLocation() == null) {
    complete(tableName, req, null,
      new HBaseIOException(String.format("No location found for '%s', row='%s', locateType=%s",
        tableName, Bytes.toStringBinary(req.row), req.locateType)));
    return true;
  }
  HRegionLocation loc = locs.getDefaultRegionLocation();
  RegionInfo info = loc.getRegion();
  if (info == null) {
    complete(tableName, req, null,
      new HBaseIOException(String.format("HRegionInfo is null for '%s', row='%s', locateType=%s",
        tableName, Bytes.toStringBinary(req.row), req.locateType)));
    return true;
  }
  if (info.isSplitParent()) {
    return false;
  }
  complete(tableName, req, locs, null);
  return true;
}
 
Example #24
Source File: UpsertSelectOverlappingBatchesIT.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
    public void preBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c, MiniBatchOperationInProgress<Mutation> miniBatchOp) throws HBaseIOException {
    	// model a slow batch that takes a long time
        if ((miniBatchOp.size()==100 || SLOW_MUTATE) && c.getEnvironment().getRegionInfo().getTable().getNameAsString().equals(dataTable)) {
        	try {
	Thread.sleep(6000);
} catch (InterruptedException e) {
	e.printStackTrace();
}
        }
    }
 
Example #25
Source File: PartialCommitIT.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void prePut(ObserverContext<RegionCoprocessorEnvironment> c, Put put, WALEdit edit,
        final Durability durability) throws HBaseIOException {
    if (shouldFail(c, put)) {
        // throwing anything other than instances of IOException result
        // in this coprocessor being unloaded
        // DoNotRetryIOException tells HBase not to retry this mutation
        // multiple times
        throw new DoNotRetryIOException();
    }
}
 
Example #26
Source File: TestAssignmentManagerUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateUnassignProcedureForSplitFail() throws IOException {
  RegionInfo region = getPrimaryRegions().get(0);
  AM.getRegionStates().getRegionStateNode(region)
    .setProcedure(TransitRegionStateProcedure.unassign(ENV, region));
  try {
    AssignmentManagerUtil.createUnassignProceduresForSplitOrMerge(ENV, Stream.of(region),
      REGION_REPLICATION);
    fail("Should fail as the region is in transition");
  } catch (HBaseIOException e) {
    // expected
  }
}
 
Example #27
Source File: ModifyTableProcedure.java    From hbase with Apache License 2.0 5 votes vote down vote up
public ModifyTableProcedure(final MasterProcedureEnv env,
    final TableDescriptor newTableDescriptor, final ProcedurePrepareLatch latch,
    final TableDescriptor oldTableDescriptor, final boolean shouldCheckDescriptor)
        throws HBaseIOException {
  super(env, latch);
  initialize(oldTableDescriptor, shouldCheckDescriptor);
  this.modifiedTableDescriptor = newTableDescriptor;
  preflightChecks(env, null/*No table checks; if changing peers, table can be online*/);
}
 
Example #28
Source File: TruncateTableProcedure.java    From hbase with Apache License 2.0 5 votes vote down vote up
public TruncateTableProcedure(final MasterProcedureEnv env, final TableName tableName,
    boolean preserveSplits, ProcedurePrepareLatch latch)
throws HBaseIOException {
  super(env, latch);
  this.tableName = tableName;
  preflightChecks(env, false);
  this.preserveSplits = preserveSplits;
}
 
Example #29
Source File: DisableTableProcedure.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor
 * @param env MasterProcedureEnv
 * @param tableName the table to operate on
 * @param skipTableStateCheck whether to check table state
 */
public DisableTableProcedure(final MasterProcedureEnv env, final TableName tableName,
    final boolean skipTableStateCheck, final ProcedurePrepareLatch syncLatch)
    throws HBaseIOException {
  super(env, syncLatch);
  this.tableName = tableName;
  preflightChecks(env, true);
  this.skipTableStateCheck = skipTableStateCheck;
}
 
Example #30
Source File: AbstractStateMachineTableProcedure.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Check that cluster is up and master is running. Check table is modifiable.
 * If <code>enabled</code>, check table is enabled else check it is disabled.
 * Call in Procedure constructor so can pass any exception to caller.
 * @param enabled If true, check table is enabled and throw exception if not. If false, do the
 *                inverse. If null, do no table checks.
 */
protected void preflightChecks(MasterProcedureEnv env, Boolean enabled) throws HBaseIOException {
  MasterServices master = env.getMasterServices();
  if (!master.isClusterUp()) {
    throw new HBaseIOException("Cluster not up!");
  }
  if (master.isStopping() || master.isStopped()) {
    throw new HBaseIOException("Master stopping=" + master.isStopping() +
        ", stopped=" + master.isStopped());
  }
  if (enabled == null) {
    // Don't do any table checks.
    return;
  }
  try {
    // Checks table exists and is modifiable.
    checkTableModifiable(env);
    TableName tn = getTableName();
    TableStateManager tsm = master.getTableStateManager();
    TableState ts = tsm.getTableState(tn);
    if (enabled) {
      if (!ts.isEnabledOrEnabling()) {
        throw new TableNotEnabledException(tn);
      }
    } else {
      if (!ts.isDisabledOrDisabling()) {
        throw new TableNotDisabledException(tn);
      }
    }
  } catch (IOException ioe) {
    if (ioe instanceof HBaseIOException) {
      throw (HBaseIOException)ioe;
    }
    throw new HBaseIOException(ioe);
  }
}