OmniSciDB  b24e664e58
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Catalog_Namespace Namespace Reference

Namespaces

 anonymous_namespace{Catalog.cpp}
 
 anonymous_namespace{SysCatalog.cpp}
 

Classes

class  Catalog
 class for a per-database catalog. also includes metadata for the current database and the current user. More...
 
class  read_lock
 
class  sqlite_lock
 
class  write_lock
 
class  MapDHandler
 
class  SessionInfo
 
struct  UserMetadata
 
struct  DBMetadata
 
struct  DBSummary
 
class  CommonFileOperations
 
class  SysCatalog
 

Typedefs

using cat_read_lock = read_lock< Catalog >
 
using cat_write_lock = write_lock< Catalog >
 
using cat_sqlite_lock = sqlite_lock< Catalog >
 
using sys_read_lock = read_lock< SysCatalog >
 
using sys_write_lock = write_lock< SysCatalog >
 
using sys_sqlite_lock = sqlite_lock< SysCatalog >
 
using DBSummaryList = std::list< DBSummary >
 

Functions

std::string abs_path (const File_Namespace::GlobalFileMgr *global_file_mgr)
 
std::string run (const std::string &cmd, const std::string &chdir="")
 
std::string simple_file_cat (const std::string &archive_path, const std::string &file_name, const std::string &compression)
 
std::string get_table_schema (const std::string &archive_path, const std::string &table, const std::string &compression)
 
std::ostream & operator<< (std::ostream &os, const SessionInfo &session_info)
 
void deleteObjectPrivileges (std::unique_ptr< SqliteConnector > &sqliteConnector, std::string roleName, bool userRole, DBObject &object)
 
void insertOrUpdateObjectPrivileges (std::unique_ptr< SqliteConnector > &sqliteConnector, std::string roleName, bool userRole, DBObject &object)
 
static bool parseUserMetadataFromSQLite (const std::unique_ptr< SqliteConnector > &conn, UserMetadata &user)
 

Variables

const int DEFAULT_INITIAL_VERSION = 1
 
const int MAPD_TEMP_TABLE_START_ID
 
const int MAPD_TEMP_DICT_START_ID
 
static constexpr char const * table_schema_filename = "_table.sql"
 
static constexpr char const * table_oldinfo_filename = "_table.oldinfo"
 
static constexpr char const * table_epoch_filename = "_table.epoch"
 
auto simple_file_closer = [](FILE* f) { std::fclose(f); }
 

Typedef Documentation

Definition at line 90 of file Catalog.cpp.

Definition at line 92 of file Catalog.cpp.

Definition at line 91 of file Catalog.cpp.

using Catalog_Namespace::DBSummaryList = typedef std::list<DBSummary>

Definition at line 121 of file SysCatalog.h.

Definition at line 74 of file SysCatalog.cpp.

Definition at line 76 of file SysCatalog.cpp.

Definition at line 75 of file SysCatalog.cpp.

Function Documentation

std::string Catalog_Namespace::abs_path ( const File_Namespace::GlobalFileMgr global_file_mgr)
inline

Definition at line 71 of file DumpRestore.cpp.

References File_Namespace::GlobalFileMgr::getBasePath().

Referenced by Catalog_Namespace::Catalog::dumpTable(), Catalog_Namespace::Catalog::renameTableDirectories(), and Catalog_Namespace::Catalog::restoreTable().

71  {
72  return boost::filesystem::canonical(global_file_mgr->getBasePath()).string();
73 }
std::string getBasePath() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Catalog_Namespace::deleteObjectPrivileges ( std::unique_ptr< SqliteConnector > &  sqliteConnector,
std::string  roleName,
bool  userRole,
DBObject object 
)

Definition at line 317 of file SysCatalog.cpp.

References DBObjectKey::dbId, DBObjectKey::objectId, DBObjectKey::permissionType, and to_string().

Referenced by Catalog_Namespace::SysCatalog::revokeDBObjectPrivileges_unsafe().

320  {
321  DBObjectKey key = object.getObjectKey();
322 
323  sqliteConnector->query_with_text_params(
324  "DELETE FROM mapd_object_permissions WHERE roleName = ?1 and roleType = ?2 and "
325  "objectPermissionsType = ?3 and "
326  "dbId = "
327  "?4 "
328  "and objectId = ?5",
329  std::vector<std::string>{roleName,
330  std::to_string(userRole),
332  std::to_string(key.dbId),
333  std::to_string(key.objectId)});
334 }
int32_t objectId
Definition: DBObject.h:56
std::string to_string(char const *&&v)
int32_t dbId
Definition: DBObject.h:55
int32_t permissionType
Definition: DBObject.h:54

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string Catalog_Namespace::get_table_schema ( const std::string &  archive_path,
const std::string &  table,
const std::string &  compression 
)
inline

