Skip to content

Commit

Permalink
Fix host compile issues with GCC 10+
Browse files Browse the repository at this point in the history
  • Loading branch information
velomatt committed Jul 26, 2024
1 parent cd1005b commit 112420e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
15 changes: 11 additions & 4 deletions host/src/include_private/nkv_framework.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@
std::atomic<uint64_t> pending_io_size;
std::atomic<uint64_t> pending_io_value;
std::condition_variable cv_path;
nkv_lruCache<std::string, nkv_value_wrapper> *cnt_cache;
//nkv_lruCache<std::string, nkv_value_wrapper> *cnt_cache;
std::vector<nkv_lruCache<std::string, nkv_value_wrapper> *> cnt_cache;
pthread_rwlock_t lru_rw_lock;
std::mutex lru_lock;
std::atomic<uint64_t> nkv_num_dc_keys;
Expand Down Expand Up @@ -281,11 +282,17 @@
pthread_rwlock_init(&data_rw_lock_list[iter], NULL);
}

listing_keys = new std::unordered_map<std::size_t, std::set<std::string> > [nkv_listing_cache_num_shards];
listing_keys = new std::unordered_map<std::size_t, std::set<std::string> > (nkv_listing_cache_num_shards);
if (nkv_in_memory_exec) {
data_cache = new std::unordered_map<std::string, nkv_value_wrapper*> [nkv_listing_cache_num_shards];
data_cache = new std::unordered_map<std::string, nkv_value_wrapper*> (nkv_listing_cache_num_shards);
}
cnt_cache.resize(nkv_read_cache_shard_size);
for (auto i=0; i<nkv_read_cache_shard_size; i++) {
// Initialize class object
nkv_lruCache<std::string, nkv_value_wrapper> *cache_obj
= new nkv_lruCache<std::string, nkv_value_wrapper>(nkv_read_cache_size);
cnt_cache.push_back(cache_obj);
}
cnt_cache = new nkv_lruCache<std::string, nkv_value_wrapper> [nkv_read_cache_shard_size](nkv_read_cache_size);
nkv_num_dc_keys = 0;

// ustats
Expand Down
18 changes: 11 additions & 7 deletions host/src/nkv_framework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ nkv_result NKVTargetPath::do_store_io_to_path(const nkv_key* n_key, const nkv_st
memcpy(c_buffer, n_value->value, n_value->length);
nkv_value_wrapper nkvvalue (c_buffer, n_value->length, n_value->length);
std::lock_guard<std::mutex> lck (lru_lock);
cnt_cache[shard_id].put(key_str, std::move(nkvvalue));
cnt_cache[shard_id]->put(key_str, std::move(nkvvalue));
}
}
}
Expand Down Expand Up @@ -969,7 +969,7 @@ nkv_result NKVTargetPath::do_retrieve_io_from_path(const nkv_key* n_key, const n
std::size_t key_prefix = std::hash<std::string>{}(key_str);
shard_id = key_prefix % nkv_read_cache_shard_size;
std::lock_guard<std::mutex> lck (lru_lock);
const nkv_value_wrapper& nkvvalue = cnt_cache[shard_id].get(key_str, cache_hit);
const nkv_value_wrapper& nkvvalue = cnt_cache[shard_id]->get(key_str, cache_hit);
//nkv_value_wrapper nkvvalue = cnt_cache[shard_id].get(key_str, cache_hit);
//nkv_value_wrapper* nkvvalue = cnt_cache[shard_id].get(key_str, cache_hit);
if (cache_hit) {
Expand Down Expand Up @@ -1058,7 +1058,7 @@ nkv_result NKVTargetPath::do_retrieve_io_from_path(const nkv_key* n_key, const n
//nkv_value_wrapper* nkvvalue = new nkv_value_wrapper(NULL, 0, 0);
smg_info(logger, "Cache put non-existence, key = %s, dev_path = %s, ip = %s", key_str.c_str(), dev_path.c_str(), path_ip.c_str());
std::lock_guard<std::mutex> lck (lru_lock);
cnt_cache[shard_id].put(key_str, std::move(nkvvalue));
cnt_cache[shard_id]->put(key_str, std::move(nkvvalue));
//cnt_cache[shard_id].put(key_str, nkvvalue);
}
}
Expand Down Expand Up @@ -1115,7 +1115,7 @@ nkv_result NKVTargetPath::do_retrieve_io_from_path(const nkv_key* n_key, const n
nkv_value_wrapper nkvvalue (c_buffer, n_value->actual_length, n_value->actual_length);
smg_info(logger, "Cache put after get, key = %s, dev_path = %s, ip = %s", key_str.c_str(), dev_path.c_str(), path_ip.c_str());
std::lock_guard<std::mutex> lck (lru_lock);
cnt_cache[shard_id].put(key_str, std::move(nkvvalue));
cnt_cache[shard_id]->put(key_str, std::move(nkvvalue));
//cnt_cache[shard_id].put(key_str, nkvvalue);
} else {
smg_warn(logger, "data key = %s, length = %u, dev_path = %s, ip = %s", key_str.c_str(), n_value->actual_length, dev_path.c_str(), path_ip.c_str());
Expand Down Expand Up @@ -1458,7 +1458,7 @@ nkv_result NKVTargetPath::do_delete_io_from_path (const nkv_key* n_key, nkv_post
int32_t shard_id = key_prefix % nkv_read_cache_shard_size;
bool cache_hit = false;
std::lock_guard<std::mutex> lck (lru_lock);
cnt_cache[shard_id].del(key_str, cache_hit);
cnt_cache[shard_id]->del(key_str, cache_hit);
}
}
}
Expand Down Expand Up @@ -2218,10 +2218,14 @@ NKVTargetPath::~NKVTargetPath() {
if (nkv_in_memory_exec) {
delete[] data_cache;
}
delete[] cnt_cache;
//delete[] cnt_cache;
for (int i=0; i<cnt_cache.size(); i++) {
delete cnt_cache[i];
}
cnt_cache.clear();
smg_info(logger, "Cleanup successful for path = %s", dev_path.c_str());


if( device_stat) {
nkv_ustat_delete(device_stat);
}
Expand Down
2 changes: 1 addition & 1 deletion host/src/remote/auto_discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ bool nvme_disconnect(std::string subsystem_nqn)
*/
void read_file(const std::string& file_path, int32_t start_line, int32_t line_to_read, std::vector<std::string>& lines)
{
ifstream fh (file_path);
std::ifstream fh (file_path);
int32_t index = 1;
try{
if (fh.is_open()) {
Expand Down

0 comments on commit 112420e

Please sign in to comment.