关于hadoop的API写文件的备份数问题

今天用hadoop API打算往hadoop集群创建几个文件,然后写入数据试试,结果问题发生了,我的配置文件备份数是1,但是不管我怎么创建,创建的文件备份数都是3。代码如下:

[html]  view plain copy print ?
  1. <span style="font-size:14px;">  public static void testHDFS() throws IOException{  
  2.         String str="hdfs://cloudgis4:9000/usr/tmp/";  
  3.         Path path=new Path(str);  
  4.         Configuration conf=new Configuration();  
  5.         FileSystem hdfs=path.getFileSystem(conf);  
  6.         long begin=System.currentTimeMillis();  
  7.         for(int i=0;i<10000;i++){  
  8.             byte [] kkk=new byte[10000+1*i];  
  9.             FSDataOutputStream fsDataOut=hdfs.create(new Path(str+i));  
  10.             fsDataOut.write(kkk);  
  11.             fsDataOut.close();  
  12.             //hdfs.close();  
  13.         }  
  14.         long end=System.currentTimeMillis();  
  15.         System.out.println("hdfs:"+(end-begin));  
  16.     }</span>  

很奇怪,上网搜了一下发现了这个API:setReplication。用了这个之后,创建的文件备份数还是3,搜了下这个API的使用,发现这个API只能更改已经存在的文件的备份数。如果先创建再修改备份,无疑增加了框架的负担。后来想了想,明明配置文件修改成了1,那么就应该是这个应用程序没有读取配置文件。所以手动读取下配置文件就可以了。

conf.addResource(new Path("/usr/local/hadoop/conf/hdfs-site.xml"));


ps:hbase 权威指南上有这样一句话:

If you are configuring an IDE to run an HBase client, you could include the conf/
directory on your classpath. That would make the configuration files discoverable by
the client code.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值