001/** 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019package org.apache.hadoop.hbase.regionserver; 020 021import java.util.Collections; 022import java.util.List; 023import org.apache.hadoop.hbase.CellComparator; 024import org.apache.hadoop.hbase.util.ClassSize; 025import org.apache.yetus.audience.InterfaceAudience; 026 027/** 028 * ImmutableSegment is an abstract class that extends the API supported by a {@link Segment}, 029 * and is not needed for a {@link MutableSegment}. 030 */ 031@InterfaceAudience.Private 032public abstract class ImmutableSegment extends Segment { 033 034 public static final long DEEP_OVERHEAD = Segment.DEEP_OVERHEAD + ClassSize.NON_SYNC_TIMERANGE_TRACKER; 035 036 // each sub-type of immutable segment knows whether it is flat or not 037 protected abstract boolean canBeFlattened(); 038 039 public int getNumUniqueKeys() { 040 return getCellSet().getNumUniqueKeys(); 041 } 042 043 ///////////////////// CONSTRUCTORS ///////////////////// 044 /**------------------------------------------------------------------------ 045 * Empty C-tor to be used only for CompositeImmutableSegment 046 */ 047 protected ImmutableSegment(CellComparator comparator) { 048 super(comparator, TimeRangeTracker.create(TimeRangeTracker.Type.NON_SYNC)); 049 } 050 051 protected ImmutableSegment(CellComparator comparator, List<ImmutableSegment> segments) { 052 super(comparator, segments, TimeRangeTracker.create(TimeRangeTracker.Type.NON_SYNC)); 053 } 054 055 /**------------------------------------------------------------------------ 056 * C-tor to be used to build the derived classes 057 */ 058 protected ImmutableSegment(CellSet cs, CellComparator comparator, MemStoreLAB memStoreLAB) { 059 super(cs, comparator, memStoreLAB, TimeRangeTracker.create(TimeRangeTracker.Type.NON_SYNC)); 060 } 061 062 /**------------------------------------------------------------------------ 063 * Copy C-tor to be used when new CSLMImmutableSegment (derived) is being built from a Mutable one. 064 * This C-tor should be used when active MutableSegment is pushed into the compaction 065 * pipeline and becomes an ImmutableSegment. 066 */ 067 protected ImmutableSegment(Segment segment) { 068 super(segment); 069 } 070 071 ///////////////////// PUBLIC METHODS ///////////////////// 072 073 public int getNumOfSegments() { 074 return 1; 075 } 076 077 public List<Segment> getAllSegments() { 078 return Collections.singletonList(this); 079 } 080 081 @Override 082 public String toString() { 083 String res = super.toString(); 084 res += "Num uniques "+getNumUniqueKeys()+"; "; 085 return res; 086 } 087 088 List<KeyValueScanner> getSnapshotScanners() { 089 return Collections.singletonList(new SnapshotSegmentScanner(this)); 090 } 091}