OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
/home/jenkins-slave/workspace/core-os-doxygen/initdb.cpp File Reference
#include <thrift/Thrift.h>
#include <array>
#include <boost/filesystem.hpp>
#include <exception>
#include <iostream>
#include <memory>
#include <string>
#include "Catalog/Catalog.h"
#include "Import/Importer.h"
#include "Shared/Logger.h"
#include "Shared/mapdpath.h"
#include "boost/program_options.hpp"
+ Include dependency graph for initdb.cpp:

Go to the source code of this file.

Macros

#define CALCITEPORT   3279
 

Functions

int main (int argc, char *argv[])
 

Variables

static const std::array
< std::string, 3 > 
SampleGeoFileNames
 
static const std::array
< std::string, 3 > 
SampleGeoTableNames
 
bool g_enable_thrift_logs {false}
 

Macro Definition Documentation

#define CALCITEPORT   3279

Definition at line 30 of file initdb.cpp.

Referenced by main().

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 41 of file initdb.cpp.

References CALCITEPORT, CHECK(), g_enable_thrift_logs, Catalog_Namespace::Catalog::get(), logger::LogOptions::get_options(), logger::init(), Catalog_Namespace::SysCatalog::instance(), mapd_root_abs_path(), OMNISCI_DEFAULT_DB, OMNISCI_ROOT_USER, run, SampleGeoFileNames, SampleGeoTableNames, and logger::LogOptions::set_base_path().

