42 lock_guard<mutex> lock(m_mutex);
45 scaninfo.
range = range;
47 scaninfo.
table= table;
49 int32_t
id = ++ms_next_id;
50 m_scanner_map[id] = scaninfo;
61 lock_guard<mutex> lock(m_mutex);
62 auto iter = m_scanner_map.find(
id);
63 if (iter == m_scanner_map.end())
65 (*iter).second.last_access_millis = get_timestamp_millis();
66 scanner = (*iter).second.scanner;
67 range = (*iter).second.range;
68 table = (*iter).second.table;
69 *profile_data = (*iter).second.profile_data;
78 lock_guard<mutex> lock(m_mutex);
79 return (m_scanner_map.erase(
id) == 0) ?
false :
true;
84 lock_guard<mutex> lock(m_mutex);
85 int64_t now_millis = get_timestamp_millis();
86 auto iter = m_scanner_map.begin();
87 while (iter != m_scanner_map.end()) {
88 if ((now_millis - (*iter).second.last_access_millis) > (int64_t)max_idle_millis) {
90 HT_WARNF(
"Destroying scanner %d because it has not been used in %u "
91 "milliseconds", (*iter).first, max_idle_millis);
93 (*tmp_iter).second.scanner = 0;
94 (*tmp_iter).second.range = 0;
95 m_scanner_map.erase(tmp_iter);
105 lock_guard<mutex> lock(m_mutex);
106 CstrToInt32Map::iterator tsc_iter;
108 *totalp = m_scanner_map.size();
110 for (
auto & entry : m_scanner_map) {
111 if ((tsc_iter = table_scanner_count_map.find(entry.second.table.id)) != table_scanner_count_map.end())
112 table_scanner_count_map[entry.second.table.id]++;
118 lock_guard<mutex> lock(m_mutex);
119 auto iter = m_scanner_map.find(
id);
120 if (iter == m_scanner_map.end())
121 HT_WARNF(
"Unable to locate scanner ID %u in scanner map", (
unsigned)id);
123 iter->second.profile_data = profile_data;
void purge_expired(int32_t max_idle_ms)
This method iterates through the scanner map purging mappings that have not been referenced for max_i...
#define HT_WARNF(msg,...)
int64_t last_access_millis
Last access time in milliseconds since epoch.
ProfileDataScanner profile_data
Accumulated profile data.
Wrapper for TableIdentifier providing member storage.
MergeScannerRangePtr scanner
Scanner.
std::shared_ptr< MergeScannerRange > MergeScannerRangePtr
Smart pointer to MergeScannerRange.
int32_t put(MergeScannerRangePtr &scanner, RangePtr &range, const TableIdentifier &table, ProfileDataScanner &profile_data)
This method computes a unique scanner ID and puts the given scanner and range pointers into a map usi...
Holds scanner information.
Compatibility Macros for C/C++.
static std::atomic< int > ms_next_id
Next available scanner ID.
Time related declarations.
std::shared_ptr< Range > RangePtr
Smart pointer to Range.
bool remove(int32_t id)
This method removes the entry in the scanner map corresponding to the given id.
void get_counts(int32_t *totalp, CstrToInt32Map &table_scanner_count_map)
This method retrieves outstanding scanner counts.
bool get(int32_t id, MergeScannerRangePtr &scanner, RangePtr &range, TableIdentifierManaged &table, ProfileDataScanner *profile_data)
This method retrieves the scanner and range mapped to the given scanner id.
TableIdentifierManaged table
Table identifier.
Declarations for ScannerMap.
int64_t get_ts64()
Returns the current time in nanoseconds as a 64bit number.
void update_profile_data(int32_t id, ProfileDataScanner &profile_data)
Updates profile data of a scanner in the map.
int64_t get_timestamp_millis()
Returns the number of milliseconds since the epoch.
std::map< const char *, int32_t, LtCstr > CstrToInt32Map
STL map from c-style string to int32_t.