Search in sources :

Example 16 with MetaTableLocator

use of org.apache.hadoop.hbase.zookeeper.MetaTableLocator in project hbase by apache.

the class ServerCrashProcedure method isMetaAssignedQuickTest.

/**
   * A quick test that hbase:meta is assigned; blocks for short time only.
   * @return True if hbase:meta location is available and verified as good.
   * @throws InterruptedException
   * @throws IOException
   */
private boolean isMetaAssignedQuickTest(final MasterProcedureEnv env) throws InterruptedException, IOException {
    ZooKeeperWatcher zkw = env.getMasterServices().getZooKeeper();
    MetaTableLocator mtl = env.getMasterServices().getMetaTableLocator();
    boolean metaAssigned = false;
    // Is hbase:meta location available yet?
    if (mtl.isLocationAvailable(zkw)) {
        ClusterConnection connection = env.getMasterServices().getClusterConnection();
        // Is hbase:meta location good yet?
        long timeout = env.getMasterConfiguration().getLong(KEY_SHORT_WAIT_ON_META, DEFAULT_SHORT_WAIT_ON_META);
        if (mtl.verifyMetaRegionLocation(connection, zkw, timeout)) {
            metaAssigned = true;
        }
    }
    return metaAssigned;
}
Also used : ClusterConnection(org.apache.hadoop.hbase.client.ClusterConnection) MetaTableLocator(org.apache.hadoop.hbase.zookeeper.MetaTableLocator) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher)

Example 17 with MetaTableLocator

use of org.apache.hadoop.hbase.zookeeper.MetaTableLocator in project hbase by apache.

the class MasterSnapshotVerifier method verifyRegions.

/**
   * Check that all the regions in the snapshot are valid, and accounted for.
   * @param manifest snapshot manifest to inspect
   * @throws IOException if we can't reach hbase:meta or read the files from the FS
   */
private void verifyRegions(final SnapshotManifest manifest) throws IOException {
    List<HRegionInfo> regions;
    if (TableName.META_TABLE_NAME.equals(tableName)) {
        regions = new MetaTableLocator().getMetaRegions(services.getZooKeeper());
    } else {
        regions = MetaTableAccessor.getTableRegions(services.getConnection(), tableName);
    }
    // Remove the non-default regions
    RegionReplicaUtil.removeNonDefaultRegions(regions);
    Map<String, SnapshotRegionManifest> regionManifests = manifest.getRegionManifestsMap();
    if (regionManifests == null) {
        String msg = "Snapshot " + ClientSnapshotDescriptionUtils.toString(snapshot) + " looks empty";
        LOG.error(msg);
        throw new CorruptedSnapshotException(msg);
    }
    String errorMsg = "";
    boolean hasMobStore = false;
    // the mob region has a special name, it could be found by the region name.
    if (regionManifests.get(MobUtils.getMobRegionInfo(tableName).getEncodedName()) != null) {
        hasMobStore = true;
    }
    int realRegionCount = hasMobStore ? regionManifests.size() - 1 : regionManifests.size();
    if (realRegionCount != regions.size()) {
        errorMsg = "Regions moved during the snapshot '" + ClientSnapshotDescriptionUtils.toString(snapshot) + "'. expected=" + regions.size() + " snapshotted=" + realRegionCount + ".";
        LOG.error(errorMsg);
    }
    // Verify HRegionInfo
    for (HRegionInfo region : regions) {
        SnapshotRegionManifest regionManifest = regionManifests.get(region.getEncodedName());
        if (regionManifest == null) {
            // could happen due to a move or split race.
            String mesg = " No snapshot region directory found for region:" + region;
            if (errorMsg.isEmpty())
                errorMsg = mesg;
            LOG.error(mesg);
            continue;
        }
        verifyRegionInfo(region, regionManifest);
    }
    if (!errorMsg.isEmpty()) {
        throw new CorruptedSnapshotException(errorMsg);
    }
    // Verify Snapshot HFiles
    SnapshotReferenceUtil.verifySnapshot(services.getConfiguration(), fs, manifest);
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) MetaTableLocator(org.apache.hadoop.hbase.zookeeper.MetaTableLocator) SnapshotRegionManifest(org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotRegionManifest) CorruptedSnapshotException(org.apache.hadoop.hbase.snapshot.CorruptedSnapshotException)

