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.master.region; 019 020import java.io.IOException; 021import java.util.concurrent.TimeUnit; 022import org.apache.hadoop.conf.Configuration; 023import org.apache.hadoop.hbase.Server; 024import org.apache.hadoop.hbase.TableName; 025import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; 026import org.apache.hadoop.hbase.client.TableDescriptor; 027import org.apache.hadoop.hbase.client.TableDescriptorBuilder; 028import org.apache.hadoop.hbase.util.Bytes; 029import org.apache.yetus.audience.InterfaceAudience; 030 031/** 032 * The factory class for creating a {@link MasterRegion}. 033 */ 034@InterfaceAudience.Private 035public final class MasterRegionFactory { 036 037 // Use the character $ to let the log cleaner know that this is not the normal wal file. 038 public static final String ARCHIVED_WAL_SUFFIX = "$masterlocalwal$"; 039 040 // this is a bit trick that in StoreFileInfo.validateStoreFileName, we just test if the file name 041 // contains '-' to determine if it is a valid store file, so here we have to add '-'in the file 042 // name to avoid being processed by normal TimeToLiveHFileCleaner. 043 public static final String ARCHIVED_HFILE_SUFFIX = "$-masterlocalhfile-$"; 044 045 private static final String MAX_WALS_KEY = "hbase.master.store.region.maxwals"; 046 047 private static final int DEFAULT_MAX_WALS = 10; 048 049 public static final String USE_HSYNC_KEY = "hbase.master.store.region.wal.hsync"; 050 051 public static final String MASTER_STORE_DIR = "MasterData"; 052 053 private static final String FLUSH_SIZE_KEY = "hbase.master.store.region.flush.size"; 054 055 private static final long DEFAULT_FLUSH_SIZE = TableDescriptorBuilder.DEFAULT_MEMSTORE_FLUSH_SIZE; 056 057 private static final String FLUSH_PER_CHANGES_KEY = "hbase.master.store.region.flush.per.changes"; 058 059 private static final long DEFAULT_FLUSH_PER_CHANGES = 1_000_000; 060 061 private static final String FLUSH_INTERVAL_MS_KEY = "hbase.master.store.region.flush.interval.ms"; 062 063 // default to flush every 15 minutes, for safety 064 private static final long DEFAULT_FLUSH_INTERVAL_MS = TimeUnit.MINUTES.toMillis(15); 065 066 private static final String COMPACT_MIN_KEY = "hbase.master.store.region.compact.min"; 067 068 private static final int DEFAULT_COMPACT_MIN = 4; 069 070 private static final String ROLL_PERIOD_MS_KEY = "hbase.master.store.region.walroll.period.ms"; 071 072 private static final long DEFAULT_ROLL_PERIOD_MS = TimeUnit.MINUTES.toMillis(15); 073 074 private static final String RING_BUFFER_SLOT_COUNT = "hbase.master.store.ringbuffer.slot.count"; 075 076 private static final int DEFAULT_RING_BUFFER_SLOT_COUNT = 128; 077 078 public static final TableName TABLE_NAME = TableName.valueOf("master:store"); 079 080 public static final byte[] PROC_FAMILY = Bytes.toBytes("proc"); 081 082 private static final TableDescriptor TABLE_DESC = TableDescriptorBuilder.newBuilder(TABLE_NAME) 083 .setColumnFamily(ColumnFamilyDescriptorBuilder.of(PROC_FAMILY)).build(); 084 085 public static MasterRegion create(Server server) throws IOException { 086 MasterRegionParams params = new MasterRegionParams().server(server) 087 .regionDirName(MASTER_STORE_DIR).tableDescriptor(TABLE_DESC); 088 Configuration conf = server.getConfiguration(); 089 long flushSize = conf.getLong(FLUSH_SIZE_KEY, DEFAULT_FLUSH_SIZE); 090 long flushPerChanges = conf.getLong(FLUSH_PER_CHANGES_KEY, DEFAULT_FLUSH_PER_CHANGES); 091 long flushIntervalMs = conf.getLong(FLUSH_INTERVAL_MS_KEY, DEFAULT_FLUSH_INTERVAL_MS); 092 int compactMin = conf.getInt(COMPACT_MIN_KEY, DEFAULT_COMPACT_MIN); 093 params.flushSize(flushSize).flushPerChanges(flushPerChanges).flushIntervalMs(flushIntervalMs) 094 .compactMin(compactMin); 095 int maxWals = conf.getInt(MAX_WALS_KEY, DEFAULT_MAX_WALS); 096 params.maxWals(maxWals); 097 if (conf.get(USE_HSYNC_KEY) != null) { 098 params.useHsync(conf.getBoolean(USE_HSYNC_KEY, false)); 099 } 100 params.ringBufferSlotCount(conf.getInt(RING_BUFFER_SLOT_COUNT, DEFAULT_RING_BUFFER_SLOT_COUNT)); 101 long rollPeriodMs = conf.getLong(ROLL_PERIOD_MS_KEY, DEFAULT_ROLL_PERIOD_MS); 102 params.rollPeriodMs(rollPeriodMs).archivedWalSuffix(ARCHIVED_WAL_SUFFIX) 103 .archivedHFileSuffix(ARCHIVED_HFILE_SUFFIX); 104 return MasterRegion.create(params); 105 } 106}