du fu
unread,Jul 31, 2011, 10:56:53 PM7/31/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to KFS User
Hi
It was said that primary-mast-chunk have the lease to prevent
write concurrently.
It seems not true. Is there something missing?
use kfs-0.5 with the following code.
.......
if ((fd = gKfsClient->Open(fileName, O_RDWR|O_CREAT)) < 0) {
cout << "Open on : " << fileName << " failed!" <<
KFS::ErrorCodeToStr(fd) << endl;
exit(-1);
}
off_t offFile;
if ((offFile = gKfsClient->Seek(fd, 0000000000L, SEEK_SET)) < 1) {
cout << "seek to failed!" << KFS::ErrorCodeToStr(offFile) <<
endl;
exit(-1);
}
int ntimes = 3;
while (ntimes--)
{
offFile = gKfsClient->Tell(fd);
if (offFile < 0) {
cout << "Tell failed! " << KFS::ErrorCodeToStr(offFile) <<
endl;
exit(-1);
}
int numBytes = 16;
char *dataBuf = new char[numBytes];
char c = 'M' - ntimes;
memset(dataBuf, c, numBytes);
res = gKfsClient->Write(fd, dataBuf, numBytes);
if (res < 0) {
cout << "Write failed!" << KFS::ErrorCodeToStr(res) << endl;
exit(-1);
}
else if (res < numBytes) {
cout << "Was able to write only: " << res << " instead of " <<
numBytes << endl;
}
cout << "Write at " << offFile << " char " << c << " bytes " <<
numBytes << endl;
delete dataBuf;
}
gKfsClient->Close(fd);