ÎÊÌâµ¼¶Á£º
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 £¬ÏÂÃæÊÇÒ»¸öÀý×Ó£º
- public static boolean createTable(HBaseAdmin admin, HTableDescriptor table, byte[][] splits) throws IOException { try {
- admin.createTable(table, splits); return true;
- } catch (TableExistsException e) {
- logger.info("table " + table.getNameAsString() + " already exists"); // the table already exists... return false;
- }
- } public static byte[][] getHexSplits(String startKey, String endKey, int numRegions) { byte[][] splits = new byte[numRegions-1][];
- BigInteger lowestKey = new BigInteger(startKey, 16);
- BigInteger highestKey = new BigInteger(endKey, 16);
- BigInteger range = highestKey.subtract(lowestKey);
- BigInteger regionIncrement = range.divide(BigInteger.valueOf(numRegions));
- lowestKey = lowestKey.add(regionIncrement); for(int i=0; i < numRegions-1;i++) {
- BigInteger key = lowestKey.add(regionIncrement.multiply(BigInteger.valueOf(i))); byte[] b = String.format("%016x", key).getBytes();
- splits[i] = b;
- } return splits;
- }
¸´ÖÆ´úÂë
1.2 Row KeyHBaseÖÐ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µÄ·¢Éú¡£
|