/** * Dump the {@link SnapshotDescription} */ private void printInfo() { SnapshotProtos.SnapshotDescription snapshotDesc = snapshotManifest.getSnapshotDescription(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); System.out.println("Snapshot Info"); System.out.println("----------------------------------------"); System.out.println(" Name: " + snapshotDesc.getName()); System.out.println(" Type: " + snapshotDesc.getType()); System.out.println(" Table: " + snapshotDesc.getTable()); System.out.println(" Format: " + snapshotDesc.getVersion()); System.out.println("Created: " + df.format(new Date(snapshotDesc.getCreationTime()))); System.out.println(" Owner: " + snapshotDesc.getOwner()); System.out.println(); }
/** * @param services services for the master * @param snapshot snapshot to check * @param workingDirFs the file system containing the temporary snapshot information */ public MasterSnapshotVerifier(MasterServices services, SnapshotDescription snapshot, FileSystem workingDirFs) { this.workingDirFs = workingDirFs; this.services = services; this.snapshot = snapshot; this.tableName = TableName.valueOf(snapshot.getTable()); }
SnapshotStats(final Configuration conf, final FileSystem fs, final SnapshotProtos.SnapshotDescription snapshot) { this.snapshot = snapshot; this.snapshotTable = TableName.valueOf(snapshot.getTable()); this.conf = conf; this.fs = fs; }
SnapshotProtos.SnapshotDescription snapshotDesc = SnapshotDescriptionUtils.readSnapshotInfo(fs, snapshotDir); final TableName table = TableName.valueOf(snapshotDesc.getTable());
assertTrue(desc.getTable().equals(tableName.getNameAsString())); return snapshotFiles;
handler.prepare(); this.executorService.submit(handler); this.snapshotHandlers.put(TableName.valueOf(snapshot.getTable()), handler); } catch (Exception e) {
/** * Determine if the snapshot should be handled on this server * * NOTE: This is racy -- the master expects a list of regionservers. * This means if a region moves somewhere between the calls we'll miss some regions. * For example, a region move during a snapshot could result in a region to be skipped or done * twice. This is manageable because the {@link MasterSnapshotVerifier} will double check the * region lists after the online portion of the snapshot completes and will explicitly fail the * snapshot. * * @param snapshot * @return the list of online regions. Empty list is returned if no regions are responsible for * the given snapshot. * @throws IOException */ private List<HRegion> getRegionsToSnapshot(SnapshotDescription snapshot) throws IOException { List<HRegion> onlineRegions = (List<HRegion>) rss .getRegions(TableName.valueOf(snapshot.getTable())); Iterator<HRegion> iterator = onlineRegions.iterator(); // remove the non-default regions while (iterator.hasNext()) { HRegion r = iterator.next(); if (!RegionReplicaUtil.isDefaultReplica(r.getRegionInfo())) { iterator.remove(); } } return onlineRegions; }
/** * Return the handler if it is currently live and has the same snapshot target name. * The handler is removed from the sentinels map if completed. * @param sentinels live handlers * @param snapshot snapshot description * @return null if doesn't match, else a live handler. */ private synchronized SnapshotSentinel removeSentinelIfFinished( final Map<TableName, SnapshotSentinel> sentinels, final SnapshotDescription snapshot) { if (!snapshot.hasTable()) { return null; } TableName snapshotTable = TableName.valueOf(snapshot.getTable()); SnapshotSentinel h = sentinels.get(snapshotTable); if (h == null) { return null; } if (!h.getSnapshot().getName().equals(snapshot.getName())) { // specified snapshot is to the one currently running return null; } // Remove from the "in-progress" list once completed if (h.isFinished()) { sentinels.remove(snapshotTable); } return h; }
/** * Check to see if there is a snapshot in progress with the same name or on the same table. * Currently we have a limitation only allowing a single snapshot per table at a time. Also we * don't allow snapshot with the same name. * @param snapshot description of the snapshot being checked. * @return <tt>true</tt> if there is a snapshot in progress with the same name or on the same * table. */ synchronized boolean isTakingSnapshot(final SnapshotDescription snapshot) { TableName snapshotTable = TableName.valueOf(snapshot.getTable()); if (isTakingSnapshot(snapshotTable)) { return true; } Iterator<Map.Entry<TableName, SnapshotSentinel>> it = this.snapshotHandlers.entrySet().iterator(); while (it.hasNext()) { Map.Entry<TableName, SnapshotSentinel> entry = it.next(); SnapshotSentinel sentinel = entry.getValue(); if (snapshot.getName().equals(sentinel.getSnapshot().getName()) && !sentinel.isFinished()) { return true; } } return false; }
public RestoreSnapshotHelper(final Configuration conf, final FileSystem fs, final SnapshotManifest manifest, final TableDescriptor tableDescriptor, final Path rootDir, final ForeignExceptionDispatcher monitor, final MonitoredTask status, final boolean createBackRefs) { this.fs = fs; this.conf = conf; this.snapshotManifest = manifest; this.snapshotDesc = manifest.getSnapshotDescription(); this.snapshotTable = TableName.valueOf(snapshotDesc.getTable()); this.tableDesc = tableDescriptor; this.rootDir = rootDir; this.tableDir = FSUtils.getTableDir(rootDir, tableDesc.getTableName()); this.monitor = monitor; this.status = status; this.createBackRefs = createBackRefs; }
public long restoreSnapshot(final SnapshotDescription snapshotDesc, final long nonceGroup, final long nonce, final boolean restoreAcl) throws IOException { checkInitialized(); getSnapshotManager().checkSnapshotSupport(); // Ensure namespace exists. Will throw exception if non-known NS. final TableName dstTable = TableName.valueOf(snapshotDesc.getTable()); getClusterSchema().getNamespace(dstTable.getNamespaceAsString()); return MasterProcedureUtil.submitProcedure( new MasterProcedureUtil.NonceProcedureRunnable(this, nonceGroup, nonce) { @Override protected void run() throws IOException { setProcId( getSnapshotManager().restoreOrCloneSnapshot(snapshotDesc, getNonceKey(), restoreAcl)); } @Override protected String getDescription() { return "RestoreSnapshotProcedure"; } }); }
/** * Check to make sure that the description of the snapshot requested is valid * @param snapshot description of the snapshot * @throws IllegalArgumentException if the name of the snapshot or the name of the table to * snapshot are not valid names. */ public static void assertSnapshotRequestIsValid(SnapshotProtos.SnapshotDescription snapshot) throws IllegalArgumentException { // make sure the snapshot name is valid TableName.isLegalTableQualifierName(Bytes.toBytes(snapshot.getName()), true); if(snapshot.hasTable()) { // make sure the table name is valid, this will implicitly check validity TableName tableName = TableName.valueOf(snapshot.getTable()); if (tableName.isSystemTable()) { throw new IllegalArgumentException("System table snapshots are not allowed"); } } }
/** * Returns a single line (no \n) representation of snapshot metadata. Use this instead of * {@link org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription#toString()}. We don't replace SnapshotDescrpition's toString * because it is auto-generated by protoc. * @param ssd * @return Single line string with a summary of the snapshot parameters */ public static String toString(SnapshotProtos.SnapshotDescription ssd) { if (ssd == null) { return null; } return "{ ss=" + ssd.getName() + " table=" + (ssd.hasTable()?TableName.valueOf(ssd.getTable()):"") + " type=" + ssd.getType() + " }"; } }
@Test public void testCloneSnapshotToSameTable() throws Exception { // take the snapshot SnapshotProtos.SnapshotDescription snapshotDesc = getSnapshot(); final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); final TableName clonedTableName = TableName.valueOf(snapshotDesc.getTable()); final TableDescriptor htd = createTableDescriptor(clonedTableName, CF); long procId = ProcedureTestingUtility.submitAndWait( procExec, new CloneSnapshotProcedure(procExec.getEnvironment(), htd, snapshotDesc)); Procedure<?> result = procExec.getResult(procId); assertTrue(result.isFailed()); LOG.debug("Clone snapshot failed with exception: " + result.getException()); assertTrue( ProcedureTestingUtility.getExceptionCause(result) instanceof TableExistsException); }
/** * Check that the table descriptor for the snapshot is a valid table descriptor * @param manifest snapshot manifest to inspect */ private void verifyTableInfo(final SnapshotManifest manifest) throws IOException { TableDescriptor htd = manifest.getTableDescriptor(); if (htd == null) { throw new CorruptedSnapshotException("Missing Table Descriptor", ProtobufUtil.createSnapshotDesc(snapshot)); } if (!htd.getTableName().getNameAsString().equals(snapshot.getTable())) { throw new CorruptedSnapshotException( "Invalid Table Descriptor. Expected " + snapshot.getTable() + " name, got " + htd.getTableName().getNameAsString(), ProtobufUtil.createSnapshotDesc(snapshot)); } }
/** * Convert from * {@link org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription} to * {@link SnapshotDescription} * @param snapshotDesc the protobuf SnapshotDescription * @return the POJO SnapshotDescription */ public static SnapshotDescription createSnapshotDesc(SnapshotProtos.SnapshotDescription snapshotDesc) { return new SnapshotDescription(snapshotDesc.getName(), snapshotDesc.hasTable() ? TableName.valueOf(snapshotDesc.getTable()) : null, createSnapshotType(snapshotDesc.getType()), snapshotDesc.getOwner(), snapshotDesc.getCreationTime(), snapshotDesc.getVersion()); }
/** * <pre> * not needed for delete, but checked for in taking snapshot * </pre> * * <code>optional string table = 2;</code> */ public Builder clearTable() { bitField0_ = (bitField0_ & ~0x00000002); table_ = getDefaultInstance().getTable(); onChanged(); return this; } /**
/** * Make sure that there is only one snapshot returned from the master */ public static void assertOneSnapshotThatMatches(Admin admin, SnapshotProtos.SnapshotDescription snapshot) throws IOException { assertOneSnapshotThatMatches(admin, snapshot.getName(), TableName.valueOf(snapshot.getTable())); }
@Override public ListMultimap<String, UserPermission> run() throws Exception { return AccessControlLists.getTablePermissions(conf, TableName.valueOf(snapshot.getTable())); } });
private void restoreSnapshotAcl(final MasterProcedureEnv env) throws IOException { if (restoreAcl && snapshot.hasUsersAndPermissions() && snapshot.getUsersAndPermissions() != null && SnapshotDescriptionUtils .isSecurityAvailable(env.getMasterServices().getConfiguration())) { // restore acl of snapshot to table. RestoreSnapshotHelper.restoreSnapshotAcl(snapshot, TableName.valueOf(snapshot.getTable()), env.getMasterServices().getConfiguration()); } }