41  {
42  std::string base_path;
43  bool force = false;
44  bool skip_geo = false;
45  namespace po = boost::program_options;
46 
47  po::options_description desc("Options");
48  desc.add_options()("help,h", "Print help messages ")(
49  "data",
50  po::value<std::string>(&base_path)->required(),
51  "Directory path to OmniSci catalogs")(
52  "force,f", "Force overwriting of existing OmniSci instance")(
53  "skip-geo", "Skip inserting sample geo data");
54 
55  desc.add_options()("enable-thrift-logs",
56  po::value<bool>(&g_enable_thrift_logs)
57  ->default_value(g_enable_thrift_logs)
58  ->implicit_value(true),
59  "Enable writing messages directly from thrift to stdout/stderr.");
60 
61  logger::LogOptions log_options(argv[0]);
62  desc.add(log_options.get_options());
63 
64  po::positional_options_description positionalOptions;
65  positionalOptions.add("data", 1);
66 
67  po::variables_map vm;
68 
69  try {
70  po::store(po::command_line_parser(argc, argv)
71  .options(desc)
72  .positional(positionalOptions)
73  .run(),
74  vm);
75  if (vm.count("help")) {
76  std::cout << "Usage: initdb [-f] <catalog path>\n";
77  return 0;
78  }
79  if (vm.count("force")) {
80  force = true;
81  }
82  if (vm.count("skip-geo")) {
83  skip_geo = true;
84  }
85  po::notify(vm);
86  } catch (boost::program_options::error& e) {
87  std::cerr << "Usage Error: " << e.what() << std::endl;
88  return 1;
89  }
90 
91  if (!g_enable_thrift_logs) {
92  apache::thrift::GlobalOutput.setOutputFunction([](const char* msg) {});
93  }
94 
95  if (!boost::filesystem::exists(base_path)) {
96  std::cerr << "Catalog basepath " + base_path + " does not exist.\n";
97  return 1;
98  }
99  std::string catalogs_path = base_path + "/mapd_catalogs";
100  if (boost::filesystem::exists(catalogs_path)) {
101  if (force) {
102  boost::filesystem::remove_all(catalogs_path);
103  } else {
104  std::cerr << "OmniSci catalogs already initialized at " + base_path +
105  ". Use -f to force reinitialization.\n";
106  return 1;
107  }
108  }
109  std::string data_path = base_path + "/mapd_data";
110  if (boost::filesystem::exists(data_path)) {
111  if (force) {
112  boost::filesystem::remove_all(data_path);
113  } else {
114  std::cerr << "OmniSci data directory already exists at " + base_path +
115  ". Use -f to force reinitialization.\n";
116  return 1;
117  }
118  }
119  std::string export_path = base_path + "/mapd_export";
120  if (boost::filesystem::exists(export_path)) {
121  if (force) {
122  boost::filesystem::remove_all(export_path);
123  } else {
124  std::cerr << "OmniSci export directory already exists at " + base_path +
125  ". Use -f to force reinitialization.\n";
126  return 1;
127  }
128  }
129  if (!boost::filesystem::create_directory(catalogs_path)) {
130  std::cerr << "Cannot create mapd_catalogs subdirectory under " << base_path
131  << std::endl;
132  }
133  if (!boost::filesystem::create_directory(export_path)) {
134  std::cerr << "Cannot create mapd_export subdirectory under " << base_path
135  << std::endl;
136  }
137 
138  log_options.set_base_path(base_path);
139  logger::init(log_options);
140 
141  try {
142  MapDParameters mapd_parms;
143  auto dummy =
144  std::make_shared<Data_Namespace::DataMgr>(data_path, mapd_parms, false, 0);
145  auto calcite = std::make_shared<Calcite>(-1, CALCITEPORT, base_path, 1024);
146  auto& sys_cat = Catalog_Namespace::SysCatalog::instance();
147  sys_cat.init(base_path, dummy, {}, calcite, true, false, {});
148 
149  if (!skip_geo) {
150  // Add geo samples to the system database using the root user
152  const std::string db_name(OMNISCI_DEFAULT_DB);
153  CHECK(sys_cat.getMetadataForDB(db_name, cur_db));
155  base_path, cur_db, dummy, std::vector<LeafHostInfo>(), calcite, false);
157  CHECK(sys_cat.getMetadataForUser(OMNISCI_ROOT_USER, user));
158 
159  Importer_NS::ImportDriver import_driver(cat, user);
160 
161  const size_t num_samples = SampleGeoFileNames.size();
162  for (size_t i = 0; i < num_samples; i++) {
163  const std::string table_name = SampleGeoTableNames[i];
164  const std::string file_name = SampleGeoFileNames[i];
165 
166  const auto file_path = boost::filesystem::path(
167  mapd_root_abs_path() + "/ThirdParty/geo_samples/" + file_name);
168  if (!boost::filesystem::exists(file_path)) {
169  throw std::runtime_error(
170  "Unable to populate geo sample data. File does not exist: " +
171  file_path.string());
172  }
173 
174  import_driver.importGeoTable(file_path.string(), table_name, true, true, false);
175  }
176  }
177 
178  } catch (std::exception& e) {
179  std::cerr << "Exception: " << e.what() << "\n";
180  }
181  return 0;
182 }
static std::shared_ptr< Catalog > get(const std::string &dbName)
Definition: Catalog.cpp:2990
std::string mapd_root_abs_path()
Definition: mapdpath.h:30
static const std::array< std::string, 3 > SampleGeoFileNames
Definition: initdb.cpp:32
static SysCatalog & instance()
Definition: SysCatalog.h:242
CHECK(cgen_state)
void init(LogOptions const &log_opts)
Definition: Logger.cpp:265
const std::string OMNISCI_DEFAULT_DB
Definition: SysCatalog.h:58
static const std::array< std::string, 3 > SampleGeoTableNames
Definition: initdb.cpp:35
bool g_enable_thrift_logs
Definition: initdb.cpp:39
const std::string OMNISCI_ROOT_USER
Definition: SysCatalog.h:59
#define CALCITEPORT
Definition: initdb.cpp:30
static bool run

+ Here is the call graph for this function:

Variable Documentation

bool g_enable_thrift_logs {false}

Definition at line 39 of file initdb.cpp.

Referenced by MapDProgramOptions::fillOptions(), main(), and startMapdServer().

const std::array<std::string, 3> SampleGeoFileNames
static
Initial value:
{"us-states.json",
"us-counties.json",
"countries.json"}

Definition at line 32 of file initdb.cpp.

Referenced by main().

const std::array<std::string, 3> SampleGeoTableNames
static
Initial value:
{"omnisci_states",
"omnisci_counties",
"omnisci_countries"}

Definition at line 35 of file initdb.cpp.

Referenced by main().