OmniSciDB  eb3a3d0a03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UpdelRoll Struct Reference

#include <UpdelRoll.h>

+ Collaboration diagram for UpdelRoll:

Public Member Functions

 ~UpdelRoll ()
 
void cancelUpdate ()
 
bool commitUpdate ()
 
void stageUpdate ()
 
void addDirtyChunk (std::shared_ptr< Chunk_NS::Chunk > chunk, int fragment_id)
 
std::shared_ptr< ChunkMetadatagetChunkMetadata (const MetaDataKey &key, int32_t column_id, Fragmenter_Namespace::FragmentInfo &fragment_info)
 
ChunkMetadataMap getChunkMetadataMap (const MetaDataKey &key) const
 
size_t getNumTuple (const MetaDataKey &key) const
 
void setNumTuple (const MetaDataKey &key, size_t num_tuple)
 

Public Attributes

const Catalog_Namespace::Catalogcatalog = nullptr
 
int logicalTableId
 
Data_Namespace::MemoryLevel memoryLevel {Data_Namespace::MemoryLevel::CPU_LEVEL}
 
bool is_varlen_update = false
 
const TableDescriptortable_descriptor {nullptr}
 

Private Member Functions

void updateFragmenterAndCleanupChunks ()
 
void initializeUnsetMetadata (const TableDescriptor *td, Fragmenter_Namespace::FragmentInfo &fragment_info)
 

Private Attributes

mapd_shared_mutex chunk_update_tracker_mutex
 
std::map< ChunkKey,
std::shared_ptr
< Chunk_NS::Chunk > > 
dirty_chunks
 
std::map< MetaDataKey, size_t > num_tuples
 
std::map< MetaDataKey,
ChunkMetadataMap
chunk_metadata_map_per_fragment
 

Detailed Description

Definition at line 43 of file UpdelRoll.h.

Constructor & Destructor Documentation

UpdelRoll::~UpdelRoll ( )
inline

Definition at line 44 of file UpdelRoll.h.

References cancelUpdate(), and dirty_chunks.

44  {
45  if (dirty_chunks.size()) {
46  cancelUpdate();
47  }
48  }
void cancelUpdate()
std::map< ChunkKey, std::shared_ptr< Chunk_NS::Chunk > > dirty_chunks
Definition: UpdelRoll.h:92

+ Here is the call graph for this function:

Member Function Documentation

void UpdelRoll::addDirtyChunk ( std::shared_ptr< Chunk_NS::Chunk chunk,
int  fragment_id 
)

Definition at line 1482 of file UpdelStorage.cpp.

References CHECK, and Catalog_Namespace::Catalog::getDatabaseId().

Referenced by Fragmenter_Namespace::set_chunk_metadata(), Fragmenter_Namespace::InsertOrderFragmenter::updateColumn(), and Fragmenter_Namespace::InsertOrderFragmenter::updateColumns().

1483  {
1484  mapd_unique_lock<mapd_shared_mutex> lock(chunk_update_tracker_mutex);
1485  CHECK(catalog);
1486  ChunkKey chunk_key{catalog->getDatabaseId(),
1487  chunk->getColumnDesc()->tableId,
1488  chunk->getColumnDesc()->columnId,
1489  fragment_id};
1490  dirty_chunks[chunk_key] = chunk;
1491 }
std::vector< int > ChunkKey
Definition: types.h:37
mapd_shared_mutex chunk_update_tracker_mutex
Definition: UpdelRoll.h:89
const Catalog_Namespace::Catalog * catalog
Definition: UpdelRoll.h:52
int getDatabaseId() const
Definition: Catalog.h:277
#define CHECK(condition)
Definition: Logger.h:209
std::map< ChunkKey, std::shared_ptr< Chunk_NS::Chunk > > dirty_chunks
Definition: UpdelRoll.h:92

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void UpdelRoll::cancelUpdate ( )

Definition at line 1456 of file UpdelStorage.cpp.

