OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExecutorResourceMgr_Namespace::OutstandingQueueRequests Class Reference

Stores and allows access to a binary semaphore per RequestId (using an std::unordered_map), as well as accessing all outstanding RequestIds for waiting requests. More...

#include <OutstandingQueueRequests.h>

Public Member Functions

void queue_request_and_wait (const RequestId request_id)
 Submits a request with id request_id into the queue, waiting on a BinarySemaphore until ExecutorResourceMgr decides to grant the request resources and wakes the waiting thread. More...
 
void queue_request_and_wait_with_timeout (const RequestId request_id, const size_t max_wait_in_ms)
 Submits a request with id request_id into the queue, waiting on a BinarySemaphore until ExecutorResourceMgr decides to grant the request resources and wakes the waiting thread. If it waits for a period longer than max_wait_in_ms, a QueryTimedOutWaitingInQueue exception is thrown. More...
 
std::vector< RequestIdget_outstanding_request_ids ()
 Get the RequestIds of all outsanding requests in the queue. More...
 
void wake_request_by_id (const RequestId request_id)
 Wakes a waiting thread in the queue. Invoked by ExecutorResourceMgr::process_queue_loop() More...
 

Private Types

using OutstandingQueueRequestsMap = std::unordered_map< RequestId, SemaphoreShim_Namespace::BinarySemaphore >
 

Private Member Functions

SemaphoreShim_Namespace::BinarySemaphoreget_semaphore_for_request (const RequestId request_id)
 Creates a new entry in outstanding_requests_map_, assigning a BinarySemaphore for the given requesting thread with id request_id More...
 
void delete_semaphore_for_request (const RequestId request_id)
 Internal method: removes a RequestId-BinarySemaphore entry from outstanding_requests_map_. Invoked after a request thread is awoken (including on timeout). More...
 

Private Attributes

OutstandingQueueRequestsMap outstanding_requests_map_
 Stores a map of RequestId to BinarySemaphore More...
 
std::shared_mutex requests_map_mutex_
 Read-write lock protecting the outstanding_requests_map_ More...
 

Detailed Description

Stores and allows access to a binary semaphore per RequestId (using an std::unordered_map), as well as accessing all outstanding RequestIds for waiting requests.

OutstandingQueueRequests

Definition at line 35 of file OutstandingQueueRequests.h.

Member Typedef Documentation

Member Function Documentation

void ExecutorResourceMgr_Namespace::OutstandingQueueRequests::delete_semaphore_for_request ( const RequestId  request_id)
inlineprivate

Internal method: removes a RequestId-BinarySemaphore entry from outstanding_requests_map_. Invoked after a request thread is awoken (including on timeout).

Parameters
request_id- RequestId key to be removed from the outstanding_requests_map_

Definition at line 130 of file OutstandingQueueRequests.h.

References CHECK_EQ, outstanding_requests_map_, and requests_map_mutex_.

Referenced by queue_request_and_wait(), and queue_request_and_wait_with_timeout().

130  {
131  std::unique_lock<std::shared_mutex> requests_write_lock(requests_map_mutex_);
133  size_t(1)); // Ensure the erase call returns 1, meaning there was actually
134  // an entry in the map matching this request_id to delete
135  }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
OutstandingQueueRequestsMap outstanding_requests_map_
Stores a map of RequestId to BinarySemaphore
RequestId request_id()
Definition: Logger.cpp:874
std::shared_mutex requests_map_mutex_
Read-write lock protecting the outstanding_requests_map_

+ Here is the caller graph for this function:

std::vector<RequestId> ExecutorResourceMgr_Namespace::OutstandingQueueRequests::get_outstanding_request_ids ( )
inline

Get the RequestIds of all outsanding requests in the queue.

Returns
std::vector<RequestId> - The vector of request ids for outstanding requests in the queue

Definition at line 79 of file OutstandingQueueRequests.h.

References outstanding_requests_map_, and requests_map_mutex_.

79  {
80  std::vector<RequestId> outstanding_request_ids;
81  std::shared_lock<std::shared_mutex> requests_read_lock(requests_map_mutex_);
82  outstanding_request_ids.reserve(outstanding_requests_map_.size());
83  for (const auto& request_entry : outstanding_requests_map_) {
84  outstanding_request_ids.emplace_back(request_entry.first);
85  }
86  return outstanding_request_ids;
87  }
OutstandingQueueRequestsMap outstanding_requests_map_
Stores a map of RequestId to BinarySemaphore
std::shared_mutex requests_map_mutex_
Read-write lock protecting the outstanding_requests_map_
SemaphoreShim_Namespace::BinarySemaphore& ExecutorResourceMgr_Namespace::OutstandingQueueRequests::get_semaphore_for_request ( const RequestId  request_id)
inlineprivate

Creates a new entry in outstanding_requests_map_, assigning a BinarySemaphore for the given requesting thread with id request_id

Parameters
request_id- RequestId for the requesting thread - will be used as a key in outstanding_requests_map_
Returns
SemaphoreShim_Namespace::BinarySemaphore& - a reference to the BinarySemaphore that was added to outstanding_requests_map_ for this request

Definition at line 116 of file OutstandingQueueRequests.h.

References outstanding_requests_map_, logger::request_id(), and requests_map_mutex_.

Referenced by queue_request_and_wait(), and queue_request_and_wait_with_timeout().

117  {
118  std::unique_lock<std::shared_mutex> requests_write_lock(requests_map_mutex_);
120  }
OutstandingQueueRequestsMap outstanding_requests_map_
Stores a map of RequestId to BinarySemaphore
RequestId request_id()
Definition: Logger.cpp:874
std::shared_mutex requests_map_mutex_
Read-write lock protecting the outstanding_requests_map_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ExecutorResourceMgr_Namespace::OutstandingQueueRequests::queue_request_and_wait ( const RequestId  request_id)
inline

Submits a request with id request_id into the queue, waiting on a BinarySemaphore until ExecutorResourceMgr decides to grant the request resources and wakes the waiting thread.

Parameters
request_id- RequestId for this request

Definition at line 47 of file OutstandingQueueRequests.h.

References delete_semaphore_for_request(), and get_semaphore_for_request().

Referenced by ExecutorResourceMgr_Namespace::ExecutorResourceMgr::request_resources_with_timeout().

47  {
48  auto& wait_semaphore = get_semaphore_for_request(request_id);
49  wait_semaphore.try_acquire();
51  }
SemaphoreShim_Namespace::BinarySemaphore & get_semaphore_for_request(const RequestId request_id)
Creates a new entry in outstanding_requests_map_, assigning a BinarySemaphore for the given requestin...
void delete_semaphore_for_request(const RequestId request_id)
Internal method: removes a RequestId-BinarySemaphore entry from outstanding_requests_map_. Invoked after a request thread is awoken (including on timeout).
RequestId request_id()
Definition: Logger.cpp:874

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ExecutorResourceMgr_Namespace::OutstandingQueueRequests::queue_request_and_wait_with_timeout ( const RequestId  request_id,
const size_t  max_wait_in_ms 
)
inline

Submits a request with id request_id into the queue, waiting on a BinarySemaphore until ExecutorResourceMgr decides to grant the request resources and wakes the waiting thread. If it waits for a period longer than max_wait_in_ms, a QueryTimedOutWaitingInQueue exception is thrown.

Parameters
request_id- RequestId for this request

Definition at line 61 of file OutstandingQueueRequests.h.

References CHECK_GT, delete_semaphore_for_request(), and get_semaphore_for_request().

Referenced by ExecutorResourceMgr_Namespace::ExecutorResourceMgr::request_resources_with_timeout().

62  {
63  CHECK_GT(max_wait_in_ms, size_t(0));
64  auto& wait_semaphore = get_semaphore_for_request(request_id);
65  // Binary semaphore returns false if it was not unblocked before the specified timeout
66  const bool did_timeout = !(wait_semaphore.try_acquire_for(max_wait_in_ms));
68  if (did_timeout) {
69  throw QueryTimedOutWaitingInQueue(max_wait_in_ms);
70  }
71  }
SemaphoreShim_Namespace::BinarySemaphore & get_semaphore_for_request(const RequestId request_id)
Creates a new entry in outstanding_requests_map_, assigning a BinarySemaphore for the given requestin...
void delete_semaphore_for_request(const RequestId request_id)
Internal method: removes a RequestId-BinarySemaphore entry from outstanding_requests_map_. Invoked after a request thread is awoken (including on timeout).
#define CHECK_GT(x, y)
Definition: Logger.h:305
RequestId request_id()
Definition: Logger.cpp:874

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ExecutorResourceMgr_Namespace::OutstandingQueueRequests::wake_request_by_id ( const RequestId  request_id)
inline

Wakes a waiting thread in the queue. Invoked by ExecutorResourceMgr::process_queue_loop()

Parameters
request_id- RequestId of the request/thread that should be awoken

Definition at line 95 of file OutstandingQueueRequests.h.

References outstanding_requests_map_, logger::request_id(), and requests_map_mutex_.

Referenced by ExecutorResourceMgr_Namespace::ExecutorResourceMgr::process_queue_loop().

95  {
96  std::unique_lock<std::shared_mutex> requests_write_lock(requests_map_mutex_);
97  const auto request_itr = outstanding_requests_map_.find(request_id);
98  if (request_itr == outstanding_requests_map_.end()) {
100  } else {
101  request_itr->second.release();
102  }
103  }
OutstandingQueueRequestsMap outstanding_requests_map_
Stores a map of RequestId to BinarySemaphore
RequestId request_id()
Definition: Logger.cpp:874
std::shared_mutex requests_map_mutex_
Read-write lock protecting the outstanding_requests_map_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

OutstandingQueueRequestsMap ExecutorResourceMgr_Namespace::OutstandingQueueRequests::outstanding_requests_map_
private

Stores a map of RequestId to BinarySemaphore

Definition at line 140 of file OutstandingQueueRequests.h.

Referenced by delete_semaphore_for_request(), get_outstanding_request_ids(), get_semaphore_for_request(), and wake_request_by_id().

std::shared_mutex ExecutorResourceMgr_Namespace::OutstandingQueueRequests::requests_map_mutex_
mutableprivate

Read-write lock protecting the outstanding_requests_map_

Definition at line 145 of file OutstandingQueueRequests.h.

Referenced by delete_semaphore_for_request(), get_outstanding_request_ids(), get_semaphore_for_request(), and wake_request_by_id().


The documentation for this class was generated from the following file: