Skip to content

Commit 5c8d55a

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 201fadc commit 5c8d55a

File tree

5 files changed

+157
-96
lines changed

5 files changed

+157
-96
lines changed

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

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

204-
205204
/**
206205
* @param fileName File name to check.
207206
* @return True if the path is a HFileLink.
@@ -322,10 +321,10 @@ public static String createHFileLinkName(final TableName tableName,
322321
* @param dstFamilyPath - Destination path (table/region/cf/)
323322
* @param hfileRegionInfo - Linked HFile Region Info
324323
* @param hfileName - Linked HFile name
325-
* @return true if the file is created, otherwise the file exists.
326-
* @throws IOException on file or parent directory creation failure
324+
* @return the file link name.
325+
* @throws IOException on file or parent directory creation failure.
327326
*/
328-
public static boolean create(final Configuration conf, final FileSystem fs,
327+
public static String create(final Configuration conf, final FileSystem fs,
329328
final Path dstFamilyPath, final RegionInfo hfileRegionInfo,
330329
final String hfileName) throws IOException {
331330
return create(conf, fs, dstFamilyPath, hfileRegionInfo, hfileName, true);
@@ -343,10 +342,10 @@ public static boolean create(final Configuration conf, final FileSystem fs,
343342
* @param hfileRegionInfo - Linked HFile Region Info
344343
* @param hfileName - Linked HFile name
345344
* @param createBackRef - Whether back reference should be created. Defaults to true.
346-
* @return true if the file is created, otherwise the file exists.
347-
* @throws IOException on file or parent directory creation failure
345+
* @return the file link name.
346+
* @throws IOException on file or parent directory creation failure.
348347
*/
349-
public static boolean create(final Configuration conf, final FileSystem fs,
348+
public static String create(final Configuration conf, final FileSystem fs,
350349
final Path dstFamilyPath, final RegionInfo hfileRegionInfo,
351350
final String hfileName, final boolean createBackRef) throws IOException {
352351
TableName linkedTable = hfileRegionInfo.getTable();
@@ -366,17 +365,18 @@ public static boolean create(final Configuration conf, final FileSystem fs,
366365
* @param linkedTable - Linked Table Name
367366
* @param linkedRegion - Linked Region Name
368367
* @param hfileName - Linked HFile name
369-
* @return true if the file is created, otherwise the file exists.
370-
* @throws IOException on file or parent directory creation failure
368+
* @return the file link name.
369+
* @throws IOException on file or parent directory creation failure.
371370
*/
372-
public static boolean create(final Configuration conf, final FileSystem fs,
371+
public static String create(final Configuration conf, final FileSystem fs,
373372
final Path dstFamilyPath, final TableName linkedTable, final String linkedRegion,
374373
final String hfileName) throws IOException {
375374
return create(conf, fs, dstFamilyPath, linkedTable, linkedRegion, hfileName, true);
376375
}
377376

378377
/**
379-
* Create a new HFileLink
378+
* Create a new HFileLink. In the event of link creation failure, this method throws an
379+
* IOException, so that the calling upper laying can decide on how to proceed with this.
380380
*
381381
* <p>It also adds a back-reference to the hfile back-reference directory
382382
* to simplify the reference-count and the cleaning process.
@@ -388,10 +388,10 @@ public static boolean create(final Configuration conf, final FileSystem fs,
388388
* @param linkedRegion - Linked Region Name
389389
* @param hfileName - Linked HFile name
390390
* @param createBackRef - Whether back reference should be created. Defaults to true.
391-
* @return true if the file is created, otherwise the file exists.
392-
* @throws IOException on file or parent directory creation failure
391+
* @return the file link name.
392+
* @throws IOException on file or parent directory creation failure.
393393
*/
394-
public static boolean create(final Configuration conf, final FileSystem fs,
394+
public static String create(final Configuration conf, final FileSystem fs,
395395
final Path dstFamilyPath, final TableName linkedTable, final String linkedRegion,
396396
final String hfileName, final boolean createBackRef) throws IOException {
397397
String familyName = dstFamilyPath.getName();
@@ -417,10 +417,10 @@ public static boolean create(final Configuration conf, final FileSystem fs,
417417
* @param linkedRegion - Linked Region Name
418418
* @param hfileName - Linked HFile name
419419
* @param createBackRef - Whether back reference should be created. Defaults to true.
420-
* @return true if the file is created, otherwise the file exists.
420+
* @return the file link name.
421421
* @throws IOException on file or parent directory creation failure
422422
*/
423-
public static boolean create(final Configuration conf, final FileSystem fs,
423+
public static String create(final Configuration conf, final FileSystem fs,
424424
final Path dstFamilyPath, final String familyName, final String dstTableName,
425425
final String dstRegionName, final TableName linkedTable, final String linkedRegion,
426426
final String hfileName, final boolean createBackRef) throws IOException {
@@ -444,7 +444,9 @@ public static boolean create(final Configuration conf, final FileSystem fs,
444444
}
445445
try {
446446
// Create the link
447-
return fs.createNewFile(new Path(dstFamilyPath, name));
447+
if (fs.createNewFile(new Path(dstFamilyPath, name))) {
448+
return name;
449+
}
448450
} catch (IOException e) {
449451
LOG.error("couldn't create the link=" + name + " for " + dstFamilyPath, e);
450452
// Revert the reference if the link creation failed
@@ -453,25 +455,8 @@ public static boolean create(final Configuration conf, final FileSystem fs,
453455
}
454456
throw e;
455457
}
456-
}
457-
458-
/**
459-
* Create a new HFileLink starting from a hfileLink name
460-
*
461-
* <p>It also adds a back-reference to the hfile back-reference directory
462-
* to simplify the reference-count and the cleaning process.
463-
*
464-
* @param conf {@link Configuration} to read for the archive directory name
465-
* @param fs {@link FileSystem} on which to write the HFileLink
466-
* @param dstFamilyPath - Destination path (table/region/cf/)
467-
* @param hfileLinkName - HFileLink name (it contains hfile-region-table)
468-
* @return true if the file is created, otherwise the file exists.
469-
* @throws IOException on file or parent directory creation failure
470-
*/
471-
public static boolean createFromHFileLink(final Configuration conf, final FileSystem fs,
472-
final Path dstFamilyPath, final String hfileLinkName)
473-
throws IOException {
474-
return createFromHFileLink(conf, fs, dstFamilyPath, hfileLinkName, true);
458+
throw new IOException("File link=" + name + " already exists under " +
459+
dstFamilyPath + " folder.");
475460
}
476461

477462
/**
@@ -485,10 +470,10 @@ public static boolean createFromHFileLink(final Configuration conf, final FileSy
485470
* @param dstFamilyPath - Destination path (table/region/cf/)
486471
* @param hfileLinkName - HFileLink name (it contains hfile-region-table)
487472
* @param createBackRef - Whether back reference should be created. Defaults to true.
488-
* @return true if the file is created, otherwise the file exists.
489-
* @throws IOException on file or parent directory creation failure
473+
* @return the file link name.
474+
* @throws IOException on file or parent directory creation failure.
490475
*/
491-
public static boolean createFromHFileLink(final Configuration conf, final FileSystem fs,
476+
public static String createFromHFileLink(final Configuration conf, final FileSystem fs,
492477
final Path dstFamilyPath, final String hfileLinkName, final boolean createBackRef)
493478
throws IOException {
494479
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)