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 java.net.InetSocketAddress; 021import java.util.Collection; 022import java.util.function.Supplier; 023import org.apache.hadoop.fs.Path; 024import org.apache.hadoop.hbase.CellComparator; 025import org.apache.hadoop.hbase.TableName; 026import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor; 027import org.apache.hadoop.hbase.client.RegionInfo; 028import org.apache.hadoop.hbase.io.HeapSize; 029import org.apache.hadoop.hbase.io.crypto.Encryption; 030import org.apache.hadoop.hbase.io.hfile.CacheConfig; 031import org.apache.hadoop.hbase.util.ClassSize; 032import org.apache.yetus.audience.InterfaceAudience; 033 034/** 035 * This carries the immutable information and references on some of the meta data about the HStore. 036 * This meta data can be used across the HFileWriter/Readers and other HStore consumers without the 037 * need of passing around the complete store. 038 */ 039@InterfaceAudience.Private 040public final class StoreContext implements HeapSize { 041 public static final long FIXED_OVERHEAD = ClassSize.estimateBase(HStore.class, false); 042 043 private final int blockSize; 044 private final Encryption.Context encryptionContext; 045 private final CacheConfig cacheConf; 046 private final HRegionFileSystem regionFileSystem; 047 private final CellComparator comparator; 048 private final BloomType bloomFilterType; 049 private final Supplier<Collection<HStoreFile>> compactedFilesSupplier; 050 private final Supplier<InetSocketAddress[]> favoredNodesSupplier; 051 private final ColumnFamilyDescriptor family; 052 private final Path familyStoreDirectoryPath; 053 private final RegionCoprocessorHost coprocessorHost; 054 055 private StoreContext(Builder builder) { 056 this.blockSize = builder.blockSize; 057 this.encryptionContext = builder.encryptionContext; 058 this.cacheConf = builder.cacheConf; 059 this.regionFileSystem = builder.regionFileSystem; 060 this.comparator = builder.comparator; 061 this.bloomFilterType = builder.bloomFilterType; 062 this.compactedFilesSupplier = builder.compactedFilesSupplier; 063 this.favoredNodesSupplier = builder.favoredNodesSupplier; 064 this.family = builder.family; 065 this.familyStoreDirectoryPath = builder.familyStoreDirectoryPath; 066 this.coprocessorHost = builder.coprocessorHost; 067 } 068 069 public int getBlockSize() { 070 return blockSize; 071 } 072 073 public Encryption.Context getEncryptionContext() { 074 return encryptionContext; 075 } 076 077 public CacheConfig getCacheConf() { 078 return cacheConf; 079 } 080 081 public HRegionFileSystem getRegionFileSystem() { 082 return regionFileSystem; 083 } 084 085 public CellComparator getComparator() { 086 return comparator; 087 } 088 089 public BloomType getBloomFilterType() { 090 return bloomFilterType; 091 } 092 093 public Supplier<Collection<HStoreFile>> getCompactedFilesSupplier() { 094 return compactedFilesSupplier; 095 } 096 097 public InetSocketAddress[] getFavoredNodes() { 098 return favoredNodesSupplier.get(); 099 } 100 101 public ColumnFamilyDescriptor getFamily() { 102 return family; 103 } 104 105 public Path getFamilyStoreDirectoryPath() { 106 return familyStoreDirectoryPath; 107 } 108 109 public RegionCoprocessorHost getCoprocessorHost() { 110 return coprocessorHost; 111 } 112 113 public TableName getTableName() { 114 return getRegionInfo().getTable(); 115 } 116 117 public RegionInfo getRegionInfo() { 118 return regionFileSystem.getRegionInfo(); 119 } 120 121 public int getMaxVersions() { 122 return family.getMaxVersions(); 123 } 124 125 public boolean getNewVersionBehavior() { 126 return family.isNewVersionBehavior(); 127 } 128 129 public boolean isPrimaryReplicaStore() { 130 return getRegionInfo().getReplicaId() == RegionInfo.DEFAULT_REPLICA_ID; 131 } 132 133 public static Builder getBuilder() { 134 return new Builder(); 135 } 136 137 @Override 138 public long heapSize() { 139 return FIXED_OVERHEAD; 140 } 141 142 public static class Builder { 143 private int blockSize; 144 private Encryption.Context encryptionContext; 145 private CacheConfig cacheConf; 146 private HRegionFileSystem regionFileSystem; 147 private CellComparator comparator; 148 private BloomType bloomFilterType; 149 private Supplier<Collection<HStoreFile>> compactedFilesSupplier; 150 private Supplier<InetSocketAddress[]> favoredNodesSupplier; 151 private ColumnFamilyDescriptor family; 152 private Path familyStoreDirectoryPath; 153 private RegionCoprocessorHost coprocessorHost; 154 155 public Builder withBlockSize(int blockSize) { 156 this.blockSize = blockSize; 157 return this; 158 } 159 160 public Builder withEncryptionContext(Encryption.Context encryptionContext) { 161 this.encryptionContext = encryptionContext; 162 return this; 163 } 164 165 public Builder withCacheConfig(CacheConfig cacheConf) { 166 this.cacheConf = cacheConf; 167 return this; 168 } 169 170 public Builder withRegionFileSystem(HRegionFileSystem regionFileSystem) { 171 this.regionFileSystem = regionFileSystem; 172 return this; 173 } 174 175 public Builder withCellComparator(CellComparator comparator) { 176 this.comparator = comparator; 177 return this; 178 } 179 180 public Builder withBloomType(BloomType bloomFilterType) { 181 this.bloomFilterType = bloomFilterType; 182 return this; 183 } 184 185 public Builder 186 withCompactedFilesSupplier(Supplier<Collection<HStoreFile>> compactedFilesSupplier) { 187 this.compactedFilesSupplier = compactedFilesSupplier; 188 return this; 189 } 190 191 public Builder withFavoredNodesSupplier(Supplier<InetSocketAddress[]> favoredNodesSupplier) { 192 this.favoredNodesSupplier = favoredNodesSupplier; 193 return this; 194 } 195 196 public Builder withColumnFamilyDescriptor(ColumnFamilyDescriptor family) { 197 this.family = family; 198 return this; 199 } 200 201 public Builder withFamilyStoreDirectoryPath(Path familyStoreDirectoryPath) { 202 this.familyStoreDirectoryPath = familyStoreDirectoryPath; 203 return this; 204 } 205 206 public Builder withRegionCoprocessorHost(RegionCoprocessorHost coprocessorHost) { 207 this.coprocessorHost = coprocessorHost; 208 return this; 209 } 210 211 public StoreContext build() { 212 return new StoreContext(this); 213 } 214 } 215 216}