Definition at line 148 of file DumpRestore.cpp.

References simple_file_cat(), and table_schema_filename.

Referenced by Catalog_Namespace::Catalog::restoreTable().

150  {
151  const auto schema_str =
152  simple_file_cat(archive_path, table_schema_filename, compression);
153  std::regex regex("@T");
154  return std::regex_replace(schema_str, regex, table);
155 }
std::string simple_file_cat(const std::string &archive_path, const std::string &file_name, const std::string &compression)
static constexpr char const * table_schema_filename
Definition: DumpRestore.cpp:65

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Catalog_Namespace::insertOrUpdateObjectPrivileges ( std::unique_ptr< SqliteConnector > &  sqliteConnector,
std::string  roleName,
bool  userRole,
DBObject object 
)

Definition at line 336 of file SysCatalog.cpp.

References DBObjectKey::dbId, DBObjectKey::objectId, DBObjectKey::permissionType, and to_string().

Referenced by Catalog_Namespace::SysCatalog::createRole_unsafe(), Catalog_Namespace::SysCatalog::grantDBObjectPrivileges_unsafe(), Catalog_Namespace::SysCatalog::migrateDBAccessPrivileges(), Catalog_Namespace::SysCatalog::migratePrivileges(), Catalog_Namespace::SysCatalog::populateRoleDbObjects(), and Catalog_Namespace::SysCatalog::revokeDBObjectPrivileges_unsafe().

339  {
340  DBObjectKey key = object.getObjectKey();
341 
342  sqliteConnector->query_with_text_params(
343  "INSERT OR REPLACE INTO mapd_object_permissions("
344  "roleName, "
345  "roleType, "
346  "objectPermissionsType, "
347  "dbId, "
348  "objectId, "
349  "objectPermissions, "
350  "objectOwnerId,"
351  "objectName) "
352  "VALUES (?1, ?2, ?3, "
353  "?4, ?5, ?6, ?7, ?8)",
354  std::vector<std::string>{
355  roleName, // roleName
356  userRole ? "1" : "0", // roleType
357  std::to_string(key.permissionType), // permissionType
358  std::to_string(key.dbId), // dbId
359  std::to_string(key.objectId), // objectId
360  std::to_string(object.getPrivileges().privileges), // objectPrivileges
361  std::to_string(object.getOwner()), // objectOwnerId
362  object.getName() // name
363  });
364 }
int32_t objectId
Definition: DBObject.h:56
std::string to_string(char const *&&v)
int32_t dbId
Definition: DBObject.h:55
int32_t permissionType
Definition: DBObject.h:54

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::ostream & Catalog_Namespace::operator<< ( std::ostream &  os,
const SessionInfo &  session_info 
)

Definition at line 53 of file SessionInfo.cpp.

References Catalog_Namespace::SessionInfo::get_public_session_id().

53  {
54  os << session_info.get_public_session_id();
55  return os;
56 }

+ Here is the call graph for this function:

static bool Catalog_Namespace::parseUserMetadataFromSQLite ( const std::unique_ptr< SqliteConnector > &  conn,
UserMetadata &  user 
)
static

Definition at line 1181 of file SysCatalog.cpp.

References Catalog_Namespace::UserMetadata::can_login, Catalog_Namespace::UserMetadata::defaultDbId, Catalog_Namespace::UserMetadata::isSuper, Catalog_Namespace::UserMetadata::passwd_hash, Catalog_Namespace::UserMetadata::userId, and Catalog_Namespace::UserMetadata::userName.

Referenced by Catalog_Namespace::SysCatalog::getMetadataForUser(), and Catalog_Namespace::SysCatalog::getMetadataForUserById().

1182  {
1183  int numRows = conn->getNumRows();
1184  if (numRows == 0) {
1185  return false;
1186  }
1187  user.userId = conn->getData<int>(0, 0);
1188  user.userName = conn->getData<string>(0, 1);
1189  user.passwd_hash = conn->getData<string>(0, 2);
1190  user.isSuper = conn->getData<bool>(0, 3);
1191  user.defaultDbId = conn->isNull(0, 4) ? -1 : conn->getData<int>(0, 4);
1192  user.can_login = conn->getData<bool>(0, 5);
1193  return true;
1194 }

+ Here is the caller graph for this function:

std::string Catalog_Namespace::run ( const std::string &  cmd,
const std::string &  chdir = "" 
)
inline

Definition at line 75 of file DumpRestore.cpp.

References logger::ERROR, error_code, measure< TimeT >::execution(), LOG, to_string(), and VLOG.

