OmniSciDB  340b00dbf6
 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 <boost/program_options.hpp>
#include <exception>
#include <iostream>
#include <memory>
#include <string>
#include "Catalog/Catalog.h"
#include "CudaMgr/CudaMgr.h"
#include "ImportExport/Importer.h"
#include "Logger/Logger.h"
#include "OSDependent/omnisci_path.h"
#include "QueryRunner/QueryRunner.h"
+ 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 33 of file initdb.cpp.

Referenced by main().

Function Documentation

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

Definition at line 44 of file initdb.cpp.

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

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

+ Here is the call graph for this function:

Variable Documentation

bool g_enable_thrift_logs {false}

Definition at line 42 of file initdb.cpp.

Referenced by CommandLineOptions::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 35 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 38 of file initdb.cpp.

Referenced by main().