Example 18 with MetaTableLocator

use of org.apache.hadoop.hbase.zookeeper.MetaTableLocator in project hbase by apache.

the class MasterFlushTableProcedureManager method execProcedure.

@Override
public void execProcedure(ProcedureDescription desc) throws IOException {
    TableName tableName = TableName.valueOf(desc.getInstance());
    // call pre coproc hook
    MasterCoprocessorHost cpHost = master.getMasterCoprocessorHost();
    if (cpHost != null) {
        cpHost.preTableFlush(tableName);
    }
    // Get the list of region servers that host the online regions for table.
    // We use the procedure instance name to carry the table name from the client.
    // It is possible that regions may move after we get the region server list.
    // Each region server will get its own online regions for the table.
    // We may still miss regions that need to be flushed.
    List<Pair<HRegionInfo, ServerName>> regionsAndLocations;
    if (TableName.META_TABLE_NAME.equals(tableName)) {
        regionsAndLocations = new MetaTableLocator().getMetaRegionsAndLocations(master.getZooKeeper());
    } else {
        regionsAndLocations = MetaTableAccessor.getTableRegionsAndLocations(master.getConnection(), tableName, false);
    }
    Set<String> regionServers = new HashSet<>(regionsAndLocations.size());
    for (Pair<HRegionInfo, ServerName> region : regionsAndLocations) {
        if (region != null && region.getFirst() != null && region.getSecond() != null) {
            HRegionInfo hri = region.getFirst();
            if (hri.isOffline() && (hri.isSplit() || hri.isSplitParent()))
                continue;
            regionServers.add(region.getSecond().toString());
        }
    }
    ForeignExceptionDispatcher monitor = new ForeignExceptionDispatcher(desc.getInstance());
    // Kick of the global procedure from the master coordinator to the region servers.
    // We rely on the existing Distributed Procedure framework to prevent any concurrent
    // procedure with the same name.
    Procedure proc = coordinator.startProcedure(monitor, desc.getInstance(), new byte[0], Lists.newArrayList(regionServers));
    monitor.rethrowException();
    if (proc == null) {
        String msg = "Failed to submit distributed procedure " + desc.getSignature() + " for '" + desc.getInstance() + "'. " + "Another flush procedure is running?";
        LOG.error(msg);
        throw new IOException(msg);
    }
    procMap.put(tableName, proc);
    try {
        // wait for the procedure to complete.  A timer thread is kicked off that should cancel this
        // if it takes too long.
        proc.waitForCompleted();
        LOG.info("Done waiting - exec procedure " + desc.getSignature() + " for '" + desc.getInstance() + "'");
        LOG.info("Master flush table procedure is successful!");
    } catch (InterruptedException e) {
        ForeignException ee = new ForeignException("Interrupted while waiting for flush table procdure to finish", e);
        monitor.receive(ee);
        Thread.currentThread().interrupt();
    } catch (ForeignException e) {
        ForeignException ee = new ForeignException("Exception while waiting for flush table procdure to finish", e);
        monitor.receive(ee);
    }
    monitor.rethrowException();
}
Also used : MasterCoprocessorHost(org.apache.hadoop.hbase.master.MasterCoprocessorHost) IOException(java.io.IOException) ForeignExceptionDispatcher(org.apache.hadoop.hbase.errorhandling.ForeignExceptionDispatcher) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) MetaTableLocator(org.apache.hadoop.hbase.zookeeper.MetaTableLocator) ServerName(org.apache.hadoop.hbase.ServerName) ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException) Procedure(org.apache.hadoop.hbase.procedure.Procedure) Pair(org.apache.hadoop.hbase.util.Pair) HashSet(java.util.HashSet)

