Skip to content

Commit

Permalink
Do not handle lookup by cache if it does not have the key
Browse files Browse the repository at this point in the history
Cache handles lookups by sending another lookups directly to the backend,
but it is unnecessary when cache does not have the key.
  • Loading branch information
shaitan committed Mar 23, 2016
1 parent 116be81 commit 33a872f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
22 changes: 6 additions & 16 deletions cache/slru_cache.cpp
Expand Up @@ -395,13 +395,12 @@ int slru_cache_t::lookup(const unsigned char *id, dnet_net_state *st, dnet_cmd *
data_t* it = m_treap.find(id);
TIMER_STOP("lookup.find");

dnet_time timestamp;
memset(&timestamp, 0, sizeof(timestamp));

if (it) {
timestamp = it->timestamp();
if (!it) {
return -ENOENT;
}

auto timestamp = it->timestamp();

guard.unlock();

// go check object on disk
Expand All @@ -415,22 +414,13 @@ int slru_cache_t::lookup(const unsigned char *id, dnet_net_state *st, dnet_cmd *
cmd->flags &= ~(DNET_FLAGS_MORE | DNET_FLAGS_NEED_ACK);

if (err) {
if (!it) {
// there is no object neither in cache nor on disk,
// we want client to notify about that, send him ACK
cmd->flags |= DNET_FLAGS_NEED_ACK;
return err;
}

// zero size means 'we didn't find key on disk', but yet it exists in cache
// lookup by its nature is 'show me what is on disk' command
return dnet_send_file_info_ts_without_fd(st, cmd, NULL, 0, &timestamp);
}

dnet_file_info *info = data.skip<dnet_addr>().data<dnet_file_info>();
if (it) {
info->mtime = timestamp;
}
auto info = data.skip<dnet_addr>().data<dnet_file_info>();
info->mtime = timestamp;

return dnet_send_reply(st, cmd, data.data(), data.size(), 0);
}
Expand Down
2 changes: 1 addition & 1 deletion library/dnet.c
Expand Up @@ -1601,7 +1601,7 @@ static int dnet_process_cmd_with_backend_raw(struct dnet_backend_io *backend, st
if (cmd->cmd == DNET_CMD_LOOKUP && !(cmd->flags & DNET_FLAGS_NOCACHE)) {
err = dnet_cmd_cache_lookup(backend, st, cmd);

if (err != -ENOTSUP) {
if (err != -ENOTSUP && err != -ENOENT) {
*handled_in_cache = 1;
break;
}
Expand Down

0 comments on commit 33a872f

Please sign in to comment.