mirror of
https://github.com/facebook/rocksdb.git
synced 2024-12-01 16:15:59 +00:00
2b443ba887
Summary: implemented a commond line shell to talk with leveldb thrift server, which is based on state pattern and can be easily extended. Test Plan: build and run Reviewers: dhruba, zshao, heyongqiang Differential Revision: https://reviews.facebook.net/D4713
65 lines
1.6 KiB
C++
65 lines
1.6 KiB
C++
|
|
#ifndef TOOLS_SHELL_DBCLIENTPROXY
|
|
#define TOOLS_SHELL_DBCLIENTPROXY
|
|
|
|
#include <vector>
|
|
#include <map>
|
|
#include <string>
|
|
#include <boost/utility.hpp>
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
#include "DB.h"
|
|
|
|
/*
|
|
* class DBClientProxy maintains:
|
|
* 1. a connection to leveldb service
|
|
* 2. a map from db names to opened db handles
|
|
*
|
|
* it's client codes' responsibility to catch all possible exceptions.
|
|
*/
|
|
|
|
namespace leveldb {
|
|
|
|
class DBClientProxy : private boost::noncopyable {
|
|
public:
|
|
// connect to host_:port_
|
|
void connect(void);
|
|
|
|
// return true on success, false otherwise
|
|
bool get(const std::string & db,
|
|
const std::string & key,
|
|
std::string & value);
|
|
|
|
// return true on success, false otherwise
|
|
bool put(const std::string & db,
|
|
const std::string & key,
|
|
const std::string & value);
|
|
|
|
// return true on success, false otherwise
|
|
bool scan(const std::string & db,
|
|
const std::string & start_key,
|
|
const std::string & end_key,
|
|
const std::string & limit,
|
|
std::vector<std::pair<std::string, std::string> > & kvs);
|
|
|
|
// return true on success, false otherwise
|
|
bool create(const std::string & db);
|
|
|
|
DBClientProxy(const std::string & host, int port);
|
|
~DBClientProxy();
|
|
|
|
private:
|
|
// some internal help functions
|
|
void cleanUp(void);
|
|
void open(const std::string & db);
|
|
std::map<std::string, Tleveldb::DBHandle>::iterator getHandle(const std::string & db);
|
|
|
|
const std::string host_;
|
|
const int port_;
|
|
std::map<std::string, Tleveldb::DBHandle> dbToHandle_;
|
|
boost::shared_ptr<Tleveldb::DBClient> dbClient_;
|
|
};
|
|
|
|
} // namespace
|
|
#endif
|