| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
|---|---|
| 2 | // Licensed under the MIT license. |
| 3 | |
| 4 | #include <cstdint> |
| 5 | #include <cstdio> |
| 6 | #include <cstdlib> |
| 7 | #include <experimental/filesystem> |
| 8 | #include <string> |
| 9 | |
| 10 | #include "concurrent_recovery_test.h" |
| 11 | #include "sum_store.h" |
| 12 | #include "single_threaded_recovery_test.h" |
| 13 | |
| 14 | int main(int argc, char* argv[]) { |
| 15 | if(argc < 3) { |
| 16 | printf("Usage: sum_store.exe single <operation>\n"); |
| 17 | printf("Where <operation> is one of \"populate\", \"recover <token>\", or " |
| 18 | "\"continue <token>\".\n"); |
| 19 | exit(0); |
| 20 | } |
| 21 | |
| 22 | std::experimental::filesystem::create_directory("sum_storage"); |
| 23 | |
| 24 | static constexpr uint64_t kKeySpace = (1L << 15); |
| 25 | |
| 26 | sum_store::store_t store{ kKeySpace, 17179869184, "sum_storage"}; |
| 27 | |
| 28 | |
| 29 | std::string type{ argv[1] }; |
| 30 | if(type == "single") { |
| 31 | sum_store::SingleThreadedRecoveryTest test{ store }; |
| 32 | |
| 33 | std::string task{ argv[2] }; |
| 34 | if(task == "populate") { |
| 35 | test.Populate(); |
| 36 | } else if(task == "recover") { |
| 37 | if(argc != 4) { |
| 38 | printf("Must specify token to recover to.\n"); |
| 39 | exit(1); |
| 40 | } |
| 41 | Guid token = Guid::Parse(argv[3]); |
| 42 | test.RecoverAndTest(token, token); |
| 43 | } |
| 44 | } else if(type == "concurrent") { |
| 45 | if(argc < 4) { |
| 46 | printf("Must specify number of threads to execute concurrently.\n"); |
| 47 | exit(1); |
| 48 | } |
| 49 | |
| 50 | size_t num_threads = std::atoi(argv[2]); |
| 51 | |
| 52 | sum_store::ConcurrentRecoveryTest test{ store, num_threads }; |
| 53 | |
| 54 | std::string task{ argv[3] }; |
| 55 | if(task == "populate") { |
| 56 | test.Populate(); |
| 57 | } else if(task == "recover") { |
| 58 | if(argc != 5) { |
| 59 | printf("Must specify token to recover to.\n"); |
| 60 | exit(1); |
| 61 | } |
| 62 | Guid token = Guid::Parse(argv[4]); |
| 63 | test.RecoverAndTest(token, token); |
| 64 | } else if(task == "continue") { |
| 65 | if(argc != 5) { |
| 66 | printf("Must specify version to continue from.\n"); |
| 67 | exit(1); |
| 68 | } |
| 69 | Guid token = Guid::Parse(argv[4]); |
| 70 | test.Continue(token, token); |
| 71 | } |
| 72 | |
| 73 | } |
| 74 | |
| 75 | |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 |