Skip to content

Commit 2afb820

Browse files
gvprathyusha6Prathyusha Garre
andcommitted
HBASE-28969 Move HFileLink file creations to SFT (#6459)
Signed-off-by: Andrew Purtell <[email protected]> Co-authored-by: Prathyusha Garre <[email protected]>
1 parent a9262aa commit 2afb820

File tree

11 files changed

+167
-213
lines changed

11 files changed

+167
-213
lines changed

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

Lines changed: 0 additions & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.regex.Matcher;
2222
import java.util.regex.Pattern;
2323
import org.apache.hadoop.conf.Configuration;
24-
import org.apache.hadoop.fs.FileSystem;
2524
import org.apache.hadoop.fs.Path;
2625
import org.apache.hadoop.hbase.HConstants;
2726
import org.apache.hadoop.hbase.TableName;
@@ -290,175 +289,6 @@ public static String createHFileLinkName(final TableName tableName, final String
290289
return s;
291290
}
292291

293-
/**
294-
* Create a new HFileLink
295-
* <p>
296-
* It also adds a back-reference to the hfile back-reference directory to simplify the
297-
* reference-count and the cleaning process.
298-
* @param conf {@link Configuration} to read for the archive directory name
299-
* @param fs {@link FileSystem} on which to write the HFileLink
300-
* @param dstFamilyPath - Destination path (table/region/cf/)
301-
* @param hfileRegionInfo - Linked HFile Region Info
302-
* @param hfileName - Linked HFile name
303-
* @return the file link name.
304-
* @throws IOException on file or parent directory creation failure.
305-
*/
306-
public static String create(final Configuration conf, final FileSystem fs,
307-
final Path dstFamilyPath, final RegionInfo hfileRegionInfo, final String hfileName)
308-
throws IOException {
309-
return create(conf, fs, dstFamilyPath, hfileRegionInfo, hfileName, true);
310-
}
311-
312-
/**
313-
* Create a new HFileLink
314-
* <p>
315-
* It also adds a back-reference to the hfile back-reference directory to simplify the
316-
* reference-count and the cleaning process.
317-
* @param conf {@link Configuration} to read for the archive directory name
318-
* @param fs {@link FileSystem} on which to write the HFileLink
319-
* @param dstFamilyPath - Destination path (table/region/cf/)
320-
* @param hfileRegionInfo - Linked HFile Region Info
321-
* @param hfileName - Linked HFile name
322-
* @param createBackRef - Whether back reference should be created. Defaults to true.
323-
* @return the file link name.
324-
* @throws IOException on file or parent directory creation failure.
325-
*/
326-
public static String create(final Configuration conf, final FileSystem fs,
327-
final Path dstFamilyPath, final RegionInfo hfileRegionInfo, final String hfileName,
328-
final boolean createBackRef) throws IOException {
329-
TableName linkedTable = hfileRegionInfo.getTable();
330-
String linkedRegion = hfileRegionInfo.getEncodedName();
331-
return create(conf, fs, dstFamilyPath, linkedTable, linkedRegion, hfileName, createBackRef);
332-
}
333-
334-
/**
335-
* Create a new HFileLink
336-
* <p>
337-
* It also adds a back-reference to the hfile back-reference directory to simplify the
338-
* reference-count and the cleaning process.
339-
* @param conf {@link Configuration} to read for the archive directory name
340-
* @param fs {@link FileSystem} on which to write the HFileLink
341-
* @param dstFamilyPath - Destination path (table/region/cf/)
342-
* @param linkedTable - Linked Table Name
343-
* @param linkedRegion - Linked Region Name
344-
* @param hfileName - Linked HFile name
345-
* @return the file link name.
346-
* @throws IOException on file or parent directory creation failure.
347-
*/
348-
public static String create(final Configuration conf, final FileSystem fs,
349-
final Path dstFamilyPath, final TableName linkedTable, final String linkedRegion,
350-
final String hfileName) throws IOException {
351-
return create(conf, fs, dstFamilyPath, linkedTable, linkedRegion, hfileName, true);
352-
}
353-
354-
/**
355-
* Create a new HFileLink. In the event of link creation failure, this method throws an
356-
* IOException, so that the calling upper laying can decide on how to proceed with this.
357-
* <p>
358-
* It also adds a back-reference to the hfile back-reference directory to simplify the
359-
* reference-count and the cleaning process.
360-
* @param conf {@link Configuration} to read for the archive directory name
361-
* @param fs {@link FileSystem} on which to write the HFileLink
362-
* @param dstFamilyPath - Destination path (table/region/cf/)
363-
* @param linkedTable - Linked Table Name
364-
* @param linkedRegion - Linked Region Name
365-
* @param hfileName - Linked HFile name
366-
* @param createBackRef - Whether back reference should be created. Defaults to true.
367-
* @return the file link name.
368-
* @throws IOException on file or parent directory creation failure.
369-
*/
370-
public static String create(final Configuration conf, final FileSystem fs,
371-
final Path dstFamilyPath, final TableName linkedTable, final String linkedRegion,
372-
final String hfileName, final boolean createBackRef) throws IOException {
373-
String familyName = dstFamilyPath.getName();
374-
String regionName = dstFamilyPath.getParent().getName();
375-
String tableName =
376-
CommonFSUtils.getTableName(dstFamilyPath.getParent().getParent()).getNameAsString();
377-
378-
return create(conf, fs, dstFamilyPath, familyName, tableName, regionName, linkedTable,
379-
linkedRegion, hfileName, createBackRef);
380-
}
381-
382-
/**
383-
* Create a new HFileLink
384-
* <p>
385-
* It also adds a back-reference to the hfile back-reference directory to simplify the
386-
* reference-count and the cleaning process.
387-
* @param conf {@link Configuration} to read for the archive directory name
388-
* @param fs {@link FileSystem} on which to write the HFileLink
389-
* @param dstFamilyPath - Destination path (table/region/cf/)
390-
* @param dstTableName - Destination table name
391-
* @param dstRegionName - Destination region name
392-
* @param linkedTable - Linked Table Name
393-
* @param linkedRegion - Linked Region Name
394-
* @param hfileName - Linked HFile name
395-
* @param createBackRef - Whether back reference should be created. Defaults to true.
396-
* @return the file link name.
397-
* @throws IOException on file or parent directory creation failure
398-
*/
399-
public static String create(final Configuration conf, final FileSystem fs,
400-
final Path dstFamilyPath, final String familyName, final String dstTableName,
401-
final String dstRegionName, final TableName linkedTable, final String linkedRegion,
402-
final String hfileName, final boolean createBackRef) throws IOException {
403-
String name = createHFileLinkName(linkedTable, linkedRegion, hfileName);
404-
String refName = createBackReferenceName(dstTableName, dstRegionName);
405-
406-
// Make sure the destination directory exists
407-
fs.mkdirs(dstFamilyPath);
408-
409-
// Make sure the FileLink reference directory exists
410-
Path archiveStoreDir =
411-
HFileArchiveUtil.getStoreArchivePath(conf, linkedTable, linkedRegion, familyName);
412-
Path backRefPath = null;
413-
if (createBackRef) {
414-
Path backRefssDir = getBackReferencesDir(archiveStoreDir, hfileName);
415-
fs.mkdirs(backRefssDir);
416-
417-
// Create the reference for the link
418-
backRefPath = new Path(backRefssDir, refName);
419-
fs.createNewFile(backRefPath);
420-
}
421-
try {
422-
// Create the link
423-
if (fs.createNewFile(new Path(dstFamilyPath, name))) {
424-
return name;
425-
}
426-
} catch (IOException e) {
427-
LOG.error("couldn't create the link=" + name + " for " + dstFamilyPath, e);
428-
// Revert the reference if the link creation failed
429-
if (createBackRef) {
430-
fs.delete(backRefPath, false);
431-
}
432-
throw e;
433-
}
434-
throw new IOException(
435-
"File link=" + name + " already exists under " + dstFamilyPath + " folder.");
436-
}
437-
438-
/**
439-
* Create a new HFileLink starting from a hfileLink name
440-
* <p>
441-
* It also adds a back-reference to the hfile back-reference directory to simplify the
442-
* reference-count and the cleaning process.
443-
* @param conf {@link Configuration} to read for the archive directory name
444-
* @param fs {@link FileSystem} on which to write the HFileLink
445-
* @param dstFamilyPath - Destination path (table/region/cf/)
446-
* @param hfileLinkName - HFileLink name (it contains hfile-region-table)
447-
* @param createBackRef - Whether back reference should be created. Defaults to true.
448-
* @return the file link name.
449-
* @throws IOException on file or parent directory creation failure.
450-
*/
451-
public static String createFromHFileLink(final Configuration conf, final FileSystem fs,
452-
final Path dstFamilyPath, final String hfileLinkName, final boolean createBackRef)
453-
throws IOException {
454-
Matcher m = LINK_NAME_PATTERN.matcher(hfileLinkName);
455-
if (!m.matches()) {
456-
throw new IllegalArgumentException(hfileLinkName + " is not a valid HFileLink name!");
457-
}
458-
return create(conf, fs, dstFamilyPath, TableName.valueOf(m.group(1), m.group(2)), m.group(3),
459-
m.group(4), createBackRef);
460-
}
461-
462292
/**
463293
* Create the back reference name
464294
*/

hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/SplitTableRegionProcedure.java

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -701,9 +701,8 @@ private Pair<List<Path>, List<Path>> splitStoreFiles(final MasterProcedureEnv en
701701
// table dir. In case of failure, the proc would go through this again, already existing
702702
// region dirs and split files would just be ignored, new split files should get created.
703703
int nbFiles = 0;
704-
final Map<String, Pair<Collection<StoreFileInfo>, StoreFileTracker>> files =
705-
new HashMap<String, Pair<Collection<StoreFileInfo>, StoreFileTracker>>(
706-
htd.getColumnFamilyCount());
704+
final Map<String, Collection<StoreFileInfo>> files =
705+
new HashMap<String, Collection<StoreFileInfo>>(htd.getColumnFamilyCount());
707706
for (ColumnFamilyDescriptor cfd : htd.getColumnFamilies()) {
708707
String family = cfd.getNameAsString();
709708
StoreFileTracker tracker =
@@ -726,7 +725,7 @@ private Pair<List<Path>, List<Path>> splitStoreFiles(final MasterProcedureEnv en
726725
}
727726
if (filteredSfis == null) {
728727
filteredSfis = new ArrayList<StoreFileInfo>(sfis.size());
729-
files.put(family, new Pair(filteredSfis, tracker));
728+
files.put(family, filteredSfis);
730729
}
731730
filteredSfis.add(sfi);
732731
nbFiles++;
@@ -749,12 +748,11 @@ private Pair<List<Path>, List<Path>> splitStoreFiles(final MasterProcedureEnv en
749748
final List<Future<Pair<Path, Path>>> futures = new ArrayList<Future<Pair<Path, Path>>>(nbFiles);
750749

751750
// Split each store file.
752-
for (Map.Entry<String, Pair<Collection<StoreFileInfo>, StoreFileTracker>> e : files
753-
.entrySet()) {
751+
for (Map.Entry<String, Collection<StoreFileInfo>> e : files.entrySet()) {
754752
byte[] familyName = Bytes.toBytes(e.getKey());
755753
final ColumnFamilyDescriptor hcd = htd.getColumnFamily(familyName);
756-
Pair<Collection<StoreFileInfo>, StoreFileTracker> storeFilesAndTracker = e.getValue();
757-
final Collection<StoreFileInfo> storeFiles = storeFilesAndTracker.getFirst();
754+
Collection<StoreFileInfo> storeFileInfos = e.getValue();
755+
final Collection<StoreFileInfo> storeFiles = storeFileInfos;
758756
if (storeFiles != null && storeFiles.size() > 0) {
759757
final Configuration storeConfiguration =
760758
StoreUtils.createStoreConfiguration(env.getMasterConfiguration(), htd, hcd);
@@ -765,9 +763,8 @@ private Pair<List<Path>, List<Path>> splitStoreFiles(final MasterProcedureEnv en
765763
// is running in a regionserver's Store context, or we might not be able
766764
// to read the hfiles.
767765
storeFileInfo.setConf(storeConfiguration);
768-
StoreFileSplitter sfs =
769-
new StoreFileSplitter(regionFs, storeFilesAndTracker.getSecond(), familyName,
770-
new HStoreFile(storeFileInfo, hcd.getBloomFilterType(), CacheConfig.DISABLED));
766+
StoreFileSplitter sfs = new StoreFileSplitter(regionFs, htd, hcd,
767+
new HStoreFile(storeFileInfo, hcd.getBloomFilterType(), CacheConfig.DISABLED));
771768
futures.add(threadPool.submit(sfs));
772769
}
773770
}
@@ -833,19 +830,27 @@ private void assertSplitResultFilesCount(final FileSystem fs,
833830
}
834831
}
835832

836-
private Pair<Path, Path> splitStoreFile(HRegionFileSystem regionFs, StoreFileTracker tracker,
837-
byte[] family, HStoreFile sf) throws IOException {
833+
private Pair<Path, Path> splitStoreFile(HRegionFileSystem regionFs, TableDescriptor htd,
834+
ColumnFamilyDescriptor hcd, HStoreFile sf) throws IOException {
838835
if (LOG.isDebugEnabled()) {
839836
LOG.debug("pid=" + getProcId() + " splitting started for store file: " + sf.getPath()
840837
+ " for region: " + getParentRegion().getShortNameToLog());
841838
}
842839

843840
final byte[] splitRow = getSplitRow();
844-
final String familyName = Bytes.toString(family);
841+
final String familyName = hcd.getNameAsString();
842+
StoreFileTracker daughterOneSft =
843+
StoreFileTrackerFactory.create(regionFs.getFileSystem().getConf(), htd, hcd,
844+
HRegionFileSystem.create(regionFs.getFileSystem().getConf(), regionFs.getFileSystem(),
845+
regionFs.getTableDir(), daughterOneRI));
846+
StoreFileTracker daughterTwoSft =
847+
StoreFileTrackerFactory.create(regionFs.getFileSystem().getConf(), htd, hcd,
848+
HRegionFileSystem.create(regionFs.getFileSystem().getConf(), regionFs.getFileSystem(),
849+
regionFs.getTableDir(), daughterTwoRI));
845850
final Path path_first = regionFs.splitStoreFile(this.daughterOneRI, familyName, sf, splitRow,
846-
false, splitPolicy, tracker);
851+
false, splitPolicy, daughterOneSft);
847852
final Path path_second = regionFs.splitStoreFile(this.daughterTwoRI, familyName, sf, splitRow,
848-
true, splitPolicy, tracker);
853+
true, splitPolicy, daughterTwoSft);
849854
if (LOG.isDebugEnabled()) {
850855
LOG.debug("pid=" + getProcId() + " splitting complete for store file: " + sf.getPath()
851856
+ " for region: " + getParentRegion().getShortNameToLog());
@@ -859,27 +864,27 @@ private Pair<Path, Path> splitStoreFile(HRegionFileSystem regionFs, StoreFileTra
859864
*/
860865
private class StoreFileSplitter implements Callable<Pair<Path, Path>> {
861866
private final HRegionFileSystem regionFs;
862-
private final byte[] family;
867+
private final ColumnFamilyDescriptor hcd;
863868
private final HStoreFile sf;
864-
private final StoreFileTracker tracker;
869+
private final TableDescriptor htd;
865870

866871
/**
867872
* Constructor that takes what it needs to split
868873
* @param regionFs the file system
869-
* @param family Family that contains the store file
874+
* @param hcd Family that contains the store file
870875
* @param sf which file
871876
*/
872-
public StoreFileSplitter(HRegionFileSystem regionFs, StoreFileTracker tracker, byte[] family,
873-
HStoreFile sf) {
877+
public StoreFileSplitter(HRegionFileSystem regionFs, TableDescriptor htd,
878+
ColumnFamilyDescriptor hcd, HStoreFile sf) {
874879
this.regionFs = regionFs;
875880
this.sf = sf;
876-
this.family = family;
877-
this.tracker = tracker;
881+
this.hcd = hcd;
882+
this.htd = htd;
878883
}
879884

880885
@Override
881886
public Pair<Path, Path> call() throws IOException {
882-
return splitStoreFile(regionFs, tracker, family, sf);
887+
return splitStoreFile(regionFs, htd, hcd, sf);
883888
}
884889
}
885890

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,8 +683,7 @@ public Path splitStoreFile(RegionInfo hri, String familyName, HStoreFile f, byte
683683
hfileName = m.group(4);
684684
}
685685
// must create back reference here
686-
HFileLink.create(conf, fs, splitDir, familyName, hri.getTable().getNameAsString(),
687-
hri.getEncodedName(), linkedTable, linkedRegion, hfileName, true);
686+
tracker.createHFileLink(linkedTable, linkedRegion, hfileName, true);
688687
Path path =
689688
new Path(splitDir, HFileLink.createHFileLinkName(linkedTable, linkedRegion, hfileName));
690689
LOG.info("Created linkFile:" + path.toString() + " for child: " + hri.getEncodedName()

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.List;
2323
import org.apache.hadoop.fs.FileStatus;
2424
import org.apache.hadoop.fs.Path;
25+
import org.apache.hadoop.hbase.TableName;
2526
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
2627
import org.apache.hadoop.hbase.io.Reference;
2728
import org.apache.hadoop.hbase.regionserver.CreateStoreFileWriterParams;
@@ -119,4 +120,30 @@ StoreFileInfo getStoreFileInfo(final FileStatus fileStatus, final Path initialPa
119120
StoreFileInfo getStoreFileInfo(final Path initialPath, final boolean primaryReplica)
120121
throws IOException;
121122

123+
/**
124+
* Create a new HFileLink
125+
* <p>
126+
* It also adds a back-reference to the hfile back-reference directory to simplify the
127+
* reference-count and the cleaning process.
128+
* @param hfileLinkName - HFileLink name (it contains hfile-region-table)
129+
* @param createBackRef - Whether back reference should be created. Defaults to true.
130+
* @return the file link name.
131+
* @throws IOException on file or parent directory creation failure.
132+
*/
133+
String createHFileLink(final TableName linkedTable, final String linkedRegion,
134+
final String hfileName, final boolean createBackRef) throws IOException;
135+
136+
/**
137+
* Create a new HFileLink starting from a hfileLink name
138+
* <p>
139+
* It also adds a back-reference to the hfile back-reference directory to simplify the
140+
* reference-count and the cleaning process.
141+
* @param hfileLinkName - HFileLink name (it contains hfile-region-table)
142+
* @param createBackRef - Whether back reference should be created. Defaults to true.
143+
* @return the file link name.
144+
* @throws IOException on file or parent directory creation failure.
145+
*/
146+
String createFromHFileLink(final String hfileName, final boolean createBackRef)
147+
throws IOException;
148+
122149
}

0 commit comments

Comments
 (0)