OmniSciDB  c0231cc57d
 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 219 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 2125 of file DdlCommandExecutor.cpp.

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

2128  : DdlCommand(ddl_data, session_ptr) {
2129  auto& ddl_payload = extractPayload(ddl_data_);
2130  if (ddl_payload.HasMember("tableNames")) {
2131  CHECK(ddl_payload["tableNames"].IsArray());
2132  for (auto const& tablename_def : ddl_payload["tableNames"].GetArray()) {
2133  CHECK(tablename_def.IsString());
2134  }
2135  }
2136 }
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

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

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

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

2161  {
2162  // valid in read_only_mode
2163 
2164  auto cat_ptr = session_ptr_->get_catalog_ptr();
2165  auto table_names = getFilteredTableNames();
2166 
2167  const auto disk_cache = cat_ptr->getDataMgr().getPersistentStorageMgr()->getDiskCache();
2168  if (!disk_cache) {
2169  throw std::runtime_error{"Disk cache not enabled. Cannot show disk cache usage."};
2170  }
2171 
2172  // label_infos -> column labels
2173  std::vector<std::string> labels{"table name", "current cache size"};
2174  std::vector<TargetMetaInfo> label_infos;
2175  label_infos.emplace_back(labels[0], SQLTypeInfo(kTEXT, true));
2176  label_infos.emplace_back(labels[1], SQLTypeInfo(kBIGINT, true));
2177 
2178  std::vector<RelLogicalValues::RowValues> logical_values;
2179 
2180  for (auto& table_name : table_names) {
2181  auto [td, td_with_lock] =
2182  get_table_descriptor_with_lock<lockmgr::ReadLock>(*cat_ptr, table_name, false);
2183 
2184  auto table_cache_size =
2185  disk_cache->getSpaceReservedByTable(cat_ptr->getDatabaseId(), td->tableId);
2186 
2187  // logical_values -> table data
2188  logical_values.emplace_back(RelLogicalValues::RowValues{});
2189  logical_values.back().emplace_back(genLiteralStr(table_name));
2190  logical_values.back().emplace_back(genLiteralBigInt(table_cache_size));
2191  }
2192 
2193  std::shared_ptr<ResultSet> rSet = std::shared_ptr<ResultSet>(
2194  ResultSetLogicalValuesBuilder::create(label_infos, logical_values));
2195 
2196  return ExecutionResult(rSet, label_infos);
2197 }
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:66
std::vector< std::string > getFilteredTableNames()
static std::unique_ptr< RexLiteral > genLiteralStr(std::string val)
Definition: DBHandler.cpp:7263
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_
std::vector< std::unique_ptr< const RexScalar >> RowValues
Definition: RelAlgDag.h:2226

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

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

Referenced by execute().

2138  {
2139  auto table_names = session_ptr_->get_catalog_ptr()->getTableNamesForUser(
2140  session_ptr_->get_currentUser(), GET_PHYSICAL_TABLES);
2141 
2142  auto& ddl_payload = extractPayload(ddl_data_);
2143  if (ddl_payload.HasMember("tableNames")) {
2144  std::vector<std::string> filtered_names;
2145  for (const auto& tablename_def : ddl_payload["tableNames"].GetArray()) {
2146  std::string filter_name = tablename_def.GetString();
2147  if (std::find(table_names.begin(), table_names.end(), filter_name) !=
2148  table_names.end()) {
2149  filtered_names.emplace_back(filter_name);
2150  } else {
2151  throw std::runtime_error("Can not show disk cache usage for table: " +
2152  filter_name + ". Table does not exist.");
2153  }
2154  }
2155  return filtered_names;
2156  } else {
2157  return table_names;
2158  }
2159 }
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: