OmniSciDB  d2f719934e
 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 () 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 Member Functions inherited from DdlCommand
bool isDefaultServer (const std::string &server_name)
 
- Protected Attributes inherited from DdlCommand
const DdlCommandDataddl_data_
 
std::shared_ptr
< Catalog_Namespace::SessionInfo
const
session_ptr_
 

Detailed Description

Definition at line 164 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 1583 of file DdlCommandExecutor.cpp.

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

1586  : DdlCommand(ddl_data, session_ptr) {
1587  auto& ddl_payload = extractPayload(ddl_data_);
1588  if (ddl_payload.HasMember("tableNames")) {
1589  CHECK(ddl_payload["tableNames"].IsArray());
1590  for (auto const& tablename_def : ddl_payload["tableNames"].GetArray()) {
1591  CHECK(tablename_def.IsString());
1592  }
1593  }
1594 }
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:211

+ Here is the call graph for this function:

Member Function Documentation

ExecutionResult ShowDiskCacheUsageCommand::execute ( )
overridevirtual

Executes the DDL command corresponding to provided JSON payload.

Parameters
_returnresult of DDL command execution (if applicable)

Implements DdlCommand.

Definition at line 1619 of file DdlCommandExecutor.cpp.

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

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

1619  {
1620  auto cat_ptr = session_ptr_->get_catalog_ptr();
1621  auto table_names = getFilteredTableNames();
1622 
1623  const auto disk_cache = cat_ptr->getDataMgr().getPersistentStorageMgr()->getDiskCache();
1624  if (!disk_cache) {
1625  throw std::runtime_error{"Disk cache not enabled. Cannot show disk cache usage."};
1626  }
1627 
1628  // label_infos -> column labels
1629  std::vector<std::string> labels{"table name", "current cache size"};
1630  std::vector<TargetMetaInfo> label_infos;
1631  label_infos.emplace_back(labels[0], SQLTypeInfo(kTEXT, true));
1632  label_infos.emplace_back(labels[1], SQLTypeInfo(kBIGINT, true));
1633 
1634  std::vector<RelLogicalValues::RowValues> logical_values;
1635 
1636  for (auto& table_name : table_names) {
1637  auto [td, td_with_lock] =
1638  get_table_descriptor_with_lock<lockmgr::ReadLock>(*cat_ptr, table_name, false);
1639 
1640  auto table_cache_size =
1641  disk_cache->getSpaceReservedByTable(cat_ptr->getDatabaseId(), td->tableId);
1642 
1643  // logical_values -> table data
1644  logical_values.emplace_back(RelLogicalValues::RowValues{});
1645  logical_values.back().emplace_back(genLiteralStr(table_name));
1646  logical_values.back().emplace_back(genLiteralBigInt(table_cache_size));
1647  }
1648 
1649  std::shared_ptr<ResultSet> rSet = std::shared_ptr<ResultSet>(
1650  ResultSetLogicalValuesBuilder::create(label_infos, logical_values));
1651 
1652  return ExecutionResult(rSet, label_infos);
1653 }
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:52
std::vector< std::string > getFilteredTableNames()
static std::unique_ptr< RexLiteral > genLiteralStr(std::string val)
Definition: DBHandler.cpp:7369
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_
std::vector< std::unique_ptr< const RexScalar >> RowValues

+ 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 1596 of file DdlCommandExecutor.cpp.

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

Referenced by execute().

1596  {
1597  auto table_names = session_ptr_->get_catalog_ptr()->getTableNamesForUser(
1598  session_ptr_->get_currentUser(), GET_PHYSICAL_TABLES);
1599 
1600  auto& ddl_payload = extractPayload(ddl_data_);
1601  if (ddl_payload.HasMember("tableNames")) {
1602  std::vector<std::string> filtered_names;
1603  for (const auto& tablename_def : ddl_payload["tableNames"].GetArray()) {
1604  std::string filter_name = tablename_def.GetString();
1605  if (std::find(table_names.begin(), table_names.end(), filter_name) !=
1606  table_names.end()) {
1607  filtered_names.emplace_back(filter_name);
1608  } else {
1609  throw std::runtime_error("Can not show disk cache usage for table: " +
1610  filter_name + ". Table does not exist.");
1611  }
1612  }
1613  return filtered_names;
1614  } else {
1615  return table_names;
1616  }
1617 }
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: