·ÖÏí

Hbase³õ²½ÈëÃÅ-- ±í¸ÃÈçºÎ¹¹ÔìºÍÉè¼Æ


ÎÊÌâµ¼¶Á£º
1.hbaseÈëÃÅ£¬ÎÒÃǸÃÈçºÎ¹¹ÔìºÍÉè¼Æ
2.hbase´´½¨±í»á×Ô¶¯´´½¨¼¸¸öregion·ÖÇø£¿
3.Column Family¸ÃÈçºÎÉè¼Æ£¿
4.¸ÃÈçºÎÉèÖÃÊý¾ÝµÄÓм¸¸ö°æ±¾£¿
5.hbaseÔÚʲôÇë¿î²»¹ýϽøÐÐCompactÓëSplit²Ù×÷£¿
6.HBaseÖÐrow keyÓÃÀ´¼ìË÷±íÖеļǼ,Óм¸ÖÖ·½Ê½£¿





1.1 Pre-Creating Regions

ĬÈÏÇé¿öÏ£¬ÔÚ´´½¨HBase±íµÄʱºò»á×Ô¶¯´´½¨Ò»¸öregion·ÖÇø£¬µ±µ¼ÈëÊý¾ÝµÄʱºò£¬ËùÓеÄHBase¿Í»§¶Ë¶¼ÏòÕâÒ»¸öregionдÊý¾Ý£¬Ö±µ½Õâ¸öregion×ã¹»´óÁ˲ŽøÐÐÇз֡£Ò»ÖÖ¿ÉÒÔ¼Ó¿ìÅúÁ¿Ð´ÈëËٶȵķ½·¨ÊÇͨ¹ýÔ¤ÏÈ´´½¨Ò»Ð©¿ÕµÄregions£¬ÕâÑùµ±Êý¾ÝдÈëHBaseʱ£¬»á°´ÕÕregion·ÖÇøÇé¿ö£¬ÔÚ¼¯ÈºÄÚ×öÊý¾ÝµÄ¸ºÔؾùºâ¡£

ÓйØÔ¤·ÖÇø£¬ÏêÇé²Î¼û£ºTable Creation: Pre-Creating Regions £¬ÏÂÃæÊÇÒ»¸öÀý×Ó£º

  1. public static boolean createTable(HBaseAdmin admin, HTableDescriptor table, byte[][] splits) throws IOException { try {
  2.     admin.createTable(table, splits); return true;
  3.   } catch (TableExistsException e) {
  4.     logger.info("table " + table.getNameAsString() + " already exists"); // the table already exists...  return false;  
  5.   }
  6. } public static byte[][] getHexSplits(String startKey, String endKey, int numRegions) { byte[][] splits = new byte[numRegions-1][];
  7.   BigInteger lowestKey = new BigInteger(startKey, 16);
  8.   BigInteger highestKey = new BigInteger(endKey, 16);
  9.   BigInteger range = highestKey.subtract(lowestKey);
  10.   BigInteger regionIncrement = range.divide(BigInteger.valueOf(numRegions));
  11.   lowestKey = lowestKey.add(regionIncrement); for(int i=0; i < numRegions-1;i++) {
  12.     BigInteger key = lowestKey.add(regionIncrement.multiply(BigInteger.valueOf(i))); byte[] b = String.format("%016x", key).getBytes();
  13.     splits[i] = b;
  14.   } return splits;
  15. }
¸´ÖÆ´úÂë
1.2 Row Key
HBaseÖÐrow keyÓÃÀ´¼ìË÷±íÖеļǼ£¬Ö§³ÖÒÔÏÂÈýÖÖ·½Ê½£º
  • ͨ¹ýµ¥¸örow key·ÃÎÊ£º¼´°´ÕÕij¸örow key¼üÖµ½øÐÐget²Ù×÷£»
  • ͨ¹ýrow keyµÄrange½øÐÐscan£º¼´Í¨¹ýÉèÖÃstartRowKeyºÍendRowKey£¬ÔÚÕâ¸ö·¶Î§ÄÚ½øÐÐɨÃ裻
  • È«±íɨÃ裺¼´Ö±½ÓɨÃèÕûÕűíÖÐËùÓÐÐмǼ¡£
ÔÚHBaseÖУ¬row key¿ÉÒÔÊÇÈÎÒâ×Ö·û´®£¬×î´ó³¤¶È64KB£¬Êµ¼ÊÓ¦ÓÃÖÐÒ»°ãΪ10~100bytes£¬´æΪbyte[]×Ö½ÚÊý×飬һ°ãÉè¼Æ³É¶¨³¤µÄ¡£
row keyÊÇ°´ÕÕ×ÖµäÐò´æ´¢£¬Òò´Ë£¬Éè¼Ærow keyʱ£¬Òª³ä·ÖÀûÓÃÕâ¸öÅÅÐòÌص㣬½«¾­³£Ò»Æð¶ÁÈ¡µÄÊý¾Ý´æ´¢µ½Ò»¿é£¬½«×î½ü¿ÉÄܻᱻ·ÃÎʵÄÊý¾Ý·ÅÔÚÒ»¿é¡£
¾Ù¸öÀý×Ó£ºÈç¹û×î½üдÈëHBase±íÖеÄÊý¾ÝÊÇ×î¿ÉÄܱ»·ÃÎʵģ¬¿ÉÒÔ¿¼Âǽ«Ê±¼ä´Á×÷Ϊrow keyµÄÒ»²¿·Ö£¬ÓÉÓÚÊÇ×ÖµäÐòÅÅÐò£¬ËùÒÔ¿ÉÒÔʹÓÃLong.MAX_VALUE - timestamp×÷Ϊrow key£¬ÕâÑùÄܱ£Ö¤ÐÂдÈëµÄÊý¾ÝÔÚ¶Áȡʱ¿ÉÒÔ±»¿ìËÙÃüÖС£
1.3 Column Family
²»ÒªÔÚÒ»ÕűíÀﶨÒåÌ«¶àµÄcolumn family¡£Ä¿Ç°Hbase²¢²»ÄܺܺõĴ¦Àí³¬¹ý2~3¸öcolumn familyµÄ±í¡£ÒòΪij¸öcolumn familyÔÚflushµÄʱºò£¬ËüÁÚ½üµÄcolumn familyÒ²»áÒò¹ØÁªÐ§Ó¦±»´¥·¢flush£¬×îÖÕµ¼ÖÂϵͳ²úÉú¸ü¶àµÄI/O¡£¸ÐÐËȤµÄͬѧ¿ÉÒÔ¶Ô×Ô¼ºµÄHBase¼¯Èº½øÐÐʵ¼Ê²âÊÔ£¬´ÓµÃµ½µÄ²âÊÔ½á¹ûÊý¾ÝÑé֤һϡ£
1.4 In Memory
´´½¨±íµÄʱºò£¬¿ÉÒÔͨ¹ýHColumnDescriptor.setInMemory(true)½«±í·Åµ½RegionServerµÄ»º´æÖУ¬±£Ö¤ÔÚ¶ÁÈ¡µÄʱºò±»cacheÃüÖС£
1.5 Max Version
´´½¨±íµÄʱºò£¬¿ÉÒÔͨ¹ýHColumnDescriptor.setMaxVersions(int maxVersions)ÉèÖñíÖÐÊý¾ÝµÄ×î´ó°æ±¾£¬Èç¹ûÖ»ÐèÒª±£´æ×îа汾µÄÊý¾Ý£¬ÄÇô¿ÉÒÔÉèÖÃsetMaxVersions(1)¡£
1.6 Time To Live
´´½¨±íµÄʱºò£¬¿ÉÒÔͨ¹ýHColumnDescriptor.setTimeToLive(int timeToLive)ÉèÖñíÖÐÊý¾ÝµÄ´æ´¢ÉúÃüÆÚ£¬¹ýÆÚÊý¾Ý½«×Ô¶¯±»É¾³ý£¬ÀýÈçÈç¹ûÖ»ÐèÒª´æ´¢×î½üÁ½ÌìµÄÊý¾Ý£¬ÄÇô¿ÉÒÔÉèÖÃsetTimeToLive(2 * 24 * 60 * 60)¡£
1.7 Compact & Split
ÔÚHBaseÖУ¬Êý¾ÝÔÚ¸üÐÂʱÊ×ÏÈдÈëWAL ÈÕÖ¾(HLog)ºÍÄÚ´æ(MemStore)ÖУ¬MemStoreÖеÄÊý¾ÝÊÇÅÅÐòµÄ£¬µ±MemStoreÀۼƵ½Ò»¶¨ãÐֵʱ£¬¾Í»á´´½¨Ò»¸öеÄMemStore£¬²¢ÇÒ½«ÀϵÄMemStoreÌí¼Óµ½flush¶ÓÁУ¬Óɵ¥¶ÀµÄÏß³Ìflushµ½´ÅÅÌÉÏ£¬³ÉΪһ¸öStoreFile¡£ÓÚ´Ëͬʱ£¬ ϵͳ»áÔÚzookeeperÖмǼһ¸öredo point£¬±íʾÕâ¸öʱ¿Ì֮ǰµÄ±ä¸üÒѾ­³Ö¾Ã»¯ÁË(minor compact)¡£
StoreFileÊÇÖ»¶ÁµÄ£¬Ò»µ©´´½¨ºó¾Í²»¿ÉÒÔÔÙÐ޸ġ£Òò´ËHbaseµÄ¸üÐÂÆäʵÊDz»¶Ï×·¼ÓµÄ²Ù×÷¡£µ±Ò»¸öStoreÖеÄStoreFile´ïµ½Ò»¶¨µÄãÐÖµºó£¬¾Í»á½øÐÐÒ»´ÎºÏ²¢(major compact)£¬½«¶Ôͬһ¸ökeyµÄÐ޸ĺϲ¢µ½Ò»Æð£¬ÐγÉÒ»¸ö´óµÄStoreFile£¬µ±StoreFileµÄ´óС´ïµ½Ò»¶¨ãÐÖµºó£¬ÓÖ»á¶Ô StoreFile½øÐзָî(split)£¬µÈ·ÖΪÁ½¸öStoreFile¡£
ÓÉÓÚ¶Ô±íµÄ¸üÐÂÊDz»¶Ï×·¼ÓµÄ£¬´¦Àí¶ÁÇëÇóʱ£¬ÐèÒª·ÃÎÊStoreÖÐÈ«²¿µÄStoreFileºÍMemStore£¬½«ËüÃÇ°´ÕÕrow key½øÐкϲ¢£¬ÓÉÓÚStoreFileºÍMemStore¶¼ÊǾ­¹ýÅÅÐòµÄ£¬²¢ÇÒStoreFile´øÓÐÄÚ´æÖÐË÷Òý£¬Í¨³£ºÏ²¢¹ý³Ì»¹ÊDZȽϿìµÄ¡£
ʵ¼ÊÓ¦ÓÃÖУ¬¿ÉÒÔ¿¼ÂDZØҪʱÊÖ¶¯½øÐÐmajor compact£¬½«Í¬Ò»¸örow keyµÄÐ޸ĽøÐкϲ¢ÐγÉÒ»¸ö´óµÄStoreFile¡£Í¬Ê±£¬¿ÉÒÔ½«StoreFileÉèÖôóЩ£¬¼õÉÙsplitµÄ·¢Éú¡£










ÒÑÓÐ(10)ÈËÆÀÂÛ

Ìøתµ½Ö¸¶¨Â¥²ã
hadoopСÏó ·¢±íÓÚ 2014-5-28 11:00:23
rowkeyÈç¹ûÊÇÓÐÐòµÄ»°£¬»á½«Êý¾Ý´æ´¢µ½Ò»¸öserverÖУ¬ÄÇôÆäËûserver¾Í»áÏÐÏÂÀ´£¬ÄÇÕâ²»ÊÇhadoopºÜ¼É»äµÄÂð
»Ø¸´

ʹÓõÀ¾ß ¾Ù±¨

sstutu ·¢±íÓÚ 2014-5-29 11:02:17
hadoopСÏó ·¢±íÓÚ 2014-5-28 11:00
rowkeyÈç¹ûÊÇÓÐÐòµÄ»°£¬»á½«Êý¾Ý´æ´¢µ½Ò»¸öserverÖУ¬ÄÇôÆäËûserver¾Í»áÏÐÏÂÀ´£¬ÄÇÕâ²»ÊÇhadoopºÜ¼É»äµÄÂð

Êý¾Ý¿ÉÒÔÊÇÓÐÐòµÄ£¬µ«ÊÇÄã¿ÉÒÔ´òÂÒËûÃǵÄÅŲ¼¡£
»Ø¸´

