你好,游客 登录 注册 搜索
背景:
阅读新闻

淘宝TFS分布式文件系统使用

[日期:2012-08-07] 来源:Linux社区  作者:javaman_chen [字体:大 中 小]

TFS作为一个开源的分布式文件系统,在处理小文件的性能上还是比较高效的。功能部署有点类似与HDFS,而且增加了nameserver HA的功能。

作为开源项目来讲,其文档资源还有规范性较比Apache的子项目还是有一定差距的。在安装过程中也遇到了很多困难,走了很多弯路。最开始的时候是在Ubuntu环境下进行的,首先需要降级安装gcc,然后安装TFS的依赖库,无奈最后编译TFS的时候还是出了异常。最后,切换到64位CentOS环境,按照如下的步骤成功搭建:http://www.linuxidc.com/Linux/2012-08/67500.htm
注:安装TFS的时候没有checkout它的chunk目录,而是直接下载了1.4的版本


有关TFS的具体介绍可以参考这个网址:http://code.taobao.org/p/tfs/wiki/index/
在使用的过程中,我们主要通过java语言来进行调用,淘宝所提供的java API中有部分代码集成了tair的功能,如果不想使用tair可以人为修改代码,将tair的功能注释掉
注释掉之后的代码和单元测试用例可到这里下载:http://www.linuxidc.com/Linux/2012-08/67506.htm

附TFS的Spring配置和单元测试类

  1. <?xml version="1.0" encoding="UTF-8"?>  
  • <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">  
  • <beans>  
  •     <bean id="tfsManager" class="com.taobao.common.tfs.DefaultTfsManager" init-method="init" >  
  •       <!-- 整个进程中系统最多等待多少个请求,取决于你有多少个线程并发的请求TFS -->  
  •        <property name="maxWaitThread">  
  •         <value>100</value>  
  •       </property>  
  •       <!-- 单个请求最大的等待时间(ms) 超过这个时间放弃这次请求-->  
  •       <property name="timeout">  
  •         <value>2000</value>  
  •       </property>  
  •       <!-- Tfs master nameserver ip address -->  
  •       <property name="nsip">  
  •         <value>192.168.7.134:8888</value>  
  •       </property>  
  •       <!-- TFS 集群的编号,这个编号只是一种参考,系统初始化的时候会从ns上取,取不到才用本地设置的.!-->  
  •       <property name="tfsClusterIndex">  
  •         <value>1</value>  
  •       </property>  
  •       <!-- TFS在读取文件的时候会缓存block所在的数据服务器ip,这个参数配置了最多缓存的记录个数!-->  
  •       <property name="maxCacheItemCount">  
  •         <value>10000</value>  
  •       </property>  
  •       <!-- 上一项缓存最大有效的时间(ms)!-->  
  •       <property name="maxCacheTime">  
  •         <value>5000</value>  
  •       </property>  
  •    </bean>  
  • </beans>  
  • 单元测试代码

    1. import org.springframework.context.ApplicationContext;  
    2. import org.springframework.context.support.ClassPathXmlApplicationContext;  
    3. import com.taobao.common.tfs.TfsManager;  
    4. import com.taobao.common.tfs.packet.FileInfo;  
    5. import junit.framework.TestCase;  
    6.   
    7. public class TFSTest extends TestCase {  
    8.     ApplicationContext context;  
    9.     protected void setUp() throws Exception {  
    10.         super.setUp();  
    11.         context=new ClassPathXmlApplicationContext("tfs.xml");  
    12.     }  
    13.     public void testTemp(){  
    14.         TfsManager tfsMgr=(TfsManager) context.getBean("tfsManager");  
    15.         System.out.println(tfsMgr);  
    16.     }  
    17.     public void testSave(){  
    18.         TfsManager tfsMgr=(TfsManager) context.getBean("tfsManager");  
    19.         String fileName=tfsMgr.saveFile("test.pdf", null, null);  
    20.         System.out.println(fileName);  
    21.     }  
    22.     public void testFetch(){  
    23.         TfsManager tfsMgr=(TfsManager) context.getBean("tfsManager");  
    24.         boolean flag=tfsMgr.fetchFile("T1_tETBCZT1RCvBVdK", null, "temp.pdf");  
    25.         System.out.println(flag);  
    26.     }  
    27.     public void testDelete(){  
    28.         TfsManager tfsMgr=(TfsManager) context.getBean("tfsManager");  
    29.         boolean flag=tfsMgr.unlinkFile("T1XRETByJT1RCvBVdK", null);  
    30.         System.out.println(flag);  
    31.     }  
    32.     public void testHide(){  
    33.         //1 隐藏;0显示   
    34.         TfsManager tfsMgr=(TfsManager) context.getBean("tfsManager");  
    35.         boolean flag=tfsMgr.hideFile("T1XRETByJT1RCvBVdK", null, 0);  
    36.         System.out.println(flag);  
    37.     }  
    38.     public void testState(){  
    39.         TfsManager tfsMgr=(TfsManager) context.getBean("tfsManager");  
    40.         FileInfo fileInfo=tfsMgr.statFile("T1_tETBCZT1RCvBVdK", null);  
    41.         int flag=fileInfo.getFlag();  
    42.         System.out.println(flag);  
    43.     }  
    44. }  
    linux
    相关资讯       分布式  TFS 
    本文评论   查看全部评论 (0)
    表情: 表情 姓名: 字数

           

    评论声明
    • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
    • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
    • 本站管理人员有权保留或删除其管辖留言中的任意内容
    • 本站有权在网站内转载或引用您的评论
    • 参与本评论即表明您已经阅读并接受上述条款