001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.regionserver;
019
020import static org.apache.hadoop.hbase.regionserver.HStoreFile.TIMERANGE_KEY;
021
022import java.io.IOException;
023import java.util.OptionalLong;
024import org.apache.hadoop.hbase.io.hfile.HFileInfo;
025import org.apache.yetus.audience.InterfaceAudience;
026import org.slf4j.Logger;
027import org.slf4j.LoggerFactory;
028
029@InterfaceAudience.Private
030public class CellTSTiering implements DataTiering {
031  private static final Logger LOG = LoggerFactory.getLogger(CellTSTiering.class);
032
033  public long getTimestamp(HStoreFile hStoreFile) {
034    OptionalLong maxTimestamp = hStoreFile.getMaximumTimestamp();
035    if (!maxTimestamp.isPresent()) {
036      LOG.debug("Maximum timestamp not present for {}", hStoreFile.getPath());
037      return Long.MAX_VALUE;
038    }
039    return maxTimestamp.getAsLong();
040  }
041
042  public long getTimestamp(HFileInfo hFileInfo) {
043    try {
044      byte[] hFileTimeRange = hFileInfo.get(TIMERANGE_KEY);
045      if (hFileTimeRange == null) {
046        LOG.debug("Timestamp information not found for file: {}",
047          hFileInfo.getHFileContext().getHFileName());
048        return Long.MAX_VALUE;
049      }
050      return TimeRangeTracker.parseFrom(hFileTimeRange).getMax();
051    } catch (IOException e) {
052      LOG.error("Error occurred while reading the timestamp metadata of file: {}",
053        hFileInfo.getHFileContext().getHFileName(), e);
054      return Long.MAX_VALUE;
055    }
056  }
057}