Yang, Tong 6182f91ba8 MRS component operation guide_normal 2.0.38.SP20 version
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com>
Co-authored-by: Yang, Tong <yangtong2@huawei.com>
Co-committed-by: Yang, Tong <yangtong2@huawei.com>
2022-12-09 14:55:21 +00:00

163 lines
24 KiB
HTML

<a name="mrs_01_0975"></a><a name="mrs_01_0975"></a>
<h1 class="topictitle1">Hive Supporting Transactions</h1>
<div id="body1590395285858"><div class="section" id="mrs_01_0975__section28311819102618"><h4 class="sectiontitle">Scenario</h4><p id="mrs_01_0975__p9831141962617">Hive supports transactions at the table and partition levels. When the transaction mode is enabled, transaction tables can be incrementally updated, deleted, and read, implementing atomicity, isolation, consistency, and durability of operations on transaction tables.</p>
<div class="note" id="mrs_01_0975__note835285022717"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="mrs_01_0975__p12363135052715">This section applies to MRS 3.<em id="mrs_01_0975__i10661548195911">x</em> or later clusters.</p>
</div></div>
</div>
<div class="section" id="mrs_01_0975__section88312019102612"><h4 class="sectiontitle">Introduction to Transaction Features</h4><p id="mrs_01_0975__p1783181942614">A transaction is a group of unitized operations. These operations are either executed together or not executed together. A transaction is an inseparable unit of work. The four basic elements of a transaction are usually called ACID features, which are as follows:</p>
<ul id="mrs_01_0975__ul1583112192264"><li id="mrs_01_0975__li9831819152616">Atomicity: A transaction is an inseparable unit of work. All operations in a transaction occur or do not occur together.</li></ul>
<ul id="mrs_01_0975__ul17831119202619"><li id="mrs_01_0975__li1083111193261">Consistency: The database integrity constraints are not damaged before and after a transaction starts.</li><li id="mrs_01_0975__li148314192264">Isolation: When multiple transactions are concurrently accessed, the transactions are isolated from each other. A transaction does not affect the running of other transactions. The impacts between transactions are as follows: dirty read, non-repeatable read, phantom read, and lost update.</li><li id="mrs_01_0975__li98311919122615">Durability: After a transaction is complete, changes made by the transaction lock to the database are permanently stored in the database.</li></ul>
<p id="mrs_01_0975__p6831121922610">Characteristics of transaction execution:</p>
<ul id="mrs_01_0975__ul108311119152612"><li id="mrs_01_0975__li8831219102617">A statement can be written to multiple partitions or tables. If the operation fails, the user cannot see partial write or insert. Even if data is frequently changed, operations can still be quickly performed.</li><li id="mrs_01_0975__li13831161972617">Hive can automatically compress ACID transaction files without affecting concurrent queries. When querying many small partition files, automatic compression can improve query performance and metadata occupation.</li><li id="mrs_01_0975__li11831101914269">Read semantics include snapshot isolation. When the read operation starts, the Hive data warehouse is logically locked. The read operation is not affected by any changes that occur during the operation.</li></ul>
</div>
<div class="section" id="mrs_01_0975__section6831141911260"><h4 class="sectiontitle">Lock Mechanism</h4><p id="mrs_01_0975__p16832111911268">Transactions implement the ACID feature through the following two aspects:</p>
<ul id="mrs_01_0975__ul4832619152620"><li id="mrs_01_0975__li148329197266">Write-ahead logging ensures atomicity and durability.</li><li id="mrs_01_0975__li183231932617">Locking ensures isolation.</li></ul>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="mrs_01_0975__table4832819132613" frame="border" border="1" rules="all"><thead align="left"><tr id="mrs_01_0975__row1183212196267"><th align="left" class="cellrowborder" valign="top" width="30%" id="mcps1.3.3.4.1.3.1.1"><p id="mrs_01_0975__p18832101902614">Operation</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="70%" id="mcps1.3.3.4.1.3.1.2"><p id="mrs_01_0975__p15832181912263">Type of Held Locks</p>
</th>
</tr>
</thead>
<tbody><tr id="mrs_01_0975__row12832121915265"><td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.3.4.1.3.1.1 "><p id="mrs_01_0975__p2832111916266">Insert overwrite</p>
</td>
<td class="cellrowborder" valign="top" width="70%" headers="mcps1.3.3.4.1.3.1.2 "><p id="mrs_01_0975__p8832161911267">If <strong id="mrs_01_0975__b1620013141985">hive.txn.xlock.iow</strong> is set to <strong id="mrs_01_0975__b5848125988">true</strong>, the exclusive lock is held. If <strong id="mrs_01_0975__b14230037980">hive.txn.xlock.iow</strong> is set to <strong id="mrs_01_0975__b6792114514818">false</strong>, the semi-shared lock is held.</p>
</td>
</tr>
<tr id="mrs_01_0975__row158326198269"><td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.3.4.1.3.1.1 "><p id="mrs_01_0975__p1883231962616">Insert</p>
</td>
<td class="cellrowborder" valign="top" width="70%" headers="mcps1.3.3.4.1.3.1.2 "><p id="mrs_01_0975__p12832191916266">Shared lock. When performing this operation, you can perform read and write operations on the current table or partition.</p>
</td>
</tr>
<tr id="mrs_01_0975__row383251918260"><td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.3.4.1.3.1.1 "><p id="mrs_01_0975__p383210194260">Update/delete</p>
</td>
<td class="cellrowborder" valign="top" width="70%" headers="mcps1.3.3.4.1.3.1.2 "><p id="mrs_01_0975__p2832121942613">Semi-shared lock. When this operation is performed, an operation of holding a shared lock can be performed, but an operation of holding an exclusive lock or a semi-shared lock cannot be performed.</p>
</td>
</tr>
<tr id="mrs_01_0975__row1483221917267"><td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.3.4.1.3.1.1 "><p id="mrs_01_0975__p9832191913263">Drop</p>
</td>
<td class="cellrowborder" valign="top" width="70%" headers="mcps1.3.3.4.1.3.1.2 "><p id="mrs_01_0975__p148320199261">Exclusive lock. You cannot perform any other operations on the current table or partition when performing this operation.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="note" id="mrs_01_0975__note083212191262"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="mrs_01_0975__p1483301917263">If a conflict caused by the lock mechanism exists in the write operation, the operation that preferentially holds the lock succeeds, and other operations fail.</p>
</div></div>
</div>
<div class="section" id="mrs_01_0975__section19833161942612"><h4 class="sectiontitle">Procedure</h4><p id="mrs_01_0975__p128337197268"><strong id="mrs_01_0975__b1483361910263">Starting a Transaction</strong></p>
</div>
<ol id="mrs_01_0975__ol1583351916261"><li id="mrs_01_0975__li1783391922613"><span>Log in to FusionInsight Manager. For details, see <a href="mrs_01_2124.html">Accessing FusionInsight Manager (MRS 3.x or Later)</a>. Choose <strong id="mrs_01_0975__b599513012611">Cluster</strong> &gt; <em id="mrs_01_0975__i106511161877">Name of the desired cluster</em> &gt; <strong id="mrs_01_0975__b1629101314711">Services</strong> &gt; <strong id="mrs_01_0975__b131378151714">Hive</strong> &gt; <strong id="mrs_01_0975__b74611217575">Configurations</strong> &gt; <strong id="mrs_01_0975__b749711191278">All Configurations</strong> &gt; <strong id="mrs_01_0975__b824017221720">MetaStore(Role)</strong> &gt; <strong id="mrs_01_0975__b118948246720">Transaction</strong>.</span></li><li id="mrs_01_0975__li4833151919266"><span>Set <strong id="mrs_01_0975__b1764813217715">metastore.compactor.initiator.on</strong> to <strong id="mrs_01_0975__b197991834976">true</strong>.</span></li><li id="mrs_01_0975__li483331912269"><span>Set <strong id="mrs_01_0975__b832014016710">metastore.compactor.worker.threads</strong> to a positive integer.</span><p><div class="note" id="mrs_01_0975__note11833121982613"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="mrs_01_0975__p483371913269"><strong id="mrs_01_0975__b9192127399">metastore.compactor.worker.threads</strong>: Specifies the number of working threads for running the compression program on MetaStore. Set this parameter based on the actual requirements. If the value is too small, the transaction compression task is executed slowly. If the value is too large, the MetaStore execution performance deteriorates.</p>
</div></div>
</p></li><li id="mrs_01_0975__li8833101932618"><span>Log in to the Hive client and run the following command to enable the following parameters. For details, see <a href="mrs_01_0952.html">Using a Hive Client</a>.</span><p><p id="mrs_01_0975__p13833151915265"><strong id="mrs_01_0975__b15834319202614">set hive.support.concurrency=true;</strong></p>
<p id="mrs_01_0975__p11834131911265"><strong id="mrs_01_0975__b1183481912619">set hive.exec.dynamic.partition.mode=nonstrict;</strong></p>
<p id="mrs_01_0975__p16834121982614"><strong id="mrs_01_0975__b48341819132615">set hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;</strong></p>
</p></li></ol>
<p id="mrs_01_0975__p48341719162617"><strong id="mrs_01_0975__b1063075716105">Create a transaction table.</strong></p>
<ol start="5" id="mrs_01_0975__ol1183491962620"><li id="mrs_01_0975__li983420198262"><span>Run the following command to create a transaction table:</span><p><p id="mrs_01_0975__p1883421914267"><strong id="mrs_01_0975__b78345199269">CREATE TABLE [IF NOT EXISTS] </strong><em id="mrs_01_0975__i13834191932615">[db_name.]table_name</em><strong id="mrs_01_0975__b78344191261"> (</strong><em id="mrs_01_0975__i20834919132614">col_name data_type </em><em id="mrs_01_0975__i283401962617">[COMMENT col_comment]</em><em id="mrs_01_0975__i1283411942620">, ...</em><strong id="mrs_01_0975__b1383414192266">) [ROW FORMAT row_format] STORED AS orc ...... TBLPROPERTIES ('transactional'='true'[,'groupId'='group1' ... ] );</strong></p>
<p id="mrs_01_0975__p683441914267">For example:</p>
<p id="mrs_01_0975__p383431915261"><strong id="mrs_01_0975__b98341819172615">CREATE TABLE acidTbl (a int, b int) STORED AS ORC TBLPROPERTIES ('transactional'='true');</strong></p>
<div class="note" id="mrs_01_0975__note1383481922612"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="mrs_01_0975__ul108341019142618"><li id="mrs_01_0975__li19834131982616">Currently, the transactions support only the ORC format.</li><li id="mrs_01_0975__li1983413194260">External tables are not supported.</li><li id="mrs_01_0975__li148345191260">Sorted tables are not supported.</li><li id="mrs_01_0975__li148340196265">To create a transaction table, you must add the table attribute <strong id="mrs_01_0975__b1369651131120">transactional'='true'</strong>.</li><li id="mrs_01_0975__li1383512193261">The transaction table can be read and written only in transaction mode.</li></ul>
</div></div>
</p></li></ol>
<p id="mrs_01_0975__p18835201992619"><strong id="mrs_01_0975__b14568219124">Use the transaction table.</strong></p>
<ol start="6" id="mrs_01_0975__ol18354199261"><li id="mrs_01_0975__li208351319192611"><span>Run commands to use the transaction table. The following uses the <strong id="mrs_01_0975__b2122015121220">acidTbl</strong> table as an example:</span><p><ul id="mrs_01_0975__ul158354197269"><li id="mrs_01_0975__li14835019192616">Insert data into an existing transaction table:<p id="mrs_01_0975__p138351719102615"><a name="mrs_01_0975__li14835019192616"></a><a name="li14835019192616"></a><strong id="mrs_01_0975__b6835319142611">INSERT INTO acidTbl VALUES(1,1);</strong></p>
</li><li id="mrs_01_0975__li2083591914267">Update an existing transaction table:<p id="mrs_01_0975__p38351519172614"><a name="mrs_01_0975__li2083591914267"></a><a name="li2083591914267"></a><strong id="mrs_01_0975__b683511992611">UPDATE acidTbl SET b = 10 where a = 1;</strong></p>
<p id="mrs_01_0975__p1483511952615">The content of <strong id="mrs_01_0975__b127542829551345">acidTbl</strong> is changed to:</p>
<p id="mrs_01_0975__p48351719142615"><span><img id="mrs_01_0975__image5835111972616" src="en-us_image_0000001295930456.jpg"></span></p>
</li><li id="mrs_01_0975__li9835201915260">Merge the old and new transaction tables:<p id="mrs_01_0975__p1835201952619"><a name="mrs_01_0975__li9835201915260"></a><a name="li9835201915260"></a>The <strong id="mrs_01_0975__b143342516051345">acidTbl_update</strong> table contains the following data:</p>
<p id="mrs_01_0975__p3835111972619"><span><img id="mrs_01_0975__image1383513191268" src="en-us_image_0000001296249936.jpg"></span></p>
<p id="mrs_01_0975__p2835121917262"><strong id="mrs_01_0975__b883514192267">MERGE INTO acidTbl AS a</strong></p>
<p id="mrs_01_0975__p128351319112615"><strong id="mrs_01_0975__b198351419162618">USING acidTbl_update AS b ON a.a = b.a</strong></p>
<p id="mrs_01_0975__p108351819102616"><strong id="mrs_01_0975__b78351019172618">WHEN MATCHED THEN UPDATE SET b = b. b</strong></p>
<p id="mrs_01_0975__p118351619182612"><strong id="mrs_01_0975__b16835219112614">WHEN NOT MATCHED THEN INSERT VALUES (b.a, b.b);</strong></p>
<p id="mrs_01_0975__p9835119172611">The content of <strong id="mrs_01_0975__b111284905251345">acidTbl</strong> is changed to:</p>
<p id="mrs_01_0975__p178351719132611"><span><img id="mrs_01_0975__image983561915260" src="en-us_image_0000001348770317.jpg"></span></p>
<div class="note" id="mrs_01_0975__note1147111310198"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="mrs_01_0975__p4665922121912">If "Error evaluating cardinality_violation" is displayed when you run the <strong id="mrs_01_0975__b6976133818512">merge</strong> command, check whether duplicate connection keys exist or run the <strong id="mrs_01_0975__b4411115355112">set hive.merge.cardinality.check=false</strong> command to avoid this exception.</p>
</div></div>
</li></ul>
<ul id="mrs_01_0975__ul168355198266"><li id="mrs_01_0975__li8835181912268">Delete records from the transaction table.<p id="mrs_01_0975__p158351819182611"><a name="mrs_01_0975__li8835181912268"></a><a name="li8835181912268"></a><strong id="mrs_01_0975__b48351919182610">DELETE FROM acidTbl where a = 2;</strong></p>
<p id="mrs_01_0975__p18836141912618"><span><img id="mrs_01_0975__image8836619122616" src="en-us_image_0000001349289613.jpg"></span></p>
</li></ul>
</p></li></ol>
<p id="mrs_01_0975__p168361919122617"><strong id="mrs_01_0975__b2836119182617">Checking the Transaction Execution Status</strong></p>
<ol start="7" id="mrs_01_0975__ol1836181942620"><li id="mrs_01_0975__li38362196266"><span>Run the following command to check the transaction execution status:</span><p><ul id="mrs_01_0975__ul198367192268"><li id="mrs_01_0975__li88361619112616">Check the lock:<p id="mrs_01_0975__p8836119172619"><a name="mrs_01_0975__li88361619112616"></a><a name="li88361619112616"></a><strong id="mrs_01_0975__b583691942619">show locks;</strong></p>
</li><li id="mrs_01_0975__li12836419192618">Check the compression task:<p id="mrs_01_0975__p178364196265"><a name="mrs_01_0975__li12836419192618"></a><a name="li12836419192618"></a><strong id="mrs_01_0975__b16836419132620">show compactions;</strong></p>
</li><li id="mrs_01_0975__li6836141912267"><a name="mrs_01_0975__li6836141912267"></a><a name="li6836141912267"></a>Check the task execution status:<p id="mrs_01_0975__p1683616194263"><a name="mrs_01_0975__li6836141912267"></a><a name="li6836141912267"></a><strong id="mrs_01_0975__b10836181942615">show transactions;</strong></p>
</li><li id="mrs_01_0975__li11836219192616">Interrupt a transaction:<p id="mrs_01_0975__p1836319122619"><a name="mrs_01_0975__li11836219192616"></a><a name="li11836219192616"></a><strong id="mrs_01_0975__b19836181916267">abort transaction</strong><strong id="mrs_01_0975__b966618152305">s</strong> <em id="mrs_01_0975__i3836161912619">TransactionId</em><strong id="mrs_01_0975__b12836619152613">;</strong></p>
<p id="mrs_01_0975__p51321349559"><em id="mrs_01_0975__i69420355313">TransactionId</em> is the value in the <strong id="mrs_01_0975__b615925611315">Transaction ID</strong> column in the command output of <a href="#mrs_01_0975__li6836141912267">Check the task execution status</a>.</p>
</li></ul>
</p></li></ol>
<div class="section" id="mrs_01_0975__section1283631922615"><h4 class="sectiontitle">Configuring the Compression Function</h4><p id="mrs_01_0975__p9836119192619">HDFS does not support in-place file changing. For the new content, HDFS does not provide read consistency either. To provide these features on HDFS, we follow the standard approach used in other data warehouse tools: table or partition data is stored in a set of base files, and new, updated, as well as deleted records are stored in incremental files. Each transaction creates a new set of incremental files to change the table or partition. When read, the base files and the incremental files are merged and the changes of the update or deletion are applied.</p>
</div>
<p id="mrs_01_0975__p283681918266">Writing a transaction table generates some small files in HDFS. Hive provides major and minor compression policies for combining these small files.</p>
<div class="section" id="mrs_01_0975__section295211137263"><h4 class="sectiontitle">Procedure of Automatic Compression</h4><ol id="mrs_01_0975__ol15836191992616"><li id="mrs_01_0975__li1983601992619"><span>Log in to FusionInsight Manager. For details, see <a href="mrs_01_2124.html">Accessing FusionInsight Manager (MRS 3.x or Later)</a>. Choose <strong id="mrs_01_0975__b3651213194920">Cluster</strong> &gt; <em id="mrs_01_0975__i765191334910">Name of the desired cluster</em> &gt; <strong id="mrs_01_0975__b16511313114917">Services</strong> &gt; <strong id="mrs_01_0975__b565171320496">Hive</strong> &gt; <strong id="mrs_01_0975__b10651151312496">Configurations</strong> &gt; <strong id="mrs_01_0975__b8652513194918">All Configurations</strong> &gt; <strong id="mrs_01_0975__b1165231394910">MetaStore(Role)</strong> &gt; <strong id="mrs_01_0975__b14652111324920">Transaction</strong>.</span></li><li id="mrs_01_0975__li1183691919266"><span>Set the following parameters as required:</span><p>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="mrs_01_0975__table383616195262" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Parameter description</caption><thead align="left"><tr id="mrs_01_0975__row17837119182615"><th align="left" class="cellrowborder" valign="top" width="30%" id="mcps1.3.14.2.2.2.1.2.3.1.1"><p id="mrs_01_0975__p98371819102616">Parameter</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="70%" id="mcps1.3.14.2.2.2.1.2.3.1.2"><p id="mrs_01_0975__p983715193263">Description</p>
</th>
</tr>
</thead>
<tbody><tr id="mrs_01_0975__row9837191912264"><td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.14.2.2.2.1.2.3.1.1 "><p id="mrs_01_0975__p11837101972617">hive.compactor.check.interval</p>
</td>
<td class="cellrowborder" valign="top" width="70%" headers="mcps1.3.14.2.2.2.1.2.3.1.2 "><p id="mrs_01_0975__p198371819122614">Interval of executing compression threads. Unit: second. Default value: <strong id="mrs_01_0975__b15714112052618">300</strong></p>
</td>
</tr>
<tr id="mrs_01_0975__row88378199263"><td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.14.2.2.2.1.2.3.1.1 "><p id="mrs_01_0975__p17837819112616">hive.compactor.cleaner.run.interval</p>
</td>
<td class="cellrowborder" valign="top" width="70%" headers="mcps1.3.14.2.2.2.1.2.3.1.2 "><p id="mrs_01_0975__p18837161913267">Interval of executing cleaning threads. Unit: millisecond. Default value: <strong id="mrs_01_0975__b3165172519268">5,000</strong>.</p>
</td>
</tr>
<tr id="mrs_01_0975__row7837419122613"><td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.14.2.2.2.1.2.3.1.1 "><p id="mrs_01_0975__p13837191912620">hive.compactor.delta.num.threshold</p>
</td>
<td class="cellrowborder" valign="top" width="70%" headers="mcps1.3.14.2.2.2.1.2.3.1.2 "><p id="mrs_01_0975__p78373195265">Threshold of the number of incremental files that trigger minor compression. Default value: <strong id="mrs_01_0975__b15491142812262">10</strong></p>
</td>
</tr>
<tr id="mrs_01_0975__row9837181992611"><td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.14.2.2.2.1.2.3.1.1 "><p id="mrs_01_0975__p17837121952616">hive.compactor.delta.pct.threshold</p>
</td>
<td class="cellrowborder" valign="top" width="70%" headers="mcps1.3.14.2.2.2.1.2.3.1.2 "><p id="mrs_01_0975__p483719198262">Ratio threshold of the total size of incremental files (delta) that trigger Major compression to the size of base files. The value <strong id="mrs_01_0975__b69131252181316">0.1</strong> indicates that Major compression is triggered when the ratio of the total size of delta files to the size of base files is 10%. Default value: <strong id="mrs_01_0975__b10108631181416">0.1</strong></p>
</td>
</tr>
<tr id="mrs_01_0975__row128372193261"><td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.14.2.2.2.1.2.3.1.1 "><p id="mrs_01_0975__p983711914268">hive.compactor.max.num.delta</p>
</td>
<td class="cellrowborder" valign="top" width="70%" headers="mcps1.3.14.2.2.2.1.2.3.1.2 "><p id="mrs_01_0975__p4837161982619">Maximum number of incremental files that the compressor will attempt to process in a single job. Default value: <strong id="mrs_01_0975__b201491535132615">500</strong></p>
</td>
</tr>
<tr id="mrs_01_0975__row138371119112610"><td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.14.2.2.2.1.2.3.1.1 "><p id="mrs_01_0975__p16838171942610">metastore.compactor.initiator.on</p>
</td>
<td class="cellrowborder" valign="top" width="70%" headers="mcps1.3.14.2.2.2.1.2.3.1.2 "><p id="mrs_01_0975__p1383891920269">Indicates whether to run the startup program thread and cleanup program thread on the MetaStore instance. The value must be <strong id="mrs_01_0975__b62153573256">true</strong>. Default value: <strong id="mrs_01_0975__b2374958172513">false</strong>.</p>
</td>
</tr>
<tr id="mrs_01_0975__row11838141902613"><td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.14.2.2.2.1.2.3.1.1 "><p id="mrs_01_0975__p17838131902611">metastore.compactor.worker.threads</p>
</td>
<td class="cellrowborder" valign="top" width="70%" headers="mcps1.3.14.2.2.2.1.2.3.1.2 "><p id="mrs_01_0975__p128381819192615">Number of compression program work threads running on MetaStore. If this parameter is set to <strong id="mrs_01_0975__b678010712275">0</strong>, no compression is performed. To use a transaction, you must set this parameter to a positive number on one or more instances of the MetaStore service. Unit: second Default value: <strong id="mrs_01_0975__b44521507351345">0</strong></p>
</td>
</tr>
</tbody>
</table>
</div>
</p></li><li id="mrs_01_0975__li8838111919268"><span>Log in to the Hive client and perform compression. For details, see <a href="mrs_01_0952.html">Using a Hive Client</a>.</span><p><pre class="screen" id="mrs_01_0975__screen19838819132619">CREATE TABLE table_name (
id int, name string
)
CLUSTERED BY (id) INTO 2 BUCKETS STORED AS ORC
TBLPROPERTIES ("transactional"="true",
"compactor.mapreduce.map.memory.mb"="2048", -- Specify the properties of a compression map job.
"compactorthreshold.hive.compactor.delta.num.threshold"="4", -- If there are more than four incremental directories, slight compression is triggered.
"compactorthreshold.hive.compactor.delta.pct.threshold"="0.5" -- If the ratio of the incremental file size to the basic file size is greater than 50%, deep compression is triggered.
);</pre>
<p id="mrs_01_0975__p58388199263">or</p>
<pre class="screen" id="mrs_01_0975__screen8838419162616">ALTER TABLE table_name COMPACT 'minor' WITH OVERWRITE TBLPROPERTIES ("compactor.mapreduce.map.memory.mb"="3072"); -- Specify the properties of a compression map job.
ALTER TABLE table_name COMPACT 'major' WITH OVERWRITE TBLPROPERTIES ("tblprops.orc.compress.size"="8192"); -- Modify any other Hive table attributes.</pre>
<div class="note" id="mrs_01_0975__note1583851917262"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="mrs_01_0975__p483817199269">After compression, small files are not deleted immediately. After the cleaner thread performs cleaning, the files are deleted in batches.</p>
</div></div>
</p></li></ol>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="mrs_01_0581.html">Using Hive</a></div>
</div>
</div>