Example 19 with MetaTableLocator

use of org.apache.hadoop.hbase.zookeeper.MetaTableLocator in project hbase by apache.

the class AssignmentManager method getReopenStatus.

/**
   * Used by the client to identify if all regions have the schema updates
   *
   * @param tableName
   * @return Pair indicating the status of the alter command
   * @throws IOException
   */
public Pair<Integer, Integer> getReopenStatus(TableName tableName) throws IOException {
    List<HRegionInfo> hris;
    if (TableName.META_TABLE_NAME.equals(tableName)) {
        hris = new MetaTableLocator().getMetaRegions(server.getZooKeeper());
    } else {
        hris = MetaTableAccessor.getTableRegions(server.getConnection(), tableName, true);
    }
    Integer pending = 0;
    for (HRegionInfo hri : hris) {
        String name = hri.getEncodedName();
        // no lock concurrent access ok: sequential consistency respected.
        if (regionsToReopen.containsKey(name) || regionStates.isRegionInTransition(name)) {
            pending++;
        }
    }
    return new Pair<>(pending, hris.size());
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MetaTableLocator(org.apache.hadoop.hbase.zookeeper.MetaTableLocator) Pair(org.apache.hadoop.hbase.util.Pair)

Example 20 with MetaTableLocator

use of org.apache.hadoop.hbase.zookeeper.MetaTableLocator in project hbase by apache.

the class TestMetaTableLocator method testVerifyMetaRegionLocationWithException.

private void testVerifyMetaRegionLocationWithException(Exception ex) throws IOException, InterruptedException, KeeperException, ServiceException {
    // Mock an ClientProtocol.
    final ClientProtos.ClientService.BlockingInterface implementation = Mockito.mock(ClientProtos.ClientService.BlockingInterface.class);
    ClusterConnection connection = mockConnection(null, implementation);
    // If a 'get' is called on mocked interface, throw connection refused.
    Mockito.when(implementation.get((RpcController) Mockito.any(), (GetRequest) Mockito.any())).thenThrow(new ServiceException(ex));
    long timeout = UTIL.getConfiguration().getLong("hbase.catalog.verification.timeout", 1000);
    MetaTableLocator.setMetaLocation(this.watcher, SN, RegionState.State.OPENING);
    assertFalse(new MetaTableLocator().verifyMetaRegionLocation(connection, watcher, timeout));
    MetaTableLocator.setMetaLocation(this.watcher, SN, RegionState.State.OPEN);
    assertFalse(new MetaTableLocator().verifyMetaRegionLocation(connection, watcher, timeout));
}
Also used : ClusterConnection(org.apache.hadoop.hbase.client.ClusterConnection) MetaTableLocator(org.apache.hadoop.hbase.zookeeper.MetaTableLocator) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException)

Aggregations

MetaTableLocator (org.apache.hadoop.hbase.zookeeper.MetaTableLocator)21 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)10 ServerName (org.apache.hadoop.hbase.ServerName)8 Pair (org.apache.hadoop.hbase.util.Pair)7 ZooKeeperWatcher (org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher)7 Test (org.junit.Test)6 IOException (java.io.IOException)3 ClusterConnection (org.apache.hadoop.hbase.client.ClusterConnection)3 NameStringPair (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.NameStringPair)3 HashSet (java.util.HashSet)2 NotServingRegionException (org.apache.hadoop.hbase.NotServingRegionException)2 ForeignException (org.apache.hadoop.hbase.errorhandling.ForeignException)2 HBaseRpcController (org.apache.hadoop.hbase.ipc.HBaseRpcController)2 ServiceException (org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException)2 FileNotFoundException (java.io.FileNotFoundException)1 ConnectException (java.net.ConnectException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1