ÎÊÌâµ¼¶Á£º
1.ÈçºÎ·ÀÖ¹Èȵ㣿
2.ÈçºÎÔ¤·ÖÇø£¿
À©Õ¹£º
Ϊʲô»á²úÉúÈȵã´æ´¢£¿
HBaseÖУ¬±í»á±»»®·ÖΪ1...n¸öRegion£¬±»ÍйÜÔÚRegionServerÖС£Region¶þ¸öÖØÒªµÄÊôÐÔ:StartKeyÓëEndKey±íʾÕâ¸öRegionά»¤µÄrowKey·¶Î§£¬µ±ÎÒÃÇÒª¶Á/дÊý¾Ýʱ£¬Èç¹ûrowKeyÂäÔÚij¸östart-end key·¶Î§ÄÚ£¬ÄÇô¾Í»á¶¨Î»µ½Ä¿±êregion²¢ÇÒ¶Á/дµ½Ïà¹ØµÄÊý¾Ý¡£¼òµ¥µØ˵£¬ÓÐÄÇôһµãµãÀàËÆÈËȺ»®·Ö£¬1-15ËêΪСÅóÓÑ,16-39ËêΪÄêÇáÈË£¬40-64ΪÖÐÄêÈË,65ËêÒÔÉÏΪÀÏÄêÈË¡£(ÕâЩÊýÖµ¶¼ÊÇÅÄÄÔ´ü³öÀ´µÄ£¬Ö»ÊǾÙÀý£¬·ÇÕæʵ),È»ºóijÈËÕÒ¶ÓÎ飬Ȼºó¸ù¾ÝÄêÁ䣬´¦ÓÚÄĸö·¶Î§£¬¾ÍÕÒµ½ËüËùÊôµÄ¶ÓÎé¡£ : ( Óеã·Ï»°ÁË¡£¡£¡£¡£
È»ºó£¬Ä¬Èϵأ¬µ±ÎÒÃÇÖ»ÊÇͨ¹ýHBaseAdminÖ¸¶¨TableDescriptorÀ´´´½¨Ò»Õűíʱ£¬Ö»ÓÐÒ»¸öregion,Õý´¦ÓÚ»ìãçʱÆÚ£¬start-end keyÎޱ߽ç,¿Éνº£ÄÉ°Ù´¨¡£É¶ÑùµÄrowKey¶¼¿ÉÒÔ½ÓÊÜ£¬¶¼ÍùÕâ¸öregionÀï×°£¬È»¶ø£¬µ±Êý¾ÝÔ½À´Ô½¶à£¬regionµÄsizeÔ½À´Ô½´óʱ£¬´óµ½Ò»¶¨µÄ·§Öµ£¬hbaseÈÏΪÔÙÍùÕâ¸öregionÀïÈûÊý¾ÝÒѾ²»ºÏÊÊÁË£¬¾Í»áÕÒµ½Ò»¸ömidKey½«regionÒ»·ÖΪ¶þ£¬³ÉΪ2¸öregion,Õâ¸ö¹ý³Ì³ÆΪ·ÖÁÑ(region-split).¶ømidKeyÔòΪÕâ¶þ¸öregionµÄÁٽ磬×óΪNÎÞϽ磬ÓÒΪMÎÞÉϽ硣< midKeyÔòΪÒõ±»Èûµ½NÇø£¬> midKeyÔò»á±»Èûµ½MÇø¡£ ÈçºÎÕÒµ½midKey?Éæ¼°µÄÄÚÈݱȽ϶࣬ÔÝÇÒ²»È¥ÌÖÂÛ£¬×î¼òµ¥µÄ¿ÉÒÔÈÏΪÊÇregionµÄ×ÜÐÐÊý / 2 µÄÄÇÒ»ÐÐÊý¾ÝµÄrowKey.ËäȻʵ¼ÊÉϱÈËü»áÉÔ¸´Ôӵ㡣
Èç¹ûÎÒÃǾÍÕâÑùĬÈϵأ¬½¨±í£¬±íÀï²»¶ÏµØPutÊý¾Ý£¬¸üÑÏÖصÄÊÇÎÒÃǵÄrowkey»¹ÊÇ˳ÐòÔö´óµÄ£¬ÊDZȽϿÉŵġ£´æÔÚµÄȱµã±È½ÏÃ÷ÏÔ¡£
Ê×ÏÈÊÇÈȵãд£¬ÎÒÃÇ×ÜÊÇ»áÍù×î´óµÄstart-keyËùÔÚµÄregion䶫Î÷£¬ÒòΪÎÒÃǵÄrowkey×ÜÊÇ»á±È֮ǰµÄ´ó£¬²¢ÇÒhbaseµÄÊÇ°´ÉýÐò·½Ê½ÅÅÐòµÄ¡£ËùÒÔд²Ù×÷×ÜÊDZ»¶¨Î»µ½ÎÞÉϽçµÄÄǸöregionÖС£
Æä´Î£¬ÓÉÓÚдÈȵ㣬ÎÒÃÇ×ÜÊÇÍù×î´óstart-keyµÄregionд¼Ç¼£¬Ö®Ç°·ÖÁѳöÀ´µÄregion²»»áÔÙ±»Ð´Êý¾Ý£¬Óе㱻´ò½øÀ乬µÄ¸Ï½Å£¬ËüÃǶ¼´¦ÓÚ°ëÂú״̬£¬ÕâÑùµÄ·Ö²¼Ò²ÊDz»ÀûµÄ¡£
Èç¹ûÔÚд±È½ÏƵÂʵij¡¾°Ï£¬Êý¾ÝÔö³¤¿ì£¬splitµÄ´ÎÊýÒ²»áÔö¶à£¬ÓÉÓÚsplitÊDZȽϺÄʱºÄ×ÊÔ´µÄ£¬ËùÒÔÎÒÃDz¢²»Ï£ÍûÕâÖÖÊÂÇé¾³£·¢Éú¡£
............
¿´µ½ÕâЩȱµã£¬ÎÒÃÇÖªµÀ£¬ÔÚ¼¯ÈºµÄ»·¾³ÖУ¬ÎªÁ˵õ½¸üºÃµÄ²¢ÐÐÐÔ£¬ÎÒÃÇÏ£ÍûÓкõÄload blance£¬ÈÃÿ¸ö½ÚµãÌṩµÄÇëÇó´¦Àí¶¼ÊǾùµÈµÄ¡£ÎÒÃÇҲϣÍû£¬region²»Òª¾³£split£¬ÒòΪsplit»áʹserverÓÐÒ»¶Îʱ¼äµÄÍ£¶Ù£¬ÈçºÎÄÜ×öµ½ÄØ£¿
Ëæ»úÉ¢ÁÐÓëÔ¤·ÖÇø¡£¶þÕß½áºÏÆðÀ´£¬ÊDZȽÏÍêÃÀµÄ£¬Ô¤·ÖÇøÒ»¿ªÊ¼¾ÍÔ¤½¨ºÃÁËÒ»²¿·Öregion,ÕâЩregion¶¼Î¬»¤×Å×ÔÒѵÄstart-end keys£¬ÔÙÅäºÏÉÏËæ»úÉ¢ÁУ¬Ð´Êý¾ÝÄܾùµÈµØÃüÖÐÕâЩԤ½¨µÄregion£¬¾ÍÄܽâ¾öÉÏÃæµÄÄÇЩȱµã£¬´ó´óµØÌá¸ßÁËÐÔÄÜ¡£
Ìṩ2ÖÖ˼·: hash Óë partition.
hash¾ÍÊÇrowkeyÇ°ÃæÓÉÒ»´®Ëæ»ú×Ö·û´®×é³É,Ëæ»ú×Ö·û´®Éú³É·½Ê½¿ÉÒÔÓÉSHA»òÕßMD5µÈ·½Ê½Éú³É£¬Ö»ÒªregionËù¹ÜÀíµÄstart-end keys·¶Î§±È½ÏËæ»ú£¬ÄÇô¾Í¿ÉÒÔ½â¾öдÈȵãÎÊÌâ¡£
- long currentId = 1L;
- byte [] rowkey = Bytes.add(MD5Hash.getMD5AsHex(Bytes.toBytes(currentId)).substring(0, 8).getBytes(),
- Bytes.toBytes(currentId));
¸´ÖÆ´úÂë
¼ÙÉèrowKeyÔ±¾ÊÇ×ÔÔö³¤µÄlongÐÍ£¬¿ÉÒÔ½«rowkeyתΪhashÔÙתΪbytes£¬¼ÓÉϱ¾Éíid תΪbytes,×é³Érowkey£¬ÕâÑù¾ÍÉú³ÉËæ±ãµÄrowkey¡£ÄÇô¶ÔÓÚÕâÖÖ·½Ê½µÄrowkeyÉè¼Æ£¬ÈçºÎÈ¥½øÐÐÔ¤·ÖÇøÄØ£¿ 1.È¡Ñù£¬ÏÈËæ»úÉú³ÉÒ»¶¨ÊýÁ¿µÄrowkey,½«È¡ÑùÊý¾Ý°´ÉýÐòÅÅÐò·Åµ½Ò»¸ö¼¯ºÏÀï 2.¸ù¾ÝÔ¤·ÖÇøµÄregion¸öÊý£¬¶ÔÕû¸ö¼¯ºÏƽ¾ù·Ö¸î£¬¼´ÊÇÏà¹ØµÄsplitKeys. 3.HBaseAdmin.createTable(HTableDescriptor tableDescriptor,byte[][] splitkeys)¿ÉÒÔÖ¸¶¨Ô¤·ÖÇøµÄsplitKey£¬¼´ÊÇÖ¸¶¨region¼äµÄrowkeyÁÙ½çÖµ.
1.´´½¨split¼ÆËãÆ÷£¬ÓÃÓÚ´Ó³éÑùÊý¾ÝÖÐÉú³ÉÒ»¸ö±È½ÏºÏÊʵÄsplitKeys
- public class HashChoreWoker implements SplitKeysCalculator{
- //Ëæ»úÈ¡»úÊýÄ¿
- private int baseRecord;
- //rowkeyÉú³ÉÆ÷
- private RowKeyGenerator rkGen;
- //È¡Ñùʱ£¬ÓÉÈ¡ÑùÊýÄ¿¼°regionÊýÏà³ýËùµÃµÄÊýÁ¿.
- private int splitKeysBase;
- //splitkeys¸öÊý
- private int splitKeysNumber;
- //ÓɳéÑù¼ÆËã³öÀ´µÄsplitkeys½á¹û
- private byte[][] splitKeys;
-
- public HashChoreWoker(int baseRecord, int prepareRegions) {
- this.baseRecord = baseRecord;
- //ʵÀý»¯rowkeyÉú³ÉÆ÷
- rkGen = new HashRowKeyGenerator();
- splitKeysNumber = prepareRegions - 1;
- splitKeysBase = baseRecord / prepareRegions;
- }
-
- public byte[][] calcSplitKeys() {
- splitKeys = new byte[splitKeysNumber][];
- //ʹÓÃtreeset±£´æ³éÑùÊý¾Ý£¬ÒÑÅÅÐò¹ý
- TreeSet<byte[]> rows = new TreeSet<byte[]>(Bytes.BYTES_COMPARATOR);
- for (int i = 0; i < baseRecord; i++) {
- rows.add(rkGen.nextId());
- }
- int pointer = 0;
- Iterator<byte[]> rowKeyIter = rows.iterator();
- int index = 0;
- while (rowKeyIter.hasNext()) {
- byte[] tempRow = rowKeyIter.next();
- rowKeyIter.remove();
- if ((pointer != 0) && (pointer % splitKeysBase == 0)) {
- if (index < splitKeysNumber) {
- splitKeys[index] = tempRow;
- index ++;
- }
- }
- pointer ++;
- }
- rows.clear();
- rows = null;
- return splitKeys;
- }
- }
¸´ÖÆ´úÂë
- KeyGenerator¼°ÊµÏÖ
- //interface
- public interface RowKeyGenerator {
- byte [] nextId();
- }
- //implements
- public class HashRowKeyGenerator implements RowKeyGenerator {
- private long currentId = 1;
- private long currentTime = System.currentTimeMillis();
- private Random random = new Random();
- public byte[] nextId() {
- try {
- currentTime += random.nextInt(1000);
- byte[] lowT = Bytes.copy(Bytes.toBytes(currentTime), 4, 4);
- byte[] lowU = Bytes.copy(Bytes.toBytes(currentId), 4, 4);
- return Bytes.add(MD5Hash.getMD5AsHex(Bytes.add(lowU, lowT)).substring(0, 8).getBytes(),
- Bytes.toBytes(currentId));
- } finally {
- currentId++;
- }
- }
- }
¸´ÖÆ´úÂë
unit test case²âÊÔ
- @Test
- public void testHashAndCreateTable() throws Exception{
- HashChoreWoker worker = new HashChoreWoker(1000000,10);
- byte [][] splitKeys = worker.calcSplitKeys();
-
- HBaseAdmin admin = new HBaseAdmin(HBaseConfiguration.create());
- TableName tableName = TableName.valueOf("hash_split_table");
-
- if (admin.tableExists(tableName)) {
- try {
- admin.disableTable(tableName);
- } catch (Exception e) {
- }
- admin.deleteTable(tableName);
- }
-
- HTableDescriptor tableDesc = new HTableDescriptor(tableName);
- HColumnDescriptor columnDesc = new HColumnDescriptor(Bytes.toBytes("info"));
- columnDesc.setMaxVersions(1);
- tableDesc.addFamily(columnDesc);
-
- admin.createTable(tableDesc ,splitKeys);
-
- admin.close();
- }
¸´ÖÆ´úÂë
²é¿´½¨±í½á¹û£ºÖ´ÐÐ scan 'hbase:meta' ÒÔÉÏÎÒÃÇÖ»ÊÇÏÔʾÁ˲¿·ÖregionµÄÐÅÏ¢£¬¿ÉÒÔ¿´µ½regionµÄstart-end key »¹ÊDZȽÏËæ»úÉ¢Áеġ£Í¬Ñù¿ÉÒԲ鿴hdfsµÄĿ¼½á¹¹,µÄÈ·ºÍÔ¤ÆÚµÄ38¸öÔ¤·ÖÇøÒ»Ö£º ÒÔÉÏ£¬¾ÍÒѾ°´hash·½Ê½£¬Ô¤½¨ºÃÁË·ÖÇø£¬ÒÔºóÔÚ²åÈëÊý¾ÝµÄʱºò£¬Ò²Òª°´ÕÕ´ËrowkeyGeneratorµÄ·½Ê½Éú³Érowkey,ÓÐÐËȤµÄ»°£¬Ò²¿ÉÒÔ×öЩÊÔÑ飬²åÈëЩÊý¾Ý£¬¿´¿´Êý¾ÝµÄ·Ö²¼¡£ partition¹ÊÃû˼Ò壬¾ÍÊÇ·ÖÇøʽ£¬ÕâÖÖ·ÖÇøÓеãÀàËÆÓÚmapreduceÖеÄpartitioner,½«ÇøÓòÓó¤ÕûÊý(Long)×÷Ϊ·ÖÇøºÅ£¬Ã¿¸öregion¹ÜÀí×ÅÏàÓ¦µÄÇøÓòÊý¾Ý£¬ÔÚrowKeyÉú³Éʱ£¬½«idÈ¡Ä£ºó£¬È»ºóÆ´ÉÏidÕûÌå×÷ΪrowKey.Õâ¸ö±È½Ï¼òµ¥£¬²»ÐèҪȡÑù£¬splitKeysÒ²·Ç³£¼òµ¥£¬Ö±½ÓÊÇ·ÖÇøºÅ¼´¿É¡£Ö±½ÓÉÏ´úÂë°É£º
- public class PartitionRowKeyManager implements RowKeyGenerator,
- SplitKeysCalculator {
-
- public static final int DEFAULT_PARTITION_AMOUNT = 20;
- private long currentId = 1;
- private int partition = DEFAULT_PARTITION_AMOUNT;
- public void setPartition(int partition) {
- this.partition = partition;
- }
-
- public byte[] nextId() {
- try {
- long partitionId = currentId % partition;
- return Bytes.add(Bytes.toBytes(partitionId),
- Bytes.toBytes(currentId));
- } finally {
- currentId++;
- }
- }
-
- public byte[][] calcSplitKeys() {
- byte[][] splitKeys = new byte[partition - 1][];
- for(int i = 1; i < partition ; i ++) {
- splitKeys[i-1] = Bytes.toBytes((long)i);
- }
- return splitKeys;
- }
- }
¸´ÖÆ´úÂë
calcSplitKeys·½·¨±È½Ïµ¥´¿£¬splitKey¾ÍÊÇpartitionµÄ±àºÅ,ÎÒÃÇ¿´¿´²âÊÔÀà:
- @Test
- public void testPartitionAndCreateTable() throws Exception{
-
- PartitionRowKeyManager rkManager = new PartitionRowKeyManager();
- //Ö»Ô¤½¨10¸ö·ÖÇø
- rkManager.setPartition(10);
-
- byte [][] splitKeys = rkManager.calcSplitKeys();
-
- HBaseAdmin admin = new HBaseAdmin(HBaseConfiguration.create());
- TableName tableName = TableName.valueOf("partition_split_table");
-
- if (admin.tableExists(tableName)) {
- try {
- admin.disableTable(tableName);
-
- } catch (Exception e) {
- }
- admin.deleteTable(tableName);
- }
-
- HTableDescriptor tableDesc = new HTableDescriptor(tableName);
- HColumnDescriptor columnDesc = new HColumnDescriptor(Bytes.toBytes("info"));
- columnDesc.setMaxVersions(1);
- tableDesc.addFamily(columnDesc);
-
- admin.createTable(tableDesc ,splitKeys);
-
- admin.close();
- }
¸´ÖÆ´úÂë
ͬÑùÎÒÃÇ¿ÉÒÔ¿´¿´meta±íºÍhdfsµÄĿ¼½á¹û£¬ÆäʵºÍhashÀàËÆ£¬region¶¼»á·ÖºÃÇø£¬ÔÚÕâÀï¾Í²»ÉÏͼÁË¡£ ͨ¹ýpartitionʵÏÖµÄloadblanceдµÄ»°£¬µ±È»Éú³Érowkey·½Ê½Ò²Òª½áºÏµ±Ç°µÄregionÊýÄ¿È¡Ä£¶øÇóµÃ£¬´ó¼ÒͬÑùÒ²¿ÉÒÔ×öЩʵÑ飬¿´¿´Êý¾Ý²åÈëºóµÄ·Ö²¼¡£
ÔÚÕâÀïҲ˳Ìáһϣ¬Èç¹ûÊÇ˳ÐòµÄÔö³¤ÐÍÔid,¿ÉÒÔ½«id±£´æµ½Ò»¸öÊý¾Ý¿â£¬´«Í³µÄÒ²ºÃ,redisµÄÒ²ºÃ£¬Ã¿´ÎÈ¡µÄʱºò£¬½«ÊýÖµÉè´ó1000×óÓÒ£¬ÒÔºóid¿ÉÒÔÔÚÄÚ´æÄÚÔö³¤£¬µ±ÄÚ´æÊýÁ¿ÒѾ³¬¹ý1000µÄ»°£¬ÔÙÈ¥loadÏÂÒ»¸ö£¬ÓеãÀàËÆÓÚoracleÖеÄsqeuence. Ëæ»ú·Ö²¼¼ÓÔ¤·ÖÇøÒ²²»ÊÇÒ»ÀÍÓÀÒݵġ£ÒòΪÊý¾ÝÊDz»¶ÏµØÔö³¤µÄ£¬Ëæ×Åʱ¼ä²»¶ÏµØÍÆÒÆ£¬ÒѾ·ÖºÃµÄÇøÓò£¬»òÐíÒѾװ²»×¡¸ü¶àµÄÊý¾Ý£¬µ±È»¾ÍÒª½øÒ»²½½øÐÐsplitÁË£¬Í¬ÑùÒ²»á³öÏÖÐÔÄÜËðºÄÎÊÌ⣬ËùÒÔÎÒÃÇ»¹ÊÇÒª¹æ»®ºÃÊý¾ÝÔö³¤ËÙÂÊ£¬¹Û²ìºÃÊý¾Ý¶¨ÆÚά»¤£¬°´Ðè·ÖÎöÊÇ·ñÒª½øÒ»²½·ÖÐÐÊÖ¹¤½«·ÖÇøÔٷֺã¬Ò²»òÕßÊǸüÑÏÖصÄÊÇн¨±í£¬×öºÃ¸ü´óµÄÔ¤·ÖÇøÈ»ºó½øÐÐÊý¾ÝǨÒÆ¡£Ð¡ÎâÖ»ÊDzËÄñ£¬ÔËά·½ÃæÒ²Ö»ÊÇ×ÔÒÑÕâÑùÈÏΪ¶øÒÑ£¬¹©´ó¼Ò×÷¼òµ¥µÄ²Î¿¼°É¡£Èç¹ûÊý¾Ý×°²»×¡ÁË£¬¶ÔÓÚpartition·½Ê½Ô¤·ÖÇøµÄ»°£¬Èç¹ûÈÃËü×ÔÈ»·ÖÁѵĻ°£¬Çé¿ö·ÖÑÏÖØÒ»µã¡£ÒòΪ·ÖÁѳöÀ´µÄ·ÖÇøºÅ»áÊÇÒ»ÑùµÄ£¬ËùÒÔ¼ÆËãµ½partitionIdµÄ»°£¬Æäʵ»¹Êǻص½ÁË˳ÐòдÄê´ú£¬»áÓв¿·ÖÈȵãдÎÊÌâ³öÏÖ£¬Èç¹ûʹÓÃpartition·½Ê½Éú³ÉÖ÷¼üµÄ»°£¬Êý¾ÝÔö³¤ºó¾ÍÒª²»¶ÏµØµ÷Õû·ÖÇøÁË£¬±ÈÈçÔö¶àÔ¤·ÖÇø£¬»òÕß¼ÓÈë×Ó·ÖÇøºÅµÄ´¦Àí.(ÎÒÃǵķÖÇøºÅΪlongÐÍ£¬¿ÉÒÔ½«Ëü×÷Ϊ¶à¼¶partition)
OK,дµ½ÕâÀ»ù±¾ÒѾ½²ÍêÁË·ÀÖ¹ÈȵãдʹÓõķ½·¨ºÍ·ÀֹƵ·±split¶ø²ÉÈ¡µÄÔ¤·ÖÇø¡£µ«rowkeyÉè¼Æ£¬Ô¶Ô¶Ò²²»Ö¹ÕâЩ£¬±ÈÈçrowkey³¤¶È£¬È»ºóËüµÄ³¤¶È×î´ó¿ÉÒÔΪcharµÄMAXVALUE,µ«ÊÇ¿´¹ý֮ǰÎÒдKeyValueµÄ·ÖÎöÖªµÀ£¬ÎÒÃǵÄÊý¾Ý¶¼ÊÇÒÔKeyValue·½Ê½´æ´¢ÔÚMemStore»òÕßHFileÖеģ¬Ã¿¸öKeyValue¶¼»á´æ´¢rowKeyµÄÐÅÏ¢£¬Èç¹ûrowkeyÌ«´óµÄ»°£¬±ÈÈçÊÇ128¸ö×Ö½Ú£¬Ò»ÐÐ10¸ö×Ö¶ÎµÄ±í£¬100ÍòÐмǼ£¬¹ârowkey¾ÍÕ¼ÁË1.2G+ËùÒÔ³¤¶È»¹ÊDz»Òª¹ý³¤£¬ÁíÍâÉè¼Æ£¬»¹ÊÇ°´ÐèÇóÀ´°É¡£ ×îºóÌâÍâ»°ÊÇÎÒÏë·ÖÏíÎÒÔÚgithubÖн¨ÁËÒ»¸öproject,Ï£Íû×öһЩhbaseһЩ¹¤¾ß£º https://github.com/bdifn/hbase-tools,Èç¹û±¾µØ×°ÁËgitµÄ»°£¬¿ÉÒÔÖ´ÐÐÃüÁî: git clone https://github.com/bdifn/hbase-tools.gitÄ¿Ç°¼ÓÁËÒ»¸öregion-helper×ÓÏîÄ¿£¬Ò²ÊÇĿǰΨһµÄÒ»¸ö×ÓÏîÄ¿£¬ÏîĿʹÓÃmaven¹ÜÀí,Ö÷ҪĿµÄÊÇ°ïÖúÎÒÃÇÉè¼Ærowkey×öһЩ²Î¿¼£¬±ÈÈçÎÒÃÇÉè¼ÆµÄËæ»úдºÍÔ¤·ÖÇø²âÊÔ£¬ÌṩÁ˳éÑùµÄ¹¦ÄÜ£¬ÌṩÁ˼ì²âËæ»úдµÄ¹¦ÄÜ£¬È»ºóͳ¼Æ°´Ä¿Ç°rowkeyÉè¼Æ£¬Ëæ»úдnÌõ¼Ç¼ºó£¬Í³¼Æÿ¸öregionµÄ¼Ç¼Êý£¬È»ºóÏÔʾ±ÈÀýµÈ¡£
²âÊÔ·ÂÕæÄ£¿éÎÒ³ÌΪsimualtor,Ö÷ÒªÊÇÄ£ÄâhbaseµÄregionÐÐΪ£¬simpleµÄʵÏÖ£¬½ö½öÊÇÉÏÃæÌáµ½µÄÔ¤²âÎÒÃÇrowkeyÉè¼Æºó£¬½¨ºÃÔ¤·ÖÇøºó£¬Ð´Êý¾ÝµÄµÄ·Ö²¼±ÈÀý£¬¶øemulationÊDZȽϱÆÕæµÄ·ÂÕ棬ÉèÏëÊÇÎÒÃÇдÊý¾Ýʱ£¬»áͳ¼ÆÊýÄ¿µÄ´óС£¬¸ù¾ÝÎÒÃǵÄhbase-site.xmlÉ趨£¬Ä£ÄâmemStoreÐÐΪ£¬Ä£ÄâhfileµÄÐÐΪ£¬×îÖÕ»áÉú³ÉÒ»·Ý±íµÄ±¨±í£¬±ÈÈç·ÖÇøµÄÊý¾Ý´óС£¬ÊÇ·ñsplitÁË£¬µÈµÈ£¬ÒÔ¹©ÎÒÃÇÈ¥Éè¼Æhbase±íʱÓÐÒ»¸ö²Î¿¼£¬µ«ÊÇÒź¶µÄÊÇ£¬ÓÉÓÚʱ¼ä¹Øϵ£¬ÎÒÖ»»¨ÁËÒ»µãÒµÓàʱ¼ä¼òµ¥´îÁËһϿò¼Ü£¬Ä¿Ç°Ã»ÓиüÒ»²½µÄʵÏÖ£¬ÒÔºóÓÐʱ¼äÔÙ¼ÓÒÔÍêÉÆ£¬µ±È»Ò²»¶Ó´ó¼ÒÒ»Æð¼ÓÈ룬һÆðѧϰ°É¡£
ÏîĿʹÓÃmaven¹ÜÀí£¬ÎªÁË·½±ã²âÊÔ£¬Ò»Ð©×é¼þµÄʵÀý»¯£¬ÎÒʹÓÃÁËjavaµÄSPI,downloadÔ´Âëºó£¬Èç¹ûÏë²âÊÔ×ÔÒѵÄrowKeyGeneatorµÄ»°£¬´ò¿ªcom.bdifn.hbasetools.regionhelper.rowkey.RowKeyGeneratorÎļþºó£¬Ìæ»»µ½ÄãÃǵÄIDÉú³ÉÆ÷¾Í¿ÉÒÔÁË¡£Èç¹ûÊÇhashµÄ»°£¬³éÑùºÍ²âÊԵȣ¬¶¼ÊÇ¿ÉÒÔ¸´Óõġ£ Èç²âÊÔ´úÂ룺
- public class HBaseSimulatorTest {
- //ͨ¹ýSPI·½Ê½»ñÈ¡HBaseSimulatorʵÀý,SPIµÄʵÏÖΪsimgple
- private HBaseSimulator hbase = BeanFactory.getInstance().getBeanInstance(HBaseSimulator.class);
- //»ñÈ¡RowKeyGeneratorʵÀý£¬SPIµÄʵÏÖΪhashRowkey
- private RowKeyGenerator rkGen = BeanFactory.getInstance().getBeanInstance(RowKeyGenerator.class);
- //³õÈ绯¿à¹¤£¬È¥¼ì²â100w¸ö³éÑùrowkey,È»ºóÉú³ÉÒ»×ésplitKeys
- HashChoreWoker worker = new HashChoreWoker(1000000,10);
-
- @Test
- public void testHash(){
- byte [][] splitKeys = worker.calcSplitKeys();
- hbase.createTable("user", splitKeys);
- //²åÈë1ÒÚÌõ¼Ç¼£¬¿´Êý¾Ý·Ö²¼
- TableName tableName = TableName.valueOf("user");
- for(int i = 0; i < 100000000; i ++) {
- Put put = new Put(rkGen.nextId());
- hbase.put(tableName, put);
- }
- hbase.report(tableName);
- }
-
- @Test
- public void testPartition(){
- //default 20 partitions.
- PartitionRowKeyManager rkManager = new PartitionRowKeyManager();
- byte [][] splitKeys = rkManager.calcSplitKeys();
-
- hbase.createTable("person", splitKeys);
-
- TableName tableName = TableName.valueOf("person");
- //²åÈë1ÒÚÌõ¼Ç¼£¬¿´Êý¾Ý·Ö²¼
- for(int i = 0; i < 100000000; i ++) {
- Put put = new Put(rkManager.nextId());
- hbase.put(tableName, put);
- }
-
- hbase.report(tableName);
- }
- }
¸´ÖÆ´úÂë
Ö´Ðнá¹û:
- Execution Reprort:[StartRowkey:puts requsts:(put ratio)]
- :9973569:(1.0015434)
- 1986344a\x00\x00\x00\x00\x00\x01\x0E\xAE:9999295:(1.0041268)
- 331ee65f\x00\x00\x00\x00\x00\x0F)g:10012532:(1.005456)
- 4cbfd4f6\x00\x00\x00\x00\x00\x00o0:9975842:(1.0017716)
- 664c6388\x00\x00\x00\x00\x00\x02\x1Du:10053337:(1.0095537)
- 800945e0\x00\x00\x00\x00\x00\x01\xADV:9998719:(1.0040689)
- 99a158d9\x00\x00\x00\x00\x00\x0BZ\xF3:10000563:(1.0042541)
- b33a2223\x00\x00\x00\x00\x00\x07\xC6\xE6:9964921:(1.000675)
- ccbcf370\x00\x00\x00\x00\x00\x00*\xE2:9958200:(1.0)
- e63b8334\x00\x00\x00\x00\x00\x03g\xC1:10063022:(1.0105262)
- total requests:100000000
- Execution Reprort:[StartRowkey:puts requsts:(put ratio)]
- :5000000:(1.0)
- \x00\x00\x00\x00\x00\x00\x00\x01:5000000:(1.0)
- \x00\x00\x00\x00\x00\x00\x00\x02:5000000:(1.0)
- \x00\x00\x00\x00\x00\x00\x00\x03:5000000:(1.0)
- \x00\x00\x00\x00\x00\x00\x00\x04:5000000:(1.0)
- \x00\x00\x00\x00\x00\x00\x00\x05:5000000:(1.0)
- \x00\x00\x00\x00\x00\x00\x00\x06:5000000:(1.0)
- \x00\x00\x00\x00\x00\x00\x00\x07:5000000:(1.0)
- \x00\x00\x00\x00\x00\x00\x00\x08:5000000:(1.0)
- \x00\x00\x00\x00\x00\x00\x00\x09:5000000:(1.0)
- \x00\x00\x00\x00\x00\x00\x00\x0A:5000000:(1.0)
- \x00\x00\x00\x00\x00\x00\x00\x0B:5000000:(1.0)
- \x00\x00\x00\x00\x00\x00\x00\x0C:5000000:(1.0)
- \x00\x00\x00\x00\x00\x00\x00\x0D:5000000:(1.0)
- \x00\x00\x00\x00\x00\x00\x00\x0E:5000000:(1.0)
- \x00\x00\x00\x00\x00\x00\x00\x0F:5000000:(1.0)
- \x00\x00\x00\x00\x00\x00\x00\x10:5000000:(1.0)
- \x00\x00\x00\x00\x00\x00\x00\x11:5000000:(1.0)
- \x00\x00\x00\x00\x00\x00\x00\x12:5000000:(1.0)
- \x00\x00\x00\x00\x00\x00\x00\x13:5000000:(1.0)
- total requests:100000000
¸´ÖÆ´úÂë
|