OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ShowDiskCacheUsageCommand Class Reference

#include <DdlCommandExecutor.h>

+ Inheritance diagram for ShowDiskCacheUsageCommand:
+ Collaboration diagram for ShowDiskCacheUsageCommand:

Public Member Functions

 ShowDiskCacheUsageCommand (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)
 

Private Member Functions

std::vector< std::string > getFilteredTableNames ()
 

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 325 of file DdlCommandExecutor.h.

Constructor & Destructor Documentation

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

Definition at line 3356 of file DdlCommandExecutor.cpp.

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

3359  : DdlCommand(ddl_data, session_ptr) {
3360  auto& ddl_payload = extractPayload(ddl_data_);
3361  if (ddl_payload.HasMember("tableNames")) {
3362  CHECK(ddl_payload["tableNames"].IsArray());
3363  for (auto const& tablename_def : ddl_payload["tableNames"].GetArray()) {
3364  CHECK(tablename_def.IsString());
3365  }
3366  }
3367 }
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:291

+ Here is the call graph for this function:

Member Function Documentation

ExecutionResult ShowDiskCacheUsageCommand::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 3392 of file DdlCommandExecutor.cpp.

References ResultSetLogicalValuesBuilder::create(), anonymous_namespace{DdlCommandExecutor.cpp}::exec_for_tables_which_exist(), anonymous_namespace{DdlCommandExecutor.cpp}::genLiteralBigInt(), genLiteralStr(), legacylockmgr::getExecuteReadLock(), getFilteredTableNames(), kBIGINT, kTEXT, and DdlCommand::session_ptr_.

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

3392  {
3393  auto execute_read_lock = legacylockmgr::getExecuteReadLock();
3394 
3395  // valid in read_only_mode
3396 
3397  auto cat_ptr = session_ptr_->get_catalog_ptr();
3398  auto table_names = getFilteredTableNames();
3399 
3400  const auto disk_cache = cat_ptr->getDataMgr().getPersistentStorageMgr()->getDiskCache();
3401  if (!disk_cache) {
3402  throw std::runtime_error{"Disk cache not enabled. Cannot show disk cache usage."};
3403  }
3404 
3405  // label_infos -> column labels
3406  std::vector<std::string> labels{"table name", "current cache size"};
3407  std::vector<TargetMetaInfo> label_infos;
3408  label_infos.emplace_back(labels[0], SQLTypeInfo(kTEXT, true));
3409  label_infos.emplace_back(labels[1], SQLTypeInfo(kBIGINT, true));
3410 
3411  std::vector<RelLogicalValues::RowValues> logical_values;
3412 
3414  table_names,
3415  cat_ptr.get(),
3416  [&logical_values, &disk_cache, &cat_ptr](const TableDescriptor* td,
3417  const std::string& table_name) {
3418  auto table_cache_size =
3419  disk_cache->getSpaceReservedByTable(cat_ptr->getDatabaseId(), td->tableId);
3420  // logical_values -> table data
3421  logical_values.emplace_back(RelLogicalValues::RowValues{});
3422  logical_values.back().emplace_back(genLiteralStr(table_name));
3423  logical_values.back().emplace_back(genLiteralBigInt(table_cache_size));
3424  });
3425 
3426  std::shared_ptr<ResultSet> rSet = std::shared_ptr<ResultSet>(
3427  ResultSetLogicalValuesBuilder::create(label_infos, logical_values));
3428 
3429  return ExecutionResult(rSet, label_infos);
3430 }
auto getExecuteReadLock()
std::unique_ptr< RexLiteral > genLiteralBigInt(int64_t val)
static ResultSet * create(std::vector< TargetMetaInfo > &label_infos, std::vector< RelLogicalValues::RowValues > &logical_values)
Definition: sqltypes.h:79
std::vector< std::string > getFilteredTableNames()
static std::unique_ptr< RexLiteral > genLiteralStr(std::string val)
Definition: DBHandler.cpp:7752
void exec_for_tables_which_exist(const std::vector< std::string > &table_names, Catalog_Namespace::Catalog *cat_ptr, Func func)
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_
std::vector< std::unique_ptr< const RexScalar >> RowValues
Definition: RelAlgDag.h:2656

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector< std::string > ShowDiskCacheUsageCommand::getFilteredTableNames ( )
private

Definition at line 3369 of file DdlCommandExecutor.cpp.

References DdlCommand::ddl_data_, anonymous_namespace{DdlCommandExecutor.cpp}::extractPayload(), GET_PHYSICAL_TABLES, and DdlCommand::session_ptr_.

Referenced by execute().

3369  {
3370  auto table_names = session_ptr_->get_catalog_ptr()->getTableNamesForUser(
3371  session_ptr_->get_currentUser(), GET_PHYSICAL_TABLES);
3372 
3373  auto& ddl_payload = extractPayload(ddl_data_);
3374  if (ddl_payload.HasMember("tableNames")) {
3375  std::vector<std::string> filtered_names;
3376  for (const auto& tablename_def : ddl_payload["tableNames"].GetArray()) {
3377  std::string filter_name = tablename_def.GetString();
3378  if (std::find(table_names.begin(), table_names.end(), filter_name) !=
3379  table_names.end()) {
3380  filtered_names.emplace_back(filter_name);
3381  } else {
3382  throw std::runtime_error("Can not show disk cache usage for table: " +
3383  filter_name + ". Table does not exist.");
3384  }
3385  }
3386  return filtered_names;
3387  } else {
3388  return table_names;
3389  }
3390 }
const DdlCommandData & ddl_data_
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_

+ 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: