专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > VSTS

淘宝TFS运用

发布时间:2011-06-20 18:27:29 文章来源:www.iduyao.cn 采编人员:星星草
淘宝TFS使用

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

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

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

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

<?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>
单元测试代码

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.taobao.common.tfs.TfsManager;
import com.taobao.common.tfs.packet.FileInfo;
import junit.framework.TestCase;

public class TFSTest extends TestCase {
	ApplicationContext context;
	protected void setUp() throws Exception {
		super.setUp();
		context=new ClassPathXmlApplicationContext("tfs.xml");
	}
	public void testTemp(){
		TfsManager tfsMgr=(TfsManager) context.getBean("tfsManager");
		System.out.println(tfsMgr);
	}
	public void testSave(){
		TfsManager tfsMgr=(TfsManager) context.getBean("tfsManager");
		String fileName=tfsMgr.saveFile("test.pdf", null, null);
		System.out.println(fileName);
	}
	public void testFetch(){
		TfsManager tfsMgr=(TfsManager) context.getBean("tfsManager");
		boolean flag=tfsMgr.fetchFile("T1_tETBCZT1RCvBVdK", null, "temp.pdf");
		System.out.println(flag);
	}
	public void testDelete(){
		TfsManager tfsMgr=(TfsManager) context.getBean("tfsManager");
		boolean flag=tfsMgr.unlinkFile("T1XRETByJT1RCvBVdK", null);
		System.out.println(flag);
	}
	public void testHide(){
		//1 隐藏;0显示
		TfsManager tfsMgr=(TfsManager) context.getBean("tfsManager");
		boolean flag=tfsMgr.hideFile("T1XRETByJT1RCvBVdK", null, 0);
		System.out.println(flag);
	}
	public void testState(){
		TfsManager tfsMgr=(TfsManager) context.getBean("tfsManager");
		FileInfo fileInfo=tfsMgr.statFile("T1_tETBCZT1RCvBVdK", null);
		int flag=fileInfo.getFlag();
		System.out.println(flag);
	}
}


友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: