From ab9e0a509d8c3e41652e0ce9b9852f72f9354ba6 Mon Sep 17 00:00:00 2001 From: Andrew Hutchings Date: Tue, 6 Jun 2017 14:17:23 +0100 Subject: [PATCH] MCOL-739 Add command to get the system catalog Added to DBRM master for use with the the new API so that it can get the system catalog via the wire protocol. --- versioning/BRM/brmtypes.h | 1 + versioning/BRM/masterdbrmnode.cpp | 61 +++++++++++++++++++++++++++++++ versioning/BRM/masterdbrmnode.h | 1 + 3 files changed, 63 insertions(+) diff --git a/versioning/BRM/brmtypes.h b/versioning/BRM/brmtypes.h index 7fa32de64..2e74e4aec 100644 --- a/versioning/BRM/brmtypes.h +++ b/versioning/BRM/brmtypes.h @@ -471,6 +471,7 @@ const uint8_t RELEASE_LBID_RANGES = 91; /* More main BRM functions 100-110 */ const uint8_t BULK_UPDATE_DBROOT = 100; +const uint8_t GET_SYSTEM_CATALOG = 101; /* Error codes returned by the DBRM functions. */ diff --git a/versioning/BRM/masterdbrmnode.cpp b/versioning/BRM/masterdbrmnode.cpp index 46f49906f..09ec7dfee 100644 --- a/versioning/BRM/masterdbrmnode.cpp +++ b/versioning/BRM/masterdbrmnode.cpp @@ -362,6 +362,7 @@ void MasterDBRMNode::msgProcessor() case SETREADONLY: doSetReadOnly(p->sock, true); continue; case SETREADWRITE: doSetReadOnly(p->sock, false); continue; case GETREADONLY: doGetReadOnly(p->sock); continue; + case GET_SYSTEM_CATALOG: doGetSystemCatalog(msg, p); continue; } /* Process SessionManager calls */ @@ -1093,6 +1094,66 @@ void MasterDBRMNode::doVerID(ByteStream &msg, ThreadParams *p) catch (exception&) { } } +void MasterDBRMNode::doGetSystemCatalog(ByteStream &msg, ThreadParams *p) +{ + ByteStream reply; + + reply << (uint8_t) ERR_OK; + + boost::shared_ptr systemCatalogPtr = + execplan::CalpontSystemCatalog::makeCalpontSystemCatalog(); + const std::vector< std::pair > catalog_tables + = systemCatalogPtr->getTables(); + + reply << (uint32_t) systemCatalogPtr->getTableCount(); + for (std::vector >::const_iterator it = catalog_tables.begin(); + it != catalog_tables.end(); ++it) + { + execplan::CalpontSystemCatalog::TableInfo tb_info = systemCatalogPtr->tableInfo((*it).second); + reply << (uint32_t)(*it).first; + reply << (*it).second.schema; + reply << (*it).second.table; + reply << (uint32_t)tb_info.numOfCols; + execplan::CalpontSystemCatalog::RIDList column_rid_list = systemCatalogPtr->columnRIDs((*it).second, true); + for (size_t col_num = 0; col_num < column_rid_list.size(); col_num++) + { + execplan::CalpontSystemCatalog::TableColName tcn = systemCatalogPtr->colName(column_rid_list[col_num].objnum); + execplan::CalpontSystemCatalog::ColType ct = systemCatalogPtr->colType(column_rid_list[col_num].objnum); + reply << (uint32_t)column_rid_list[col_num].objnum; + reply << tcn.column; + if (ct.ddn.dictOID == std::numeric_limits::min()) + { + reply << (uint32_t) 0; + } + else + { + reply << (uint32_t) ct.ddn.dictOID; + } + reply << (uint8_t) ct.colDataType; + reply << (uint32_t) ct.colWidth; + reply << (uint32_t) ct.colPosition; + reply << ct.defaultValue; + reply << (uint8_t) ct.autoincrement; + reply << (uint32_t) ct.precision; + reply << (uint32_t) ct.scale; + if (ct.constraintType != execplan::CalpontSystemCatalog::NOTNULL_CONSTRAINT) + { + reply << (uint8_t) 1; + } + else + { + reply << (uint8_t) 0; + } + reply << (uint8_t) ct.compressionType; + } + } + + try { + p->sock->write(reply); + } + catch (exception&) { } +} + void MasterDBRMNode::doSysCatVerID(ByteStream &msg, ThreadParams *p) { ByteStream reply; diff --git a/versioning/BRM/masterdbrmnode.h b/versioning/BRM/masterdbrmnode.h index 0ce98fe8b..880586775 100644 --- a/versioning/BRM/masterdbrmnode.h +++ b/versioning/BRM/masterdbrmnode.h @@ -180,6 +180,7 @@ private: /* SessionManager interface */ SessionManagerServer sm; void doVerID(messageqcpp::ByteStream &msg, ThreadParams *p); + void doGetSystemCatalog(messageqcpp::ByteStream &msg, ThreadParams *p); void doSysCatVerID(messageqcpp::ByteStream &msg, ThreadParams *p); void doNewTxnID(messageqcpp::ByteStream &msg, ThreadParams *p); void doCommitted(messageqcpp::ByteStream &msg, ThreadParams *p);