Skip to content

Commit 742e737

Browse files
abhishekkhanna01Stephen Wu
authored andcommitted
HBASE-25249 Adding HStoreContext
Adding HStoreContext which contains the metadata about the HStore. This meta data can be used across the HFileWriter/Readers and other HStore consumers without the need of passing around the complete store and exposing its internals.
1 parent 15d229e commit 742e737

File tree

11 files changed

+371
-143
lines changed

11 files changed

+371
-143
lines changed

hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/HFileOutputFormat2.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
import org.apache.hadoop.hbase.regionserver.BloomType;
7171
import org.apache.hadoop.hbase.regionserver.HStore;
7272
import org.apache.hadoop.hbase.regionserver.StoreFileWriter;
73+
import org.apache.hadoop.hbase.regionserver.StoreUtils;
7374
import org.apache.hadoop.hbase.util.BloomFilterUtil;
7475
import org.apache.hadoop.hbase.util.Bytes;
7576
import org.apache.hadoop.hbase.util.CommonFSUtils;
@@ -369,8 +370,8 @@ private WriterLength getNewWriter(byte[] tableName, byte[] family, Configuration
369370
encoding = encoding == null ? datablockEncodingMap.get(tableAndFamily) : encoding;
370371
encoding = encoding == null ? DataBlockEncoding.NONE : encoding;
371372
HFileContextBuilder contextBuilder = new HFileContextBuilder().withCompression(compression)
372-
.withDataBlockEncoding(encoding).withChecksumType(HStore.getChecksumType(conf))
373-
.withBytesPerCheckSum(HStore.getBytesPerChecksum(conf)).withBlockSize(blockSize)
373+
.withDataBlockEncoding(encoding).withChecksumType(StoreUtils.getChecksumType(conf))
374+
.withBytesPerCheckSum(StoreUtils.getBytesPerChecksum(conf)).withBlockSize(blockSize)
374375
.withColumnFamily(family).withTableName(tableName);
375376

376377
if (HFile.getFormatVersion(conf) >= HFile.MIN_FORMAT_VERSION_WITH_TAGS) {

hbase-server/src/main/java/org/apache/hadoop/hbase/mob/MobUtils.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import org.apache.hadoop.hbase.regionserver.HStore;
6060
import org.apache.hadoop.hbase.regionserver.HStoreFile;
6161
import org.apache.hadoop.hbase.regionserver.StoreFileWriter;
62+
import org.apache.hadoop.hbase.regionserver.StoreUtils;
6263
import org.apache.hadoop.hbase.util.Bytes;
6364
import org.apache.hadoop.hbase.util.ChecksumType;
6465
import org.apache.hadoop.hbase.util.CommonFSUtils;
@@ -540,8 +541,8 @@ public static StoreFileWriter createWriter(Configuration conf, FileSystem fs,
540541
Compression.Algorithm compression, CacheConfig cacheConfig, Encryption.Context cryptoContext,
541542
boolean isCompaction) throws IOException {
542543
return createWriter(conf, fs, family, new Path(basePath, mobFileName.getFileName()),
543-
maxKeyCount, compression, cacheConfig, cryptoContext, HStore.getChecksumType(conf),
544-
HStore.getBytesPerChecksum(conf), family.getBlocksize(), BloomType.NONE, isCompaction);
544+
maxKeyCount, compression, cacheConfig, cryptoContext, StoreUtils.getChecksumType(conf),
545+
StoreUtils.getBytesPerChecksum(conf), family.getBlocksize(), BloomType.NONE, isCompaction);
545546
}
546547

547548
/**

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HMobStore.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ public class HMobStore extends HStore {
9393
private AtomicLong mobFlushedCellsSize = new AtomicLong();
9494
private AtomicLong mobScanCellsCount = new AtomicLong();
9595
private AtomicLong mobScanCellsSize = new AtomicLong();
96-
private ColumnFamilyDescriptor family;
9796
private Map<TableName, List<Path>> map = new ConcurrentHashMap<>();
9897
private final IdLock keyLock = new IdLock();
9998
// When we add a MOB reference cell to the HFile, we will add 2 tags along with it
@@ -107,16 +106,15 @@ public class HMobStore extends HStore {
107106
public HMobStore(final HRegion region, final ColumnFamilyDescriptor family,
108107
final Configuration confParam, boolean warmup) throws IOException {
109108
super(region, family, confParam, warmup);
110-
this.family = family;
111109
this.mobFileCache = region.getMobFileCache();
112110
this.homePath = MobUtils.getMobHome(conf);
113111
this.mobFamilyPath = MobUtils.getMobFamilyPath(conf, this.getTableName(),
114-
family.getNameAsString());
112+
getColumnFamilyName());
115113
List<Path> locations = new ArrayList<>(2);
116114
locations.add(mobFamilyPath);
117115
TableName tn = region.getTableDescriptor().getTableName();
118116
locations.add(HFileArchiveUtil.getStoreArchivePath(conf, tn, MobUtils.getMobRegionInfo(tn)
119-
.getEncodedName(), family.getNameAsString()));
117+
.getEncodedName(), getColumnFamilyName()));
120118
map.put(tn, locations);
121119
List<Tag> tags = new ArrayList<>(2);
122120
tags.add(MobConstants.MOB_REF_TAG);
@@ -209,7 +207,7 @@ public StoreFileWriter createWriterInTmp(String date, Path basePath, long maxKey
209207
Compression.Algorithm compression, byte[] startKey,
210208
boolean isCompaction) throws IOException {
211209
MobFileName mobFileName = MobFileName.create(startKey, date, UUID.randomUUID()
212-
.toString().replaceAll("-", ""), region.getRegionInfo().getEncodedName());
210+
.toString().replaceAll("-", ""), getHRegion().getRegionInfo().getEncodedName());
213211
return createWriterInTmp(mobFileName, basePath, maxKeyCount, compression, isCompaction);
214212
}
215213

@@ -226,9 +224,10 @@ public StoreFileWriter createWriterInTmp(String date, Path basePath, long maxKey
226224
public StoreFileWriter createWriterInTmp(MobFileName mobFileName, Path basePath,
227225
long maxKeyCount, Compression.Algorithm compression,
228226
boolean isCompaction) throws IOException {
229-
return MobUtils.createWriter(conf, region.getFilesystem(), family,
230-
new Path(basePath, mobFileName.getFileName()), maxKeyCount, compression, cacheConf,
231-
cryptoContext, checksumType, bytesPerChecksum, blocksize, BloomType.NONE, isCompaction);
227+
return MobUtils.createWriter(conf, getFileSystem(), getColumnFamilyDescriptor(),
228+
new Path(basePath, mobFileName.getFileName()), maxKeyCount, compression, getCacheConfig(),
229+
getEncryptionContext(), StoreUtils.getChecksumType(conf), StoreUtils.getBytesPerChecksum(conf),
230+
blocksize, BloomType.NONE, isCompaction);
232231
}
233232

234233
/**
@@ -245,10 +244,10 @@ public void commitFile(final Path sourceFile, Path targetPath) throws IOExceptio
245244
validateMobFile(sourceFile);
246245
LOG.info(" FLUSH Renaming flushed file from {} to {}", sourceFile, dstPath);
247246
Path parent = dstPath.getParent();
248-
if (!region.getFilesystem().exists(parent)) {
249-
region.getFilesystem().mkdirs(parent);
247+
if (!getFileSystem().exists(parent)) {
248+
getFileSystem().mkdirs(parent);
250249
}
251-
if (!region.getFilesystem().rename(sourceFile, dstPath)) {
250+
if (!getFileSystem().rename(sourceFile, dstPath)) {
252251
throw new IOException("Failed rename of " + sourceFile + " to " + dstPath);
253252
}
254253
}
@@ -261,7 +260,7 @@ public void commitFile(final Path sourceFile, Path targetPath) throws IOExceptio
261260
private void validateMobFile(Path path) throws IOException {
262261
HStoreFile storeFile = null;
263262
try {
264-
storeFile = new HStoreFile(region.getFilesystem(), path, conf, this.cacheConf,
263+
storeFile = new HStoreFile(getFileSystem(), path, conf, getCacheConfig(),
265264
BloomType.NONE, isPrimaryReplicaStore());
266265
storeFile.initReader();
267266
} catch (IOException e) {
@@ -352,9 +351,11 @@ public List<Path> getLocations(TableName tableName) throws IOException {
352351
locations = map.get(tableName);
353352
if (locations == null) {
354353
locations = new ArrayList<>(2);
355-
locations.add(MobUtils.getMobFamilyPath(conf, tableName, family.getNameAsString()));
354+
locations.add(MobUtils.getMobFamilyPath(conf, tableName, getColumnFamilyDescriptor()
355+
.getNameAsString()));
356356
locations.add(HFileArchiveUtil.getStoreArchivePath(conf, tableName,
357-
MobUtils.getMobRegionInfo(tableName).getEncodedName(), family.getNameAsString()));
357+
MobUtils.getMobRegionInfo(tableName).getEncodedName(), getColumnFamilyDescriptor()
358+
.getNameAsString()));
358359
map.put(tableName, locations);
359360
}
360361
} finally {
@@ -388,7 +389,7 @@ private MobCell readCell(List<Path> locations, String fileName, Cell search,
388389
MobFile file = null;
389390
Path path = new Path(location, fileName);
390391
try {
391-
file = mobFileCache.openFile(fs, path, cacheConf);
392+
file = mobFileCache.openFile(fs, path, getCacheConfig());
392393
return readPt != -1 ? file.readCell(search, cacheMobBlocks, readPt)
393394
: file.readCell(search, cacheMobBlocks);
394395
} catch (IOException e) {

0 commit comments

Comments
 (0)