lock tables in Hive

For enabling locking in Hive, you must first enable the LockManager by setting the two params in hive-site.xml :

<property>
<name>hive.zookeeper.quorum</name>
<value>sandbox.hortonworks.com:2181</value>
<description>The list of zookeeper servers to talk to.
This is only needed for read/write locks.</description>
</property>

<property>
<name>hive.support.concurrency</name>
<value>true</value>
<description>Whether Hive supports concurrency or not.
A Zookeeper instance must be up and running for the default
Hive lock manager to support read-write locks.</description>
</property>

After restarting Hive, here is how to use that :

hive> lock table my_table exclusive;
OK

You can see if there’s a lock on a table

hive> show locks my_table;
OK
default@my_table EXCLUSIVE
Time taken: 0.952 seconds, Fetched: 1 row(s)

When trying to access the table during this time :

hive> select count(*) from my_table;
conflicting lock present for default@my_table mode SHARED
conflicting lock present for default@my_table mode SHARED
...

and you can release the lock with

hive> unlock table my_table;
OK
Time taken: 1.126 seconds

then the previous request will be executed (by default the request is executed x times every 60 seconds (hive.lock.sleep.between.retries))
Locks (hive.lock.numretries) are tried 100 times, unlocks (hive.unlock.numretries) 10 times.


So, what do you think ?

  • Time limit is exhausted. Please reload CAPTCHA.