7 #define NUM_APP_ARGS (1) 11 std::cerr <<
"Usage: " << argv[0] <<
" [ derecho-config-list -- ] <aio|bio>" << std::endl;
18 }
else if(strcmp(
"bio", argv[1]) != 0) {
19 std::cerr <<
"unrecognized argument:" << argv[argc -
NUM_APP_ARGS] <<
". Using bio (blocking io) instead." << std::endl;
23 std::cout <<
"Starting object store service..." << std::endl;
27 std::cout <<
"watcher: " << oid <<
"->" <<
object << std::endl;
30 std::cout <<
"Object store service started. \n\tIs replica:" << std::boolalpha << oss.
isReplica()
31 <<
"\n\tUsing aio API:" << use_aio
32 << std::noboolalpha <<
"." << std::endl;
34 bool bNextCommand =
true;
37 std::map<std::string, std::pair<std::string, std::function<bool(std::string&)>>> commands = {
41 [&oss, use_aio](std::string args) ->
bool {
42 std::istringstream ss(args);
43 std::string oid, odata;
50 decltype(results)::ReplyMap& replies = results.
get();
51 std::cout <<
"aio returns:" << std::endl;
52 for(
auto& reply_pair : replies) {
53 std::tuple<persistent::version_t,uint64_t> res = reply_pair.second.get();
54 std::cout << reply_pair.first <<
": version=" << std::get<0>(res)
55 <<
", timestamp=" << std::get<1>(res) << std::endl;
58 std::tuple<persistent::version_t,uint64_t> result = oss.bio_put(
object);
60 std::cout <<
"version:" << std::get<0>(result)
61 <<
", timestamp:" << std::get<1>(result) << std::endl;
70 "get <oid> [version]",
71 [&oss, use_aio](std::string& args) ->
bool {
72 char* argcopy = strdup(args.c_str());
73 char* token = std::strtok(argcopy,
" ");
74 uint64_t oid = std::stol(token);
76 if((token = std::strtok(
nullptr,
" ")) !=
nullptr) {
77 ver = std::stol(token);
83 decltype(results)::ReplyMap& replies = results.
get();
84 std::cout <<
"aio returns:" << std::endl;
85 for(
auto& reply_pair : replies) {
86 std::cout << reply_pair.first <<
":" << reply_pair.second.get() << std::endl;
91 std::cout << obj << std::endl;
102 "tget <oid> <unix time in us>",
103 [&oss, use_aio](std::string& args) ->
bool {
104 std::istringstream ss(args);
112 decltype(results)::ReplyMap& replies = results.
get();
113 std::cout <<
"aio returns:" << std::endl;
114 for(
auto& reply_pair : replies) {
115 std::cout << reply_pair.first <<
":" << reply_pair.second.get() << std::endl;
120 std::cout << obj << std::endl;
130 [&oss, use_aio](std::string& args) ->
bool {
135 decltype(results)::ReplyMap& replies = results.
get();
136 std::cout <<
"aio returns:" << std::endl;
137 for(
auto& reply_pair : replies) {
138 std::tuple<version_t,uint64_t> res = reply_pair.second.get();
139 std::cout << reply_pair.first <<
": version=" << std::get<0>(res)
140 <<
", timestamp=" << std::get<1>(res) << std::endl;
143 std::tuple<version_t,uint64_t> ver = oss.bio_remove(std::stol(args));
144 std::cout <<
"version:" << std::get<0>(ver)
145 <<
", timestamp:" << std::get<1>(ver) << std::endl;
155 [&oss, &bNextCommand](std::string&) ->
bool {
157 bNextCommand =
false;
161 std::function<void()> help = [commands]() {
162 std::cout <<
"Commands:" << std::endl;
163 for(
auto& cmd_entry : commands) {
164 std::cout <<
"\t" << cmd_entry.second.first << std::endl;
170 while(bNextCommand) {
173 std::getline(std::cin, line,
'\n');
174 std::string::size_type first_space_pos = line.find(
' ');
176 std::string arguments;
177 if(first_space_pos == std::string::npos) {
180 command = line.substr(0, first_space_pos);
181 arguments = line.substr(first_space_pos + 1);
183 if(commands.find(command) == commands.end()) {
186 bool bRet = commands[command].second(arguments);
187 std::cout <<
"Result:" << std::boolalpha << bRet << std::noboolalpha
static IObjectStoreService & getObjectStoreService(int argc, char **argv, const ObjectWatcher &ow={})
virtual const bool isReplica()=0
static void initialize(int argc, char *argv[], const char *conf_file=nullptr)
int main(int argc, char **argv)
Data structure that (indirectly) holds a set of futures for a single RPC function call; there is one ...
ReplyMap & get()
Block until the ReplyMap is fulfilled, then return the map by reference.