Hive应用(10.1)锁

Hive可以通过Zookeeper来实现锁定功能。安装好zookeeper后对Hive进行如下配置:

1
2
3
4
5
6
7
8
<property>
<name>hive.zookeeper.quorum</name>
<value>zk1:2181,zk2:2181,zk3:2181</value>
</property>
<property>
<name>hive.support.concurrency</name>
<value>true</value>
</property>

配置完成后Hive会在特定类型的操作时进行加锁,此时可以通过show locks命令来显示当前的锁。

1.1 共享锁和互斥锁

共享锁(s)支持并发执行,互斥锁(x)则不能进行并发操作。各个操作加锁的情况如下:

命令 加锁情况
select .. T1 partition P1 S on T1, T1.P1
insert into T2(partition P2) select .. T1 partition P1 S on T2, T1, T1.P1 and X on T2.P2
insert into T2(partition P.Q) select .. T1 partition P1 S on T2, T2.P, T1, T1.P1 and X on T2.P.Q
alter table T1 rename T2 X on T1
alter table T1 add cols X on T1
alter table T1 replace cols X on T1
alter table T1 change cols X on T1
alter table T1 add partition P1 S on T1, X on T1.P1
alter table T1 drop partition P1 S on T1, X on T1.P1
alter table T1 set serdeproperties S on T1
alter table T1 set serializer S on T1
alter table T1 set file format S on T1
alter table T1 set file format X on T1
alter table T1 set tblproperties X on T1