References CHECK, Data_Namespace::DataMgr::free(), Catalog_Namespace::Catalog::getDatabaseId(), Catalog_Namespace::Catalog::getDataMgr(), Catalog_Namespace::Catalog::getMetadataForTable(), Catalog_Namespace::Catalog::getTableEpochs(), lockmgr::TableLockMgrImpl< TableDataLockMgr >::getWriteLockForTable(), TableDescriptor::persistenceLevel, and Catalog_Namespace::Catalog::setTableEpochs().

Referenced by ~UpdelRoll().

1456  {
1457  if (nullptr == catalog) {
1458  return;
1459  }
1460 
1461  // TODO: needed?
1463  const auto table_lock = lockmgr::TableDataLockMgr::getWriteLockForTable(chunk_key);
1464  if (is_varlen_update) {
1465  int databaseId = catalog->getDatabaseId();
1466  auto table_epochs = catalog->getTableEpochs(databaseId, logicalTableId);
1467 
1468  dirty_chunks.clear();
1469  catalog->setTableEpochs(databaseId, table_epochs);
1470  } else {
1471  const auto td = catalog->getMetadataForTable(logicalTableId);
1472  CHECK(td);
1473  if (td->persistenceLevel != memoryLevel) {
1474  for (const auto& [chunk_key, chunk] : dirty_chunks) {
1475  catalog->getDataMgr().free(chunk->getBuffer());
1476  chunk->setBuffer(nullptr);
1477  }
1478  }
1479  }
1480 }
Data_Namespace::MemoryLevel memoryLevel
Definition: UpdelRoll.h:54
bool is_varlen_update
Definition: UpdelRoll.h:56
std::vector< int > ChunkKey
Definition: types.h:37
Data_Namespace::DataMgr & getDataMgr() const
Definition: Catalog.h:223
static WriteLock getWriteLockForTable(const Catalog_Namespace::Catalog &cat, const std::string &table_name)
Definition: LockMgrImpl.h:155
const Catalog_Namespace::Catalog * catalog
Definition: UpdelRoll.h:52
int getDatabaseId() const
Definition: Catalog.h:277
int logicalTableId
Definition: UpdelRoll.h:53
void setTableEpochs(const int32_t db_id, const std::vector< TableEpochInfo > &table_epochs) const
Definition: Catalog.cpp:3127
#define CHECK(condition)
Definition: Logger.h:209
const TableDescriptor * getMetadataForTable(const std::string &tableName, const bool populateFragmenter=true) const
Returns a pointer to a const TableDescriptor struct matching the provided tableName.
void free(AbstractBuffer *buffer)
Definition: DataMgr.cpp:475
std::map< ChunkKey, std::shared_ptr< Chunk_NS::Chunk > > dirty_chunks
Definition: UpdelRoll.h:92
std::vector< TableEpochInfo > getTableEpochs(const int32_t db_id, const int32_t table_id) const
Definition: Catalog.cpp:3099

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool UpdelRoll::commitUpdate ( )

Definition at line 1398 of file UpdelStorage.cpp.

References CHECK, Catalog_Namespace::Catalog::checkpoint(), Data_Namespace::DISK_LEVEL, Catalog_Namespace::Catalog::getDatabaseId(), Catalog_Namespace::Catalog::getMetadataForTable(), Catalog_Namespace::Catalog::getTableEpochs(), lockmgr::TableLockMgrImpl< TableDataLockMgr >::getWriteLockForTable(), TableDescriptor::persistenceLevel, Catalog_Namespace::Catalog::setTableEpochsLogExceptions(), and TableDescriptor::tableId.

Referenced by StorageIOFacility::TransactionParameters::finalizeTransaction().

1398  {
1399  if (nullptr == catalog) {
1400  return false;
1401  }
1402  const auto td = catalog->getMetadataForTable(logicalTableId);
1403  CHECK(td);
1404  ChunkKey chunk_key{catalog->getDatabaseId(), td->tableId};
1405  const auto table_lock = lockmgr::TableDataLockMgr::getWriteLockForTable(chunk_key);
1406 
1407  // Checkpoint all shards. Otherwise, epochs can go out of sync.
1408  if (td->persistenceLevel == Data_Namespace::MemoryLevel::DISK_LEVEL) {
1409  auto table_epochs = catalog->getTableEpochs(catalog->getDatabaseId(), logicalTableId);
1410  try {
1411  // `checkpointWithAutoRollback` is not called here because, if a failure occurs,
1412  // `dirtyChunks` has to be cleared before resetting epochs
1414  } catch (...) {
1415  dirty_chunks.clear();
1417  throw;
1418  }
1419  }
1421  return true;
1422 }
std::vector< int > ChunkKey
Definition: types.h:37
static WriteLock getWriteLockForTable(const Catalog_Namespace::Catalog &cat, const std::string &table_name)
Definition: LockMgrImpl.h:155
void updateFragmenterAndCleanupChunks()
const Catalog_Namespace::Catalog * catalog
Definition: UpdelRoll.h:52
int getDatabaseId() const
Definition: Catalog.h:277
void checkpoint(const int logicalTableId) const
Definition: Catalog.cpp:4260
int logicalTableId
Definition: UpdelRoll.h:53
#define CHECK(condition)
Definition: Logger.h:209
void setTableEpochsLogExceptions(const int32_t db_id, const std::vector< TableEpochInfo > &table_epochs) const
Definition: Catalog.cpp:3164
const TableDescriptor * getMetadataForTable(const std::string &tableName, const bool populateFragmenter=true) const
Returns a pointer to a const TableDescriptor struct matching the provided tableName.
std::map< ChunkKey, std::shared_ptr< Chunk_NS::Chunk > > dirty_chunks
Definition: UpdelRoll.h:92
std::vector< TableEpochInfo > getTableEpochs(const int32_t db_id, const int32_t table_id) const
Definition: Catalog.cpp:3099

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::shared_ptr< ChunkMetadata > UpdelRoll::getChunkMetadata ( const MetaDataKey key,
int32_t  column_id,
Fragmenter_Namespace::FragmentInfo fragment_info 
)

Definition at line 1507 of file UpdelStorage.cpp.

References CHECK.

Referenced by Fragmenter_Namespace::set_chunk_metadata(), Fragmenter_Namespace::InsertOrderFragmenter::updateColumnMetadata(), and Fragmenter_Namespace::InsertOrderFragmenter::updateColumns().

1510  {
1511  initializeUnsetMetadata(key.first, fragment_info);
1512  mapd_shared_lock<mapd_shared_mutex> lock(chunk_update_tracker_mutex);
1513  auto metadata_map_it = chunk_metadata_map_per_fragment.find(key);
1514  CHECK(metadata_map_it != chunk_metadata_map_per_fragment.end());
1515  auto chunk_metadata_it = metadata_map_it->second.find(column_id);
1516  CHECK(chunk_metadata_it != metadata_map_it->second.end());
1517  return chunk_metadata_it->second;
1518 }
mapd_shared_mutex chunk_update_tracker_mutex
Definition: UpdelRoll.h:89
std::map< MetaDataKey, ChunkMetadataMap > chunk_metadata_map_per_fragment
Definition: UpdelRoll.h:98
void initializeUnsetMetadata(const TableDescriptor *td, Fragmenter_Namespace::FragmentInfo &fragment_info)
#define CHECK(condition)
Definition: Logger.h:209

+ Here is the caller graph for this function:

ChunkMetadataMap UpdelRoll::getChunkMetadataMap ( const MetaDataKey key) const

Definition at line 1520 of file UpdelStorage.cpp.

References CHECK.

Referenced by Fragmenter_Namespace::InsertOrderFragmenter::updateMetadata().

