Skip to content

Commit 1a03775

Browse files
committed
HBASE-28535: Addressed the review comments.
Change-Id: I95ec8691f5d511a8bd452c1492de7ff1222980b6
1 parent fe6bc46 commit 1a03775

5 files changed

Lines changed: 164 additions & 135 deletions

File tree

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.apache.hadoop.conf.Configuration;
2424
import org.apache.hadoop.fs.Path;
2525
import org.apache.hadoop.hbase.io.FSDataInputStreamWrapper;
26-
import org.apache.hadoop.hbase.regionserver.DataTieringManager;
2726
import org.apache.yetus.audience.InterfaceAudience;
2827
import org.slf4j.Logger;
2928
import org.slf4j.LoggerFactory;
@@ -41,13 +40,8 @@ public HFilePreadReader(ReaderContext context, HFileInfo fileInfo, CacheConfig c
4140

4241
final MutableBoolean shouldCache = new MutableBoolean(true);
4342

44-
DataTieringManager dataTieringManager = DataTieringManager.getInstance();
45-
if (dataTieringManager != null) {
46-
// Initialize HFileInfo object with metadata for caching decisions.
47-
// Initialize the metadata only if the data-tiering is enabled.
48-
// If not, the metadata will be initialized later.
49-
fileInfo.initMetaAndIndex(this);
50-
}
43+
// Initialize HFileInfo object with metadata for caching decisions
44+
fileInfo.initMetaAndIndex(this);
5145

5246
cacheConf.getBlockCache().ifPresent(cache -> {
5347
Optional<Boolean> result = cache.shouldCacheFile(fileInfo, conf);

hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,18 +2195,11 @@ public Optional<Boolean> blockFitsIntoTheCache(HFileBlock block) {
21952195
public Optional<Boolean> shouldCacheFile(HFileInfo hFileInfo, Configuration conf) {
21962196
String fileName = hFileInfo.getHFileContext().getHFileName();
21972197
DataTieringManager dataTieringManager = DataTieringManager.getInstance();
2198-
if (dataTieringManager != null) {
2199-
if (!dataTieringManager.isHotData(hFileInfo, conf)) {
2200-
LOG.debug("Data tiering is enabled for file: '{}' and it is not hot data", fileName);
2201-
return Optional.of(false);
2202-
} else {
2203-
LOG.debug("Data tiering is enabled for file: '{}' and it is hot data", fileName);
2204-
}
2205-
} else {
2206-
LOG.debug("Data tiering feature is not enabled. "
2207-
+ " The file: '{}' will be loaded if not already loaded", fileName);
2198+
if (dataTieringManager != null && !dataTieringManager.isHotData(hFileInfo, conf)) {
2199+
LOG.debug("Data tiering is enabled for file: '{}' and it is not hot data", fileName);
2200+
return Optional.of(false);
22082201
}
2209-
// if we don't have the file in fullyCachedFiles, we should cache it.
2202+
// if we don't have the file in fullyCachedFiles, we should cache it
22102203
return Optional.of(!fullyCachedFiles.containsKey(fileName));
22112204
}
22122205

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

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@
4545
@InterfaceAudience.Private
4646
public class DataTieringManager {
4747
private static final Logger LOG = LoggerFactory.getLogger(DataTieringManager.class);
48-
public static final String DATA_TIERING_ENABLED_KEY = "hbase.hstore.datatiering.enable";
49-
public static final boolean DEFAULT_DATA_TIERING_ENABLED = false; // disabled by default
48+
public static final String GLOBAL_DATA_TIERING_ENABLED_KEY =
49+
"hbase.regionserver.datatiering.enable";
50+
public static final boolean DEFAULT_GLOBAL_DATA_TIERING_ENABLED = false; // disabled by default
5051
public static final String DATATIERING_KEY = "hbase.hstore.datatiering.type";
5152
public static final String DATATIERING_HOT_DATA_AGE_KEY =
5253
"hbase.hstore.datatiering.hot.age.millis";
@@ -60,26 +61,25 @@ private DataTieringManager(Map<String, HRegion> onlineRegions) {
6061
}
6162

6263
/**
63-
* Initializes the DataTieringManager instance with the provided map of online regions.
64+
* Initializes the DataTieringManager instance with the provided map of online regions, only if
65+
* the configuration "hbase.regionserver.datatiering.enable" is enabled.
6466
* @param onlineRegions A map containing online regions.
6567
*/
66-
public static synchronized void instantiate(Configuration conf,
68+
public static synchronized boolean instantiate(Configuration conf,
6769
Map<String, HRegion> onlineRegions) {
68-
if (isDataTieringFeatureEnabled(conf)) {
69-
if (instance == null) {
70-
instance = new DataTieringManager(onlineRegions);
71-
LOG.info("DataTieringManager instantiated successfully.");
72-
} else {
73-
LOG.warn("DataTieringManager is already instantiated.");
74-
}
70+
if (isDataTieringFeatureEnabled(conf) && instance == null) {
71+
instance = new DataTieringManager(onlineRegions);
72+
LOG.info("DataTieringManager instantiated successfully.");
73+
return true;
7574
} else {
76-
LOG.info("Data-Tiering feature is not enabled.");
75+
LOG.warn("DataTieringManager is already instantiated.");
7776
}
77+
return false;
7878
}
7979

8080
/**
8181
* Retrieves the instance of DataTieringManager.
82-
* @return The instance of DataTieringManager.
82+
* @return The instance of DataTieringManager, if instantiated, null otherwise.
8383
*/
8484
public static synchronized DataTieringManager getInstance() {
8585
return instance;
@@ -311,8 +311,13 @@ public Map<String, String> getColdFilesList() {
311311
return coldFiles;
312312
}
313313

314-
public static boolean isDataTieringFeatureEnabled(Configuration conf) {
315-
return conf.getBoolean(DataTieringManager.DATA_TIERING_ENABLED_KEY,
316-
DataTieringManager.DEFAULT_DATA_TIERING_ENABLED);
314+
private static boolean isDataTieringFeatureEnabled(Configuration conf) {
315+
return conf.getBoolean(DataTieringManager.GLOBAL_DATA_TIERING_ENABLED_KEY,
316+
DataTieringManager.DEFAULT_GLOBAL_DATA_TIERING_ENABLED);
317+
}
318+
319+
// Resets the instance to null. To be used only for testing.
320+
public static void resetForTestingOnly() {
321+
instance = null;
317322
}
318323
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,10 @@ public HRegionServer(final Configuration conf) throws IOException {
534534
regionServerAccounting = new RegionServerAccounting(conf);
535535

536536
blockCache = BlockCacheFactory.createBlockCache(conf);
537-
if (DataTieringManager.isDataTieringFeatureEnabled(conf)) {
538-
DataTieringManager.instantiate(conf, onlineRegions);
539-
}
537+
// The call below, instantiates the DataTieringManager only when
538+
// the configuration "hbase.regionserver.datatiering.enable" is set to true.
539+
DataTieringManager.instantiate(conf, onlineRegions);
540+
540541
mobFileCache = new MobFileCache(conf);
541542

542543
rsSnapshotVerifier = new RSSnapshotVerifier(conf);

0 commit comments

Comments
 (0)