return 0;
}
-int RedisDriver::insert_entry(const DoutPrefixProvider* dpp, std::string key, off_t offset, uint64_t len)
-{
- auto ret = entries.emplace(key, Entry(key, offset, len));
- return ret.second;
-}
-
-std::optional<Entry> RedisDriver::get_entry(const DoutPrefixProvider* dpp, std::string key)
-{
- auto iter = entries.find(key);
-
- if (iter != entries.end()) {
- return iter->second;
- }
-
- return std::nullopt;
-}
-
-int RedisDriver::remove_entry(const DoutPrefixProvider* dpp, std::string key)
-{
- return entries.erase(key);
-}
-
int RedisDriver::add_partition_info(Partition& info)
{
std::string key = info.name + info.type;
return partitions.erase(key);
}
-bool RedisDriver::key_exists(const DoutPrefixProvider* dpp, const std::string& key)
-{
- int result;
- std::string entry = partition_info.location + key;
- std::vector<std::string> keys;
- keys.push_back(entry);
-
- if (!client.is_connected())
- find_client(dpp);
-
- try {
- client.exists(keys, [&result](cpp_redis::reply &reply) {
- if (reply.is_integer()) {
- result = reply.as_integer();
- }
- });
-
- client.sync_commit(std::chrono::milliseconds(1000));
- } catch(std::exception &e) {}
-
- return result;
-}
-
-std::vector<Entry> RedisDriver::list_entries(const DoutPrefixProvider* dpp)
-{
- std::vector<Entry> result;
-
- for (auto it = entries.begin(); it != entries.end(); ++it)
- result.push_back(it->second);
-
- return result;
-}
-
-size_t RedisDriver::get_num_entries(const DoutPrefixProvider* dpp)
-{
- return entries.size();
-}
-
/*
uint64_t RedisDriver::get_free_space(const DoutPrefixProvider* dpp)
{
return -1;
}
- return insert_entry(dpp, key, 0, len); // why is offset necessarily 0? -Sam
+ return 0; // why is offset necessarily 0? -Sam
}
int RedisDriver::get(const DoutPrefixProvider* dpp, const std::string& key, off_t offset, uint64_t len, bufferlist& bl, rgw::sal::Attrs& attrs)
if (!client.is_connected())
find_client(dpp);
- if (key_exists(dpp, key)) {
/* Retrieve existing values from cache */
- try {
+ try {
client.hgetall(entry, [&bl, &attrs](cpp_redis::reply &reply) {
if (reply.is_array()) {
auto arr = reply.as_array();
} catch(std::exception &e) {
return -1;
}
- } else {
- ldpp_dout(dpp, 20) << "RGW Redis Cache: Object was not retrievable." << dendl;
- return -2;
- }
+
return 0;
}
if (!client.is_connected())
find_client(dpp);
- if (key_exists(dpp, key)) {
- try {
- client.hget(entry, "data", [&value](cpp_redis::reply &reply) {
- if (!reply.is_null()) {
- value = reply.as_string();
- }
- });
+ try {
+ client.hget(entry, "data", [&value](cpp_redis::reply &reply) {
+ if (!reply.is_null()) {
+ value = reply.as_string();
+ }
+ });
- client.sync_commit(std::chrono::milliseconds(1000));
- } catch(std::exception &e) {
- return -1;
- }
+ client.sync_commit(std::chrono::milliseconds(1000));
+ } catch(std::exception &e) {
+ return -1;
}
try { // do we want key check here? -Sam
if (!client.is_connected())
find_client(dpp);
- if (key_exists(dpp, key)) {
- int exists = -2;
+ int exists = -2;
- try {
+ try {
client.hexists(entry, "data", [&exists](cpp_redis::reply &reply) {
if (!reply.is_null()) {
exists = reply.as_integer();
if (!result) {
return -1;
- } else {
- return remove_entry(dpp, key);
}
} catch(std::exception &e) {
return -1;
} else {
return 0; /* No delete was necessary */
}
- } else {
- return 0; /* No delete was necessary */
- }
+ return 0;
}
int RedisDriver::get_attrs(const DoutPrefixProvider* dpp, const std::string& key, rgw::sal::Attrs& attrs)
if (!client.is_connected())
find_client(dpp);
- if (key_exists(dpp, key)) {
- try {
+ try {
client.hgetall(entry, [&attrs](cpp_redis::reply &reply) {
if (reply.is_array()) {
auto arr = reply.as_array();
} catch(std::exception &e) {
return -1;
}
- } else {
- ldpp_dout(dpp, 20) << "RGW Redis Cache: Object was not retrievable." << dendl;
- return -2;
- }
return 0;
}
if (!client.is_connected())
find_client(dpp);
- if (key_exists(dpp, key)) {
- /* Every attr set will be treated as new */
- try {
- std::string result;
- auto redisAttrs = build_attrs(&attrs);
-
- client.hmset(entry, redisAttrs, [&result](cpp_redis::reply &reply) {
- if (!reply.is_null()) {
- result = reply.as_string();
- }
- });
-
- client.sync_commit(std::chrono::milliseconds(1000));
+ /* Every attr set will be treated as new */
+ try {
+ std::string result;
+ auto redisAttrs = build_attrs(&attrs);
- if (result != "OK") {
- return -1;
+ client.hmset(entry, redisAttrs, [&result](cpp_redis::reply &reply) {
+ if (!reply.is_null()) {
+ result = reply.as_string();
}
- } catch(std::exception &e) {
- return -1;
+ });
+
+ client.sync_commit(std::chrono::milliseconds(1000));
+
+ if (result != "OK") {
+return -1;
}
- } else {
- ldpp_dout(dpp, 20) << "RGW Redis Cache: Object was not retrievable." << dendl;
- return -2;
+ } catch(std::exception &e) {
+ return -1;
}
return 0;
if (!client.is_connected())
find_client(dpp);
- if (key_exists(dpp, key)) {
- try {
- std::string result;
- auto redisAttrs = build_attrs(&attrs);
+ try {
+ std::string result;
+ auto redisAttrs = build_attrs(&attrs);
- client.hmset(entry, redisAttrs, [&result](cpp_redis::reply &reply) {
- if (!reply.is_null()) {
- result = reply.as_string();
- }
- });
+ client.hmset(entry, redisAttrs, [&result](cpp_redis::reply &reply) {
+ if (!reply.is_null()) {
+ result = reply.as_string();
+ }
+ });
- client.sync_commit(std::chrono::milliseconds(1000));
+ client.sync_commit(std::chrono::milliseconds(1000));
- if (result != "OK") {
- return -1;
- }
- } catch(std::exception &e) {
+ if (result != "OK") {
return -1;
}
- } else {
- ldpp_dout(dpp, 20) << "RGW Redis Cache: Object was not retrievable." << dendl;
- return -2;
+ } catch(std::exception &e) {
+ return -1;
}
return 0;
if (!client.is_connected())
find_client(dpp);
- if (key_exists(dpp, key)) {
- std::vector<std::string> getFields;
-
- try {
- client.hgetall(entry, [&getFields](cpp_redis::reply &reply) {
- if (reply.is_array()) {
- auto arr = reply.as_array();
-
- if (!arr[0].is_null()) {
- for (long unsigned int i = 0; i < arr.size() - 1; i += 2) {
- getFields.push_back(arr[i].as_string());
- }
- }
- }
- });
+ std::vector<std::string> getFields;
- client.sync_commit(std::chrono::milliseconds(1000));
- } catch(std::exception &e) {
- return -1;
+ try {
+ client.hgetall(entry, [&getFields](cpp_redis::reply &reply) {
+if (reply.is_array()) {
+ auto arr = reply.as_array();
+
+ if (!arr[0].is_null()) {
+ for (long unsigned int i = 0; i < arr.size() - 1; i += 2) {
+ getFields.push_back(arr[i].as_string());
}
+ }
+}
+ });
+
+ client.sync_commit(std::chrono::milliseconds(1000));
+ } catch(std::exception &e) {
+ return -1;
+ }
- auto redisAttrs = build_attrs(&del_attrs);
- std::vector<std::string> redisFields;
+ auto redisAttrs = build_attrs(&del_attrs);
+ std::vector<std::string> redisFields;
- std::transform(begin(redisAttrs), end(redisAttrs), std::back_inserter(redisFields),
- [](auto const& pair) { return pair.first; });
+ std::transform(begin(redisAttrs), end(redisAttrs), std::back_inserter(redisFields),
+ [](auto const& pair) { return pair.first; });
- /* Only delete attributes that have been stored */
- for (const auto& it : redisFields) {
- if (std::find(getFields.begin(), getFields.end(), it) == getFields.end()) {
- redisFields.erase(std::find(redisFields.begin(), redisFields.end(), it));
- }
+ /* Only delete attributes that have been stored */
+ for (const auto& it : redisFields) {
+ if (std::find(getFields.begin(), getFields.end(), it) == getFields.end()) {
+ redisFields.erase(std::find(redisFields.begin(), redisFields.end(), it));
}
+ }
- try {
- int result = 0;
+ try {
+ int result = 0;
- client.hdel(entry, redisFields, [&result](cpp_redis::reply &reply) {
- if (reply.is_integer()) {
- result = reply.as_integer();
- }
- });
+ client.hdel(entry, redisFields, [&result](cpp_redis::reply &reply) {
+ if (reply.is_integer()) {
+ result = reply.as_integer();
+ }
+ });
- client.sync_commit(std::chrono::milliseconds(1000));
+ client.sync_commit(std::chrono::milliseconds(1000));
- return result - 1;
- } catch(std::exception &e) {
- return -1;
- }
+ return result - 1;
+ } catch(std::exception &e) {
+ return -1;
}
ldpp_dout(dpp, 20) << "RGW Redis Cache: Object is not in cache." << dendl;
if (!client.is_connected())
find_client(dpp);
- if (key_exists(dpp, key)) {
- int exists = -2;
- std::string getValue;
+ int exists = -2;
+ std::string getValue;
- /* Ensure field was set */
- try {
- client.hexists(entry, attr_name, [&exists](cpp_redis::reply& reply) {
- if (!reply.is_null()) {
- exists = reply.as_integer();
- }
- });
+ /* Ensure field was set */
+ try {
+ client.hexists(entry, attr_name, [&exists](cpp_redis::reply& reply) {
+ if (!reply.is_null()) {
+ exists = reply.as_integer();
+ }
+ });
- client.sync_commit(std::chrono::milliseconds(1000));
- } catch(std::exception &e) {
- return {};
- }
-
- if (!exists) {
- ldpp_dout(dpp, 20) << "RGW Redis Cache: Attribute was not set." << dendl;
- return {};
- }
+ client.sync_commit(std::chrono::milliseconds(1000));
+ } catch(std::exception &e) {
+ return {};
+ }
+
+ if (!exists) {
+ ldpp_dout(dpp, 20) << "RGW Redis Cache: Attribute was not set." << dendl;
+ return {};
+ }
- /* Retrieve existing value from cache */
- try {
- client.hget(entry, attr_name, [&exists, &attrValue](cpp_redis::reply &reply) {
- if (!reply.is_null()) {
- attrValue = reply.as_string();
- }
- });
+ /* Retrieve existing value from cache */
+ try {
+ client.hget(entry, attr_name, [&exists, &attrValue](cpp_redis::reply &reply) {
+ if (!reply.is_null()) {
+ attrValue = reply.as_string();
+ }
+ });
- client.sync_commit(std::chrono::milliseconds(1000));
- } catch(std::exception &e) {
- return {};
- }
- } else {
- ldpp_dout(dpp, 20) << "RGW Redis Cache: Object is not in cache." << dendl;
+ client.sync_commit(std::chrono::milliseconds(1000));
+ } catch(std::exception &e) {
return {};
}
if (!client.is_connected())
find_client(dpp);
- if (key_exists(dpp, key)) {
- /* Every attr set will be treated as new */
- try {
- client.hset(entry, attr_name, attrVal, [&result](cpp_redis::reply& reply) {
- if (!reply.is_null()) {
- result = reply.as_integer();
- }
- });
+ /* Every attr set will be treated as new */
+ try {
+ client.hset(entry, attr_name, attrVal, [&result](cpp_redis::reply& reply) {
+ if (!reply.is_null()) {
+ result = reply.as_integer();
+ }
+ });
- client.sync_commit(std::chrono::milliseconds(1000));
- } catch(std::exception &e) {
- return -1;
- }
- } else {
- ldpp_dout(dpp, 20) << "RGW Redis Cache: Object is not in cache." << dendl;
- return -2;
+ client.sync_commit(std::chrono::milliseconds(1000));
+ } catch(std::exception &e) {
+ return -1;
}
return result - 1;
return partitions.erase(key);
}
-int SSDDriver::insert_entry(const DoutPrefixProvider* dpp, std::string key, off_t offset, uint64_t len)
-{
- auto ret = entries.emplace(key, Entry(key, offset, len));
- return ret.second;
-}
-
-int SSDDriver::remove_entry(const DoutPrefixProvider* dpp, std::string key)
-{
- return entries.erase(key);
-}
-
-std::optional<Entry> SSDDriver::get_entry(const DoutPrefixProvider* dpp, std::string key)
-{
- auto iter = entries.find(key);
- if (iter != entries.end()) {
- return iter->second;
- }
-
- return std::nullopt;
-}
-
-std::vector<Entry> SSDDriver::list_entries(const DoutPrefixProvider* dpp)
-{
- std::vector<Entry> entries_v;
- for (auto& it : entries) {
- entries_v.emplace_back(it.second);
- }
- return entries_v;
-}
-
SSDDriver::SSDDriver(Partition& partition_info) : partition_info(partition_info),
- free_space(partition_info.size), outstanding_write_size(0)
+ free_space(partition_info.size)
{
add_partition_info(partition_info);
}
int SSDDriver::put(const DoutPrefixProvider* dpp, const std::string& key, bufferlist& bl, uint64_t len, rgw::sal::Attrs& attrs)
{
- if (key_exists(dpp, key)) {
- return 0;
- }
-
std::string location = partition_info.location + key;
ldpp_dout(dpp, 20) << __func__ << "(): location=" << location << dendl;
}
}
- return insert_entry(dpp, key, 0, len);
+ return 0;
}
int SSDDriver::get(const DoutPrefixProvider* dpp, const std::string& key, off_t offset, uint64_t len, bufferlist& bl, rgw::sal::Attrs& attrs)
{
- if (!key_exists(dpp, key)) {
- return -ENOENT;
- }
-
char buffer[len];
std::string location = partition_info.location + key;
{
efs::space_info space = efs::space(partition_info.location);
this->free_space = space.available;
-
- insert_entry(c->dpp, c->key, 0, c->cb->aio_nbytes);
}
int SSDDriver::put_async(const DoutPrefixProvider* dpp, const std::string& key, bufferlist& bl, uint64_t len, rgw::sal::Attrs& attrs)
efs::space_info space = efs::space(partition_info.location);
this->free_space = space.available;
- return remove_entry(dpp, key);
+ return 0;
}
int SSDDriver::append_data(const DoutPrefixProvider* dpp, const::std::string& key, bufferlist& bl_data)