distributed system summary Jan 2

distributes system is a capstone course of NYU CS master program, which I pick in the first semester.   

the course web site is  http://www.news.cs.nyu.edu/~jinyang/fa10/

this course includes several papers for reading and 8 labs, among which the labs are quite challenging.

the overview shows as follows.

---------------------------------------------------------------------------

In this sequence of labs, you'll build a multi-server file system called Yet-Another File System (yfs) in the spirit of Frangipani. At the end of all the labs, your file server architecture will look like this:

 

You'll write a file server process, labeled yfs above, using the FUSE toolkit. Each client host will run a copy of yfsyfs will appear to local applications on the same machine by registering via FUSE to receive file system events from the operating system. The yfs extent server will store all the file system data on an extent server on the network, instead of on a local disk. yfs servers on multiple client hosts can share the file system by sharing a single extent server.

------------------------------------------------------------------------------------------------------------

lets start with lab1: 

LAB 1 :

familiarize the RPC calls,  pthread mutex.

key points:

1, use RPC calls.   in the client side, use ".call()" and in the server side implement RPC handler. in this lab, the server side need not to run to completion. 

2, familiarize the pthread mutex. the lock_server achieve a simple lock and unlock by using pthread. one caveat is that before we return and exit one function, we should release all mutex we are holding!!  this is a common mistake.   

 

we should also modify rpc.cc to achieve at-most-once delivery. 

here we don't talk about the specific implementation. instead, we point out several general regulation in coding. 

1, template. 

in the rpc.h, rpcc class

代码
 
   
class rpcc : public changer {

// ..........
struct TO{...};

template
< class R >
int call_m(unsigned int proc, marshall & req, R & r, TO to)

template
< class R >
int call(unsigned int proc, R & r, TO to = tp_max)

// other template

}

template
< class R > int
rpcc::call_m(unsigned
int proc, marshall & req, R & r, TO to)
{
unmarshall u;
int intret = call1(proc, req, u, to);
// ......
}

// here we use marshall and unmarshall
template < class R > int
rpcc::call(unsigned
int proc, R & r, TO to)
{
marshall m;
return call_m(proc, m, r, to);
}

template
< class R, class A1 > int
rpcc::call(unsigned
int proc, const A1 & a1, R & r, TO to)
{
marshall m;
m
<< a1;
return call_m(proc, m, r, to);
}
// ......

 

2, mashall and unmarshall 

is used to envelop the data. 

代码
 
   
class marshall{
// ........
// in mashall, we can transfer marshall to string
std:: string str() {
return get_content();
}
// .....
}

marshall
& operator << (marshall & , unsigned int );
marshall
& operator << (marshall & , int );
// mashall vector
template < class C > marshall &
operator << (marshall & m, std::vector < C > v)
{
m
<< (unsigned int ) v.size();
for (unsigned i = 0 ; i < v.size(); i ++ )
m
<< v[i];
return m;
}

 

and unmarshall has the same principle  

 
  
template < class C > unmarshall &
operator >> (unmarshall & u, std::vector < C > & v)
{
unsigned n;
u
>> n;
for (unsigned i = 0 ; i < n; i ++ ){
C z;
u
>> z;
v.push_back(z);
}
return u;
}

 

in the latter lab, we also use marshall and unmarhsall to transfer data 

代码
 
   
int extent_server::getattr(extent_protocol::extentid_t id, extent_protocol::attr & a)
{
// You replace this with a real implementation. We send a phony response
// for now because it's difficult to get FUSE to do anything (including
// unmount) if getattr fails.
// .......this is a good example for how to use marshall and unmarshall
pthread_mutex_lock( & extent_mutex);
std::
string temp = meta_data[id];
pthread_mutex_unlock(
& extent_mutex);

unmarshall at(temp);
extent_protocol::attr attr_temp;
at
>> attr_temp; // unmarshall, convert string to attr

a.size
= attr_temp.size;
a.atime
= attr_temp.atime;
a.mtime
= attr_temp.mtime;
a.ctime
= attr_temp.ctime;


return extent_protocol::OK;
}

 

 

3, pay attention to the scope of the lock. 

i.e,  add_reply and check_duplicate_update may be not consistent. 

scopedlock:

代码
 
   
ifndef Foundation_ScopedLock_INCLUDED
#define Foundation_ScopedLock_INCLUDED


#ifndef Foundation_Foundation_INCLUDED
#include
" Foundation/Foundation.h "
#endif

Foundation_BEGIN

template
< class M >
class ScopedLock
/// A class that simplifies thread synchronization
/// with a mutex.
/// The constructor accepts a Mutex and locks it.
/// The destructor unlocks the mutex.
{
public :
inline ScopedLock(M
& mutex): _mutex(mutex)
{
_mutex.
lock ();
}
inline
~ ScopedLock()
{
_mutex.unlock();
}

private :
M
& _mutex;

ScopedLock();
ScopedLock(
const ScopedLock & );
ScopedLock
& operator = ( const ScopedLock & );
};

Foundation_END

#endif // Foundation_ScopedLock_INCLUDED

 

 

转载于:https://www.cnblogs.com/ggppwx/archive/2011/01/03/1924476.html

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值