Set replication in Hadoop
I was trying loading file using hadoop API as an experiment.
I want to set replication to minimum as this one is for experiment. I first tried this with FileSystem.setReplication():
Configuration config = new Configuration();
config.set("fs.defaultFS","hdfs://192.168.248.166:8020");
FileSystem dfs2 = FileSystem.get(config);
Path src2 = new Path("C:\\Users\\abc\\Desktop\\testfile.txt");
Path dst2 = new Path(dfs2.getWorkingDirectory()+"/tempdir");
dfs2.copyFromLocalFile(src2, dst2);
dfs2.setReplication(dst2, (short)1); /**setting replication**/
The replica was shown as 1, but it was available on 3 datanodes.
When I tried it with Configuration.set():
Configuration config = new Configuration();
config.set("fs.defaultFS","hdfs://192.168.248.166:8020");
config.set("dfs.replication", "1"); /**setting replication**/
FileSystem dfs2 = FileSystem.get(config);
Path src2 = new Path("C:\\Users\\abc\\Desktop\\testfile.txt");
Path dst2 = new Path(dfs2.getWorkingDirectory()+"/tempdir");
This gave the desired outcome (1 replica available on 1 datanode)
Why there are two APIs for the same thing? What is the difference between these two?
The difference is that Filesystem's setReplication() sets the replication of an existing file on HDFS. In your case, you first copy the local file testFile.txt to HDFS, using the default replication factor (3) and then change the replication factor of this file to 1. After this command, it takes a while until the over-replicated blocks get deleted. (source)
On the other hand, when you use the config.set("dfs.replication", "1"); command to set the replication, you can copy the local file after that, so its blocks get copied just once, from the first time.
In other words, I believe (but I might be wrong) that both commands have the same final result, but you have to wait a little bit until the first one is carried out.
Set replication in Hadoop的更多相关文章
- Hadoop学习之路(十)HDFS API的使用
HDFS API的高级编程 HDFS的API就两个:FileSystem 和Configuration 1.文件的上传和下载 package com.ghgj.hdfs.api; import org ...
- 跟着我一起学习大数据——Hadoop
hadoop配置文件:http://archive.cloudera.com/cdh5/cdh/5/hadoop-2.6.0-cdh5.9.0/ 一:Hadoop简介 总结下起源于Nutch项目,社区 ...
- [转载] 首席工程师揭秘:LinkedIn大数据后台是如何运作的?(一)
本文作者:Jay Kreps,linkedin公司首席工程师:文章来自于他在linkedin上的分享:原文标题:The Log: What every software engineer should ...
- 我的简历 PHP Java C# 技术总监
石先生 ID:303321266 目前正在找工作 13611326258 hr_msn@163.com 男|32 岁 (1985/08/06)|现居住北京-海淀区|12年工作经验 ...
- 云计算分布式大数据Hadoop实战高手之路第七讲Hadoop图文训练课程:通过HDFS的心跳来测试replication具体的工作机制和流程
这一讲主要深入使用HDFS命令行工具操作Hadoop分布式集群,主要是通过实验的配置hdfs-site.xml文件的心跳来测试replication具体的工作和流程. 通过HDFS的心跳来测试repl ...
- [大牛翻译系列]Hadoop(2)MapReduce 连接:复制连接(Replication join)
4.1.2 复制连接(Replication join) 复制连接是map端的连接.复制连接得名于它的具体实现:连接中最小的数据集将会被复制到所有的map主机节点.复制连接有一个假设前提:在被连接的数 ...
- Data Replication in a Multi-Cloud Environment using Hadoop & Peer-to-Peer technologies
http://fbevmware.blogspot.com/2013/12/data-replication-in-multi-cloud.html 要FQ... —————————————————— ...
- Hadoop 50090端口的页面, Replication的数字是真实的文件备份数吗? (不是)
红色方框的部分,代表Hadoop系统,人工设定的文件备份数,但不是实际的备份数.文件备份数 不会大于集群机器的总数目(因为备份文件不会同时存在一台机器上,这样就没有意义),所以如果总集群数目是2,即使 ...
- hadoop 3.x Replication与Availability不一致
看下面的文字前先确保你的Replication值不大于你设置的虚拟机数量 如图,显示的副本数为3,但是实际可用的只有一台机器,查看了下hadoop003,hadoop004两台机器,果然没有存储数据, ...
随机推荐
- [转]如何在Angular4中引入jquery
本文转自:https://blog.csdn.net/home_zhang/article/details/77992734 1.anjq是我的项目名称: 在anjq目录下打开dos命令窗口,然后依次 ...
- MEF 基础简介 二
MEF的导出(Export)和导入(Import) using System; using System.Collections.Generic; using System.Linq; using S ...
- .NET MVC项目设置包含Areas中的页面为默认启动页
利用vs创建一个MVC项目后,一般的默认启动页是根目录下-->Controllers-->HomeController-->Index这个方法对应的页面. 我先说下创建Areas的流 ...
- WPF 绕圈进度条(一)
在设计界面时,有时会遇到进度条,本次讲解如何设计自定义的绕圈进度条,直接上代码: 1.控件界面 <UserControl x:Class="ProgressBarControl&quo ...
- 【微服务No.3】AOP组件ASPectCore简单使用
介绍: AspectCore是.NET标准的基于AOP的跨平台框架[github解释].主要支持:对方面拦截器,依赖注入集成,Web应用程序,数据验证等的核心支持. 使用实例: 首先安装dll: In ...
- Spring Data REST API集成Springfox、Swagger
原文: Documenting a Spring Data REST API with Springfox and Swagger 使用Spring Date REST,你可以迅速为Spring Da ...
- angularjs+webapi2 跨域Basic 认证授权(一)
如今的app,利用各种前端框架结合html5的混合开发模式已然盛极一时.其中ionic+angularjs更是如日中天.这种模式利用angularjs $http 请求数据api 以达到前后端分离深得 ...
- idea代码快捷
idea代码快捷:main函数快捷:psvmfor循环快捷:fori.foreach系统输出快捷:sout.serr 更多的提示可以按Ctrl+ J 进行查看 更改快捷:File-->Setti ...
- angular ztree 梯形结构json配置、点击节点事件、默认展开所有
// 获取树数据 $scope.initZtreeData = function () { var url = '/bpopstation/func/queryAll.do'; $http.post( ...
- JS检测浏览器Adobe Reader插件
Web应用中当我们希望向用户显示pdf文档时候,如果用户安装了Adobe Reader之类的pdf阅读器,就可以直接打开文档在浏览器中显示, 但是,当用户没有安装这类软件的时候,自然是打不开的,为了系 ...