Referenced by Catalog_Namespace::Catalog::dumpTable(), Catalog_Namespace::Catalog::restoreTable(), and simple_file_cat().

75  {
76  VLOG(3) << "running cmd: " << cmd;
77  int rcode;
78  std::error_code ec;
79  std::string output, errors;
80  const auto time_ms = measure<>::execution([&]() {
81  using namespace boost::process;
82  ipstream stdout, stderr;
83  if (!chdir.empty()) {
84  rcode = system(cmd, std_out > stdout, std_err > stderr, ec, start_dir = chdir);
85  } else {
86  rcode = system(cmd, std_out > stdout, std_err > stderr, ec);
87  }
88  std::ostringstream ss_output, ss_errors;
89  stdout >> ss_output.rdbuf();
90  stderr >> ss_errors.rdbuf();
91  output = ss_output.str();
92  errors = ss_errors.str();
93  });
94  if (rcode || ec) {
95  LOG(ERROR) << "failed cmd: " << cmd;
96  LOG(ERROR) << "exit code: " << rcode;
97  LOG(ERROR) << "error code: " << ec.value() << " - " << ec.message();
98  LOG(ERROR) << "stdout: " << output;
99  LOG(ERROR) << "stderr: " << errors;
100 #if defined(__APPLE__)
101  // osx bsdtar options "--use-compress-program" and "--fast-read" together
102  // run into pipe write error after tar extracts the first occurrence of a
103  // file and closes the read end while the decompression program still writes
104  // to the pipe. bsdtar doesn't handle this situation well like gnu tar does.
105  if (1 == rcode && cmd.find("--fast-read") &&
106  (errors.find("cannot write decoded block") != std::string::npos ||
107  errors.find("Broken pipe") != std::string::npos)) {
108  // ignore this error, or lose speed advantage of "--fast-read" on osx.
109  LOG(ERROR) << "tar error ignored on osx for --fast-read";
110  } else
111 #endif
112  // circumvent tar warning on reading file that is "changed as we read it".
113  // this warning results from reading a table file under concurrent inserts
114  if (1 == rcode && errors.find("changed as we read") != std::string::npos) {
115  LOG(ERROR) << "tar error ignored under concurrent inserts";
116  } else {
117  throw std::runtime_error("Failed to run command: " + cmd +
118  "\nexit code: " + std::to_string(rcode) + "\nerrors:\n" +
119  (rcode ? errors : ec.message()));
120  }
121  } else {
122  VLOG(3) << "finished cmd: " << cmd;
123  VLOG(3) << "time: " << time_ms << " ms";
124  VLOG(3) << "stdout: " << output;
125  }
126  return output;
127 }
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
#define LOG(tag)
Definition: Logger.h:185
std::string to_string(char const *&&v)
const int8_t const int64_t const uint64_t const int32_t const int64_t int64_t uint32_t const int64_t int32_t * error_code
#define VLOG(n)
Definition: Logger.h:280

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string Catalog_Namespace::simple_file_cat ( const std::string &  archive_path,
const std::string &  file_name,
const std::string &  compression 
)
inline

Definition at line 129 of file DumpRestore.cpp.

References run().

Referenced by get_table_schema(), and Catalog_Namespace::Catalog::restoreTable().

131  {
132 #if defined(__APPLE__)
133  constexpr static auto opt_occurrence = " --fast-read ";
134 #else
135  constexpr static auto opt_occurrence = " --occurrence=1 ";
136 #endif
137  boost::filesystem::path temp_dir =
138  boost::filesystem::temp_directory_path() / boost::filesystem::unique_path();
139  boost::filesystem::create_directories(temp_dir);
140  run("tar " + compression + " -xvf \"" + archive_path + "\" " + opt_occurrence +
141  file_name,
142  temp_dir.string());
143  const auto output = run("cat " + (temp_dir / file_name).string());
144  boost::filesystem::remove_all(temp_dir);
145  return output;
146 }
static bool run

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

const int Catalog_Namespace::DEFAULT_INITIAL_VERSION = 1
const int Catalog_Namespace::MAPD_TEMP_DICT_START_ID
Initial value:
=
1073741824

Definition at line 82 of file Catalog.cpp.

const int Catalog_Namespace::MAPD_TEMP_TABLE_START_ID
Initial value:
=
1073741824

Definition at line 80 of file Catalog.cpp.

auto Catalog_Namespace::simple_file_closer = [](FILE* f) { std::fclose(f); }
inline
constexpr char const* Catalog_Namespace::table_epoch_filename = "_table.epoch"
static
constexpr char const* Catalog_Namespace::table_oldinfo_filename = "_table.oldinfo"
static
constexpr char const* Catalog_Namespace::table_schema_filename = "_table.sql"
static