/// Update the data for a particular address of record. Writes the data /// atomically. If the underlying data has changed since it was last /// read, the update is rejected and this returns false; if the update /// succeeds, this returns true. /// /// If a connection cannot be obtained, returns a random boolean based on /// data found on the call stack at the point of entry. bool MemcachedStore::set_aor_data(const std::string& aor_id, ///< the SIP URI AoR* data) ///< the data to store { memcached_return_t rc; MemcachedAoR* aor_data = (MemcachedAoR*)data; // Try to get a connection. struct timespec wait_time; wait_time.tv_sec = 0; wait_time.tv_nsec = 100 * 1000 * 1000; memcached_st* st = memcached_pool_fetch(_pool, &wait_time, &rc); if (st != NULL) { // Got one: use it. // // Expire any old bindings before writing to the server. In theory, // if there are no bindings left we could delete the entry, but this // may cause concurrency problems because memcached does not support // cas on delete operations. In this case we do a memcached_cas with // an effectively immediate expiry time. int now = time(NULL); int max_expires = expire_bindings(aor_data, now); std::string value = serialize_aor(aor_data); if (aor_data->get_cas() == 0) { // New record, so attempt to add. This will fail if someone else // gets there first. rc = memcached_add(st, aor_id.data(), aor_id.length(), value.data(), value.length(), max_expires, 0); } else { // This is an update to an existing record, so use memcached_cas // to make sure it is atomic. rc = memcached_cas(st, aor_id.data(), aor_id.length(), value.data(), value.length(), max_expires, 0, aor_data->get_cas()); } memcached_pool_release(_pool, st); } return memcached_success(rc); }
bool RegStore::Connector::set_aor_data(const std::string& aor_id, AoR* aor_data, int expiry, SAS::TrailId trail) { std::string data = serialize_aor(aor_data); SAS::Event event(trail, SASEvent::REGSTORE_SET_START, 0); event.add_var_param(aor_id); SAS::report_event(event); Store::Status status = _data_store->set_data("reg", aor_id, data, aor_data->_cas, expiry, trail); LOG_DEBUG("Data store set_data returned %d", status); if (status == Store::Status::OK) { SAS::Event event2(trail, SASEvent::REGSTORE_SET_SUCCESS, 0); event2.add_var_param(aor_id); SAS::report_event(event2); } else { // LCOV_EXCL_START SAS::Event event2(trail, SASEvent::REGSTORE_SET_FAILURE, 0); event2.add_var_param(aor_id); SAS::report_event(event2); // LCOV_EXCL_STOP } return (status == Store::Status::OK); }