ʹÓõÀ¾ß ¾Ù±¨

hadoopСÏó ·¢±íÓÚ 2014-5-29 13:18:32
sstutu ·¢±íÓÚ 2014-5-29 11:02
Êý¾Ý¿ÉÒÔÊÇÓÐÐòµÄ£¬µ«ÊÇÄã¿ÉÒÔ´òÂÒËûÃǵÄÅŲ¼¡£

Ŷ£¬ÈçºÎ´òÂÒËûÃǵÄÅŲ¼
»Ø¸´

ʹÓõÀ¾ß ¾Ù±¨

wpf0909 ·¢±íÓÚ 2014-5-29 13:48:47
ѧϰеĶ«¶«£¬ºÜ²»ÈÝÒ×Ŷ
»Ø¸´

ʹÓõÀ¾ß ¾Ù±¨

sstutu ·¢±íÓÚ 2014-5-29 23:22:22
hadoopСÏó ·¢±íÓÚ 2014-5-29 13:18
Ŷ£¬ÈçºÎ´òÂÒËûÃǵÄÅŲ¼
Äã˵µÄrowkey£¬¸úÎÒ˵µÄ²»Ì«Ò»Ñù¡£´òÂҵķ½Ê½ÓкܶàÖС£

¶Ôʱ¼äÐòµÄkey£¬µ¼Ö¼¯Öе¥µ÷µÄke£¬¶¼²Ù×÷Ò»¸öregionµÄÎÊÌ⣺
1.¿ÉÒÔÔö¼Óprefixkey£¬ÈçrowkeyÇ°¼ÓÉÏ£¨time%<number of Server>£©Ê±¼ä¶Ô»ú×ÓÊýÈ¡Ä£µÄÖµ£¬0myrowkey£¬1myrowkey¡£
2.½«Ê±¼äÉú³ÉËæ»úÊýMD5£¨time£©


»Ø¸´

ʹÓõÀ¾ß ¾Ù±¨

sstutu ·¢±íÓÚ 2014-5-29 23:23:34
ÏÂÃæµÄÄÚÈÝ£¬Äã¿ÉÒԲο¼£º


