wchevreuil commented on code in PR #5793:
URL: https://github.com/apache/hbase/pull/5793#discussion_r1551838394


##########
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/DataTieringManager.java:
##########
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.regionserver;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.OptionalLong;
+import java.util.Set;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.io.hfile.BlockCacheKey;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
[email protected]
+public class DataTieringManager {
+  private static final Logger LOG = 
LoggerFactory.getLogger(DataTieringManager.class);
+  public static final String DATATIERING_KEY = "hbase.hstore.datatiering.type";
+  public static final String DATATIERING_HOT_DATA_AGE_KEY =
+    "hbase.hstore.datatiering.hot.age.millis";
+  public static final DataTieringType DEFAULT_DATATIERING = 
DataTieringType.NONE;
+  public static final long DEFAULT_DATATIERING_HOT_DATA_AGE = 7 * 24 * 60 * 60 
* 1000; // 7 Days
+  private static DataTieringManager instance;
+  private final Map<String, HRegion> onlineRegions;
+
+  private DataTieringManager(Map<String, HRegion> onlineRegions) {
+    this.onlineRegions = onlineRegions;
+  }
+
+  public static synchronized void instantiate(Map<String, HRegion> 
onlineRegions) {
+    if (instance == null) {
+      instance = new DataTieringManager(onlineRegions);
+      LOG.info("DataTieringManager instantiated successfully.");
+    } else {
+      LOG.warn("DataTieringManager is already instantiated.");
+    }
+  }
+
+  public static synchronized DataTieringManager getInstance() {
+    if (instance == null) {
+      throw new IllegalStateException(
+        "DataTieringManager has not been instantiated. Call instantiate() 
first.");
+    }
+    return instance;
+  }
+
+  public boolean isDataTieringEnabled(BlockCacheKey key) throws 
DataTieringException {
+    Path hFilePath = key.getFilePath();
+    if (hFilePath == null) {
+      throw new DataTieringException("BlockCacheKey Doesn't Contain HFile 
Path");
+    }
+    return isDataTieringEnabled(hFilePath);
+  }
+
+  public boolean isDataTieringEnabled(Path hFilePath) throws 
DataTieringException {
+    Configuration configuration = getConfiguration(hFilePath);
+    DataTieringType dataTieringType = getDataTieringType(configuration);
+    return !dataTieringType.equals(DataTieringType.NONE);
+  }
+
+  public boolean isHotData(BlockCacheKey key) throws DataTieringException {
+    Path hFilePath = key.getFilePath();
+    if (hFilePath == null) {
+      throw new DataTieringException("BlockCacheKey Doesn't Contain HFile 
Path");
+    }
+    return isHotData(hFilePath);
+  }
+
+  public boolean isHotData(Path hFilePath) throws DataTieringException {
+    Configuration configuration = getConfiguration(hFilePath);
+    DataTieringType dataTieringType = getDataTieringType(configuration);
+
+    if (dataTieringType.equals(DataTieringType.TIME_RANGE)) {
+      long hotDataAge = getDataTieringHotDataAge(configuration);
+
+      HStoreFile hStoreFile = getHStoreFile(hFilePath);
+      if (hStoreFile == null) {
+        throw new DataTieringException(

Review Comment:
   Rather than throwing exception, maybe just return false? I wonder if it 
would be possible that a compaction completed and moved the given file away 
just after we entered this method.



##########
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/DataTieringManager.java:
##########
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.regionserver;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.OptionalLong;
+import java.util.Set;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.io.hfile.BlockCacheKey;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
[email protected]
+public class DataTieringManager {
+  private static final Logger LOG = 
LoggerFactory.getLogger(DataTieringManager.class);
+  public static final String DATATIERING_KEY = "hbase.hstore.datatiering.type";
+  public static final String DATATIERING_HOT_DATA_AGE_KEY =
+    "hbase.hstore.datatiering.hot.age.millis";
+  public static final DataTieringType DEFAULT_DATATIERING = 
DataTieringType.NONE;
+  public static final long DEFAULT_DATATIERING_HOT_DATA_AGE = 7 * 24 * 60 * 60 
* 1000; // 7 Days
+  private static DataTieringManager instance;
+  private final Map<String, HRegion> onlineRegions;
+
+  private DataTieringManager(Map<String, HRegion> onlineRegions) {
+    this.onlineRegions = onlineRegions;
+  }
+
+  public static synchronized void instantiate(Map<String, HRegion> 
onlineRegions) {
+    if (instance == null) {
+      instance = new DataTieringManager(onlineRegions);
+      LOG.info("DataTieringManager instantiated successfully.");
+    } else {
+      LOG.warn("DataTieringManager is already instantiated.");
+    }
+  }
+
+  public static synchronized DataTieringManager getInstance() {
+    if (instance == null) {
+      throw new IllegalStateException(
+        "DataTieringManager has not been instantiated. Call instantiate() 
first.");
+    }
+    return instance;
+  }
+
+  public boolean isDataTieringEnabled(BlockCacheKey key) throws 
DataTieringException {
+    Path hFilePath = key.getFilePath();
+    if (hFilePath == null) {
+      throw new DataTieringException("BlockCacheKey Doesn't Contain HFile 
Path");
+    }
+    return isDataTieringEnabled(hFilePath);
+  }
+
+  public boolean isDataTieringEnabled(Path hFilePath) throws 
DataTieringException {
+    Configuration configuration = getConfiguration(hFilePath);
+    DataTieringType dataTieringType = getDataTieringType(configuration);
+    return !dataTieringType.equals(DataTieringType.NONE);
+  }
+
+  public boolean isHotData(BlockCacheKey key) throws DataTieringException {
+    Path hFilePath = key.getFilePath();
+    if (hFilePath == null) {
+      throw new DataTieringException("BlockCacheKey Doesn't Contain HFile 
Path");
+    }
+    return isHotData(hFilePath);
+  }
+
+  public boolean isHotData(Path hFilePath) throws DataTieringException {
+    Configuration configuration = getConfiguration(hFilePath);
+    DataTieringType dataTieringType = getDataTieringType(configuration);
+
+    if (dataTieringType.equals(DataTieringType.TIME_RANGE)) {
+      long hotDataAge = getDataTieringHotDataAge(configuration);
+
+      HStoreFile hStoreFile = getHStoreFile(hFilePath);
+      if (hStoreFile == null) {
+        throw new DataTieringException(
+          "HStoreFile corresponding to " + hFilePath + " doesn't exist");
+      }
+      OptionalLong maxTimestamp = hStoreFile.getMaximumTimestamp();
+      if (!maxTimestamp.isPresent()) {
+        throw new DataTieringException("Maximum timestamp not present for " + 
hFilePath);
+      }
+
+      long currentTimestamp = 
EnvironmentEdgeManager.getDelegate().currentTime();
+      long diff = currentTimestamp - maxTimestamp.getAsLong();
+      return diff <= hotDataAge;
+    }
+    return false;

Review Comment:
   Shouldn't we return "true" by default? I.e., if not using 
DataTieringType.TIME_RANGE, this should consider all data as hot and let the 
LFU logic decide on the eviction right?



##########
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/DataTieringManager.java:
##########
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.regionserver;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.OptionalLong;
+import java.util.Set;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.io.hfile.BlockCacheKey;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
[email protected]
+public class DataTieringManager {
+  private static final Logger LOG = 
LoggerFactory.getLogger(DataTieringManager.class);
+  public static final String DATATIERING_KEY = "hbase.hstore.datatiering.type";
+  public static final String DATATIERING_HOT_DATA_AGE_KEY =
+    "hbase.hstore.datatiering.hot.age.millis";
+  public static final DataTieringType DEFAULT_DATATIERING = 
DataTieringType.NONE;
+  public static final long DEFAULT_DATATIERING_HOT_DATA_AGE = 7 * 24 * 60 * 60 
* 1000; // 7 Days
+  private static DataTieringManager instance;
+  private final Map<String, HRegion> onlineRegions;
+
+  private DataTieringManager(Map<String, HRegion> onlineRegions) {
+    this.onlineRegions = onlineRegions;
+  }
+
+  public static synchronized void instantiate(Map<String, HRegion> 
onlineRegions) {
+    if (instance == null) {
+      instance = new DataTieringManager(onlineRegions);
+      LOG.info("DataTieringManager instantiated successfully.");
+    } else {
+      LOG.warn("DataTieringManager is already instantiated.");
+    }
+  }
+
+  public static synchronized DataTieringManager getInstance() {
+    if (instance == null) {
+      throw new IllegalStateException(
+        "DataTieringManager has not been instantiated. Call instantiate() 
first.");
+    }
+    return instance;
+  }
+
+  public boolean isDataTieringEnabled(BlockCacheKey key) throws 
DataTieringException {
+    Path hFilePath = key.getFilePath();
+    if (hFilePath == null) {
+      throw new DataTieringException("BlockCacheKey Doesn't Contain HFile 
Path");
+    }
+    return isDataTieringEnabled(hFilePath);
+  }
+
+  public boolean isDataTieringEnabled(Path hFilePath) throws 
DataTieringException {
+    Configuration configuration = getConfiguration(hFilePath);
+    DataTieringType dataTieringType = getDataTieringType(configuration);
+    return !dataTieringType.equals(DataTieringType.NONE);
+  }
+
+  public boolean isHotData(BlockCacheKey key) throws DataTieringException {
+    Path hFilePath = key.getFilePath();
+    if (hFilePath == null) {
+      throw new DataTieringException("BlockCacheKey Doesn't Contain HFile 
Path");
+    }
+    return isHotData(hFilePath);
+  }
+
+  public boolean isHotData(Path hFilePath) throws DataTieringException {
+    Configuration configuration = getConfiguration(hFilePath);
+    DataTieringType dataTieringType = getDataTieringType(configuration);
+
+    if (dataTieringType.equals(DataTieringType.TIME_RANGE)) {
+      long hotDataAge = getDataTieringHotDataAge(configuration);
+
+      HStoreFile hStoreFile = getHStoreFile(hFilePath);
+      if (hStoreFile == null) {
+        throw new DataTieringException(
+          "HStoreFile corresponding to " + hFilePath + " doesn't exist");
+      }
+      OptionalLong maxTimestamp = hStoreFile.getMaximumTimestamp();
+      if (!maxTimestamp.isPresent()) {
+        throw new DataTieringException("Maximum timestamp not present for " + 
hFilePath);

Review Comment:
   This is delegating the decision on how to treat the block priority to the 
upper layer, so we should document that in this method javadoc.



##########
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDataTieringManager.java:
##########
@@ -0,0 +1,378 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.regionserver;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseTestingUtil;
+import org.apache.hadoop.hbase.KeyValue;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor;
+import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
+import org.apache.hadoop.hbase.client.RegionInfo;
+import org.apache.hadoop.hbase.client.RegionInfoBuilder;
+import org.apache.hadoop.hbase.client.TableDescriptor;
+import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
+import org.apache.hadoop.hbase.fs.HFileSystem;
+import org.apache.hadoop.hbase.io.hfile.BlockCache;
+import org.apache.hadoop.hbase.io.hfile.BlockCacheFactory;
+import org.apache.hadoop.hbase.io.hfile.BlockCacheKey;
+import org.apache.hadoop.hbase.io.hfile.BlockType;
+import org.apache.hadoop.hbase.io.hfile.CacheConfig;
+import org.apache.hadoop.hbase.io.hfile.HFileContextBuilder;
+import org.apache.hadoop.hbase.testclassification.RegionServerTests;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.CommonFSUtils;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+/**
+ * This class is used to test the functionality of the DataTieringManager.
+ *
+ * The mock online regions are stored in {@link 
TestDataTieringManager#testOnlineRegions}.
+ * For all tests, the setup of {@link 
TestDataTieringManager#testOnlineRegions} occurs only once.
+ * Please refer to {@link TestDataTieringManager#setupOnlineRegions()} for the 
structure.
+ * Additionally, a list of all store files is maintained in {@link 
TestDataTieringManager#hStoreFiles}.
+ * The characteristics of these store files are listed below:
+ * ## HStoreFile Information
+ *
+ * | HStoreFile       | Region             | Store               | DataTiering 
          | isHot |
+ * 
|------------------|--------------------|---------------------|-----------------------|-------|
+ * | hStoreFile0      | region1            | hStore11            | TIME_RANGE  
          | true  |
+ * | hStoreFile1      | region1            | hStore12            | NONE        
          | false |
+ * | hStoreFile2      | region2            | hStore21            | TIME_RANGE  
          | true  |
+ * | hStoreFile3      | region2            | hStore22            | TIME_RANGE  
          | false |
+ */
+
+@Category({ RegionServerTests.class, SmallTests.class })
+public class TestDataTieringManager {
+
+  @ClassRule
+  public static final HBaseClassTestRule CLASS_RULE =
+    HBaseClassTestRule.forClass(TestDataTieringManager.class);
+
+  private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();
+  private static Configuration defaultConf;
+  private static FileSystem fs;
+  private static CacheConfig cacheConf;
+  private static Path testDir;
+  private static Map<String, HRegion> testOnlineRegions;
+
+  private static DataTieringManager dataTieringManager;
+  private static List<HStoreFile> hStoreFiles;
+
+  @BeforeClass
+  public static void setupBeforeClass() throws Exception {
+    testDir = 
TEST_UTIL.getDataTestDir(TestDataTieringManager.class.getSimpleName());
+    defaultConf = TEST_UTIL.getConfiguration();
+    fs = HFileSystem.get(defaultConf);
+    BlockCache blockCache = BlockCacheFactory.createBlockCache(defaultConf);
+    cacheConf = new CacheConfig(defaultConf, blockCache);
+    setupOnlineRegions();
+    DataTieringManager.instantiate(testOnlineRegions);
+    dataTieringManager = DataTieringManager.getInstance();
+  }
+
+  @FunctionalInterface
+  interface DataTieringMethodCallerWithPath {
+    boolean call(DataTieringManager manager, Path path) throws 
DataTieringException;
+  }
+
+  @FunctionalInterface
+  interface DataTieringMethodCallerWithKey {
+    boolean call(DataTieringManager manager, BlockCacheKey key) throws 
DataTieringException;
+  }
+
+  @Test
+  public void testDataTieringEnabledWithKey() {
+    DataTieringMethodCallerWithKey methodCallerWithKey = 
DataTieringManager::isDataTieringEnabled;
+
+    // Test with valid key
+    BlockCacheKey key = new BlockCacheKey(hStoreFiles.get(0).getPath(), 0, 
true, BlockType.DATA);
+    testDataTieringMethodWithKeyNoException(methodCallerWithKey, key, true);
+
+    // Test with another valid key
+    key = new BlockCacheKey(hStoreFiles.get(1).getPath(), 0, true, 
BlockType.DATA);
+    testDataTieringMethodWithKeyNoException(methodCallerWithKey, key, false);
+
+    // Test with valid key with no HFile Path
+    key = new BlockCacheKey(hStoreFiles.get(0).getPath().getName(), 0);
+    testDataTieringMethodWithKeyExpectingException(methodCallerWithKey, key,
+      new DataTieringException("BlockCacheKey Doesn't Contain HFile Path"));
+  }
+
+  @Test
+  public void testDataTieringEnabledWithPath() {
+    DataTieringMethodCallerWithPath methodCallerWithPath = 
DataTieringManager::isDataTieringEnabled;
+
+    // Test with valid path
+    Path hFilePath = hStoreFiles.get(1).getPath();
+    testDataTieringMethodWithPathNoException(methodCallerWithPath, hFilePath, 
false);
+
+    // Test with another valid path
+    hFilePath = hStoreFiles.get(3).getPath();
+    testDataTieringMethodWithPathNoException(methodCallerWithPath, hFilePath, 
true);
+
+    // Test with an incorrect path
+    hFilePath = new Path("incorrectPath");
+    testDataTieringMethodWithPathExpectingException(methodCallerWithPath, 
hFilePath,
+      new DataTieringException("Incorrect HFile Path: " + hFilePath));
+
+    // Test with a non-existing HRegion path
+    Path basePath = 
hStoreFiles.get(0).getPath().getParent().getParent().getParent();
+    hFilePath = new Path(basePath, "incorrectRegion/cf1/filename");
+    testDataTieringMethodWithPathExpectingException(methodCallerWithPath, 
hFilePath,
+      new DataTieringException("HRegion corresponding to " + hFilePath + " 
doesn't exist"));
+
+    // Test with a non-existing HStore path
+    basePath = hStoreFiles.get(0).getPath().getParent().getParent();
+    hFilePath = new Path(basePath, "incorrectCf/filename");
+    testDataTieringMethodWithPathExpectingException(methodCallerWithPath, 
hFilePath,
+      new DataTieringException("HStore corresponding to " + hFilePath + " 
doesn't exist"));
+  }
+
+  @Test
+  public void testHotDataWithKey() {
+    DataTieringMethodCallerWithKey methodCallerWithKey = 
DataTieringManager::isHotData;
+
+    // Test with valid key
+    BlockCacheKey key = new BlockCacheKey(hStoreFiles.get(0).getPath(), 0, 
true, BlockType.DATA);
+    testDataTieringMethodWithKeyNoException(methodCallerWithKey, key, true);
+
+    // Test with another valid key
+    key = new BlockCacheKey(hStoreFiles.get(1).getPath(), 0, true, 
BlockType.DATA);
+    testDataTieringMethodWithKeyNoException(methodCallerWithKey, key, false);
+  }
+
+  @Test
+  public void testHotDataWithPath() {
+    DataTieringMethodCallerWithPath methodCallerWithPath = 
DataTieringManager::isHotData;
+
+    // Test with valid path
+    Path hFilePath = hStoreFiles.get(2).getPath();
+    testDataTieringMethodWithPathNoException(methodCallerWithPath, hFilePath, 
true);
+
+    // Test with another valid path
+    hFilePath = hStoreFiles.get(3).getPath();
+    testDataTieringMethodWithPathNoException(methodCallerWithPath, hFilePath, 
false);
+
+    // Test with an incorrect filename
+    hFilePath = new Path(hStoreFiles.get(0).getPath().getParent(), 
"incorrectFileName");
+    testDataTieringMethodWithPathExpectingException(methodCallerWithPath, 
hFilePath,
+      new DataTieringException("HStoreFile corresponding to " + hFilePath + " 
doesn't exist"));
+  }
+
+  private void testDataTieringMethodWithPath(DataTieringMethodCallerWithPath 
caller, Path path,
+    boolean expectedResult, DataTieringException exception) {
+    try {
+      boolean value = caller.call(dataTieringManager, path);
+      if (exception != null) {
+        fail("Expected DataTieringException to be thrown");
+      }
+      assertEquals(value, expectedResult);
+    } catch (DataTieringException e) {
+      if (exception == null) {
+        fail("Unexpected DataTieringException: " + e.getMessage());
+      }
+      assertEquals(exception.getMessage(), e.getMessage());
+    }
+  }
+
+  private void testDataTieringMethodWithKey(DataTieringMethodCallerWithKey 
caller,
+    BlockCacheKey key, boolean expectedResult, DataTieringException exception) 
{
+    try {
+      boolean value = caller.call(dataTieringManager, key);
+      if (exception != null) {
+        fail("Expected DataTieringException to be thrown");
+      }
+      assertEquals(value, expectedResult);
+    } catch (DataTieringException e) {
+      if (exception == null) {
+        fail("Unexpected DataTieringException: " + e.getMessage());
+      }
+      assertEquals(exception.getMessage(), e.getMessage());
+    }
+  }
+
+  private void testDataTieringMethodWithPathExpectingException(
+    DataTieringMethodCallerWithPath caller, Path path, DataTieringException 
exception) {
+    testDataTieringMethodWithPath(caller, path, false, exception);
+  }
+
+  private void 
testDataTieringMethodWithPathNoException(DataTieringMethodCallerWithPath caller,
+    Path path, boolean expectedResult) {
+    testDataTieringMethodWithPath(caller, path, expectedResult, null);
+  }
+
+  private void 
testDataTieringMethodWithKeyExpectingException(DataTieringMethodCallerWithKey 
caller,
+    BlockCacheKey key, DataTieringException exception) {
+    testDataTieringMethodWithKey(caller, key, false, exception);
+  }
+
+  private void 
testDataTieringMethodWithKeyNoException(DataTieringMethodCallerWithKey caller,
+    BlockCacheKey key, boolean expectedResult) {
+    testDataTieringMethodWithKey(caller, key, expectedResult, null);
+  }
+
+  @Test
+  public void testColdDataFiles() {
+    Set<BlockCacheKey> allCachedBlocks = new HashSet<>();
+    for (HStoreFile file : hStoreFiles) {
+      allCachedBlocks.add(new BlockCacheKey(file.getPath(), 0, true, 
BlockType.DATA));
+    }
+
+    try {
+      Set<String> coldFilePaths = 
dataTieringManager.getColdDataFiles(allCachedBlocks);
+      assertEquals(1, coldFilePaths.size());

Review Comment:
   We should explain better why we only get 1 here, even though we say there 
are two non-hot files in the javadoc header. 
   
   Also, shouldn't we assert on the exact cold file, just to make sure our 
logic does mark the file we know is cold?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to