Posts tagged with: lock

lock tables in Hive

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

<description>The list of zookeeper servers to talk to.
This is only needed for read/write locks.</description>

<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>

After restarting Hive, here is how to use that :

hive> lock table my_table exclusive;

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

hive> show locks my_table;
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;
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.