42 lock_guard<mutex> lock(m_mutex);
44 LocationMap::iterator iter;
56 newval->
addrp = get_constant_address(range_loc_info.
addr);
63 if ((iter = m_location_map.find(key)) != m_location_map.end())
64 remove((*iter).second);
67 while (m_location_map.size() >= m_max_entries) {
78 m_head = m_tail = newval;
81 m_head->
next = newval;
82 newval->
prev = m_head;
89 std::pair<LocationMap::iterator, bool> old_entry;
90 LocationMap::value_type map_value(key, newval);
91 old_entry = m_location_map.insert(map_value);
92 assert(old_entry.second);
102 for (AddressSet::iterator iter = m_addresses.begin();
103 iter != m_addresses.end(); ++iter)
105 for (LocationMap::iterator lm_it = m_location_map.begin();
106 lm_it != m_location_map.end(); ++lm_it)
107 delete (*lm_it).second;
117 lock_guard<mutex> lock(m_mutex);
120 if (!lookup(table_name, rowkey, cacheval, inclusive))
125 range_loc_infop->
addr = *cacheval->
addrp;
133 lock_guard<mutex> lock(m_mutex);
136 if (!lookup(table_name, rowkey, cacheval, inclusive))
139 range_addr_infop->
addr = *cacheval->
addrp;
145 lock_guard<mutex> lock(m_mutex);
146 LocationMap::iterator iter;
156 if ((iter = m_location_map.lower_bound(key)) == m_location_map.end())
159 if (strcmp((*iter).first.table_name, table_name))
163 if (rowkey && strcmp(rowkey, (*iter).second->start_row.c_str()) < 0)
166 if ((rowkey == 0 && !(*iter).second->start_row.empty()) ||
167 (rowkey && strcmp(rowkey, (*iter).second->start_row.c_str()) < 0))
170 remove((*iter).second);
175 lock_guard<mutex> lock(m_mutex);
179 const CommAddress *addrp = get_constant_address(addr);
181 LocationMap::iterator iter = m_location_map.begin();
183 while (iter != m_location_map.end()) {
185 if (iter->second->addrp == addrp)
195 for (
Value *value = m_head; value; value = value->
prev)
196 out <<
"DUMP: end=" << value->end_row <<
" start=" << value->start_row
201 Value*& cacheval,
bool inclusive) {
202 LocationMap::iterator iter;
210 if ((iter = m_location_map.lower_bound(key)) == m_location_map.end())
213 if (strcmp((*iter).first.table_name, table_name))
217 if (strcmp(rowkey, (*iter).second->start_row.c_str()) < 0)
221 if (strcmp(rowkey, (*iter).second->start_row.c_str()) <= 0)
225 cacheval = (*iter).second;
226 move_to_head(cacheval);
237 if (m_head == cacheval)
242 if (cacheval->
prev == 0)
243 m_tail = cacheval->
next;
248 cacheval->
prev = m_head;
249 m_head->
next = cacheval;
259 if (m_tail == cacheval) {
260 m_tail = cacheval->
next;
264 assert (m_head == cacheval);
268 else if (m_head == cacheval) {
269 m_head = m_head->prev;
276 m_location_map.erase(cacheval->
map_iter);
282 AddressSet::iterator iter = m_addresses.find(&addr);
284 if (iter != m_addresses.end())
288 m_addresses.insert(new_addr);
void display(std::ostream &)
const CommAddress * get_constant_address(const CommAddress &addr)
void insert(const char *table_name, RangeLocationInfo &range_loc_info, bool pegged=false)
Insert.
bool invalidate(const char *table_name, const char *rowkey)
Holds range start and end row plus location.
void move_to_head(Value *cacheval)
MoveToHead.
void set_proxy(const String &str)
Sets address type to CommAddress::PROXY and proxy name to p.
Compatibility Macros for C/C++.
const CommAddress * addrp
bool lookup(const char *table_name, const char *rowkey, RangeLocationInfo *range_loc_infop, bool inclusive=false)
Lookup.
Key type for Range location cache.
Internet address wrapper classes and utility functions.
void invalidate_host(const std::string &hostname)
void remove(Value *cacheval)
remove
Address abstraction to hold either proxy name or IPv4:port address.
std::map< LocationCacheKey, Value * >::iterator map_iter