User's Guide
Developers can write distributed applications using the Sector client API. The client API is in the form of C++ classes. Currently there are two different Sector clients: file client and Sphere distributed computing client. The file client allows user applications to access a Sector file just like a local file.The Sphere client supports simple and fast development of distributed data processing applications.
Example client programs can found in ./client directory.
Preparation
The application should include proper Sector client header files of <fsclient.h>, <sqlclient.h>, and <speclient.h>, respectively. These client files may also further include other Sector header files. See the example Makefile for details. The application also need proper Sector libraries to compile and run. These libraries can be found in ./lib directory.
Common APIs
Sector client has a set of common APIs for operations that are not associated with any specific client. These APIs are static global functions.
- int Sector::init(ip, port). This function must be called at least once in an application, and must be before all other Sector calls. The function initialize the client and connect it to a Sector server at <ip:port>.
- int Sector::close(). This function should be called if the Sector client is not required any more in the application.
- int Sector::lookup(const string& name, vector<Node>& nl). This function looks up a particular resource in Sector networks, and returns the information about all servers that has the resource indicated by "name".
File Client
The file client contains the following static functions to create and release file handles, and check file statistics, respectively.
- File* Sector::createFileHandle(). This function creates a handle to a Sector file.
- void Sector::releaseFileHandle(File* f). This function release the file handle "f".
- int Sector::stat(const string& filename, CFileAttr& attr). This function returns the statistics information about the file specified by "filename".
The following functions can be used to the Sector file handle:
- int open(const string& filename, const int& mode = 1, char* cert = NULL);
- int read(char* buf, const int64_t& offset, const int64_t& size);
- int readridx(char* index, const int64_t& offset, const int64_t& rows);
- int write(const char* buf, const int64_t& offset, const int64_t& size);
- int download(const char* localpath, const bool& cont = false);
- int upload(const char* localpath, const bool& cont = false);
int close();
Sphere Client
SImilar to the file client, user applications must create the Sphere process handles using the following global functions:
- Process* Sector::createJob().
- int Sector::releaseJob(Process* proc).
After the application obtains a Process handle, it can use the following functions to create and run a distributed data processing task.
- int open(vector<string> stream, string op, const char* param = NULL, const int& size = 0).
- int close().
- int run().
- int checkProgress().
- int read(char*& data, int& size, string& file, int64_t& offset, int& rows, const bool& inorder = true, const bool& wait = true).