From cc8751a752b6a5d878e1044509fbd89bd436fc9c Mon Sep 17 00:00:00 2001 From: poojanilangekar Date: Fri, 11 May 2018 21:12:42 -0400 Subject: [PATCH] Changed after Prashanth's review --- src/catalog/catalog.cpp | 2 +- src/include/common/exception.h | 13 ++++++++++++- src/include/storage/layout.h | 4 ++-- src/storage/layout.cpp | 4 ++-- src/storage/tile_group_factory.cpp | 4 ++++ 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/catalog/catalog.cpp b/src/catalog/catalog.cpp index fe91b340ed3..a36eb71c4bd 100644 --- a/src/catalog/catalog.cpp +++ b/src/catalog/catalog.cpp @@ -579,7 +579,7 @@ std::shared_ptr Catalog::CreateLayout( bool result = pg_layout->InsertLayout(table_oid, new_layout, pool_.get(), txn); if (!result) { - LOG_DEBUG("Failed to create a new layout for table %u", table_oid); + LOG_ERROR("Failed to create a new layout for table %u", table_oid); return nullptr; } return new_layout; diff --git a/src/include/common/exception.h b/src/include/common/exception.h index 4c201891751..7f25ec20e9f 100644 --- a/src/include/common/exception.h +++ b/src/include/common/exception.h @@ -59,7 +59,8 @@ enum class ExceptionType { SETTINGS = 23, // settings related BINDER = 24, // binder related NETWORK = 25, // network related - OPTIMIZER = 26 // optimizer related + OPTIMIZER = 26, // optimizer related + NULL_POINTER = 27 // nullptr exception }; class Exception : public std::runtime_error { @@ -132,6 +133,8 @@ class Exception : public std::runtime_error { return "Settings"; case ExceptionType::OPTIMIZER: return "Optimizer"; + case ExceptionType::NULL_POINTER: + return "NullPointer"; default: return "Unknown"; } @@ -467,4 +470,12 @@ class OptimizerException : public Exception { : Exception(ExceptionType::OPTIMIZER, msg) {} }; +class NullPointerException : public Exception { + NullPointerException() = delete; + + public: + NullPointerException(std::string msg) + : Exception(ExceptionType::NULL_POINTER, msg) {} +}; + } // namespace peloton diff --git a/src/include/storage/layout.h b/src/include/storage/layout.h index d06fe93427e..ce726d5d729 100644 --- a/src/include/storage/layout.h +++ b/src/include/storage/layout.h @@ -34,7 +34,7 @@ namespace storage { /** @brief used to store the mapping between a tile and its columns * to vector{} */ -typedef std::map>> tile_map_type; +typedef std::map>> TileToColumnMap; /** * @brief Class to store the physical layout of a TileGroup. @@ -100,7 +100,7 @@ class Layout : public Printable { uint32_t GetColumnCount() const { return num_columns_; } /** @brief Returns the tile-columns map for each tile in the TileGroup. */ - tile_map_type GetTileMap() const; + TileToColumnMap GetTileMap() const; /** @brief Constructs the schema for the given layout. This function * is used only in TempTables and LogicalTiles. diff --git a/src/storage/layout.cpp b/src/storage/layout.cpp index 37664a42f77..c03b721087f 100644 --- a/src/storage/layout.cpp +++ b/src/storage/layout.cpp @@ -137,8 +137,8 @@ oid_t Layout::GetTileIdFromColumnId(oid_t column_id) const { return tile_offset; } -tile_map_type Layout::GetTileMap() const { - tile_map_type tile_map; +TileToColumnMap Layout::GetTileMap() const { + TileToColumnMap tile_map; if (layout_type_ == LayoutType::ROW) { // Row store layout, hence all columns are contained in tile 0. diff --git a/src/storage/tile_group_factory.cpp b/src/storage/tile_group_factory.cpp index c1fd897c09b..2c0da483619 100644 --- a/src/storage/tile_group_factory.cpp +++ b/src/storage/tile_group_factory.cpp @@ -31,6 +31,10 @@ TileGroup *TileGroupFactory::GetTileGroup( // Allocate the data on appropriate backend BackendType backend_type = BackendType::MM; // logging::LoggingUtil::GetBackendType(peloton_logging_mode); + // Ensure that the layout of the new TileGroup is not null. + if (layout == nullptr) { + throw NullPointerException("Layout of the TileGroup must be non-null."); + } TileGroupHeader *tile_header = new TileGroupHeader(backend_type, tuple_count); TileGroup *tile_group = new TileGroup(backend_type, tile_header, table,