⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 request.h

📁 nandflash文件系统源代码
💻 H
📖 第 1 页 / 共 3 页
字号:
/*! * $Id: request.h 237 2009-01-09 07:45:20Z sriramsrao $  * * \file request.h * \brief protocol requests to KFS metadata server * \author Blake Lewis (Kosmix Corp.) * * The model is that various receiver threads handle network * connections and extract RPC parameters, then queue a request * of the appropriate type for the metadata server to process. * When the operation is finished, the server calls back to the * receiver with status and any results. * * 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. */#if !defined(KFS_REQUEST_H)#define KFS_REQUEST_H#include "common/kfsdecls.h"#include "kfstypes.h"#include "meta.h"#include "thread.h"#include "util.h"#include <deque>#include <fstream>#include <sstream>#include <vector>#include "libkfsIO/KfsCallbackObj.h"using std::ofstream;using std::vector;using std::ostringstream;namespace KFS {/*! * \brief Metadata server operations */enum MetaOp {	// Client -> Metadata server ops	META_LOOKUP,	META_LOOKUP_PATH,	META_CREATE,	META_MKDIR,	META_REMOVE,	META_RMDIR,	META_READDIR,	META_READDIRPLUS,	META_GETALLOC,	META_GETLAYOUT,	META_GETDIRSUMMARY,	META_ALLOCATE,	META_TRUNCATE,	META_RENAME,	META_LOG_ROLLOVER,	META_CHANGE_FILE_REPLICATION, //! < Client is asking for a change in file's replication factor	//!< Admin is notifying us to retire a chunkserver	META_RETIRE_CHUNKSERVER,	//!< Admin is notifying us to toggle rebalancing	META_TOGGLE_REBALANCING,	//!< Admin is notifying us to execute a rebalance plan	META_EXECUTE_REBALANCEPLAN,	META_TOGGLE_WORM, //!< Toggle metaserver's WORM mode	//!< Metadata server <-> Chunk server ops	META_HELLO,  //!< Hello RPC sent by chunkserver on startup	META_BYE,  //!< Internally generated op whenever a chunkserver goes down	META_CHUNK_HEARTBEAT, //!< Periodic heartbeat from meta->chunk	META_CHUNK_ALLOCATE, //!< Allocate chunk RPC from meta->chunk	META_CHUNK_DELETE,  //!< Delete chunk RPC from meta->chunk	META_CHUNK_TRUNCATE, //!< Truncate chunk RPC from meta->chunk	META_CHUNK_STALENOTIFY, //!< Stale chunk notification RPC from meta->chunk	META_CHUNK_VERSCHANGE, //!< Notify chunkserver of version # change from meta->chunk	META_CHUNK_REPLICATE, //!< Ask chunkserver to replicate a chunk	META_CHUNK_SIZE, //!< Ask chunkserver for the size of a chunk	META_CHUNK_REPLICATION_CHECK, //!< Internally generated	META_CHUNK_CORRUPT, //!< Chunkserver is notifying us that a chunk is corrupt	//!< All the blocks on the retiring server have been evacuated and the	//!< server can safely go down.  We are asking the server to take a graceful bow	META_CHUNK_RETIRE,	//!< Lease related messages	META_LEASE_ACQUIRE,	META_LEASE_RENEW,	META_LEASE_RELINQUISH,	//!< Internally generated to cleanup leases	META_LEASE_CLEANUP,	//!< Internally generated to update the increment for chunk version #'s	META_CHANGE_CHUNKVERSIONINC,	//!< Metadata server monitoring	META_PING, //!< Print out chunkserves and their configs	META_STATS, //!< Print out whatever statistics/counters we have	META_DUMP_CHUNKTOSERVERMAP, //! < Dump out the chunk -> location map	META_OPEN_FILES, //!< Print out open files---for which there is a valid read/write lease	META_UPSERVERS //!< Print out live chunk servers};/*! * \brief Meta request base class */struct MetaRequest {	const MetaOp op; //!< type of request	int status;	//!< returned status	seq_t opSeqno;	//!< command sequence # sent by the client	seq_t seqno;	//!< sequence no. in log	const bool mutation; //!< mutates metatree	bool suspended;  //!< is this request suspended somewhere	KfsCallbackObj *clnt; //!< a handle to the client that generated this request.	MetaRequest(MetaOp o, seq_t ops, bool mu):		op(o), status(0), opSeqno(ops), seqno(0), mutation(mu),		suspended(false), clnt(NULL) { }	virtual ~MetaRequest() { }	//!< when an op finishes execution, we send a response back to	//!< the client.  This function should generate the appropriate	//!< response to be sent back as per the KFS protocol.	virtual void response(ostringstream &os)	{		(void) os; // XXX avoid spurious compiler warnings	};	virtual int log(ofstream &file) const = 0; //!< write request to log	virtual string Show() { return ""; }};/*! * \brief look up a file name */struct MetaLookup: public MetaRequest {	fid_t dir;	//!< parent directory fid	string name;	//!< name to look up	MetaFattr result; //!< result of lookup	MetaLookup(seq_t s, fid_t d, string n):		MetaRequest(META_LOOKUP, s, false), dir(d), name(n) { }	int log(ofstream &file) const;	void response(ostringstream &os);	string Show()	{		ostringstream os;		os << "lookup: name = " << name;		os << " (parent fid = " << dir << ")";		return os.str();	}};/*! * \brief look up a complete path */struct MetaLookupPath: public MetaRequest {	fid_t root;	//!< fid of starting directory	string path;	//!< path to look up	MetaFattr result; //!< result of lookup;	MetaLookupPath(seq_t s, fid_t r, string p):		MetaRequest(META_LOOKUP_PATH, s, false), root(r), path(p) { }	int log(ofstream &file) const;	void response(ostringstream &os);	string Show()	{		ostringstream os;		os << "lookup_path: path = " << path;		os << " (root fid = " << root << ")";		return os.str();	}};/*! * \brief create a file */struct MetaCreate: public MetaRequest {	fid_t dir;	//!< parent directory fid	string name;	//!< name to create	fid_t fid;	//!< file ID of new file	int16_t numReplicas; //!< desired degree of replication	bool exclusive;  //!< model the O_EXCL flag	MetaCreate(seq_t s, fid_t d, string n, int16_t r, bool e):		MetaRequest(META_CREATE, s, true), dir(d),		name(n), numReplicas(r), exclusive(e) { }	int log(ofstream &file) const;	void response(ostringstream &os);	string Show()	{		ostringstream os;		os << "create: name = " << name;		os << " (parent fid = " << dir << ")";		os << " desired replication = " << numReplicas;		return os.str();	}};/*! * \brief create a directory */struct MetaMkdir: public MetaRequest {	fid_t dir;	//!< parent directory fid	string name;	//!< name to create	fid_t fid;	//!< file ID of new directory	MetaMkdir(seq_t s, fid_t d, string n):		MetaRequest(META_MKDIR, s, true), dir(d), name(n) { }	int log(ofstream &file) const;	void response(ostringstream &os);	string Show()	{		ostringstream os;		os << "mkdir: name = " << name;		os << " (parent fid = " << dir << ")";		return os.str();	}};/*! * \brief remove a file */struct MetaRemove: public MetaRequest {	fid_t dir;	//!< parent directory fid	string name;	//!< name to remove	MetaRemove(seq_t s, fid_t d, string n):		MetaRequest(META_REMOVE, s, true), dir(d), name(n) { }	int log(ofstream &file) const;	void response(ostringstream &os);	string Show()	{		ostringstream os;		os << "remove: name = " << name;		os << " (parent fid = " << dir << ")";		return os.str();	}};/*! * \brief remove a directory */struct MetaRmdir: public MetaRequest {	fid_t dir;	//!< parent directory fid	string name;	//!< name to remove	MetaRmdir(seq_t s, fid_t d, string n):		MetaRequest(META_RMDIR, s, true), dir(d), name(n) { }	int log(ofstream &file) const;	void response(ostringstream &os);	string Show()	{		ostringstream os;		os << "rmdir: name = " << name;		os << " (parent fid = " << dir << ")";		return os.str();	}};/*! * \brief read directory contents */struct MetaReaddir: public MetaRequest {	fid_t dir;	//!< directory to read	vector <MetaDentry> v; //!< vector of results	MetaReaddir(seq_t s, fid_t d):		MetaRequest(META_READDIR, s, false), dir(d) { }	int log(ofstream &file) const;	void response(ostringstream &os);	string Show()	{		ostringstream os;		os << "readdir: dir fid = " << dir;		return os.str();	}};/*! * \brief read directory contents and get file attributes */struct MetaReaddirPlus: public MetaRequest {	fid_t dir;	//!< directory to read	ostringstream v; //!< results built out into a string	int numEntries; //!< # of entries in the directory	MetaReaddirPlus(seq_t s, fid_t d):		MetaRequest(META_READDIRPLUS, s, false), dir(d) { }	int log(ofstream &file) const;	void response(ostringstream &os);	string Show()	{		ostringstream os;		os << "readdir: dir fid = " << dir;		return os.str();	}};/*! * \brief get allocation info. a chunk for a file */struct MetaGetalloc: public MetaRequest {	fid_t fid;	//!< file for alloc info is needed	chunkOff_t offset; //!< offset of chunk within file	chunkId_t chunkId; //!< Id of the chunk corresponding to offset	seq_t chunkVersion; //!< version # assigned to this chunk	vector<ServerLocation> locations; //!< where the copies of the chunks are	MetaGetalloc(seq_t s, fid_t f, chunkOff_t o):		MetaRequest(META_GETALLOC, s, false), fid(f), offset(o) { }	int log(ofstream &file) const;	void response(ostringstream &os);	string Show()	{		ostringstream os;		os << "getalloc: fid = " << fid;		os << " offset = " << offset;		return os.str();	}};/*! * \brief layout information for a chunk */struct ChunkLayoutInfo {	chunkOff_t offset; //!< offset of chunk within file	chunkId_t chunkId; //!< Id of the chunk corresponding to offset	seq_t chunkVersion; //!< version # assigned to this chunk	vector<ServerLocation> locations; //!< where the copies of the chunks are	string toString()	{		ostringstream os;		os << offset << " " << chunkId << " " ;		os << chunkVersion << " " << locations.size() << " ";		for (vector<ServerLocation>::size_type i = 0;			i < locations.size(); ++i) {			os << locations[i].hostname << " " << locations[i].port << " ";		}		return os.str();	}};/*! * \brief get allocation info. for all chunks of a file */struct MetaGetlayout: public MetaRequest {	fid_t fid;	//!< file for layout info is needed	vector <ChunkLayoutInfo> v; //!< vector of results	MetaGetlayout(seq_t s, fid_t f):		MetaRequest(META_GETLAYOUT, s, false), fid(f) { }	int log(ofstream &file) const;	void response(ostringstream &os);	string Show()	{		ostringstream os;		os << "getlayout: fid = " << fid;		return os.str();	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -