Skip to content

Commit 92d0223

Browse files
wchevreuilApache9
authored andcommitted
HBASE-26328 Clone snapshot doesn't load reference files into FILE SFT impl (#3749)
Signed-off-by: Duo Zhang <[email protected]>
1 parent 5c93fc9 commit 92d0223

File tree

5 files changed

+155
-94
lines changed

5 files changed

+155
-94
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/io/HFileLink.java

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ public static boolean isHFileLink(final Path path) {
202202
return isHFileLink(path.getName());
203203
}
204204

205-
206205
/**
207206
* @param fileName File name to check.
208207
* @return True if the path is a HFileLink.
@@ -323,10 +322,10 @@ public static String createHFileLinkName(final TableName tableName,
323322
* @param dstFamilyPath - Destination path (table/region/cf/)
324323
* @param hfileRegionInfo - Linked HFile Region Info
325324
* @param hfileName - Linked HFile name
326-
* @return true if the file is created, otherwise the file exists.
327-
* @throws IOException on file or parent directory creation failure
325+
* @return the file link name.
326+
* @throws IOException on file or parent directory creation failure.
328327
*/
329-
public static boolean create(final Configuration conf, final FileSystem fs,
328+
public static String create(final Configuration conf, final FileSystem fs,
330329
final Path dstFamilyPath, final RegionInfo hfileRegionInfo,
331330
final String hfileName) throws IOException {
332331
return create(conf, fs, dstFamilyPath, hfileRegionInfo, hfileName, true);
@@ -344,10 +343,10 @@ public static boolean create(final Configuration conf, final FileSystem fs,
344343
* @param hfileRegionInfo - Linked HFile Region Info
345344
* @param hfileName - Linked HFile name
346345
* @param createBackRef - Whether back reference should be created. Defaults to true.
347-
* @return true if the file is created, otherwise the file exists.
348-
* @throws IOException on file or parent directory creation failure
346+
* @return the file link name.
347+
* @throws IOException on file or parent directory creation failure.
349348
*/
350-
public static boolean create(final Configuration conf, final FileSystem fs,
349+
public static String create(final Configuration conf, final FileSystem fs,
351350
final Path dstFamilyPath, final RegionInfo hfileRegionInfo,
352351
final String hfileName, final boolean createBackRef) throws IOException {
353352
TableName linkedTable = hfileRegionInfo.getTable();
@@ -367,17 +366,18 @@ public static boolean create(final Configuration conf, final FileSystem fs,
367366
* @param linkedTable - Linked Table Name
368367
* @param linkedRegion - Linked Region Name
369368
* @param hfileName - Linked HFile name
370-
* @return true if the file is created, otherwise the file exists.
371-
* @throws IOException on file or parent directory creation failure
369+
* @return the file link name.
370+
* @throws IOException on file or parent directory creation failure.
372371
*/
373-
public static boolean create(final Configuration conf, final FileSystem fs,
372+
public static String create(final Configuration conf, final FileSystem fs,
374373
final Path dstFamilyPath, final TableName linkedTable, final String linkedRegion,
375374
final String hfileName) throws IOException {
376375
return create(conf, fs, dstFamilyPath, linkedTable, linkedRegion, hfileName, true);
377376
}
378377

379378
/**
380-
* Create a new HFileLink
379+
* Create a new HFileLink. In the event of link creation failure, this method throws an
380+
* IOException, so that the calling upper laying can decide on how to proceed with this.
381381
*
382382
* <p>It also adds a back-reference to the hfile back-reference directory
383383
* to simplify the reference-count and the cleaning process.
@@ -389,10 +389,10 @@ public static boolean create(final Configuration conf, final FileSystem fs,
389389
* @param linkedRegion - Linked Region Name
390390
* @param hfileName - Linked HFile name
391391
* @param createBackRef - Whether back reference should be created. Defaults to true.
392-
* @return true if the file is created, otherwise the file exists.
393-
* @throws IOException on file or parent directory creation failure
392+
* @return the file link name.
393+
* @throws IOException on file or parent directory creation failure.
394394
*/
395-
public static boolean create(final Configuration conf, final FileSystem fs,
395+
public static String create(final Configuration conf, final FileSystem fs,
396396
final Path dstFamilyPath, final TableName linkedTable, final String linkedRegion,
397397
final String hfileName, final boolean createBackRef) throws IOException {
398398
String familyName = dstFamilyPath.getName();
@@ -420,7 +420,9 @@ public static boolean create(final Configuration conf, final FileSystem fs,
420420
}
421421
try {
422422
// Create the link
423-
return fs.createNewFile(new Path(dstFamilyPath, name));
423+
if(fs.createNewFile(new Path(dstFamilyPath, name))){
424+
return name;
425+
}
424426
} catch (IOException e) {
425427
LOG.error("couldn't create the link=" + name + " for " + dstFamilyPath, e);
426428
// Revert the reference if the link creation failed
@@ -429,25 +431,8 @@ public static boolean create(final Configuration conf, final FileSystem fs,
429431
}
430432
throw e;
431433
}
432-
}
433-
434-
/**
435-
* Create a new HFileLink starting from a hfileLink name
436-
*
437-
* <p>It also adds a back-reference to the hfile back-reference directory
438-
* to simplify the reference-count and the cleaning process.
439-
*
440-
* @param conf {@link Configuration} to read for the archive directory name
441-
* @param fs {@link FileSystem} on which to write the HFileLink
442-
* @param dstFamilyPath - Destination path (table/region/cf/)
443-
* @param hfileLinkName - HFileLink name (it contains hfile-region-table)
444-
* @return true if the file is created, otherwise the file exists.
445-
* @throws IOException on file or parent directory creation failure
446-
*/
447-
public static boolean createFromHFileLink(final Configuration conf, final FileSystem fs,
448-
final Path dstFamilyPath, final String hfileLinkName)
449-
throws IOException {
450-
return createFromHFileLink(conf, fs, dstFamilyPath, hfileLinkName, true);
434+
throw new IOException("File link=" + name + " already exists under " +
435+
dstFamilyPath + " folder.");
451436
}
452437

453438
/**
@@ -461,10 +446,10 @@ public static boolean createFromHFileLink(final Configuration conf, final FileSy
461446
* @param dstFamilyPath - Destination path (table/region/cf/)
462447
* @param hfileLinkName - HFileLink name (it contains hfile-region-table)
463448
* @param createBackRef - Whether back reference should be created. Defaults to true.
464-
* @return true if the file is created, otherwise the file exists.
465-
* @throws IOException on file or parent directory creation failure
449+
* @return the file link name.
450+
* @throws IOException on file or parent directory creation failure.
466451
*/
467-
public static boolean createFromHFileLink(final Configuration conf, final FileSystem fs,
452+
public static String createFromHFileLink(final Configuration conf, final FileSystem fs,
468453
final Path dstFamilyPath, final String hfileLinkName, final boolean createBackRef)
469454
throws IOException {
470455
Matcher m = LINK_NAME_PATTERN.matcher(hfileLinkName);

hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CloneSnapshotProcedure.java

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import org.apache.hadoop.hbase.master.RegionState;
4141
import org.apache.hadoop.hbase.master.assignment.AssignmentManager;
4242
import org.apache.hadoop.hbase.master.procedure.CreateTableProcedure.CreateHdfsRegions;
43-
import org.apache.hadoop.hbase.mob.MobUtils;
4443
import org.apache.hadoop.hbase.monitoring.MonitoredTask;
4544
import org.apache.hadoop.hbase.monitoring.TaskMonitor;
4645
import org.apache.hadoop.hbase.procedure2.ProcedureStateSerializer;
@@ -453,56 +452,25 @@ private List<RegionInfo> createFsLayout(
453452
List<RegionInfo> newRegions,
454453
final CreateHdfsRegions hdfsRegionHandler) throws IOException {
455454
final MasterFileSystem mfs = env.getMasterServices().getMasterFileSystem();
456-
final Path tempdir = mfs.getTempDir();
457455

458456
// 1. Create Table Descriptor
459457
// using a copy of descriptor, table will be created enabling first
460-
final Path tempTableDir = CommonFSUtils.getTableDir(tempdir, tableDescriptor.getTableName());
461-
if (CommonFSUtils.isExists(mfs.getFileSystem(), tempTableDir)) {
458+
final Path tableDir = CommonFSUtils.getTableDir(mfs.getRootDir(),
459+
tableDescriptor.getTableName());
460+
if (CommonFSUtils.isExists(mfs.getFileSystem(), tableDir)) {
462461
// if the region dirs exist, will cause exception and unlimited retry (see HBASE-24546)
463-
LOG.warn("temp table dir already exists on disk: {}, will be deleted.", tempTableDir);
464-
CommonFSUtils.deleteDirectory(mfs.getFileSystem(), tempTableDir);
462+
LOG.warn("temp table dir already exists on disk: {}, will be deleted.", tableDir);
463+
CommonFSUtils.deleteDirectory(mfs.getFileSystem(), tableDir);
465464
}
466-
((FSTableDescriptors) (env.getMasterServices().getTableDescriptors()))
467-
.createTableDescriptorForTableDirectory(tempTableDir,
468-
TableDescriptorBuilder.newBuilder(tableDescriptor).build(), false);
465+
((FSTableDescriptors)(env.getMasterServices().getTableDescriptors()))
466+
.createTableDescriptorForTableDirectory(tableDir,
467+
TableDescriptorBuilder.newBuilder(tableDescriptor).build(), false);
469468

470469
// 2. Create Regions
471470
newRegions = hdfsRegionHandler.createHdfsRegions(
472-
env, tempdir, tableDescriptor.getTableName(), newRegions);
473-
474-
// 3. Move Table temp directory to the hbase root location
475-
CreateTableProcedure.moveTempDirectoryToHBaseRoot(env, tableDescriptor, tempTableDir);
476-
// Move Table temp mob directory to the hbase root location
477-
Path tempMobTableDir = MobUtils.getMobTableDir(tempdir, tableDescriptor.getTableName());
478-
if (mfs.getFileSystem().exists(tempMobTableDir)) {
479-
moveTempMobDirectoryToHBaseRoot(mfs, tableDescriptor, tempMobTableDir);
480-
}
481-
return newRegions;
482-
}
471+
env, mfs.getRootDir(), tableDescriptor.getTableName(), newRegions);
483472

484-
/**
485-
* Move table temp mob directory to the hbase root location
486-
* @param mfs The master file system
487-
* @param tableDescriptor The table to operate on
488-
* @param tempMobTableDir The temp mob directory of table
489-
* @throws IOException If failed to move temp mob dir to hbase root dir
490-
*/
491-
private void moveTempMobDirectoryToHBaseRoot(final MasterFileSystem mfs,
492-
final TableDescriptor tableDescriptor, final Path tempMobTableDir) throws IOException {
493-
FileSystem fs = mfs.getFileSystem();
494-
final Path tableMobDir =
495-
MobUtils.getMobTableDir(mfs.getRootDir(), tableDescriptor.getTableName());
496-
if (!fs.delete(tableMobDir, true) && fs.exists(tableMobDir)) {
497-
throw new IOException("Couldn't delete mob table " + tableMobDir);
498-
}
499-
if (!fs.exists(tableMobDir.getParent())) {
500-
fs.mkdirs(tableMobDir.getParent());
501-
}
502-
if (!fs.rename(tempMobTableDir, tableMobDir)) {
503-
throw new IOException("Unable to move mob table from temp=" + tempMobTableDir
504-
+ " to hbase root=" + tableMobDir);
505-
}
473+
return newRegions;
506474
}
507475

508476
/**

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/storefiletracker/StoreFileTrackerBase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import java.io.IOException;
2323
import java.util.Collection;
24+
2425
import org.apache.hadoop.conf.Configuration;
2526
import org.apache.hadoop.fs.Path;
2627
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor;

0 commit comments

Comments
 (0)