Created on 03-21-2017 12:58 PM - edited 09-16-2022 04:18 AM
I have
INSERT OVERWRITE
statements scheduled as hive queries through oozie. Before running INSERT OVERWRITE, I want to check if locks exist on the table
i.e something like show locks dbname.tablename
but it should basically return somethign that I can use to decide if I have to run UNLOCK TABLE dbname.tblname or not.
OR
Do we have somethign like UNLOCK TABLE IF EXISTS LOCK dbname.tblname?
It is really important as I have been tryign to find a way to update my tables in hive at the scheduled time but oozie gets stuck if a user was using select on the table and my scheduled queries tried to run right at the same time. I want to make sure that the query runs at its scheduled time even if the select may or may not give the updated results
Created 03-21-2017 05:27 PM
Hive does provide a show locks command, for more details refer to Apache Hive documentation.
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-ShowLocks
Created 03-22-2017 05:22 AM
@Deepesh: How do I use that in query scheduled through oozie?
I need to have something like this in hive:
IF(LOCK EXISTS ON TABLE)
unlock table
else
nothing
OR
UNLOCK TABLE IF LOCK EXISTS tablename
This is because the query is going to be scheduled through oozie and I need the INSERT OVERWRITE TO always execute and not fail because of any locks.
One liner answers like this barely help. Request the questions be read with attention before answering like this.
Created 09-06-2017 10:58 AM
try to lock the table before and then unlock it
LOCK TABLE tablename SHARED; UNLOCK TABLE tablename;