Skip to content

Commit

Permalink
ovsdb: Add raft memory usage to memory report.
Browse files Browse the repository at this point in the history
Memory reports could be found in logs or by calling 'memory/show'
appctl command.  For ovsdb-server it includes information about db
cells, monitor connections with their backlog size, etc.  But it
doesn't contain any information about memory consumed by raft.
Backlogs of raft connections could be insanely large because of
snapshot installation requests that simply contains the whole database.
In not that healthy clusters where one of ovsdb servers is not able to
timely handle all the incoming raft traffic, backlog on a sender's side
could cause significant memory consumption issues.

Adding new 'raft-connections' and 'raft-backlog' counters to the
memory report to better track such conditions.

Acked-by: Han Zhou <hzhou@ovn.org>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
  • Loading branch information
igsilya committed May 25, 2020
1 parent 33f9c87 commit 3423cd9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ovsdb/ovsdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,10 @@ ovsdb_get_memory_usage(const struct ovsdb *db, struct simap *usage)
}

simap_increase(usage, "cells", cells);

if (db->storage) {
ovsdb_storage_get_memory_usage(db->storage, usage);
}
}

struct ovsdb_table *
Expand Down
16 changes: 16 additions & 0 deletions ovsdb/raft.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "ovsdb/log.h"
#include "raft-rpc.h"
#include "random.h"
#include "simap.h"
#include "socket-util.h"
#include "stream.h"
#include "timeval.h"
Expand Down Expand Up @@ -1014,6 +1015,21 @@ raft_get_sid(const struct raft *raft)
return &raft->sid;
}

/* Adds memory consumption info to 'usage' for later use by memory_report(). */
void
raft_get_memory_usage(const struct raft *raft, struct simap *usage)
{
struct raft_conn *conn;
int cnt = 0;

LIST_FOR_EACH (conn, list_node, &raft->conns) {
simap_increase(usage, "raft-backlog",
jsonrpc_session_get_backlog(conn->js));
cnt++;
}
simap_increase(usage, "raft-connections", cnt);
}

/* Returns true if 'raft' has completed joining its cluster, has not left or
* initiated leaving the cluster, does not have failed disk storage, and is
* apparently connected to the leader in a healthy way (or is itself the
Expand Down
2 changes: 2 additions & 0 deletions ovsdb/raft.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
struct json;
struct ovsdb_log;
struct raft;
struct simap;
struct sset;

#define RAFT_MAGIC "CLUSTER"
Expand Down Expand Up @@ -113,6 +114,7 @@ const struct uuid *raft_get_cid(const struct raft *);
const struct uuid *raft_get_sid(const struct raft *);
bool raft_is_connected(const struct raft *);
bool raft_is_leader(const struct raft *);
void raft_get_memory_usage(const struct raft *, struct simap *usage);

/* Joining a cluster. */
bool raft_is_joining(const struct raft *);
Expand Down
10 changes: 10 additions & 0 deletions ovsdb/storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "ovsdb.h"
#include "raft.h"
#include "random.h"
#include "simap.h"
#include "timeval.h"
#include "util.h"

Expand Down Expand Up @@ -188,6 +189,15 @@ ovsdb_storage_get_applied_index(const struct ovsdb_storage *storage)
return storage->raft ? raft_get_applied_index(storage->raft) : 0;
}

void
ovsdb_storage_get_memory_usage(const struct ovsdb_storage *storage,
struct simap *usage)
{
if (storage->raft) {
raft_get_memory_usage(storage->raft, usage);
}
}

void
ovsdb_storage_run(struct ovsdb_storage *storage)
{
Expand Down
3 changes: 3 additions & 0 deletions ovsdb/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
struct json;
struct ovsdb_schema;
struct ovsdb_storage;
struct simap;
struct uuid;

struct ovsdb_error *ovsdb_storage_open(const char *filename, bool rw,
Expand All @@ -39,6 +40,8 @@ bool ovsdb_storage_is_leader(const struct ovsdb_storage *);
const struct uuid *ovsdb_storage_get_cid(const struct ovsdb_storage *);
const struct uuid *ovsdb_storage_get_sid(const struct ovsdb_storage *);
uint64_t ovsdb_storage_get_applied_index(const struct ovsdb_storage *);
void ovsdb_storage_get_memory_usage(const struct ovsdb_storage *,
struct simap *usage);

void ovsdb_storage_run(struct ovsdb_storage *);
void ovsdb_storage_wait(struct ovsdb_storage *);
Expand Down

0 comments on commit 3423cd9

Please sign in to comment.