hive超级用户drop partition权限问题bug

今天有个etl开发在drop partition的时候遇到了问题,因为是使用了自己的账号,而hdfs中对应partition的文件属主是hdfs的,在删除时会因为权限问题报错,切换用户为hdfs,做drop partition的错误,还是报错,看来没这么简单。

查看表的hdfs属性,目录的属主不是hdfs且目录对hdfs没有写权限:

[hdfs@nfzm~]$hadoopfs-ls-dhdfs://xxxx:9000/bip/external_table/vipdw/droptestFound1itemsdrwxr-xr-x-ericnihdfs02014-08-2117:13hdfs://xxxxx:9000/bip/external_table/vipdw/droptest

drop partition报错,报hdfs用户没有权限,在hive中是设置了hdfs为超级管理员的,所以如果直接用hadoop fs命令是可以删除的,也就是权限问题不是出在hdfs上,而是在hive上,这里怎么会没有权限呢?

hive(vipdw)>ALTERTABLEdroptestDROPPARTITION(dt=’20140840′);14/08/2117:31:21ERRORmetastore.RetryingHMSHandler:MetaException(message:Tablepartitionnotdeletedsincehdfs://xxxx:9000/bip/external_table/vipdw/droptestisnotwritablebyhdfs

根据调用信息,,异常是在HiveMetaStore类中的verifyIsWritablePath方法中抛出,verifyIsWritablePath类用来判断本目录的上层目录对当前用户是否可写,按照一般的思路,所有的hdfs目录都应该对超级管理员可写的。

privatevoidverifyIsWritablePath(Pathdir)throwsMetaException{try{if(!wh.isWritable(dir.getParent())){thrownewMetaException(“Tablepartitionnotdeletedsince”+dir.getParent()+”isnotwritableby”+hiveConf.getUser());}}catch(IOExceptionex){LOG.warn(“ErrorfromisWritable”,ex);thrownewMetaException(“Tablepartitionnotdeletedsince”+dir.getParent()+”accesscannotbechecked:”+ex.getMessage());}}

这里判断调用了Warehouse类的isWritable的方法,但是实现方法有些问题,不会区分超级用户,只会根据目录的属主和属组的权限做判断。

publicbooleanisWritable(Pathpath)throwsIOException{if(!storageAuthCheck){//nochecksfornon-securehadoopinstallationsreturntrue;}if(path==null){//what??!!returnfalse;}finalFileStatusstat;try{stat=getFs(path).getFileStatus(path);}catch(FileNotFoundExceptionfnfe){//Filenamedbypathdoesn’texist;nothingtovalidate.returntrue;}catch(Exceptione){//allotherexceptionsareconsideredasemanatingfrom//unauthorizedaccessesreturnfalse;}finalUserGroupInformationugi;try{ugi=ShimLoader.getHadoopShims().getUGIForConf(conf);}catch(LoginExceptionle){thrownewIOException(le);}Stringuser=ShimLoader.getHadoopShims().getShortUserName(ugi);//checkwhetherownercandeleteif(stat.getOwner().equals(user)&&stat.getPermission().getUserAction().implies(FsAction.WRITE)){//判断属主有没有写权限returntrue;}//checkwhethergroupoftheusercandeleteif(stat.getPermission().getGroupAction().implies(FsAction.WRITE)){//判断属组有没有有写权限String[]groups=ugi.getGroupNames();if(ArrayUtils.contains(groups,stat.getGroup())){returntrue;}}//checkwhetherotherscandelete(uncommoncase!!)////判断other有没有写权限if(stat.getPermission().getOtherAction().implies(FsAction.WRITE)){returntrue;}returnfalse;}当你感到悲哀痛苦时,最好是去学些什么东西。

hive超级用户drop partition权限问题bug

相关文章:

你感兴趣的文章:

标签云: