memgraph/tests/manual/kvstore_console.cpp
Matej Ferencevic 75950664a7 Separate distributed from single node storage
Summary:
This diff splits single node and distributed storage from each other.
Currently all of the storage code is copied into two directories (one single
node, one distributed).  The logic used in the storage implementation isn't
touched, it will be refactored in following diffs.

To clean the working directory after this diff you should execute:
```
rm database/state_delta.capnp
rm database/state_delta.hpp
rm storage/concurrent_id_mapper_rpc_messages.capnp
rm storage/concurrent_id_mapper_rpc_messages.hpp
```

Reviewers: teon.banek, buda, msantl

Reviewed By: teon.banek, msantl

Subscribers: teon.banek, pullbot

Differential Revision: https://phabricator.memgraph.io/D1625
2018-10-05 09:19:33 +02:00

67 lines
1.9 KiB
C++

#include <gflags/gflags.h>
#include <glog/logging.h>
#include "storage/kvstore/kvstore.hpp"
#include "utils/string.hpp"
DEFINE_string(path, "", "Path to the storage directory.");
int main(int argc, char **argv) {
gflags::SetVersionString("kvstore_console");
gflags::ParseCommandLineFlags(&argc, &argv, true);
google::InitGoogleLogging(argv[0]);
CHECK(FLAGS_path != "") << "Please specify a path to the KVStore!";
storage::KVStore kvstore(std::experimental::filesystem::path{FLAGS_path});
while (true) {
std::string s;
std::getline(std::cin, s);
if (s == "") {
break;
}
auto split = utils::Split(utils::Trim(s));
if (split[0] == "list") {
if (split.size() != 1) {
std::cout << "`list' takes no arguments!" << std::endl;
}
for (auto it = kvstore.begin(); it != kvstore.end(); ++it) {
std::cout << it->first << " --> " << it->second << std::endl;
}
} else if (split[0] == "get") {
if (split.size() != 2) {
std::cout << "`get' takes exactly one argument!" << std::endl;
}
auto item = kvstore.Get(split[1]);
if (item != std::experimental::nullopt) {
std::cout << split[1] << " --> " << *item << std::endl;
} else {
std::cout << "Key doesn't exist in the database!" << std::endl;
}
} else if (split[0] == "put") {
if (split.size() != 3) {
std::cout << "`put' takes exactly two arguments!" << std::endl;
}
if (kvstore.Put(split[1], split[2])) {
std::cout << "Success." << std::endl;
} else {
std::cout << "Failure!" << std::endl;
}
} else if (split[0] == "delete") {
if (split.size() != 2) {
std::cout << "`delete' takes exactly one argument!" << std::endl;
}
if (kvstore.Delete(split[1])) {
std::cout << "Success." << std::endl;
} else {
std::cout << "Failure!" << std::endl;
}
}
std::cout << std::endl;
}
return 0;
}