HBaseģʽÉè¼ÆÖ®ID˳ÐòÔö³¤£¨rowkey˳ÐòÔö³¤£©

   ÔÚÉè¼ÆRowKeyµÄʱºò£¬³£³£ÓÐÓ¦ÓõÄRowKey±ØÐë°üº¬ID²¿·Ö£¬ÕâÑù²Å¿ÉÒÔÖ§³Ö²éѯ·ÃÎÊ¡£µ«ID×ÔÔö³¤£¬»áµ¼ÖÂдÈëÊý¾ÝµÄʱºòѹÁ¦¼¯ÖÐÔÚijһ¸ö»òÉÙÊý¼¸¸öRegionÉÏ£¬ÕâÊÇHBaseÉè¼ÆµÄ´ó¼É¡£

   ¾­¹ý¶à¸öÓ¦ÓõÄʵ¼ù£¬ÎÒ´´ÔìÁËIDµÄ¶þ½øÖÆ·´×ªµÄ·½Ê½À´±ÜÃâ¡£

   ¼òµ¥ËµÃ÷: ±ÈÈçIDÊÇByteÐÍ(Ò»°ãΪint»òÕßlong£¬´Ë´¦Îª·½±ã½âÊÍ)£¬RowKey=ID+timestamp£¬1,2,3,4¡­¡­ÕâÑùÔö³¤£¬¶ÔÓ¦¶þ½øÖÆΪ0000 0001£¬0000 0010£¬0000 0011,0000 0100¡­¡­£¬ÒòΪǰÃæµÄbitÊDz»»á±ä»¯µÄ£¬ËùÒÔÒÔIDΪRowKey£¨»òÕßID´òÍ·£©µÄÊý¾ÝдÈëµÄʱºò»á¼¯ÖÐÔÚÒ»¸öregionÉÏ£¬È»ºóÓÖ¼¯ÖÐÔÚÏÂÒ»¸öregionÉÏ¡£Îª´Ë½«±ä»¯µÄ²¿·Ö·Åµ½RowKeyµÄÇ°Ã棬À´·ÖɢдÈëµÄѹÁ¦¡£Ç°ÃæµÄÔö³¤ÔÚRowKeyµÄIDÉϾͱä³É1000 0000£¬ 0100 0000£¬ 1100 0000£¬0010 0000¡­¡­ÎÒÃÇÔ¤·ÖÇø£¬¼ÙÈçÐèÒª16-1¸ö·ÖÇø£¬¾Í¿ÉÒÔ·ÖΪ[,0x01)£¬[0x01,0x02),[0x02,0x03)¡­¡­[0xFE,0xFF), [0xFF,)£¬×¢ÒâËãһϣ¬ÕâÑù£¬1,2,3,4¡­¡­¾Í»áдµ½²»Í¬µÄÇø¼äÉÏ£¬´Ó¶ø·ÖÉ¢µ½²»Í¬µÄregionÁË¡££¨ÌáÐÑ£ºÎªÊ²Ã´Ö»ÄÃID˵Ê£¬²»¿¼ÂÇtimestampÄØ£¬ÒòΪHBaseµÄRowKeyʱ×Ö½ÚÂë±È½ÏµÄ£¬ÏÈ´Ó¸ßλ¿ªÊ¼£¬¸ßλ·Ö³öʤ¸º£¬ºóÃæ¾Í²»careÁË~£©

Óŵ㣺ת˳ÐòΪ·ÖÉ¢£¬¾ùºâ¼¯ÈºÑ¹Á¦£»¿ÉÒÔ×öµ½Ô¤·ÖÇø£»²»ÓÃhash£¬²»Óÿ¼ÂÇIDµÄhashÅöײ£¬´Ó¶ø½ÚÔ¼´æ´¢¿Õ¼ä£»
ÏÞÖÆ£ºscanÖ»ÄÜÔÚͬһID´òÍ·µÄrowkeyÄÚ½øÐУ¬Á¬ÐøIDµÄscan²»ÄÜÖ±½ÓÖ§³Ö£¬ÐèÒª³ÌÐòÂß¼­´¦Àí¡£

»Ø¸´

ʹÓõÀ¾ß ¾Ù±¨

СС²¼Ò ·¢±íÓÚ 2014-7-18 18:42:39
sstutu ·¢±íÓÚ 2014-5-29 23:23
ÏÂÃæµÄÄÚÈÝ£¬Äã¿ÉÒԲο¼£º

ÎÒ·¢ÏÖÕâÀï½²µÄÌ«ºÃÁË£¬¶ÔÓÚûÓÐʵ¼ùµÄÎÒÀ´Ëµ£¬Ñ§µÄÊÇ˼Ïë
»Ø¸´

ʹÓõÀ¾ß ¾Ù±¨

tang ·¢±íÓÚ 2015-6-10 21:17:25
»Ø¸´

ʹÓõÀ¾ß ¾Ù±¨

¹Â¶ÀµÄÕ½Éñ ·¢±íÓÚ 2015-11-18 15:31:06
ÐÂÊÖŬÁ¦Ñ§Ï°ÖÐ
»Ø¸´

ʹÓõÀ¾ß ¾Ù±¨

12ÏÂÒ»Ò³
ÄúÐèÒªµÇ¼ºó²Å¿ÉÒÔ»ØÌû µÇ¼ | Á¢¼´×¢²á

±¾°æ»ý·Ö¹æÔò

¹Ø±Õ

ÍƼöÉÏÒ»Ìõ /2 ÏÂÒ»Ìõ