1520  {
1521  mapd_shared_lock<mapd_shared_mutex> lock(chunk_update_tracker_mutex);
1522  auto metadata_map_it = chunk_metadata_map_per_fragment.find(key);
1523  CHECK(metadata_map_it != chunk_metadata_map_per_fragment.end());
1524  return metadata_map_it->second;
1525 }
mapd_shared_mutex chunk_update_tracker_mutex
Definition: UpdelRoll.h:89
std::map< MetaDataKey, ChunkMetadataMap > chunk_metadata_map_per_fragment
Definition: UpdelRoll.h:98
#define CHECK(condition)
Definition: Logger.h:209

+ Here is the caller graph for this function:

size_t UpdelRoll::getNumTuple ( const MetaDataKey key) const

Definition at line 1527 of file UpdelStorage.cpp.

References CHECK.

Referenced by Fragmenter_Namespace::InsertOrderFragmenter::updateMetadata().

1527  {
1528  mapd_shared_lock<mapd_shared_mutex> lock(chunk_update_tracker_mutex);
1529  auto it = num_tuples.find(key);
1530  CHECK(it != num_tuples.end());
1531  return it->second;
1532 }
mapd_shared_mutex chunk_update_tracker_mutex
Definition: UpdelRoll.h:89
std::map< MetaDataKey, size_t > num_tuples
Definition: UpdelRoll.h:95
#define CHECK(condition)
Definition: Logger.h:209

+ Here is the caller graph for this function:

void UpdelRoll::initializeUnsetMetadata ( const TableDescriptor td,
Fragmenter_Namespace::FragmentInfo fragment_info 
)
private

Definition at line 1493 of file UpdelStorage.cpp.

References Fragmenter_Namespace::FragmentInfo::getChunkMetadataMapPhysicalCopy(), and Fragmenter_Namespace::FragmentInfo::shadowNumTuples.

1495  {
1496  mapd_unique_lock<mapd_shared_mutex> lock(chunk_update_tracker_mutex);
1497  MetaDataKey key{td, &fragment_info};
1498  if (chunk_metadata_map_per_fragment.count(key) == 0) {
1500  fragment_info.getChunkMetadataMapPhysicalCopy();
1501  }
1502  if (num_tuples.count(key) == 0) {
1503  num_tuples[key] = fragment_info.shadowNumTuples;
1504  }
1505 }
ChunkMetadataMap getChunkMetadataMapPhysicalCopy() const
std::pair< const TableDescriptor *, Fragmenter_Namespace::FragmentInfo * > MetaDataKey
Definition: UpdelRoll.h:40
mapd_shared_mutex chunk_update_tracker_mutex
Definition: UpdelRoll.h:89
std::map< MetaDataKey, ChunkMetadataMap > chunk_metadata_map_per_fragment
Definition: UpdelRoll.h:98
std::map< MetaDataKey, size_t > num_tuples
Definition: UpdelRoll.h:95

+ Here is the call graph for this function:

void UpdelRoll::setNumTuple ( const MetaDataKey key,
size_t  num_tuple 
)

Definition at line 1534 of file UpdelStorage.cpp.

Referenced by Fragmenter_Namespace::InsertOrderFragmenter::compactRows().

1534  {
1535  mapd_unique_lock<mapd_shared_mutex> lock(chunk_update_tracker_mutex);
1536  num_tuples[key] = num_tuple;
1537 }
mapd_shared_mutex chunk_update_tracker_mutex
Definition: UpdelRoll.h:89
std::map< MetaDataKey, size_t > num_tuples
Definition: UpdelRoll.h:95

+ Here is the caller graph for this function:

void UpdelRoll::stageUpdate ( )

Definition at line 1424 of file UpdelStorage.cpp.

References CHECK, CHECK_EQ, Data_Namespace::DataMgr::checkpoint(), Data_Namespace::CPU_LEVEL, Data_Namespace::DISK_LEVEL, Catalog_Namespace::Catalog::getDatabaseId(), and Catalog_Namespace::Catalog::getDataMgr().

Referenced by TableOptimizer::vacuumFragments().

1424  {
1425  CHECK(catalog);
1426  auto db_id = catalog->getDatabaseId();
1428  auto table_id = table_descriptor->tableId;
1431  try {
1432  catalog->getDataMgr().checkpoint(db_id, table_id, memoryLevel);
1433  } catch (...) {
1434  dirty_chunks.clear();
1435  throw;
1436  }
1438 }
Data_Namespace::MemoryLevel memoryLevel
Definition: UpdelRoll.h:54
#define CHECK_EQ(x, y)
Definition: Logger.h:217
const TableDescriptor * table_descriptor
Definition: UpdelRoll.h:57
Data_Namespace::DataMgr & getDataMgr() const
Definition: Catalog.h:223
void checkpoint(const int db_id, const int tb_id)
Definition: DataMgr.cpp:495
void updateFragmenterAndCleanupChunks()
const Catalog_Namespace::Catalog * catalog
Definition: UpdelRoll.h:52
int getDatabaseId() const
Definition: Catalog.h:277
Data_Namespace::MemoryLevel persistenceLevel
#define CHECK(condition)
Definition: Logger.h:209
std::map< ChunkKey, std::shared_ptr< Chunk_NS::Chunk > > dirty_chunks
Definition: UpdelRoll.h:92

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void UpdelRoll::updateFragmenterAndCleanupChunks ( )
private

Definition at line 1440 of file UpdelStorage.cpp.

References Data_Namespace::DataMgr::deleteChunksWithPrefix(), Catalog_Namespace::Catalog::getDataMgr(), and Data_Namespace::GPU_LEVEL.

1440  {
1441  // for each dirty fragment
1442  for (auto& cm : chunk_metadata_map_per_fragment) {
1443  cm.first.first->fragmenter->updateMetadata(catalog, cm.first, *this);
1444  }
1445 
1446  // flush gpu dirty chunks if update was not on gpu
1448  for (const auto& [chunk_key, chunk] : dirty_chunks) {
1451  }
1452  }
1453  dirty_chunks.clear();
1454 }
Data_Namespace::MemoryLevel memoryLevel
Definition: UpdelRoll.h:54
Data_Namespace::DataMgr & getDataMgr() const
Definition: Catalog.h:223
std::map< MetaDataKey, ChunkMetadataMap > chunk_metadata_map_per_fragment
Definition: UpdelRoll.h:98
const Catalog_Namespace::Catalog * catalog
Definition: UpdelRoll.h:52
void deleteChunksWithPrefix(const ChunkKey &keyPrefix)
Definition: DataMgr.cpp:442
std::map< ChunkKey, std::shared_ptr< Chunk_NS::Chunk > > dirty_chunks
Definition: UpdelRoll.h:92

+ Here is the call graph for this function:

Member Data Documentation

std::map<MetaDataKey, ChunkMetadataMap> UpdelRoll::chunk_metadata_map_per_fragment
private

Definition at line 98 of file UpdelRoll.h.

mapd_shared_mutex UpdelRoll::chunk_update_tracker_mutex
mutableprivate

Definition at line 89 of file UpdelRoll.h.

std::map<ChunkKey, std::shared_ptr<Chunk_NS::Chunk> > UpdelRoll::dirty_chunks
private

Definition at line 92 of file UpdelRoll.h.

Referenced by ~UpdelRoll().

bool UpdelRoll::is_varlen_update = false
std::map<MetaDataKey, size_t> UpdelRoll::num_tuples
private

Definition at line 95 of file UpdelRoll.h.

const TableDescriptor* UpdelRoll::table_descriptor {nullptr}

Definition at line 57 of file UpdelRoll.h.

Referenced by TableOptimizer::vacuumFragments().


The documentation for this struct was generated from the following files: