OmniSciDB  29e35f4d58
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 (query_state::QueryStateProxy query_state_proxy, const std::string &query_str)
 
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 37 of file LockMgr.h.

Function Documentation

◆ getTableChunkKey()

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

Definition at line 67 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().

68  {
69  if (const auto tdp = cat.getMetadataForTable(tableName, false)) {
70  ChunkKey chunk_key{cat.getCurrentDB().dbId, tdp->tableId};
71  return chunk_key;
72  } else {
73  throw std::runtime_error("Table " + tableName + " does not exist.");
74  }
75 }
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 86 of file LockMgr.h.

References getTableChunkKey().

88  {
89  auto lock = LockType<MutexType>(*getTableMutex<MutexType>(cat, tableName, lockType));
90  // "... we need to make sure that the table (and after alter column) the columns are
91  // still around after obtaining our locks ..."
92  auto chunkKey = getTableChunkKey(cat, tableName);
93  return lock;
94 }
ChunkKey getTableChunkKey(const Catalog_Namespace::Catalog &cat, const std::string &tableName)
Definition: LockMgr.cpp:67
+ 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 97 of file LockMgr.h.

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

100  {
101  for (const auto& tableName : tableNames) {
102  if (tableName.second) {
103  tableLocks.emplace_back(std::make_shared<LockTypeContainer>(
104  getTableLock<MutexType, mapd_unique_lock>(cat, tableName.first, lockType)));
105  } else {
106  tableLocks.emplace_back(std::make_shared<LockTypeContainer>(
107  getTableLock<MutexType, mapd_shared_lock>(cat, tableName.first, lockType)));
108  }
109  }
110 }
+ 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 113 of file LockMgr.h.

References getTableNames().

116  {
117  // parse ra to learn involved table names
118  std::map<std::string, bool> tableNames;
119  getTableNames(tableNames, query_ra);
120  getTableLocks<MutexType>(cat, tableNames, tableLocks, lockType);
121 }
void getTableNames(std::map< std::string, bool > &tableNames, const std::string query_ra)
Definition: LockMgr.cpp:27
+ 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 78 of file LockMgr.h.

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

80  {
82  lockType, getTableChunkKey(cat, tableName));
83 }
ChunkKey getTableChunkKey(const Catalog_Namespace::Catalog &cat, const std::string &tableName)
Definition: LockMgr.cpp:67
static std::shared_ptr< MutexType > getMutex(const LockType lockType, const KeyType &key)
Definition: LockMgr.h:56
+ 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 27 of file LockMgr.cpp.

References CHECK.

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

27  {
28  rapidjson::Document query_ast;
29  query_ast.Parse(query_ra.c_str());
30  CHECK(!query_ast.HasParseError());
31  CHECK(query_ast.IsObject());
32  getTableNames(tableNames, query_ast);
33 }
void getTableNames(std::map< std::string, bool > &tableNames, const Value &value)
Definition: LockMgr.cpp:35
#define CHECK(condition)
Definition: Logger.h:193
+ 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 35 of file LockMgr.cpp.

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

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

◆ parse_to_ra()

std::string Lock_Namespace::parse_to_ra ( query_state::QueryStateProxy  query_state_proxy,
const std::string &  query_str 
)

Definition at line 77 of file LockMgr.cpp.

References query_state::QueryState::getConstSessionInfo(), and query_state::QueryStateProxy::getQueryState().

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

78  {
79  auto const session = query_state_proxy.getQueryState().getConstSessionInfo();
80  auto const& cat = session->getCatalog();
81  return cat.getCalciteMgr()
82  ->process(query_state_proxy, query_str, {}, true, false, false)
83  .plan_result;
84 }
QueryState & getQueryState()
Definition: QueryState.h:172
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Definition: QueryState.cpp:75
+ Here is the call graph for this function:
+ Here is the caller graph for this function: