OmniSciDB  5ade3759e0
Lock_Namespace Namespace Reference

Classes

class  LockMgr
 
struct  TableLock
 
class  TableLockMgr
 
class  TableLockMgrImpl
 

Typedefs

using LockTypeContainer = boost::variant< mapd_shared_lock< mapd_shared_mutex >, mapd_unique_lock< mapd_shared_mutex > >
 
using MutexType = mapd_shared_mutex
 
using WriteLock = mapd_unique_lock< MutexType >
 
using ReadLock = mapd_shared_lock< MutexType >
 

Enumerations

enum  LockType { TableMetadataLock, CheckpointLock, ExecutorOuterLock, LockMax }
 

Functions

void getTableNames (std::map< std::string, bool > &tableNames, const std::string query_ra)
 
void getTableNames (std::map< std::string, bool > &tableNames, const Value &value)
 
ChunkKey getTableChunkKey (const Catalog_Namespace::Catalog &cat, const std::string &tableName)
 
std::string parse_to_ra (const Catalog_Namespace::Catalog &cat, const std::string &query_str, const Catalog_Namespace::SessionInfo &session_info)
 
template<typename MutexType >
std::shared_ptr< MutexTypegetTableMutex (const Catalog_Namespace::Catalog &cat, const std::string &tableName, const Lock_Namespace::LockType lockType)
 
template<typename MutexType , template< typename > class LockType>
LockType< MutexTypegetTableLock (const Catalog_Namespace::Catalog &cat, const std::string &tableName, const Lock_Namespace::LockType lockType)
 
template<typename MutexType >
void getTableLocks (const Catalog_Namespace::Catalog &cat, const std::map< std::string, bool > &tableNames, std::vector< std::shared_ptr< LockTypeContainer >> &tableLocks, const Lock_Namespace::LockType lockType)
 
template<typename MutexType >
void getTableLocks (const Catalog_Namespace::Catalog &cat, const std::string &query_ra, std::vector< std::shared_ptr< LockTypeContainer >> &tableLocks, const Lock_Namespace::LockType lockType)
 

Typedef Documentation

◆ LockTypeContainer

◆ MutexType

Definition at line 45 of file TableLockMgr.h.

◆ ReadLock

Definition at line 48 of file TableLockMgr.h.

◆ WriteLock

Definition at line 47 of file TableLockMgr.h.

Enumeration Type Documentation

◆ LockType

Enumerator
TableMetadataLock 
CheckpointLock 
ExecutorOuterLock 
LockMax 

Definition at line 36 of file LockMgr.h.

Function Documentation

◆ getTableChunkKey()

ChunkKey Lock_Namespace::getTableChunkKey ( const Catalog_Namespace::Catalog cat,
const std::string &  tableName 
)

Definition at line 66 of file LockMgr.cpp.

References Catalog_Namespace::DBMetadata::dbId, Catalog_Namespace::Catalog::getCurrentDB(), and Catalog_Namespace::Catalog::getMetadataForTable().

Referenced by Lock_Helpers::getLockForTableImpl(), Lock_Namespace::LockMgr< MutexType, KeyType >::getMutex(), getTableLock(), and getTableMutex().

67  {
68  if (const auto tdp = cat.getMetadataForTable(tableName, false)) {
69  ChunkKey chunk_key{cat.getCurrentDB().dbId, tdp->tableId};
70  return chunk_key;
71  } else {
72  throw std::runtime_error("Table " + tableName + " does not exist.");
73  }
74 }
const TableDescriptor * getMetadataForTable(const std::string &tableName, const bool populateFragmenter=true) const
Returns a pointer to a const TableDescriptor struct matching the provided tableName.
const DBMetadata & getCurrentDB() const
Definition: Catalog.h:176
std::vector< int > ChunkKey
Definition: types.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTableLock()

template<typename MutexType , template< typename > class LockType>
LockType<MutexType> Lock_Namespace::getTableLock ( const Catalog_Namespace::Catalog cat,
const std::string &  tableName,
const Lock_Namespace::LockType  lockType 
)

Definition at line 87 of file LockMgr.h.

References getTableChunkKey().

89  {
90  auto lock = LockType<MutexType>(*getTableMutex<MutexType>(cat, tableName, lockType));
91  // "... we need to make sure that the table (and after alter column) the columns are
92  // still around after obtaining our locks ..."
93  auto chunkKey = getTableChunkKey(cat, tableName);
94  return lock;
95 }
ChunkKey getTableChunkKey(const Catalog_Namespace::Catalog &cat, const std::string &tableName)
Definition: LockMgr.cpp:66
+ Here is the call graph for this function:

◆ getTableLocks() [1/2]

template<typename MutexType >
void Lock_Namespace::getTableLocks ( const Catalog_Namespace::Catalog cat,
const std::map< std::string, bool > &  tableNames,
std::vector< std::shared_ptr< LockTypeContainer >> &  tableLocks,
const Lock_Namespace::LockType  lockType 
)

Definition at line 98 of file LockMgr.h.

Referenced by Lock_Namespace::TableLockMgrImpl< TableLockMgr >::getTableLocks(), MapDHandler::sql_execute_df(), and MapDHandler::sql_execute_impl().

101  {
102  for (const auto& tableName : tableNames) {
103  if (tableName.second) {
104  tableLocks.emplace_back(std::make_shared<LockTypeContainer>(
105  getTableLock<MutexType, mapd_unique_lock>(cat, tableName.first, lockType)));
106  } else {
107  tableLocks.emplace_back(std::make_shared<LockTypeContainer>(
108  getTableLock<MutexType, mapd_shared_lock>(cat, tableName.first, lockType)));
109  }
110  }
111 }
+ Here is the caller graph for this function:

◆ getTableLocks() [2/2]

template<typename MutexType >
void Lock_Namespace::getTableLocks ( const Catalog_Namespace::Catalog cat,
const std::string &  query_ra,
std::vector< std::shared_ptr< LockTypeContainer >> &  tableLocks,
const Lock_Namespace::LockType  lockType 
)

Definition at line 114 of file LockMgr.h.

References getTableNames().

117  {
118  // parse ra to learn involved table names
119  std::map<std::string, bool> tableNames;
120  getTableNames(tableNames, query_ra);
121  getTableLocks<MutexType>(cat, tableNames, tableLocks, lockType);
122 }
void getTableNames(std::map< std::string, bool > &tableNames, const std::string query_ra)
Definition: LockMgr.cpp:26
+ Here is the call graph for this function:

◆ getTableMutex()

template<typename MutexType >
std::shared_ptr<MutexType> Lock_Namespace::getTableMutex ( const Catalog_Namespace::Catalog cat,
const std::string &  tableName,
const Lock_Namespace::LockType  lockType 
)

Definition at line 79 of file LockMgr.h.

References Lock_Namespace::LockMgr< MutexType, KeyType >::getMutex(), and getTableChunkKey().

81  {
83  lockType, getTableChunkKey(cat, tableName));
84 }
ChunkKey getTableChunkKey(const Catalog_Namespace::Catalog &cat, const std::string &tableName)
Definition: LockMgr.cpp:66
static std::shared_ptr< MutexType > getMutex(const LockType lockType, const KeyType &key)
Definition: LockMgr.h:55
+ Here is the call graph for this function:

◆ getTableNames() [1/2]

void Lock_Namespace::getTableNames ( std::map< std::string, bool > &  tableNames,
const std::string  query_ra 
)

Definition at line 26 of file LockMgr.cpp.

References CHECK.

Referenced by Lock_Namespace::LockMgr< MutexType, KeyType >::getMutex(), Lock_Namespace::TableLockMgrImpl< TableLockMgr >::getTableLocks(), getTableLocks(), and getTableNames().

26  {
27  rapidjson::Document query_ast;
28  query_ast.Parse(query_ra.c_str());
29  CHECK(!query_ast.HasParseError());
30  CHECK(query_ast.IsObject());
31  getTableNames(tableNames, query_ast);
32 }
void getTableNames(std::map< std::string, bool > &tableNames, const Value &value)
Definition: LockMgr.cpp:34
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the caller graph for this function:

◆ getTableNames() [2/2]

void Lock_Namespace::getTableNames ( std::map< std::string, bool > &  tableNames,
const Value &  value 
)

Definition at line 34 of file LockMgr.cpp.

References CHECK, getTableNames(), and json_str().

34  {
35  if (value.IsArray()) {
36  for (SizeType i = 0; i < value.Size(); ++i) {
37  getTableNames(tableNames, value[i]);
38  }
39  return;
40  } else if (value.IsObject()) {
41  for (auto mit = value.MemberBegin(); mit != value.MemberEnd(); ++mit) {
42  getTableNames(tableNames, mit->value);
43  }
44  } else {
45  return;
46  }
47 
48  if (value.FindMember("rels") == value.MemberEnd()) {
49  return;
50  }
51  const auto& rels = value["rels"];
52  CHECK(rels.IsArray());
53  for (SizeType i = 0; i < rels.Size(); ++i) {
54  const auto& rel = rels[i];
55  const auto& relop = json_str(rel["relOp"]);
56  if (rel.FindMember("table") != rel.MemberEnd()) {
57  if ("EnumerableTableScan" == relop || "LogicalTableModify" == relop) {
58  const auto t = rel["table"].GetArray();
59  CHECK(t[1].IsString());
60  tableNames[t[1].GetString()] |= "LogicalTableModify" == relop;
61  }
62  }
63  }
64 }
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
void getTableNames(std::map< std::string, bool > &tableNames, const Value &value)
Definition: LockMgr.cpp:34
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the call graph for this function:

◆ parse_to_ra()

std::string Lock_Namespace::parse_to_ra ( const Catalog_Namespace::Catalog cat,
const std::string &  query_str,
const Catalog_Namespace::SessionInfo session_info 
)

Definition at line 76 of file LockMgr.cpp.

References Catalog_Namespace::Catalog::getCalciteMgr().

Referenced by Lock_Namespace::LockMgr< MutexType, KeyType >::getMutex(), and Parser::InsertIntoTableAsSelectStmt::LocalConnector::query().

78  {
79  return cat.getCalciteMgr()
80  ->process(session_info, query_str, {}, true, false, false)
81  .plan_result;
82 }
std::shared_ptr< Calcite > getCalciteMgr() const
Definition: Catalog.h:178
+ Here is the call graph for this function:
+ Here is the caller graph for this function: