Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ public final class TagType {
// String based tag type used in replication
public static final byte STRING_VIS_TAG_TYPE = (byte) 7;
public static final byte TTL_TAG_TYPE = (byte) 8;
// tag with the custom cell tiering value for the row
public static final byte CELL_VALUE_TIERING_TAG_TYPE = (byte) 9;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.conf.ConfigurationObserver;
import org.apache.hadoop.hbase.regionserver.TimeRangeTracker;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.yetus.audience.InterfaceAudience;

Expand Down Expand Up @@ -214,13 +213,13 @@ default Optional<Boolean> shouldCacheFile(HFileInfo hFileInfo, Configuration con
* not be overridden by all implementing classes. In such cases, the returned Optional will be
* empty. For subclasses implementing this logic, the returned Optional would contain the boolean
* value reflecting if the passed block should indeed be cached.
* @param key The key representing the block to check if it should be cached.
* @param timeRangeTracker the time range tracker containing the timestamps
* @param conf The configuration object to use for determining caching behavior.
* @param key The key representing the block to check if it should be cached.
* @param maxTimeStamp The maximum timestamp for the block to check if it should be cached.
* @param conf The configuration object to use for determining caching behavior.
* @return An empty Optional if this method is not supported; otherwise, the returned Optional
* contains the boolean value indicating if the block should be cached.
*/
default Optional<Boolean> shouldCacheBlock(BlockCacheKey key, TimeRangeTracker timeRangeTracker,
default Optional<Boolean> shouldCacheBlock(BlockCacheKey key, long maxTimeStamp,
Configuration conf) {
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ public boolean shouldCacheBlockOnRead(BlockCategory category) {
public boolean shouldCacheBlockOnRead(BlockCategory category, HFileInfo hFileInfo,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this branch based on master? I didn't find this function on the master branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is based out of the HBASE-28463 branch, which was last rebased with master around 23/06/2025. The reason this method is not in master branch is because it was added on this HBASE-28463 branch by HBASE-28467.

Configuration conf) {
Optional<Boolean> cacheFileBlock = Optional.of(true);
if (getBlockCache().isPresent()) {
// For DATA blocks only, if BuckeCache is in use, we don't need to cache block again
if (getBlockCache().isPresent() && category.equals(BlockCategory.DATA)) {
Optional<Boolean> result = getBlockCache().get().shouldCacheFile(hFileInfo, conf);
if (result.isPresent()) {
cacheFileBlock = result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.io.HeapSize;
import org.apache.hadoop.hbase.io.hfile.bucket.BucketCache;
import org.apache.hadoop.hbase.regionserver.TimeRangeTracker;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
Expand Down Expand Up @@ -494,10 +493,10 @@ public Optional<Boolean> shouldCacheFile(HFileInfo hFileInfo, Configuration conf
}

@Override
public Optional<Boolean> shouldCacheBlock(BlockCacheKey key, TimeRangeTracker timeRangeTracker,
public Optional<Boolean> shouldCacheBlock(BlockCacheKey key, long maxTimeStamp,
Configuration conf) {
return combineCacheResults(l1Cache.shouldCacheBlock(key, timeRangeTracker, conf),
l2Cache.shouldCacheBlock(key, timeRangeTracker, conf));
return combineCacheResults(l1Cache.shouldCacheBlock(key, maxTimeStamp, conf),
l2Cache.shouldCacheBlock(key, maxTimeStamp, conf));
}

private Optional<Boolean> combineCacheResults(Optional<Boolean> result1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.apache.hadoop.hbase.ipc.RpcServer;
import org.apache.hadoop.hbase.regionserver.CellSink;
import org.apache.hadoop.hbase.regionserver.ShipperListener;
import org.apache.hadoop.hbase.regionserver.TimeRangeTracker;
import org.apache.hadoop.hbase.util.BloomFilterWriter;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.FSUtils;
Expand Down Expand Up @@ -217,6 +218,12 @@ public interface Writer extends Closeable, CellSink, ShipperListener {
*/
void appendTrackedTimestampsToMetadata() throws IOException;

/**
* Add Custom cell timestamp to Metadata
*/
public void appendCustomCellTimestampsToMetadata(TimeRangeTracker timeRangeTracker)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why do we need TimeRangeTracker instead of max timestamp here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need min and max to calculate compaction boundaries properly, as we can have files where the max TS is higher than the threshold, but the min is lower. In such cases, the tiered compaction should know it has to split the file.

throws IOException;

/** Returns the path to this {@link HFile} */
Path getPath();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,7 @@ public HFileBlock readBlock(long dataBlockOffset, long onDiskBlockSize, final bo
HFileBlock unpackedNoChecksum = BlockCacheUtil.getBlockForCaching(cacheConf, unpacked);
// Cache the block if necessary
cacheConf.getBlockCache().ifPresent(cache -> {
if (cacheBlock && cacheConf.shouldCacheBlockOnRead(category)) {
if (cacheBlock && cacheOnRead) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we change from cacheConf.shouldCacheBlockOnRead(category) to cacheOnRead = cacheConf.shouldCacheBlockOnRead(category, getHFileInfo(), conf); , is it right about only caching DATA block?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it right about only caching DATA block?

We are not caching only DATA blocks here. We are actually applying the DataTieringManager for DATA blocks only. If the block type isn't DATA, we just apply the shouldCacheBlockOnRead(BlockCategory category) logic (as we call it at line #292).

// Using the wait on cache during compaction and prefetching.
cache.cacheBlock(cacheKey,
cacheCompressed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.hadoop.hbase.io.hfile;

import static org.apache.hadoop.hbase.io.hfile.BlockCompressedSizePredicator.MAX_BLOCK_SIZE_UNCOMPRESSED;
import static org.apache.hadoop.hbase.regionserver.CustomTieringMultiFileWriter.CUSTOM_TIERING_TIME_RANGE;
import static org.apache.hadoop.hbase.regionserver.HStoreFile.EARLIEST_PUT_TS;
import static org.apache.hadoop.hbase.regionserver.HStoreFile.TIMERANGE_KEY;

Expand All @@ -29,6 +30,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
Expand Down Expand Up @@ -127,6 +129,12 @@ public class HFileWriterImpl implements HFile.Writer {
/** Cache configuration for caching data on write. */
protected final CacheConfig cacheConf;

public void setTimeRangeTrackerForTiering(Supplier<TimeRangeTracker> timeRangeTrackerForTiering) {
this.timeRangeTrackerForTiering = timeRangeTrackerForTiering;
}

private Supplier<TimeRangeTracker> timeRangeTrackerForTiering;

/**
* Name for this object used when logging or in toString. Is either the result of a toString on
* stream or else name of passed file Path.
Expand Down Expand Up @@ -186,7 +194,9 @@ public HFileWriterImpl(final Configuration conf, CacheConfig cacheConf, Path pat
this.path = path;
this.name = path != null ? path.getName() : outputStream.toString();
this.hFileContext = fileContext;
// TODO: Move this back to upper layer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit : should we delete this TODO ? or should we have new JIRA for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, added this back then because I wasn't happy with adding time range tracking logic into HFileWriterImpl (originally, it was in StoreFileWriter). This was introduced here by HBASE-28469, IIRC, as a mean to track dates also when flushing, rather than at compaction only.

I think we should keep the TODO and revisit this code later on a separate JIRA. We still have to work on how to track custom tiering value on flushes, maybe that would be a good time to solve this TODO as well.

this.timeRangeTracker = TimeRangeTracker.create(TimeRangeTracker.Type.NON_SYNC);
this.timeRangeTrackerForTiering = () -> this.timeRangeTracker;
DataBlockEncoding encoding = hFileContext.getDataBlockEncoding();
if (encoding != DataBlockEncoding.NONE) {
this.blockEncoder = new HFileDataBlockEncoderImpl(encoding);
Expand Down Expand Up @@ -588,7 +598,8 @@ private BlockCacheKey buildCacheBlockKey(long offset, BlockType blockType) {
}

private boolean shouldCacheBlock(BlockCache cache, BlockCacheKey key) {
Optional<Boolean> result = cache.shouldCacheBlock(key, timeRangeTracker, conf);
Optional<Boolean> result =
cache.shouldCacheBlock(key, timeRangeTrackerForTiering.get().getMax(), conf);
return result.orElse(true);
}

Expand Down Expand Up @@ -899,12 +910,19 @@ public void appendTrackedTimestampsToMetadata() throws IOException {
appendFileInfo(EARLIEST_PUT_TS, Bytes.toBytes(earliestPutTs));
}

public void appendCustomCellTimestampsToMetadata(TimeRangeTracker timeRangeTracker)
throws IOException {
// TODO: The StoreFileReader always converts the byte[] to TimeRange
// via TimeRangeTracker, so we should write the serialization data of TimeRange directly.
Comment on lines +915 to +916
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: new JIRA need?

Copy link
Contributor Author

@wchevreuil wchevreuil Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole code (TODO comments included) came together from StoreFileWriter with the changes of HBASE-28469.
I think this TODO refers to a nice to have that would easy debugging. I guess a separate, minor priority JIRA.

appendFileInfo(CUSTOM_TIERING_TIME_RANGE, TimeRangeTracker.toByteArray(timeRangeTracker));
}

/**
* Record the earliest Put timestamp. If the timeRangeTracker is not set, update TimeRangeTracker
* to include the timestamp of this key
*/
private void trackTimestamps(final ExtendedCell cell) {
if (Cell.Type.Put == cell.getType()) {
if (KeyValue.Type.Put == KeyValue.Type.codeToType(cell.getTypeByte())) {
earliestPutTs = Math.min(earliestPutTs, cell.getTimestamp());
}
timeRangeTracker.includeTimestamp(cell);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
import org.apache.hadoop.hbase.regionserver.DataTieringManager;
import org.apache.hadoop.hbase.regionserver.HRegion;
import org.apache.hadoop.hbase.regionserver.StoreFileInfo;
import org.apache.hadoop.hbase.regionserver.TimeRangeTracker;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.IdReadWriteLock;
Expand Down Expand Up @@ -1195,8 +1194,9 @@ void freeSpace(final String why) {
}
}

if (bytesFreed < bytesToFreeWithExtra &&
coldFiles != null && coldFiles.containsKey(bucketEntryWithKey.getKey().getHfileName())
if (
bytesFreed < bytesToFreeWithExtra && coldFiles != null
&& coldFiles.containsKey(bucketEntryWithKey.getKey().getHfileName())
) {
int freedBlockSize = bucketEntryWithKey.getValue().getLength();
if (evictBlockIfNoRpcReferenced(bucketEntryWithKey.getKey())) {
Expand Down Expand Up @@ -2458,10 +2458,10 @@ public Optional<Boolean> shouldCacheFile(HFileInfo hFileInfo, Configuration conf
}

@Override
public Optional<Boolean> shouldCacheBlock(BlockCacheKey key, TimeRangeTracker timeRangeTracker,
public Optional<Boolean> shouldCacheBlock(BlockCacheKey key, long maxTimestamp,
Configuration conf) {
DataTieringManager dataTieringManager = DataTieringManager.getInstance();
if (dataTieringManager != null && !dataTieringManager.isHotData(timeRangeTracker, conf)) {
if (dataTieringManager != null && !dataTieringManager.isHotData(maxTimestamp, conf)) {
LOG.debug("Data tiering is enabled for file: '{}' and it is not hot data",
key.getHfileName());
return Optional.of(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.hadoop.hbase.procedure2.ProcedureStateSerializer;
import org.apache.hadoop.hbase.procedure2.ProcedureSuspendedException;
import org.apache.hadoop.hbase.procedure2.ProcedureUtil;
import org.apache.hadoop.hbase.regionserver.compactions.CustomCellTieredUtils;
import org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTrackerFactory;
import org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTrackerValidationUtils;
import org.apache.hadoop.hbase.rsgroup.RSGroupInfo;
Expand Down Expand Up @@ -314,6 +315,8 @@ private boolean prepareCreate(final MasterProcedureEnv env) throws IOException {
StoreFileTrackerValidationUtils.checkForCreateTable(env.getMasterConfiguration(),
tableDescriptor);

CustomCellTieredUtils.checkForModifyTable(tableDescriptor);

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.apache.hadoop.hbase.master.MasterCoprocessorHost;
import org.apache.hadoop.hbase.master.zksyncer.MetaLocationSyncer;
import org.apache.hadoop.hbase.procedure2.ProcedureStateSerializer;
import org.apache.hadoop.hbase.regionserver.compactions.CustomCellTieredUtils;
import org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTrackerValidationUtils;
import org.apache.hadoop.hbase.rsgroup.RSGroupInfo;
import org.apache.hadoop.hbase.util.Bytes;
Expand Down Expand Up @@ -420,6 +421,7 @@ private void prepareModify(final MasterProcedureEnv env) throws IOException {
// check for store file tracker configurations
StoreFileTrackerValidationUtils.checkForModifyTable(env.getMasterConfiguration(),
unmodifiedTableDescriptor, modifiedTableDescriptor, !isTableEnabled(env));
CustomCellTieredUtils.checkForModifyTable(modifiedTableDescriptor);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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.apache.hadoop.hbase.regionserver.HStoreFile.TIMERANGE_KEY;

import java.io.IOException;
import java.util.OptionalLong;
import org.apache.hadoop.hbase.io.hfile.HFileInfo;
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@InterfaceAudience.Private
public class CellTSTiering implements DataTiering {
private static final Logger LOG = LoggerFactory.getLogger(CellTSTiering.class);

public long getTimestamp(HStoreFile hStoreFile) {
OptionalLong maxTimestamp = hStoreFile.getMaximumTimestamp();
if (!maxTimestamp.isPresent()) {
LOG.debug("Maximum timestamp not present for {}", hStoreFile.getPath());
return Long.MAX_VALUE;
}
return maxTimestamp.getAsLong();
}

public long getTimestamp(HFileInfo hFileInfo) {
try {
byte[] hFileTimeRange = hFileInfo.get(TIMERANGE_KEY);
if (hFileTimeRange == null) {
LOG.debug("Timestamp information not found for file: {}",
hFileInfo.getHFileContext().getHFileName());
return Long.MAX_VALUE;
}
return TimeRangeTracker.parseFrom(hFileTimeRange).getMax();
} catch (IOException e) {
LOG.error("Error occurred while reading the timestamp metadata of file: {}",
hFileInfo.getHFileContext().getHFileName(), e);
return Long.MAX_VALUE;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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.apache.hadoop.hbase.regionserver.DefaultStoreEngine.DEFAULT_COMPACTION_POLICY_CLASS_KEY;

import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.CellComparator;
import org.apache.hadoop.hbase.CompoundConfiguration;
import org.apache.hadoop.hbase.regionserver.compactions.CustomDateTieredCompactionPolicy;
import org.apache.hadoop.hbase.regionserver.compactions.CustomTieredCompactor;
import org.apache.yetus.audience.InterfaceAudience;

/**
* Extension of {@link DateTieredStoreEngine} that uses a pluggable value provider for extracting
* the value to be used for comparison in this tiered compaction. Differently from the existing Date
* Tiered Compaction, this doesn't yield multiple tiers or files, but rather provides two tiers
* based on a configurable “cut-off” age. All rows with the cell tiering value older than this
* “cut-off” age would be placed together in an “old” tier, whilst younger rows would go to a
* separate, “young” tier file.
*/
@InterfaceAudience.Private
public class CustomTieredStoreEngine extends DateTieredStoreEngine {

@Override
protected void createComponents(Configuration conf, HStore store, CellComparator kvComparator)
throws IOException {
CompoundConfiguration config = new CompoundConfiguration();
config.add(conf);
config.add(store.conf);
config.set(DEFAULT_COMPACTION_POLICY_CLASS_KEY,
CustomDateTieredCompactionPolicy.class.getName());
createCompactionPolicy(config, store);
this.storeFileManager = new DefaultStoreFileManager(kvComparator,
StoreFileComparators.SEQ_ID_MAX_TIMESTAMP, config, compactionPolicy.getConf());
this.storeFlusher = new DefaultStoreFlusher(config, store);
this.compactor = new CustomTieredCompactor(config, store);
}

}
Loading