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
;
24 import java
.util
.NavigableMap
;
25 import java
.util
.TreeMap
;
27 import org
.apache
.hadoop
.hbase
.Cell
;
28 import org
.apache
.yetus
.audience
.InterfaceAudience
;
31 * class for cell sink that separates the provided cells into multiple files for date tiered
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
;
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
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
;
58 public void append(Cell cell
) throws IOException
{
59 Map
.Entry
<Long
, StoreFileWriter
> entry
= lowerBoundary2Writer
.floorEntry(cell
.getTimestamp());
60 StoreFileWriter writer
= entry
.getValue();
62 String lowerBoundaryStoragePolicy
= lowerBoundariesPolicies
.get(entry
.getKey());
63 if (lowerBoundaryStoragePolicy
!= null) {
64 writer
= writerFactory
.createWriterWithStoragePolicy(lowerBoundaryStoragePolicy
);
66 writer
= writerFactory
.createWriter();
68 lowerBoundary2Writer
.put(entry
.getKey(), writer
);
74 public Collection
<StoreFileWriter
> writers() {
75 return lowerBoundary2Writer
.values();
79 protected void preCommitWriters() throws IOException
{
83 for (StoreFileWriter writer
: lowerBoundary2Writer
.values()) {
88 // we haven't written out any data, create an empty file to retain metadata
89 lowerBoundary2Writer
.put(lowerBoundary2Writer
.firstKey(), writerFactory
.createWriter());