OmniSciDB  c0231cc57d
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RefreshForeignTablesCommand Class Reference

#include <DdlCommandExecutor.h>

+ Inheritance diagram for RefreshForeignTablesCommand:
+ Collaboration diagram for RefreshForeignTablesCommand:

Public Member Functions

 RefreshForeignTablesCommand (const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
 
ExecutionResult execute (bool read_only_mode) override
 
- Public Member Functions inherited from DdlCommand
 DdlCommand (const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
 

Additional Inherited Members

- Protected Attributes inherited from DdlCommand
const DdlCommandDataddl_data_
 
std::shared_ptr
< Catalog_Namespace::SessionInfo
const > 
session_ptr_
 

Detailed Description

Definition at line 248 of file DdlCommandExecutor.h.

Constructor & Destructor Documentation

RefreshForeignTablesCommand::RefreshForeignTablesCommand ( const DdlCommandData ddl_data,
std::shared_ptr< Catalog_Namespace::SessionInfo const >  session_ptr 
)

Definition at line 1922 of file DdlCommandExecutor.cpp.

References CHECK, DdlCommand::ddl_data_, anonymous_namespace{DdlCommandExecutor.cpp}::extractPayload(), and g_enable_fsi.

1925  : DdlCommand(ddl_data, session_ptr) {
1926  if (!g_enable_fsi) {
1927  throw std::runtime_error("Unsupported command: REFRESH FOREIGN TABLE");
1928  }
1929  auto& ddl_payload = extractPayload(ddl_data_);
1930  CHECK(ddl_payload.HasMember("tableNames"));
1931  CHECK(ddl_payload["tableNames"].IsArray());
1932  for (auto const& tablename_def : ddl_payload["tableNames"].GetArray()) {
1933  CHECK(tablename_def.IsString());
1934  }
1935 }
const DdlCommandData & ddl_data_
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
DdlCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
#define CHECK(condition)
Definition: Logger.h:222
bool g_enable_fsi
Definition: Catalog.cpp:96

+ Here is the call graph for this function:

Member Function Documentation

ExecutionResult RefreshForeignTablesCommand::execute ( bool  read_only_mode)
overridevirtual

Executes the DDL command corresponding to provided JSON payload.

Parameters
_returnresult of DDL command execution (if applicable)

Implements DdlCommand.

Definition at line 1937 of file DdlCommandExecutor.cpp.

References cat(), CHECK, shared::contains(), DdlCommand::ddl_data_, legacylockmgr::ExecutorOuterLock, anonymous_namespace{DdlCommandExecutor.cpp}::extractPayload(), legacylockmgr::LockMgr< MutexType, KeyType >::getMutex(), Catalog_Namespace::SysCatalog::instance(), CacheInvalidator< CACHE_HOLDING_TYPES >::invalidateCaches(), join(), foreign_storage::OptionsContainer::options, foreign_storage::OptionsContainer::populateOptionsMap(), foreign_storage::refresh_foreign_table(), Catalog_Namespace::REQUEST_LOGS_SYS_TABLE_NAME, Catalog_Namespace::SERVER_LOGS_SYS_TABLE_NAME, DdlCommand::session_ptr_, TableDBObjectType, Catalog_Namespace::WS_SERVER_ACCESS_LOGS_SYS_TABLE_NAME, and Catalog_Namespace::WS_SERVER_LOGS_SYS_TABLE_NAME.

Referenced by heavydb.cursor.Cursor::executemany().

1937  {
1938  if (read_only_mode) {
1939  throw std::runtime_error("REFRESH FOREIGN TABLE invalid in read only mode.");
1940  }
1941 
1942  const auto execute_read_lock =
1946 
1947  bool evict_cached_entries{false};
1949  auto& ddl_payload = extractPayload(ddl_data_);
1950  if (ddl_payload.HasMember("options") && !ddl_payload["options"].IsNull()) {
1951  opt.populateOptionsMap(ddl_payload["options"]);
1952  for (const auto& entry : opt.options) {
1953  if (entry.first != "EVICT") {
1954  throw std::runtime_error{
1955  "Invalid option \"" + entry.first +
1956  "\" provided for refresh command. Only \"EVICT\" option is supported."};
1957  }
1958  }
1959  CHECK(opt.options.find("EVICT") != opt.options.end());
1960 
1961  if (boost::iequals(opt.options["EVICT"], "true") ||
1962  boost::iequals(opt.options["EVICT"], "false")) {
1963  if (boost::iequals(opt.options["EVICT"], "true")) {
1964  evict_cached_entries = true;
1965  }
1966  } else {
1967  throw std::runtime_error{
1968  "Invalid value \"" + opt.options["EVICT"] +
1969  "\" provided for EVICT option. Value must be either \"true\" or \"false\"."};
1970  }
1971  }
1972 
1973  auto& cat = session_ptr_->getCatalog();
1974  const auto& current_user = session_ptr_->get_currentUser();
1975  /* verify object ownership if not suser */
1976  if (!current_user.isSuper) {
1977  for (const auto& table_name_json : ddl_payload["tableNames"].GetArray()) {
1978  std::string table_name = table_name_json.GetString();
1979  if (!Catalog_Namespace::SysCatalog::instance().verifyDBObjectOwnership(
1980  current_user, DBObject(table_name, TableDBObjectType), cat)) {
1981  throw std::runtime_error(
1982  std::string("REFRESH FOREIGN TABLES failed on table \"") + table_name +
1983  "\". It can only be executed by super user or "
1984  "owner of the "
1985  "object.");
1986  }
1987  }
1988  }
1989 
1990  for (const auto& table_name_json : ddl_payload["tableNames"].GetArray()) {
1991  std::string table_name = table_name_json.GetString();
1992  static const std::array<std::string, 4> log_system_tables{
1997  if (cat.isInfoSchemaDb() && !shared::contains(log_system_tables, table_name)) {
1998  throw std::runtime_error(
1999  "REFRESH FOREIGN TABLE can only be executed for the following tables: " +
2000  join(log_system_tables, ","));
2001  }
2002  foreign_storage::refresh_foreign_table(cat, table_name, evict_cached_entries);
2003  }
2004 
2005  // todo(yoonmin) : allow per-table cache invalidation for the foreign table
2007 
2008  return ExecutionResult();
2009 }
static std::shared_ptr< WrapperType< MutexType > > getMutex(const LockType lockType, const KeyType &key)
bool contains(const T &container, const U &element)
Definition: misc.h:195
static constexpr const char * WS_SERVER_ACCESS_LOGS_SYS_TABLE_NAME
Definition: Catalog.h:117
static constexpr const char * SERVER_LOGS_SYS_TABLE_NAME
Definition: Catalog.h:114
std::string cat(Ts &&...args)
std::string join(T const &container, std::string const &delim)
void refresh_foreign_table(Catalog_Namespace::Catalog &catalog, const std::string &table_name, const bool evict_cached_entries)
static void invalidateCaches()
static constexpr const char * REQUEST_LOGS_SYS_TABLE_NAME
Definition: Catalog.h:115
std::shared_lock< T > shared_lock
const DdlCommandData & ddl_data_
static SysCatalog & instance()
Definition: SysCatalog.h:341
void populateOptionsMap(OptionsMap &&options_map, bool clear=false)
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
#define CHECK(condition)
Definition: Logger.h:222
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_
static constexpr const char * WS_SERVER_LOGS_SYS_TABLE_NAME
Definition: Catalog.h:116

+ Here is the call graph for this function:

+ Here is the caller graph for this function:


The documentation for this class was generated from the following files: