如何查看hbase region数
1个回答
2014-12-13 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517196
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
regionname查询:
HBase写记录过程中regionname查找简介:主要是看如何进行region选择,完成按domain域的数据散列,分摊至不同region上
|-->HTable table = new HTable(config, tablename);
|-->Put put = new Put(Bytes.toBytes("test2"));
|-->put.add(Bytes.toBytes(cfs[j]), Bytes.toBytes(String.valueOf(1)), Bytes.toBytes("value_3"));
|-->table.put(put);
HTable-->put() |利用HTable管理记录
|-->doPut(Arrays.asList(put));
|-->for (Put put : puts)
|-->writeBuffer.add(put);
|-->if (n % DOPUT_WB_CHECK == 0 && currentWriteBufferSize > writeBufferSize)
|-->flushCommits();
|-->if (autoFlush || currentWriteBufferSize > writeBufferSize)
|-->flushCommits();
HTable-->flushCommits() |提交添加的记录,内存阀值可控制
|-->Object[] results = new Object[writeBuffer.size()];
|-->this.connection.processBatch(writeBuffer, tableName, pool, results);
|-->finally
|-->for (int i = results.length - 1; i>=0; i--)
|-->if (results[i] instanceof Result)
|-->writeBuffer.remove(i);
HConnection--->processBatch() |HConnectionImplementation 批量处理
|-->processBatchCallback(list, tableName, pool, results, null)
|-->List<Row> workingList = new ArrayList<Row>(list);
|-->Map<HRegionLocation, MultiAction<R>> actionsByServer = new HashMap<HRegionLocation, MultiAction<R>>();
|-->for (int i = 0; i < workingList.size(); i++) |逐行处理Batch的每一行
|-->Row row = workingList.get(i);
|-->HRegionLocation loc = locateRegion(tableName, row.getRow(), true); |根据行获取对应的Region
|-->byte[] regionName = loc.getRegionInfo().getRegionName();
|-->MultiAction<R> actions = actionsByServer.get(loc);
|-->Action<R> action = new Action<R>(row, i);
|-->lastServers[i] = loc;
|-->actions.add(regionName, action);
|-->for (Entry<HRegionLocation, MultiAction<R>> e: actionsByServer.entrySet()) { |根据actionsByServer进行执行,执行过程在Callable中完成
futures.put(e.getKey(), pool.submit(createCallable(e.getKey(), e.getValue(), tableName)));}
|-->for (Entry<HRegionLocation, Future<MultiResponse>> responsePerServer : futures.entrySet()) |提交完成后,对future的返回对象进行处理
HConnectionImplementation--->locateRegion(final byte [] tableName,final byte [] row, boolean useCache)
|-->if (tableName == null || tableName.length == 0) |非空判断
|-->ensureZookeeperTrackers(); |ZK确认跟踪器
|-->if (Bytes.equals(tableName, HConstants.ROOT_TABLE_NAME)) |根据tableName判断为root,meta,还是一般类型表
|-->ServerName servername = this.rootRegionTracker.getRootRegionLocation(); |从zk获取root的regionserver
|-->return new HRegionLocation(HRegionInfo.ROOT_REGIONINFO, |从ZK中返回root表存储的位置,建立server连接,用于获取meta表信息
servername.getHostname(), servername.getPort());
|-->else if (Bytes.equals(tableName, HConstants.META_TABLE_NAME)) |从meta表中获取region的信息
|-->return locateRegionInMeta(HConstants.ROOT_TABLE_NAME, tableName, row,
useCache, metaRegionLock);
|-->else |此时从meta中获取信息
|-->return locateRegionInMeta(HConstants.META_TABLE_NAME, tableName, row,
useCache, userRegionLock);
HConnectionImplementation--->locateRegionInMeta() |获取真正的region的location信息
|-->if (useCache) |客户端获取时会做cache,保存Location信息
|-->location = getCachedLocation(tableName, row);
|-->byte [] metaKey = HRegionInfo.createRegionName(tableName, row, HConstants.NINES, false);
|-->metaLocation = locateRegion(parentTable, metaKey); |定位root/meta的region信息
|-->HRegionInterface server = getHRegionConnection(metaLocation.getHostname(), metaLocation.getPort());
|-->regionInfoRow = server.getClosestRowBefore( metaLocation.getRegionInfo().getRegionName(), metaKey,
HConstants.CATALOG_FAMILY);
|-->byte [] value = regionInfoRow.getValue(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER);
|-->HRegionInfo regionInfo = (HRegionInfo) Writables.getWritable(value, new HRegionInfo());
|-->value = regionInfoRow.getValue(HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER);
|-->location = new HRegionLocation(regionInfo, hostname, port); |通过regionInfo和对应的regionserver机器名确认Location
|-->cacheLocation(tableName, location);
|-->return location;
HRegionServer-->getClosestRowBefore() |用于寻找目标row最接近的行,在此用于meta表中寻找最近的regionname
|-->HRegion region = getRegion(regionName); |根据regionname获取对应的region信息
|-->Result r = region.getClosestRowBefore(row, family); |在region中寻找最近的row
|-->coprocessorHost.preGetClosestRowBefore(row, family, result) |coprocessorHost预处理
|-->checkRow(row, "getClosestRowBefore"); |确认合法性
|-->startRegionOperation(); |设置读写锁
|-->Store store = getStore(family); |
|-->KeyValue key = store.getRowKeyAtOrBefore(row); |获取最接近的row行,并返回KeyValue对象
|-->Get get = new Get(key.getRow());
|-->get.addFamily(family);
|-->result = get(get, null);
|-->coprocessorHost.postGetClosestRowBefore(row, family, result); |处理完成后的钩子程序
Store-->getRowKeyAtOrBefore() |获取具体的family对应的存储单元Store,每一个Store中存储一列簇
|-->KeyValue kv = new KeyValue(row, HConstants.LATEST_TIMESTAMP); |包装row为KeyValue对象值,用于比较
|-->GetClosestRowBeforeTracker state = new GetClosestRowBeforeTracker( |封装比较对象
this.comparator, kv, ttlToUse, this.region.getRegionInfo().isMetaRegion());
|-->this.lock.readLock().lock(); |设定读写锁
|-->this.memstore.getRowKeyAtOrBefore(state); |分别在meta和HFile中进行搜索
|-->for (StoreFile sf : Lists.reverse(storefiles))
|-->rowAtOrBeforeFromStoreFile(sf, state);
|-->return state.getCandidate();
HConnection-->createCallable(final HRegionLocation loc, final MultiAction<R> multi, final byte [] tableName) |创建处理线程
|-->call() |在call对象中生成新的ServerCallable处理线程
|-->ServerCallable<MultiResponse> callable = new ServerCallable<MultiResponse>(connection, tableName, null) {}
|-->call()
|-->return server.multi(multi); |转换为HRegionServer的multi()方法
|-->connect(boolean reload)
|-->server = connection.getHRegionConnection(loc.getHostname(), loc.getPort()); |确认为哪个RegionServer
HBase写记录过程中regionname查找简介:主要是看如何进行region选择,完成按domain域的数据散列,分摊至不同region上
|-->HTable table = new HTable(config, tablename);
|-->Put put = new Put(Bytes.toBytes("test2"));
|-->put.add(Bytes.toBytes(cfs[j]), Bytes.toBytes(String.valueOf(1)), Bytes.toBytes("value_3"));
|-->table.put(put);
HTable-->put() |利用HTable管理记录
|-->doPut(Arrays.asList(put));
|-->for (Put put : puts)
|-->writeBuffer.add(put);
|-->if (n % DOPUT_WB_CHECK == 0 && currentWriteBufferSize > writeBufferSize)
|-->flushCommits();
|-->if (autoFlush || currentWriteBufferSize > writeBufferSize)
|-->flushCommits();
HTable-->flushCommits() |提交添加的记录,内存阀值可控制
|-->Object[] results = new Object[writeBuffer.size()];
|-->this.connection.processBatch(writeBuffer, tableName, pool, results);
|-->finally
|-->for (int i = results.length - 1; i>=0; i--)
|-->if (results[i] instanceof Result)
|-->writeBuffer.remove(i);
HConnection--->processBatch() |HConnectionImplementation 批量处理
|-->processBatchCallback(list, tableName, pool, results, null)
|-->List<Row> workingList = new ArrayList<Row>(list);
|-->Map<HRegionLocation, MultiAction<R>> actionsByServer = new HashMap<HRegionLocation, MultiAction<R>>();
|-->for (int i = 0; i < workingList.size(); i++) |逐行处理Batch的每一行
|-->Row row = workingList.get(i);
|-->HRegionLocation loc = locateRegion(tableName, row.getRow(), true); |根据行获取对应的Region
|-->byte[] regionName = loc.getRegionInfo().getRegionName();
|-->MultiAction<R> actions = actionsByServer.get(loc);
|-->Action<R> action = new Action<R>(row, i);
|-->lastServers[i] = loc;
|-->actions.add(regionName, action);
|-->for (Entry<HRegionLocation, MultiAction<R>> e: actionsByServer.entrySet()) { |根据actionsByServer进行执行,执行过程在Callable中完成
futures.put(e.getKey(), pool.submit(createCallable(e.getKey(), e.getValue(), tableName)));}
|-->for (Entry<HRegionLocation, Future<MultiResponse>> responsePerServer : futures.entrySet()) |提交完成后,对future的返回对象进行处理
HConnectionImplementation--->locateRegion(final byte [] tableName,final byte [] row, boolean useCache)
|-->if (tableName == null || tableName.length == 0) |非空判断
|-->ensureZookeeperTrackers(); |ZK确认跟踪器
|-->if (Bytes.equals(tableName, HConstants.ROOT_TABLE_NAME)) |根据tableName判断为root,meta,还是一般类型表
|-->ServerName servername = this.rootRegionTracker.getRootRegionLocation(); |从zk获取root的regionserver
|-->return new HRegionLocation(HRegionInfo.ROOT_REGIONINFO, |从ZK中返回root表存储的位置,建立server连接,用于获取meta表信息
servername.getHostname(), servername.getPort());
|-->else if (Bytes.equals(tableName, HConstants.META_TABLE_NAME)) |从meta表中获取region的信息
|-->return locateRegionInMeta(HConstants.ROOT_TABLE_NAME, tableName, row,
useCache, metaRegionLock);
|-->else |此时从meta中获取信息
|-->return locateRegionInMeta(HConstants.META_TABLE_NAME, tableName, row,
useCache, userRegionLock);
HConnectionImplementation--->locateRegionInMeta() |获取真正的region的location信息
|-->if (useCache) |客户端获取时会做cache,保存Location信息
|-->location = getCachedLocation(tableName, row);
|-->byte [] metaKey = HRegionInfo.createRegionName(tableName, row, HConstants.NINES, false);
|-->metaLocation = locateRegion(parentTable, metaKey); |定位root/meta的region信息
|-->HRegionInterface server = getHRegionConnection(metaLocation.getHostname(), metaLocation.getPort());
|-->regionInfoRow = server.getClosestRowBefore( metaLocation.getRegionInfo().getRegionName(), metaKey,
HConstants.CATALOG_FAMILY);
|-->byte [] value = regionInfoRow.getValue(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER);
|-->HRegionInfo regionInfo = (HRegionInfo) Writables.getWritable(value, new HRegionInfo());
|-->value = regionInfoRow.getValue(HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER);
|-->location = new HRegionLocation(regionInfo, hostname, port); |通过regionInfo和对应的regionserver机器名确认Location
|-->cacheLocation(tableName, location);
|-->return location;
HRegionServer-->getClosestRowBefore() |用于寻找目标row最接近的行,在此用于meta表中寻找最近的regionname
|-->HRegion region = getRegion(regionName); |根据regionname获取对应的region信息
|-->Result r = region.getClosestRowBefore(row, family); |在region中寻找最近的row
|-->coprocessorHost.preGetClosestRowBefore(row, family, result) |coprocessorHost预处理
|-->checkRow(row, "getClosestRowBefore"); |确认合法性
|-->startRegionOperation(); |设置读写锁
|-->Store store = getStore(family); |
|-->KeyValue key = store.getRowKeyAtOrBefore(row); |获取最接近的row行,并返回KeyValue对象
|-->Get get = new Get(key.getRow());
|-->get.addFamily(family);
|-->result = get(get, null);
|-->coprocessorHost.postGetClosestRowBefore(row, family, result); |处理完成后的钩子程序
Store-->getRowKeyAtOrBefore() |获取具体的family对应的存储单元Store,每一个Store中存储一列簇
|-->KeyValue kv = new KeyValue(row, HConstants.LATEST_TIMESTAMP); |包装row为KeyValue对象值,用于比较
|-->GetClosestRowBeforeTracker state = new GetClosestRowBeforeTracker( |封装比较对象
this.comparator, kv, ttlToUse, this.region.getRegionInfo().isMetaRegion());
|-->this.lock.readLock().lock(); |设定读写锁
|-->this.memstore.getRowKeyAtOrBefore(state); |分别在meta和HFile中进行搜索
|-->for (StoreFile sf : Lists.reverse(storefiles))
|-->rowAtOrBeforeFromStoreFile(sf, state);
|-->return state.getCandidate();
HConnection-->createCallable(final HRegionLocation loc, final MultiAction<R> multi, final byte [] tableName) |创建处理线程
|-->call() |在call对象中生成新的ServerCallable处理线程
|-->ServerCallable<MultiResponse> callable = new ServerCallable<MultiResponse>(connection, tableName, null) {}
|-->call()
|-->return server.multi(multi); |转换为HRegionServer的multi()方法
|-->connect(boolean reload)
|-->server = connection.getHRegionConnection(loc.getHostname(), loc.getPort()); |确认为哪个RegionServer
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询