forked from heavyai/heavydb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
initdb.cpp
108 lines (98 loc) · 3.52 KB
/
initdb.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
* Copyright 2017 MapD Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <iostream>
#include <string>
#include <exception>
#include "boost/program_options.hpp"
#include <boost/filesystem.hpp>
#include "Catalog/Catalog.h"
#ifdef STANDALONE_CALCITE
#define CALCITEPORT 9093
#else
#define CALCITEPORT -1
#endif
int main(int argc, char* argv[]) {
std::string base_path;
bool force = false;
namespace po = boost::program_options;
google::InitGoogleLogging(argv[0]);
po::options_description desc("Options");
desc.add_options()("help,h", "Print help messages ")(
"data", po::value<std::string>(&base_path)->required(), "Directory path to MapD catalogs")(
"force,f", "Force overwriting of existing MapD instance");
po::positional_options_description positionalOptions;
positionalOptions.add("data", 1);
po::variables_map vm;
try {
po::store(po::command_line_parser(argc, argv).options(desc).positional(positionalOptions).run(), vm);
if (vm.count("help")) {
std::cout << "Usage: initdb [-f] <catalog path>\n";
return 0;
}
if (vm.count("force"))
force = true;
po::notify(vm);
} catch (boost::program_options::error& e) {
std::cerr << "Usage Error: " << e.what() << std::endl;
return 1;
}
if (!boost::filesystem::exists(base_path)) {
std::cerr << "Catalog basepath " + base_path + " does not exist.\n";
return 1;
}
std::string catalogs_path = base_path + "/mapd_catalogs";
if (boost::filesystem::exists(catalogs_path)) {
if (force)
boost::filesystem::remove_all(catalogs_path);
else {
std::cerr << "MapD catalogs already initialized at " + base_path + ". Use -f to force reinitialization.\n";
return 1;
}
}
std::string data_path = base_path + "/mapd_data";
if (boost::filesystem::exists(data_path)) {
if (force)
boost::filesystem::remove_all(data_path);
else {
std::cerr << "MapD data directory already exists at " + base_path + ". Use -f to force reinitialization.\n";
return 1;
}
}
std::string export_path = base_path + "/mapd_export";
if (boost::filesystem::exists(export_path)) {
if (force)
boost::filesystem::remove_all(export_path);
else {
std::cerr << "MapD export directory already exists at " + base_path + ". Use -f to force reinitialization.\n";
return 1;
}
}
if (!boost::filesystem::create_directory(catalogs_path)) {
std::cerr << "Cannot create mapd_catalogs subdirectory under " << base_path << std::endl;
}
if (!boost::filesystem::create_directory(export_path)) {
std::cerr << "Cannot create mapd_export subdirectory under " << base_path << std::endl;
}
try {
auto dummy = std::make_shared<Data_Namespace::DataMgr>(data_path, 0, false, 0);
auto dummy_calcite = std::make_shared<Calcite>(-1, 0, base_path, 1024);
Catalog_Namespace::SysCatalog sys_cat(base_path, dummy, dummy_calcite, true);
sys_cat.initDB();
} catch (std::exception& e) {
std::cerr << "Exception: " << e.what() << "\n";
}
return 0;
}