📄 kfsops.cc
字号:
//---------------------------------------------------------- -*- Mode: C++ -*-// $Id: KfsOps.cc 216 2008-11-07 07:43:36Z sriramsrao $ //// Created 2006/05/24// Author: Sriram Rao//// Copyright 2008 Quantcast Corp.// Copyright 2006-2008 Kosmix Corp.//// This file is part of Kosmos File System (KFS).//// Licensed under the Apache License, Version 2.0// (the "License"); you may not use this file except in compliance with// the License. You may obtain a copy of the License at//// http://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or// implied. See the License for the specific language governing// permissions and limitations under the License.//////----------------------------------------------------------------------------#include "KfsOps.h"#include <cassert>extern "C" {#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>}#include "libkfsIO/Checksum.h"#include "Utils.h"using std::istringstream;using std::ostringstream;using std::string;#include <iostream>using std::cout;using std::endl;static const char *KFS_VERSION_STR = "KFS/1.0";using namespace KFS;////// All Request() methods build a request RPC based on the KFS/// protocol and output the request into a ostringstream./// @param[out] os which contains the request RPC.///voidCreateOp::Request(ostringstream &os){ int e = exclusive ? 1 : 0; os << "CREATE " << "\r\n"; os << "Cseq: " << seq << "\r\n"; os << "Version: " << KFS_VERSION_STR << "\r\n"; os << "Parent File-handle: " << parentFid << "\r\n"; os << "Filename: " << filename << "\r\n"; os << "Num-replicas: " << numReplicas << "\r\n"; os << "Exclusive: " << e << "\r\n\r\n";}voidMkdirOp::Request(ostringstream &os){ os << "MKDIR " << "\r\n"; os << "Cseq: " << seq << "\r\n"; os << "Version: " << KFS_VERSION_STR << "\r\n"; os << "Parent File-handle: " << parentFid << "\r\n"; os << "Directory: " << dirname << "\r\n\r\n";}voidRmdirOp::Request(ostringstream &os){ os << "RMDIR " << "\r\n"; os << "Cseq: " << seq << "\r\n"; os << "Version: " << KFS_VERSION_STR << "\r\n"; os << "Parent File-handle: " << parentFid << "\r\n"; os << "Directory: " << dirname << "\r\n\r\n";}voidRenameOp::Request(ostringstream &os){ int o = overwrite ? 1 : 0; os << "RENAME " << "\r\n"; os << "Cseq: " << seq << "\r\n"; os << "Version: " << KFS_VERSION_STR << "\r\n"; os << "Parent File-handle: " << parentFid << "\r\n"; os << "Old-name: " << oldname << "\r\n"; os << "New-path: " << newpath << "\r\n"; os << "Overwrite: " << o << "\r\n\r\n";}voidReaddirOp::Request(ostringstream &os){ os << "READDIR " << "\r\n"; os << "Cseq: " << seq << "\r\n"; os << "Version: " << KFS_VERSION_STR << "\r\n"; os << "Directory File-handle: " << fid << "\r\n\r\n";}voidDumpChunkServerMapOp::Request(ostringstream &os){ os << "DUMP_CHUNKTOSERVERMAP" << "\r\n"; os << "Cseq: " << seq << "\r\n"; os << "Version: " << KFS_VERSION_STR << "\r\n\r\n";}voidDumpChunkMapOp::Request(ostringstream &os){ os << "DUMP_CHUNKMAP" << "\r\n"; os << "Cseq: " << seq << "\r\n"; os << "Version: " << KFS_VERSION_STR << "\r\n\r\n";}voidUpServersOp::Request(ostringstream &os){ os << "UPSERVERS" << "\r\n"; os << "Cseq: " << seq << "\r\n"; os << "Version: " << KFS_VERSION_STR << "\r\n\r\n";}voidReaddirPlusOp::Request(ostringstream &os){ os << "READDIRPLUS " << "\r\n"; os << "Cseq: " << seq << "\r\n"; os << "Version: " << KFS_VERSION_STR << "\r\n"; os << "Directory File-handle: " << fid << "\r\n\r\n";}voidGetDirSummaryOp::Request(ostringstream &os){ os << "GETDIRSUMMARY " << "\r\n"; os << "Cseq: " << seq << "\r\n"; os << "Version: " << KFS_VERSION_STR << "\r\n"; os << "Directory File-handle: " << fid << "\r\n\r\n";}voidRemoveOp::Request(ostringstream &os){ os << "REMOVE " << "\r\n"; os << "Cseq: " << seq << "\r\n"; os << "Version: " << KFS_VERSION_STR << "\r\n"; os << "Parent File-handle: " << parentFid << "\r\n"; os << "Filename: " << filename << "\r\n\r\n";}voidLookupOp::Request(ostringstream &os){ os << "LOOKUP \r\n"; os << "Cseq: " << seq << "\r\n"; os << "Version: " << KFS_VERSION_STR << "\r\n"; os << "Parent File-handle: " << parentFid << "\r\n"; os << "Filename: " << filename << "\r\n\r\n";}voidLookupPathOp::Request(ostringstream &os){ os << "LOOKUP_PATH \r\n"; os << "Cseq: " << seq << "\r\n"; os << "Version: " << KFS_VERSION_STR << "\r\n"; os << "Root File-handle: " << rootFid << "\r\n"; os << "Pathname: " << filename << "\r\n\r\n";}voidGetAllocOp::Request(ostringstream &os){ assert(fileOffset >= 0); os << "GETALLOC \r\n"; os << "Cseq: " << seq << "\r\n"; os << "Version: " << KFS_VERSION_STR << "\r\n"; os << "File-handle: " << fid << "\r\n"; os << "Chunk-offset: " << fileOffset << "\r\n\r\n";}voidGetLayoutOp::Request(ostringstream &os){ os << "GETLAYOUT \r\n"; os << "Cseq: " << seq << "\r\n"; os << "Version: " << KFS_VERSION_STR << "\r\n"; os << "File-handle: " << fid << "\r\n\r\n";}voidGetChunkMetadataOp::Request(ostringstream &os){ os << "GET_CHUNK_METADATA \r\n"; os << "Cseq: " << seq << "\r\n"; os << "Version: " << KFS_VERSION_STR << "\r\n"; os << "Chunk-handle: " << chunkId << "\r\n\r\n";}voidAllocateOp::Request(ostringstream &os){ static const int MAXHOSTNAMELEN = 256; char hostname[MAXHOSTNAMELEN]; gethostname(hostname, MAXHOSTNAMELEN); os << "ALLOCATE \r\n"; os << "Cseq: " << seq << "\r\n"; os << "Version: " << KFS_VERSION_STR << "\r\n"; os << "Client-host: " << hostname << "\r\n"; os << "File-handle: " << fid << "\r\n"; os << "Chunk-offset: " << fileOffset << "\r\n\r\n";}voidTruncateOp::Request(ostringstream &os){ os << "TRUNCATE \r\n"; os << "Cseq: " << seq << "\r\n"; os << "Version: " << KFS_VERSION_STR << "\r\n"; os << "File-handle: " << fid << "\r\n"; os << "Offset: " << fileOffset << "\r\n\r\n";}voidOpenOp::Request(ostringstream &os){ const char *modeStr; os << "OPEN \r\n"; os << "Cseq: " << seq << "\r\n"; os << "Version: " << KFS_VERSION_STR << "\r\n"; os << "Chunk-handle: " << chunkId << "\r\n"; if (openFlags == O_RDONLY) modeStr = "READ"; else { assert(openFlags == O_WRONLY || openFlags == O_RDWR); modeStr = "WRITE"; } os << "Intent: " << modeStr << "\r\n\r\n";}voidCloseOp::Request(ostringstream &os){ os << "CLOSE \r\n"; os << "Cseq: " << seq << "\r\n"; os << "Version: " << KFS_VERSION_STR << "\r\n"; os << "Chunk-handle: " << chunkId << "\r\n\r\n";}voidReadOp::Request(ostringstream &os){ os << "READ \r\n"; os << "Cseq: " << seq << "\r\n"; os << "Version: " << KFS_VERSION_STR << "\r\n"; os << "Chunk-handle: " << chunkId << "\r\n"; os << "Chunk-version: " << chunkVersion << "\r\n"; os << "Offset: " << offset << "\r\n"; os << "Num-bytes: " << numBytes << "\r\n\r\n";}voidWriteIdAllocOp::Request(ostringstream &os){ os << "WRITE_ID_ALLOC \r\n"; os << "Cseq: " << seq << "\r\n"; os << "Version: " << KFS_VERSION_STR << "\r\n"; os << "Chunk-handle: " << chunkId << "\r\n"; os << "Chunk-version: " << chunkVersion << "\r\n"; os << "Offset: " << offset << "\r\n"; os << "Num-bytes: " << numBytes << "\r\n"; if (chunkServerLoc.size() > 1) { os << "Num-servers: " << chunkServerLoc.size() << "\r\n"; os << "Servers:"; for (vector<ServerLocation>::size_type i = 0; i < chunkServerLoc.size(); ++i) { os << chunkServerLoc[i].ToString().c_str() << ' '; } os << "\r\n"; } os << "\r\n";}voidWritePrepareOp::Request(ostringstream &os){ os << "WRITE_PREPARE \r\n"; os << "Cseq: " << seq << "\r\n"; os << "Version: " << KFS_VERSION_STR << "\r\n"; os << "Chunk-handle: " << chunkId << "\r\n"; os << "Chunk-version: " << chunkVersion << "\r\n"; os << "Offset: " << offset << "\r\n"; os << "Num-bytes: " << numBytes << "\r\n"; os << "Checksum: " << checksum << "\r\n"; os << "Num-servers: " << writeInfo.size() << "\r\n"; os << "Servers:"; for (vector<WriteInfo>::size_type i = 0; i < writeInfo.size(); ++i) { os << writeInfo[i].serverLoc.ToString().c_str(); os << ' ' << writeInfo[i].writeId << ' '; } os << "\r\n\r\n";}voidWriteSyncOp::Request(ostringstream &os){ os << "WRITE_SYNC \r\n"; os << "Cseq: " << seq << "\r\n"; os << "Version: " << KFS_VERSION_STR << "\r\n"; os << "Chunk-handle: " << chunkId << "\r\n"; os << "Chunk-version: " << chunkVersion << "\r\n"; os << "Num-servers: " << writeInfo.size() << "\r\n"; os << "Servers:"; for (vector<WriteInfo>::size_type i = 0; i < writeInfo.size(); ++i) { os << writeInfo[i].serverLoc.ToString().c_str(); os << ' ' << writeInfo[i].writeId << ' '; } os << "\r\n\r\n";}voidSizeOp::Request(ostringstream &os){ os << "SIZE \r\n"; os << "Cseq: " << seq << "\r\n"; os << "Version: " << KFS_VERSION_STR << "\r\n"; os << "Chunk-handle: " << chunkId << "\r\n"; os << "Chunk-version: " << chunkVersion << "\r\n\r\n";}voidLeaseAcquireOp::Request(ostringstream &os){ os << "LEASE_ACQUIRE \r\n"; os << "Cseq: " << seq << "\r\n"; os << "Version: " << KFS_VERSION_STR << "\r\n"; os << "Chunk-handle: " << chunkId << "\r\n\r\n";}voidLeaseRenewOp::Request(ostringstream &os){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -