HBASE-26286: Add support for specifying store file tracker when restoring or cloning...
[hbase.git] / hbase-server / src / main / java / org / apache / hadoop / hbase / regionserver / DateTieredMultiFileWriter.java
blob1e10eb2db2318785f7a903fabcad023f65a3ce2f
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.apache.hadoop.hbase.regionserver;
20 import java.io.IOException;
21 import java.util.Collection;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.NavigableMap;
25 import java.util.TreeMap;
27 import org.apache.hadoop.hbase.Cell;
28 import org.apache.yetus.audience.InterfaceAudience;
30 /**
31 * class for cell sink that separates the provided cells into multiple files for date tiered
32 * compaction.
34 @InterfaceAudience.Private
35 public class DateTieredMultiFileWriter extends AbstractMultiFileWriter {
37 private final NavigableMap<Long, StoreFileWriter> lowerBoundary2Writer = new TreeMap<>();
39 private final boolean needEmptyFile;
41 private final Map<Long, String> lowerBoundariesPolicies;
43 /**
44 * @param lowerBoundariesPolicies each window to storage policy map.
45 * @param needEmptyFile whether need to create an empty store file if we haven't written out
46 * anything.
48 public DateTieredMultiFileWriter(List<Long> lowerBoundaries,
49 Map<Long, String> lowerBoundariesPolicies, boolean needEmptyFile) {
50 for (Long lowerBoundary : lowerBoundaries) {
51 lowerBoundary2Writer.put(lowerBoundary, null);
53 this.needEmptyFile = needEmptyFile;
54 this.lowerBoundariesPolicies = lowerBoundariesPolicies;
57 @Override
58 public void append(Cell cell) throws IOException {
59 Map.Entry<Long, StoreFileWriter> entry = lowerBoundary2Writer.floorEntry(cell.getTimestamp());
60 StoreFileWriter writer = entry.getValue();
61 if (writer == null) {
62 String lowerBoundaryStoragePolicy = lowerBoundariesPolicies.get(entry.getKey());
63 if (lowerBoundaryStoragePolicy != null) {
64 writer = writerFactory.createWriterWithStoragePolicy(lowerBoundaryStoragePolicy);
65 } else {
66 writer = writerFactory.createWriter();
68 lowerBoundary2Writer.put(entry.getKey(), writer);
70 writer.append(cell);
73 @Override
74 public Collection<StoreFileWriter> writers() {
75 return lowerBoundary2Writer.values();
78 @Override
79 protected void preCommitWriters() throws IOException {
80 if (!needEmptyFile) {
81 return;
83 for (StoreFileWriter writer : lowerBoundary2Writer.values()) {
84 if (writer != null) {
85 return;
88 // we haven't written out any data, create an empty file to retain metadata
89 lowerBoundary2Writer.put(lowerBoundary2Writer.firstKey(), writerFactory.createWriter());