storage/ssd_layout/main.cc
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "storage/ssd_layout/ssd_layout.h" | ||
| 2 | |||
| 3 | #include <cstdlib> | ||
| 4 | #include <iostream> | ||
| 5 | #include <string> | ||
| 6 | |||
| 7 | namespace { | ||
| 8 | |||
| 9 | ✗ | void Usage() { | |
| 10 | std::cerr << "usage:\n" | ||
| 11 | << " recstore_ssd_layout partition --query PATH --output PATH\n" | ||
| 12 | << " --row-size N [--page-size 4096] [--keys PATH]\n" | ||
| 13 | << " [--binary]\n" | ||
| 14 | << " recstore_ssd_layout replicate --query PATH --mapping PATH\n" | ||
| 15 | << " --output PATH --rep-ratio F [--keys PATH] [--binary]\n" | ||
| 16 | << " recstore_ssd_layout shrink --mapping PATH --output PATH\n" | ||
| 17 | << " --rep-ratio F\n" | ||
| 18 | ✗ | << " recstore_ssd_layout inspect --mapping PATH\n"; | |
| 19 | ✗ | } | |
| 20 | |||
| 21 | ✗ | std::string Need(int argc, char** argv, int* i) { | |
| 22 | ✗ | if (*i + 1 >= argc) { | |
| 23 | ✗ | Usage(); | |
| 24 | ✗ | std::exit(2); | |
| 25 | } | ||
| 26 | ✗ | return argv[++(*i)]; | |
| 27 | } | ||
| 28 | |||
| 29 | } // namespace | ||
| 30 | |||
| 31 | ✗ | int main(int argc, char** argv) { | |
| 32 | try { | ||
| 33 | ✗ | if (argc < 2) { | |
| 34 | ✗ | Usage(); | |
| 35 | ✗ | return 2; | |
| 36 | } | ||
| 37 | ✗ | const std::string command = argv[1]; | |
| 38 | ✗ | std::string query; | |
| 39 | ✗ | std::string mapping; | |
| 40 | ✗ | std::string output; | |
| 41 | ✗ | std::string keys_path; | |
| 42 | ✗ | uint32_t row_size = 0; | |
| 43 | ✗ | uint32_t page_size = 4096; | |
| 44 | ✗ | double rep_ratio = 0; | |
| 45 | ✗ | bool binary = false; | |
| 46 | ✗ | for (int i = 2; i < argc; ++i) { | |
| 47 | ✗ | const std::string flag = argv[i]; | |
| 48 | ✗ | if (flag == "--binary") { | |
| 49 | ✗ | binary = true; | |
| 50 | ✗ | } else if (flag == "--query") { | |
| 51 | ✗ | query = Need(argc, argv, &i); | |
| 52 | ✗ | } else if (flag == "--mapping") { | |
| 53 | ✗ | mapping = Need(argc, argv, &i); | |
| 54 | ✗ | } else if (flag == "--output") { | |
| 55 | ✗ | output = Need(argc, argv, &i); | |
| 56 | ✗ | } else if (flag == "--keys") { | |
| 57 | ✗ | keys_path = Need(argc, argv, &i); | |
| 58 | ✗ | } else if (flag == "--row-size") { | |
| 59 | ✗ | row_size = static_cast<uint32_t>(std::stoul(Need(argc, argv, &i))); | |
| 60 | ✗ | } else if (flag == "--page-size") { | |
| 61 | ✗ | page_size = static_cast<uint32_t>(std::stoul(Need(argc, argv, &i))); | |
| 62 | ✗ | } else if (flag == "--rep-ratio") { | |
| 63 | ✗ | rep_ratio = std::stod(Need(argc, argv, &i)); | |
| 64 | } else { | ||
| 65 | ✗ | Usage(); | |
| 66 | ✗ | return 2; | |
| 67 | } | ||
| 68 | ✗ | } | |
| 69 | |||
| 70 | ✗ | if (command == "inspect") { | |
| 71 | ✗ | const ssd_layout::Artifact artifact = ssd_layout::LoadArtifact(mapping); | |
| 72 | ✗ | uint64_t copies = 0; | |
| 73 | ✗ | for (const auto& row : artifact.copies) { | |
| 74 | ✗ | copies += row.size(); | |
| 75 | } | ||
| 76 | ✗ | std::cout << "strategy=" << ssd_layout::StrategyName(artifact.strategy) | |
| 77 | ✗ | << " page_size=" << artifact.page_size << " row_size=" | |
| 78 | ✗ | << artifact.row_size << " keys=" << artifact.keys.size() | |
| 79 | ✗ | << " pages=" << artifact.pages.size() << " copies=" << copies | |
| 80 | ✗ | << " checksum=" << artifact.checksum << "\n"; | |
| 81 | ✗ | return 0; | |
| 82 | ✗ | } | |
| 83 | ✗ | if (output.empty()) { | |
| 84 | ✗ | Usage(); | |
| 85 | ✗ | return 2; | |
| 86 | } | ||
| 87 | ✗ | if (command == "partition") { | |
| 88 | const ssd_layout::Hypergraph graph = | ||
| 89 | ✗ | ssd_layout::ReadQueryLog(query, binary); | |
| 90 | ✗ | const auto keys = ssd_layout::ReadKeyMap(keys_path, graph.vertex_count); | |
| 91 | ✗ | ssd_layout::SaveArtifact( | |
| 92 | ✗ | ssd_layout::Partition(graph, keys, page_size, row_size), output); | |
| 93 | ✗ | return 0; | |
| 94 | ✗ | } | |
| 95 | ✗ | if (command == "replicate") { | |
| 96 | const ssd_layout::Hypergraph graph = | ||
| 97 | ✗ | ssd_layout::ReadQueryLog(query, binary); | |
| 98 | ✗ | const auto keys = ssd_layout::ReadKeyMap(keys_path, graph.vertex_count); | |
| 99 | ✗ | const ssd_layout::Artifact base = ssd_layout::LoadArtifact(mapping); | |
| 100 | ✗ | auto replicated = ssd_layout::Replicate(base, graph, keys, rep_ratio); | |
| 101 | ✗ | ssd_layout::SaveArtifact(replicated, output); | |
| 102 | ✗ | return 0; | |
| 103 | ✗ | } | |
| 104 | ✗ | if (command == "shrink") { | |
| 105 | ✗ | ssd_layout::SaveArtifact( | |
| 106 | ✗ | ssd_layout::Shrink(ssd_layout::LoadArtifact(mapping), rep_ratio), | |
| 107 | output); | ||
| 108 | ✗ | return 0; | |
| 109 | } | ||
| 110 | ✗ | Usage(); | |
| 111 | ✗ | return 2; | |
| 112 | ✗ | } catch (const std::exception& error) { | |
| 113 | ✗ | std::cerr << "recstore_ssd_layout: " << error.what() << "\n"; | |
| 114 | ✗ | return 1; | |
| 115 | ✗ | } | |
| 116 | } | ||
| 117 |