Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection cache improvements #3546

Merged
merged 2 commits into from Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 34 additions & 19 deletions libcfnet/conn_cache.c
Expand Up @@ -32,6 +32,7 @@
#include <mutex.h> /* ThreadLock */
#include <communication.h> /* Hostname2IPString */
#include <misc_lib.h> /* CF_ASSERT */
#include <string_lib.h> /* StringSafeEqual */


/**
Expand Down Expand Up @@ -88,6 +89,16 @@ void ConnCache_Destroy()
ThreadUnlock(&cft_conncache);
}

static bool ConnCacheEntryMatchesConnection(ConnCache_entry *entry,
const char *server,
const char *port,
ConnectionFlags flags)
{
return ConnectionFlagsEqual(&flags, &entry->conn->flags) &&
StringSafeEqual(port, entry->conn->this_port) &&
StringSafeEqual(server, entry->conn->this_server);
}

AgentConnection *ConnCache_FindIdleMarkBusy(const char *server,
const char *port,
ConnectionFlags flags)
Expand All @@ -105,26 +116,27 @@ AgentConnection *ConnCache_FindIdleMarkBusy(const char *server,
"FindIdle: NULL connection in ConnCache_entry!");


if (strcmp(server, svp->conn->this_server) == 0 &&
ConnectionFlagsEqual(&flags, &svp->conn->flags) &&
(port == svp->conn->this_port
||
(port != NULL && svp->conn->this_port != NULL &&
strcmp(port, svp->conn->this_port) == 0)))
if (svp->status == CONNCACHE_STATUS_BUSY)
{
if (svp->status == CONNCACHE_STATUS_BUSY)
{
Log(LOG_LEVEL_DEBUG, "FindIdle:"
" connection to '%s' seems to be busy.",
server);
}
else if (svp->status == CONNCACHE_STATUS_OFFLINE)
{
Log(LOG_LEVEL_DEBUG, "FindIdle:"
" connection to '%s' is marked as offline.",
server);
}
else if (svp->conn->conn_info->sd >= 0)
Log(LOG_LEVEL_DEBUG,
"FindIdle: connection %p seems to be busy.",
svp->conn);
}
else if (svp->status == CONNCACHE_STATUS_OFFLINE)
{
Log(LOG_LEVEL_DEBUG,
"FindIdle: connection %p is marked as offline.",
svp->conn);
}
else if (svp->status == CONNCACHE_STATUS_BROKEN)
{
Log(LOG_LEVEL_DEBUG,
"FindIdle: connection %p is marked as broken.",
svp->conn);
}
else if (ConnCacheEntryMatchesConnection(svp, server, port, flags))
{
if (svp->conn->conn_info->sd >= 0)
{
assert(svp->status == CONNCACHE_STATUS_IDLE);

Expand All @@ -135,12 +147,14 @@ AgentConnection *ConnCache_FindIdleMarkBusy(const char *server,
{
Log(LOG_LEVEL_DEBUG, "FindIdle: found connection to '%s' but could not get socket status, skipping.",
server);
svp->status = CONNCACHE_STATUS_BROKEN;
continue;
}
if (error != 0)
{
Log(LOG_LEVEL_DEBUG, "FindIdle: found connection to '%s' but connection is broken, skipping.",
server);
svp->status = CONNCACHE_STATUS_BROKEN;
continue;
}

Expand All @@ -157,6 +171,7 @@ AgentConnection *ConnCache_FindIdleMarkBusy(const char *server,
Log(LOG_LEVEL_VERBOSE, "FindIdle:"
" connection to '%s' has invalid socket descriptor %d!",
server, svp->conn->conn_info->sd);
svp->status = CONNCACHE_STATUS_BROKEN;
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion libcfnet/conn_cache.h
Expand Up @@ -32,7 +32,8 @@ enum ConnCacheStatus
{
CONNCACHE_STATUS_IDLE = 0,
CONNCACHE_STATUS_BUSY,
CONNCACHE_STATUS_OFFLINE
CONNCACHE_STATUS_OFFLINE,
CONNCACHE_STATUS_BROKEN,
};


Expand Down