Search in sources :

Example 1 with CorruptedSnapshotException

use of org.apache.hadoop.hbase.snapshot.CorruptedSnapshotException in project hbase by apache.

the class SnapshotFileCache method getSnapshotsInProgress.

@VisibleForTesting
List<String> getSnapshotsInProgress(final SnapshotManager snapshotManager) throws IOException {
    List<String> snapshotInProgress = Lists.newArrayList();
    // only add those files to the cache, but not to the known snapshots
    Path snapshotTmpDir = new Path(snapshotDir, SnapshotDescriptionUtils.SNAPSHOT_TMP_DIR_NAME);
    // only add those files to the cache, but not to the known snapshots
    FileStatus[] running = FSUtils.listStatus(fs, snapshotTmpDir);
    if (running != null) {
        for (FileStatus run : running) {
            ReentrantLock lock = null;
            if (snapshotManager != null) {
                lock = snapshotManager.getLocks().acquireLock(run.getPath().getName());
            }
            try {
                snapshotInProgress.addAll(fileInspector.filesUnderSnapshot(run.getPath()));
            } catch (CorruptedSnapshotException e) {
                // See HBASE-16464
                if (e.getCause() instanceof FileNotFoundException) {
                    // If the snapshot is corrupt, we will delete it
                    fs.delete(run.getPath(), true);
                    LOG.warn("delete the " + run.getPath() + " due to exception:", e.getCause());
                } else {
                    throw e;
                }
            } finally {
                if (lock != null) {
                    lock.unlock();
                }
            }
        }
    }
    return snapshotInProgress;
}
Also used : Path(org.apache.hadoop.fs.Path) ReentrantLock(java.util.concurrent.locks.ReentrantLock) FileStatus(org.apache.hadoop.fs.FileStatus) FileNotFoundException(java.io.FileNotFoundException) CorruptedSnapshotException(org.apache.hadoop.hbase.snapshot.CorruptedSnapshotException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with CorruptedSnapshotException

use of org.apache.hadoop.hbase.snapshot.CorruptedSnapshotException 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 3 with CorruptedSnapshotException

use of org.apache.hadoop.hbase.snapshot.CorruptedSnapshotException in project hbase by apache.

the class TestRestoreSnapshotFromClient method testCorruptedSnapshot.

@Test
public void testCorruptedSnapshot() throws IOException, InterruptedException {
    SnapshotTestingUtils.corruptSnapshot(TEST_UTIL, Bytes.toString(snapshotName0));
    TableName cloneName = TableName.valueOf(name.getMethodName() + "-" + System.currentTimeMillis());
    try {
        admin.cloneSnapshot(snapshotName0, cloneName);
        fail("Expected CorruptedSnapshotException, got succeeded cloneSnapshot()");
    } catch (CorruptedSnapshotException e) {
        // Got the expected corruption exception.
        // check for no references of the cloned table.
        assertFalse(admin.tableExists(cloneName));
    } catch (Exception e) {
        fail("Expected CorruptedSnapshotException got: " + e);
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) CorruptedSnapshotException(org.apache.hadoop.hbase.snapshot.CorruptedSnapshotException) CorruptedSnapshotException(org.apache.hadoop.hbase.snapshot.CorruptedSnapshotException) IOException(java.io.IOException) NoSuchColumnFamilyException(org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException) Test(org.junit.Test)

Aggregations

CorruptedSnapshotException (org.apache.hadoop.hbase.snapshot.CorruptedSnapshotException)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 FileStatus (org.apache.hadoop.fs.FileStatus)1 Path (org.apache.hadoop.fs.Path)1 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)1 TableName (org.apache.hadoop.hbase.TableName)1 NoSuchColumnFamilyException (org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException)1 SnapshotRegionManifest (org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotRegionManifest)1 MetaTableLocator (org.apache.hadoop.hbase.zookeeper.MetaTableLocator)1 Test (org.junit.Test)1