{"id":150,"date":"2023-12-20T11:51:20","date_gmt":"2023-12-20T03:51:20","guid":{"rendered":"https:\/\/www.aiapaas.com\/?p=150"},"modified":"2023-12-20T11:52:39","modified_gmt":"2023-12-20T03:52:39","slug":"hbase2-0-in-memory-compaction","status":"publish","type":"post","link":"https:\/\/www.aiapaas.com\/index.php\/2023\/12\/20\/hbase2-0-in-memory-compaction\/","title":{"rendered":"HBase2 0 In-Memory Compaction"},"content":{"rendered":"<h1><\/h1>\n<h1>\u539f\u7406<\/h1>\n<p>HBase 2.0\u5f15\u5165\u4e86\u4e00\u9879\u65b0\u7684\u7279\u6027\u5185\u5b58\u538b\u7f29\uff08<strong><strong>In-Memory Compaction<\/strong><\/strong>\uff09\uff0c\u57fa\u4e8eAccordion\u7b97\u6cd5\u5b9e\u73b0\u3002<\/p>\n<p>Accordion\u91cd\u65b0\u5e94\u7528\u4e86LSM\u8bbe\u8ba1\u539f\u5219\uff08Log-Structured-Merge Tree\uff0cHBase\u57fa\u4e8eMemStore\u7684\u8bbe\u8ba1\u6a21\u5f0f\uff09\u3002<\/p>\n<p>HBase\u6570\u636e\u7684\u4fee\u6539\u90fd\u4f1a\u5199\u5165\u5230\u4e00\u4e2aMemStore\uff08\u6bcf\u4e2a\u5217\u65cf\u6709\u4e00\u4e2aMemStore\uff09\uff0c\u5f53MemStore\u6570\u636e\u91cf\u8fbe\u5230\u966a\u7740\u7684\u9608\u503c\u6216\u8005\u89e6\u53d1\u4e86\u5176\u4ed6\u5237\u65b0\u6761\u4ef6\uff0cMemStore\u4f1a\u88ab\u5237\u65b0\u5230\u78c1\u76d8\uff0c\u4ece\u800c\u521b\u5efa\u4e00\u4e2aStoreFile\uff0cStoreFile\u662f\u987a\u5e8f\u5199\u5165\uff0c\u5199\u5165\u4ee5\u540e\u4e5f\u4e0d\u80fd\u88ab\u53d8\u66f4\uff0c\u6240\u4ee5LSM\u901a\u8fc7\u5c06\u6570\u636e\u5199\u5165\u4ece\u78c1\u76d8\u7684\u968f\u673a\u5199\u5165\u8f6c\u6362\u4e3a\u5185\u5b58\u7684\u968f\u673a\u5199\u5165\u52a0\u4e0a\u78c1\u76d8\u7684\u987a\u5e8f\u5199\u5165\u6765\u63d0\u5347\u6027\u80fd\u3002<br \/>\n\u4f46\u662f\u8fd9\u6837\u4e5f\u4f1a\u5e26\u6765\u4e00\u4e2a\u6570\u636e\u7684\u591a\u7248\u672c\u95ee\u9898\uff0c\u540c\u4e00\u884c\u6570\u636e\u591a\u6b21\u4fee\u6539\u540e\uff0c\u53ef\u80fd\u4f1a\u5b58\u5728\u4e8e\u591a\u4e2aStoreFile\u6587\u4ef6\u4e2d\uff0c\u6240\u4ee5HBase\u8bfb\u53d6\u6570\u636e\u7684\u65f6\u5019\uff0c\u9700\u8981\u626b\u63cfMemStore\u8ddf\u591a\u4e2aStoreFile\u6765\u7efc\u5408\u67e5\u8be2\u5230\u8fd9\u884c\u6570\u636e\u7684\u6700\u65b0\u7248\u672c\uff0c\u4e3a\u4e86\u51cf\u5c11\u9700\u8981\u8bfb\u53d6\u7684\u6570\u636e\u7248\u672c\u6570\u4ee5\u53ca\u78c1\u76d8\u8bbf\u95ee\u6b21\u6570\uff0cHBase\u5728\u540e\u53f0\u8fdb\u884cCompact\u538b\u7f29\u5408\u5e76StoreFile\u6587\u4ef6\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u4f1a\u6e05\u7406\u8fc7\u671f\u3001\u5220\u9664\u7684\u6570\u636e\uff0c\u5e76\u5c06\u591a\u4e2aStoreFile\u5408\u5e76\u6210\u4e00\u4e2a\u5927\u7684StoreFile\u3002<\/p>\n<p>Accordion\u7b97\u6cd5\u5c06LSM\u539f\u7406\u91cd\u65b0\u5e94\u7528\u4e8eMemStore\uff0c\u4ee5\u4fbf\u5728\u6570\u636e\u4ecd\u5728RAM\u4e2d\u65f6\u4fbf\u53ef\u4ee5\u6d88\u9664\u8fc7\u671f\u8ddf\u5197\u4f59\u6570\u636e\u3002\u5185\u5b58\u538b\u7f29\u53ef\u4ee5\u964d\u4f4e\u6570\u636e\u5237\u65b0\u5230HDFS\u7684\u9891\u7387\uff0c\u4ece\u800c\u51cf\u5c11\u5199\u5165\u653e\u5927\uff08LSM\u5237\u65b0\u5230\u78c1\u76d8\u4ea7\u751f\u7684StoreFile\u6587\u4ef6\u4f1a\u6709\u591a\u8f6e\u5408\u5e76\uff0c\u6570\u636e\u7684\u591a\u6b21\u5408\u5e76\u4f1a\u5bfc\u81f4\u6570\u636e\u7684\u591a\u6b21\u8bfb\u53d6\u3001\u5408\u5e76\u3001\u5199\u5165\u5230\u5927\u6587\u4ef6\uff0c\u79f0\u4e4b\u4e3a\u5199\u5165\u653e\u5927\uff09\u548c\u6574\u4e2a\u78c1\u76d8\u5360\u7528\u7a7a\u95f4\u3002\u7531\u4e8e\u5237\u65b0\u6b21\u6570\u8f83\u5c11\uff0c\u56e0\u6b64MemStore\u6ea2\u51fa\u65f6\u5199\u5165\u64cd\u4f5c\u505c\u6b62\u7684\u9891\u7387\u964d\u4f4e\uff0c\u56e0\u6b64\u5199\u5165\u6027\u80fd\u5f97\u5230\u6539\u5584\u3002\u78c1\u76d8\u4e0a\u7684\u6570\u636e\u8d8a\u5c11\uff0c\u5bf9\u5757\u7f13\u5b58\u7684\u538b\u529b\u8d8a\u5c0f\uff0c\u547d\u4e2d\u7387\u8d8a\u9ad8\uff0c\u6700\u7ec8\u8bfb\u53d6\u54cd\u5e94\u65f6\u95f4\u8d8a\u5feb\u3002\u6700\u540e\uff0c\u51cf\u5c11\u78c1\u76d8\u5199\u5165\u4e5f\u610f\u5473\u7740\u5728\u540e\u53f0\u6267\u884c\u7684\u538b\u7f29\u66f4\u5c11\uff0c\u5373\u4ece\u751f\u4ea7\uff08\u8bfb\u53d6\u548c\u5199\u5165\uff09\u5de5\u4f5c\u4e2d\u7a83\u53d6\u7684\u5468\u671f\u66f4\u5c11\u3002\u603b\u800c\u8a00\u4e4b\uff0c\u5185\u5b58\u538b\u7f29\u7684\u6548\u679c\u53ef\u4ee5\u88ab\u8bbe\u60f3\u4e3a\u50ac\u5316\u5242\uff0c\u4f7f\u7cfb\u7edf\u6574\u4f53\u4e0a\u54cd\u5e94\u5f97\u66f4\u5feb\u3002<\/p>\n<p>\u5185\u5b58\u538b\u7f29\u5728\u5927\u91cf\u6570\u636e\u6d41\u5931\u65f6\u6548\u679c\u6700\u4f73\uff1b\u5f53\u6570\u636e\u4ecd\u5728\u5185\u5b58\u4e2d\u65f6\uff0c\u53ef\u4ee5\u6d88\u9664\u8986\u76d6\u6216\u8fc7\u671f\u7248\u672c\u3002\u5982\u679c\u5199\u5165\u90fd\u662f\u552f\u4e00\u7684\uff0c\u5219\u53ef\u80fd\u4f1a\u964d\u4f4e\u5199\u5165\u541e\u5410\u91cf\uff08\u5185\u5b58\u4e2d\u538b\u7f29\u4f7f\u7528CPU\u7684\u6210\u672c\uff09\u3002\u6240\u4ee5\u4f7f\u7528\u4e4b\u524d\u9700\u8981\u8bc4\u4f30\u4e1a\u52a1\u573a\u666f\u5e76\u8fdb\u884c\u6d4b\u8bd5\u3002<\/p>\n<p>HBase2.0\u5f15\u5165\u7684CompactingMemStore\u5373\u4e3a\u5185\u5b58\u538b\u7f29\u7684\u5b9e\u73b0\u7c7b\uff1a<\/p>\n<p>\u5728CompactingMemStore\u4e2d\uff0c\u6570\u636e\u662f\u4ee5\u6bb5\uff08Segment\uff09\u4e3a\u5355\u4f4d\u5b58\u50a8\u6570\u636e\u7684\u3002CompactingMemStore\u5305\u542b\u4e86\u4e00\u4e2aCompactionPipeline\uff0cCompactionPipeline\u5305\u542b\u4e86\u591a\u4e2a\u4e0d\u53ef\u53d8\u7684Segment\u3002<br \/>\n\u5f53\u6570\u636e\u5199\u5165\u65f6\uff0c\u9996\u5148\u5199\u5165\u5230\u7684\u662fActive Segment\u4e2d<br \/>\n\u5982\u679c\u6ca1\u6709\u542f\u7528\u5185\u5b58\u538b\u7f29\uff0c\u5f53MemStore\u4e2d\u7684\u6570\u636e\u91cf\u8fbe\u5230\u6307\u5b9a\u7684\u9608\u503c\u65f6\uff0c\u5c31\u4f1a\u5c06\u6570\u636e\u5237\u65b0\u8f93\u51fa\u5230\u78c1\u76d8\u4e2d\u7684\u4e00\u4e2aStoreFile<br \/>\n\u5982\u679c\u542f\u7528\u4e86\u5185\u5b58\u538b\u7f29\uff0c\u5f53Active Segment\u6ee1\u4e86\u540e\uff0c\u4f1a\u5c06Segment\u79fb\u52a8\u5230CompactionPipeline\u4e2d\uff0c\u5185\u5b58\u538b\u7f29\u4f1a\u7ba1\u7406\u8fd9\u4e2aCompactionPipeline\uff0c\u5c06CompactionPipeline\u4e2d\u7684\u591a\u4e2aSegment\u5408\u5e76\u4e3a\u66f4\u5927\u7684\u3001\u66f4\u7d27\u51d1\u7684Segment\uff0c\u8fd9\u5c31\u662fIn-Memory Compaction<\/p>\n<h1>\u5982\u4f55\u4f7f\u7528<\/h1>\n<p>In-Memory Compaction\u53ef\u4ee5\u5168\u5c40\u914d\u7f6e\uff0c\u4e5f\u53ef\u4ee5\u6309\u5217\u65cf\u914d\u7f6e\u3002 \u652f\u6301\u7684\u7ea7\u522b\u4e3aNONE\u3001BASIC\u3001EAGER\u3001ADAPTIVE\uff1a<\/p>\n<pre><code class=\"language-xml\">public enum MemoryCompactionPolicy {\n  \/**\n   * No memory compaction, when size threshold is exceeded data is flushed to disk\n   *\/\n  NONE,\n  \/**\n   * Basic policy applies optimizations which modify the index to a more compacted representation.\n   * This is beneficial in all access patterns. The smaller the cells are the greater the benefit of\n   * this policy. This is the default policy.\n   *\/\n  BASIC,\n  \/**\n   * In addition to compacting the index representation as the basic policy, eager policy eliminates\n   * duplication while the data is still in memory (much like the on-disk compaction does after the\n   * data is flushed to disk). This policy is most useful for applications with high data churn or\n   * small working sets.\n   *\/\n  EAGER,\n  \/**\n   * Adaptive compaction adapts to the workload. It applies either index compaction or data\n   * compaction based on the ratio of duplicate cells in the data.\n   *\/\n  ADAPTIVE\n\n}<\/code><\/pre>\n<ul>\n<li>BASIC\uff1a \u8be5\u7b56\u7565\u4e0d\u6e05\u7406\u591a\u4f59\u7684\u6570\u636e\u7248\u672c\uff0c\u5c06\u6570\u636e\u7d22\u5f15\u4fee\u6539\u4e3a\u4e00\u4e2a\u66f4\u52a0\u7d27\u51d1\u7684\u89c6\u7ebf\uff0c\u5728\u6240\u6709\u7684\u8bfb\u5199\u6a21\u5f0f\u4e0b\u90fd\u80fd\u591f\u5e26\u6765\u6536\u76ca\uff0c\u5355\u5143\u683c\u8d8a\u5c0f\u6536\u76ca\u8d8a\u660e\u663e\u3002<\/li>\n<li>EAGER\uff1a\u8be5\u7b56\u7565\u4f1a\u8fc7\u6ee4\u91cd\u590d\u7684\u6570\u636e\uff0c\u6e05\u7406\u591a\u4f59\u7684\u7248\u672c\uff0c\u7c7b\u4f3c\u4e8eLSM\u5bf9StoreFile\u505a\u7684\u5408\u5e76\u5904\u7406\u903b\u8f91\uff0c\u8be5\u6a21\u5f0f\u9002\u7528\u4e8e\u6570\u636e\u66f4\u65b0\u9891\u7e41\u6216\u5de5\u4f5c\u96c6\u8f83\u5c0f\u7684\u573a\u666f\u3002<\/li>\n<li>ADAPTIVE\uff1a\u6839\u636e\u6570\u636eCell\u7684\u91cd\u590d\u60c5\u51b5\u6765\u51b3\u5b9a\u662f\u5426\u4f7f\u7528Eager\u7b56\u7565\uff0c\u8be5\u7b56\u7565\u8ba1\u7b97\u91cd\u590dCell\u7684\u6bd4\u5217\uff0c\u5982\u679c\u6bd4\u4f8b\u8d85\u51fa\u9608\u503c\uff0c\u5219\u4f7f\u7528Eager\u7b56\u7565\uff0c\u5426\u5219\u4f7f\u7528Basic\u7b56\u7565<\/li>\n<\/ul>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0bHBase\u4e0d\u542f\u7528\u5185\u5b58\u538b\u7f29\u3002 \u53ef\u4ee5\u5728hbase-site.xml\u4e2d\u5168\u5c40\u914d\u7f6e\uff0c\u914d\u7f6e\u540e\u4f1a\u5bf9\u65b0\u5efa\u7684\u8868\u751f\u6548\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre><code class=\"language-xml\">&lt;property&gt;\n    &lt;name&gt;hbase.hregion.compacting.memstore.type&lt;\/name&gt;\n    &lt;value&gt;&lt; NONE | BASIC | EAGER | ADAPTIVE&gt;&lt;\/value&gt;\n&lt;\/property&gt;<\/code><\/pre>\n<p>\u4e5f\u53ef\u4ee5\u5728HBase Shell\u4e2d\u6309\u5217\u65cf\u914d\u7f6e\u7ea7\u522b\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre><code class=\"language-xml\">### \u4fee\u6539\u5df2\u6709\u8868\nhbase:077:0&gt; desc 'test'\nTable test is ENABLED\ntest, {TABLE_ATTRIBUTES =&gt; {METADATA =&gt; {'hbase.store.file-tracker.impl' =&gt; 'DEFAULT'}}}\nCOLUMN FAMILIES DESCRIPTION\n{NAME =&gt; 'cf', INDEX_BLOCK_ENCODING =&gt; 'NONE', VERSIONS =&gt; '1', KEEP_DELETED_CELLS =&gt; 'FALSE', DATA_BLOCK_ENCODING =&gt; 'NONE', TTL =&gt; 'FOREVER', MIN_VERSIONS =&gt; '0', REPLICATION_SCOPE =&gt; '0', BLOOMFILTER =&gt; 'ROW',\nIN_MEMORY =&gt; 'false', COMPRESSION =&gt; 'NONE', BLOCKCACHE =&gt; 'true', BLOCKSIZE =&gt; '65536 B (64KB)'}\n\n1 row(s)\nQuota is disabled\nTook 10.2678 seconds\nhbase:078:0&gt; disable 'test'\nTook 0.6925 seconds\nhbase:079:0&gt; alter 'test', {NAME =&gt; 'cf', IN_MEMORY_COMPACTION =&gt; 'BASIC'}\nUpdating all regions with the new schema...\nAll regions updated.\nDone.\nTook 1.1548 seconds\nhbase:080:0&gt; desc 'test'\nTable test is DISABLED\ntest, {TABLE_ATTRIBUTES =&gt; {METADATA =&gt; {'hbase.store.file-tracker.impl' =&gt; 'DEFAULT'}}}\nCOLUMN FAMILIES DESCRIPTION\n{NAME =&gt; 'cf', INDEX_BLOCK_ENCODING =&gt; 'NONE', VERSIONS =&gt; '1', KEEP_DELETED_CELLS =&gt; 'FALSE', DATA_BLOCK_ENCODING =&gt; 'NONE', TTL =&gt; 'FOREVER', MIN_VERSIONS =&gt; '0', REPLICATION_SCOPE =&gt; '0', BLOOMFILTER =&gt; 'ROW',\nIN_MEMORY =&gt; 'false', COMPRESSION =&gt; 'NONE', BLOCKCACHE =&gt; 'true', BLOCKSIZE =&gt; '65536 B (64KB)', METADATA =&gt; {'IN_MEMORY_COMPACTION' =&gt; 'BASIC'}}\n\n1 row(s)\nQuota is disabled\nTook 0.0424 seconds\nhbase:081:0&gt; enable 'test'\nTook 0.7040 seconds<\/code><\/pre>\n<pre><code class=\"language-xml\">### \u65b0\u5efa\u8868\nhbase:082:0&gt; create 'test2', {NAME =&gt; 'cf', IN_MEMORY_COMPACTION =&gt; 'EAGER'}\nCreated table test2\nTook 0.7031 seconds\n=&gt; Hbase::Table - test2\nhbase:083:0&gt; desc 'test2'\nTable test2 is ENABLED\ntest2, {TABLE_ATTRIBUTES =&gt; {METADATA =&gt; {'hbase.store.file-tracker.impl' =&gt; 'DEFAULT'}}}\nCOLUMN FAMILIES DESCRIPTION\n{NAME =&gt; 'cf', INDEX_BLOCK_ENCODING =&gt; 'NONE', VERSIONS =&gt; '1', KEEP_DELETED_CELLS =&gt; 'FALSE', DATA_BLOCK_ENCODING =&gt; 'NONE', TTL =&gt; 'FOREVER', MIN_VERSIONS =&gt; '0', REPLICATION_SCOPE =&gt; '0', BLOOMFILTER =&gt; 'ROW',\nIN_MEMORY =&gt; 'false', COMPRESSION =&gt; 'NONE', BLOCKCACHE =&gt; 'true', BLOCKSIZE =&gt; '65536 B (64KB)', METADATA =&gt; {'IN_MEMORY_COMPACTION' =&gt; 'EAGER'}}\n\n1 row(s)\nQuota is disabled\nTook 0.0489 seconds\nhbase:084:0&gt;<\/code><\/pre>\n<h1>\u6027\u80fd\u63d0\u5347<\/h1>\n<p>\u793e\u533a\u7684\u535a\u5ba2\u4e2d\u7ed9\u51fa\u4e86\u4e24\u4e2a\u4e0d\u540c\u573a\u666f\u7684\u6d4b\u8bd5\u7ed3\u679c\u3002<br \/>\n\u4f7f\u7528YCSB\u6d4b\u8bd5\u5de5\u5177\uff0c100-200GB\u6570\u636e\u96c6\u3002<br \/>\n\u5206\u522b\u5728key\u70ed\u5ea6\u7b26\u5408Zipf\u5206\u5e03\u548c\u5e73\u5747\u5206\u5e03\u4e24\u79cd\u60c5\u51b5\u4e0b\uff0c\u6d4b\u8bd5\u4e86\u53ea\u6709\u5199\u64cd\u4f5c\u60c5\u51b5\u4e0b\u5199\u653e\u5927\u3001\u541e\u5410\u3001GC\u76f8\u6bd4\u9ed8\u8ba4Memstore\u7684\u53d8\u5316\uff0c\u4ee5\u53ca\u8bfb\u5199\u5404\u536050%\u60c5\u51b5\u4e0b\u5c3e\u90e8\u8bfb\u5ef6\u65f6\u7684\u53d8\u5316\u3002<br \/>\n\u6d4b\u8bd5\u7ed3\u679c\u5982\u4e0b\u8868:<\/p>\n<table>\n<thead>\n<tr>\n<th>Key\u70ed\u5ea6\u5206\u5e03<\/th>\n<th>\u5199\u653e\u5927<\/th>\n<th>\u541e\u5410<\/th>\n<th>GC<\/th>\n<th>\u5c3e\u90e8\u8bfb\u5ef6\u65f6<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Zipf<\/td>\n<td>\u964d\u4f4e30%<\/td>\n<td>\u63d0\u534720%<\/td>\n<td>\u4e0b\u964d22%<\/td>\n<td>\u4e0b\u964d12%<\/td>\n<\/tr>\n<tr>\n<td>\u5e73\u5747\u5206\u5e03<\/td>\n<td>\u964d\u4f4e25%<\/td>\n<td>\u63d0\u534750%<\/td>\n<td>\u4e0b\u964d36%<\/td>\n<td>\u65e0\u53d8\u5316<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u7406 HBase 2.0\u5f15\u5165\u4e86\u4e00\u9879\u65b0\u7684\u7279\u6027\u5185\u5b58\u538b\u7f29\uff08In-Memory Compaction\uff09\uff0c\u57fa\u4e8eAccor [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-150","post","type-post","status-publish","format-standard","hentry","category-hbase"],"_links":{"self":[{"href":"https:\/\/www.aiapaas.com\/index.php\/wp-json\/wp\/v2\/posts\/150","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aiapaas.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aiapaas.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aiapaas.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aiapaas.com\/index.php\/wp-json\/wp\/v2\/comments?post=150"}],"version-history":[{"count":2,"href":"https:\/\/www.aiapaas.com\/index.php\/wp-json\/wp\/v2\/posts\/150\/revisions"}],"predecessor-version":[{"id":152,"href":"https:\/\/www.aiapaas.com\/index.php\/wp-json\/wp\/v2\/posts\/150\/revisions\/152"}],"wp:attachment":[{"href":"https:\/\/www.aiapaas.com\/index.php\/wp-json\/wp\/v2\/media?parent=150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aiapaas.com\/index.php\/wp-json\/wp\/v2\/categories?post=150"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aiapaas.com\/index.php\/wp-json\/wp\/v2\/tags?post=150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}