3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 package org
.apache
.hadoop
.hbase
.regionserver
;
21 import java
.util
.Collections
;
22 import java
.util
.List
;
23 import org
.apache
.hadoop
.hbase
.CellComparator
;
24 import org
.apache
.hadoop
.hbase
.util
.ClassSize
;
25 import org
.apache
.yetus
.audience
.InterfaceAudience
;
28 * ImmutableSegment is an abstract class that extends the API supported by a {@link Segment},
29 * and is not needed for a {@link MutableSegment}.
31 @InterfaceAudience.Private
32 public abstract class ImmutableSegment
extends Segment
{
34 public static final long DEEP_OVERHEAD
= Segment
.DEEP_OVERHEAD
+ ClassSize
.NON_SYNC_TIMERANGE_TRACKER
;
36 // each sub-type of immutable segment knows whether it is flat or not
37 protected abstract boolean canBeFlattened();
39 public int getNumUniqueKeys() {
40 return getCellSet().getNumUniqueKeys();
43 ///////////////////// CONSTRUCTORS /////////////////////
44 /**------------------------------------------------------------------------
45 * Empty C-tor to be used only for CompositeImmutableSegment
47 protected ImmutableSegment(CellComparator comparator
) {
48 super(comparator
, TimeRangeTracker
.create(TimeRangeTracker
.Type
.NON_SYNC
));
51 protected ImmutableSegment(CellComparator comparator
, List
<ImmutableSegment
> segments
) {
52 super(comparator
, segments
, TimeRangeTracker
.create(TimeRangeTracker
.Type
.NON_SYNC
));
55 /**------------------------------------------------------------------------
56 * C-tor to be used to build the derived classes
58 protected ImmutableSegment(CellSet cs
, CellComparator comparator
, MemStoreLAB memStoreLAB
) {
59 super(cs
, comparator
, memStoreLAB
, TimeRangeTracker
.create(TimeRangeTracker
.Type
.NON_SYNC
));
62 /**------------------------------------------------------------------------
63 * Copy C-tor to be used when new CSLMImmutableSegment (derived) is being built from a Mutable one.
64 * This C-tor should be used when active MutableSegment is pushed into the compaction
65 * pipeline and becomes an ImmutableSegment.
67 protected ImmutableSegment(Segment segment
) {
71 ///////////////////// PUBLIC METHODS /////////////////////
73 public int getNumOfSegments() {
77 public List
<Segment
> getAllSegments() {
78 return Collections
.singletonList(this);
82 public String
toString() {
83 String res
= super.toString();
84 res
+= "Num uniques "+getNumUniqueKeys()+"; ";
89 * We create a new {@link SnapshotSegmentScanner} to increase the reference count of
90 * {@link MemStoreLABImpl} used by this segment.
92 List
<KeyValueScanner
> getSnapshotScanners() {
93 return Collections
.singletonList(new SnapshotSegmentScanner(this));