Skip to contentSkip to conversation

xenstore: rework of transaction handling

PATCH In review Juergen Gross 2 participants 7 messages Mar 31, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v5 3/4 xenstore: rework of transaction handling

The handling of transactions in xenstored is rather clumsy today:

- Each transaction in progress is keeping a local copy of the complete xenstore data base
- A transaction will fail as soon as any node is being modified outside the transaction

This is leading to a very bad behavior in case of a large xenstore. Memory consumption of xenstored is much higher than necessary and with many domains up transactions failures will be more and more common.

Instead of keeping a complete copy of the data base for each transaction store the transaction data in the same data base as the normal xenstore entries prepended with the transaction in the single nodes either read or modified. At the end of the transaction walk through all nodes accessed and check for conflicting modifications. In case no conflicts are found write all modified nodes to the data base without transaction identifier.

Following tests have been performed:
- create/destroy of various domains, including HVM with ioemu-stubdom (xenstored and xenstore-stubdom)
- multiple concurrent runs of xs-test over several minutes (xenstored and xenstore-stubdom)
- test for memory leaks of xenstored by dumping talloc reports before and after the tests

---
 tools/xenstore/xenstored_core.c        | 147 +++++------
 tools/xenstore/xenstored_core.h        |  20 +-
 tools/xenstore/xenstored_domain.c      |  24 +-
 tools/xenstore/xenstored_domain.h      |   2 +-
 tools/xenstore/xenstored_transaction.c | 443 +++++++++++++++++++++++++++------
 tools/xenstore/xenstored_transaction.h |  18 +-
 6 files changed, 480 insertions(+), 174 deletions(-)
tools/xenstore/xenstored_core.c +65 -82
index ee4c9e1..c8e4237 100644
@@ -54,8 +54,6 @@
 #include "xenstored_control.h"
 #include "tdb.h"
 
-#include "hashtable.h"
-
 #ifndef NO_SOCKETS
 #if defined(HAVE_SYSTEMD)
 #define XEN_SYSTEMD_ENABLED 1
@@ -81,9 +79,8 @@ static bool recovery = true;
 static int reopen_log_pipe[2];
 static int reopen_log_pipe0_pollfd_idx = -1;
 char *tracefile = NULL;
-static TDB_CONTEXT *tdb_ctx = NULL;
+TDB_CONTEXT *tdb_ctx = NULL;
 
-static void corrupt(struct connection *conn, const char *fmt, ...);
 static const char *sockmsg_string(enum xsd_sockmsg_type type);
 
 #define log(...)							\
@@ -105,24 +102,6 @@ int quota_nb_watch_per_domain = 128;
 int quota_max_entry_size = 2048; /* 2K */
 int quota_max_transaction = 10;
 
-TDB_CONTEXT *tdb_context(struct connection *conn)
-{
-	/* conn = NULL used in manual_node at setup. */
-	if (!conn || !conn->transaction)
-		return tdb_ctx;
-	return tdb_transaction_context(conn->transaction);
-}
-
-bool replace_tdb(const char *newname, TDB_CONTEXT *newtdb)
-{
-	if (!(tdb_ctx->flags & TDB_INTERNAL))
-		if (rename(newname, xs_daemon_tdb()) != 0)
-			return false;
-	tdb_close(tdb_ctx);
-	tdb_ctx = talloc_steal(talloc_autofree_context(), newtdb);
-	return true;
-}
-
 void trace(const char *fmt, ...)
 {
 	va_list arglist;
@@ -385,35 +364,38 @@ static struct node *read_node(struct connection *conn, const void *ctx,
 	TDB_DATA key, data;
 	struct xs_tdb_record_hdr *hdr;
 	struct node *node;
-	TDB_CONTEXT * context = tdb_context(conn);
 
-	key.dptr = (void *)name;
-	key.dsize = strlen(name);
-	data = tdb_fetch(context, key);
+	node = talloc(ctx, struct node);
+	if (!node) {
+		errno = ENOMEM;
+		return NULL;
+	}
+	node->name = talloc_strdup(node, name);
+	if (!node->name) {
+		talloc_free(node);
+		errno = ENOMEM;
+		return NULL;
+	}
+
+	if (transaction_prepend(conn, name, &key))
+		return NULL;
+
+	data = tdb_fetch(tdb_ctx, key);
 
 	if (data.dptr == NULL) {
-		if (tdb_error(context) == TDB_ERR_NOEXIST)
+		if (tdb_error(tdb_ctx) == TDB_ERR_NOEXIST) {
+			node->generation = NO_GENERATION;
+			access_node(conn, node, NODE_ACCESS_READ, NULL);
 			errno = ENOENT;
-		else {
-			log("TDB error on read: %s", tdb_errorstr(context));
+		} else {
+			log("TDB error on read: %s", tdb_errorstr(tdb_ctx));
 			errno = EIO;
 		}
-		return NULL;
-	}
-
-	node = talloc(ctx, struct node);
-	if (!node) {
-		errno = ENOMEM;
-		return NULL;
-	}
-	node->name = talloc_strdup(node, name);
-	if (!node->name) {
 		talloc_free(node);
-		errno = ENOMEM;
 		return NULL;
 	}
+
 	node->parent = NULL;
-	node->tdb = tdb_context(conn);
 	talloc_steal(node, data.dptr);
 
 	/* Datalen, childlen, number of permissions */
@@ -430,32 +412,26 @@ static struct node *read_node(struct connection *conn, const void *ctx,
 	/* Children is strings, nul separated. */
 	node->children = node->data + node->datalen;
 
+	access_node(conn, node, NODE_ACCESS_READ, NULL);
+
 	return node;
 }
 
-static int write_node(struct connection *conn, struct node *node)
+int write_node_raw(struct connection *conn, TDB_DATA *key, struct node *node)
 {
-	/*
-	 * conn will be null when this is called from manual_node.
-	 * tdb_context copes with this.
-	 */
-
-	TDB_DATA key, data;
+	TDB_DATA data;
 	void *p;
 	struct xs_tdb_record_hdr *hdr;
 
-	key.dptr = (void *)node->name;
-	key.dsize = strlen(node->name);
-
 	data.dsize = sizeof(*hdr)
 		+ node->num_perms*sizeof(node->perms[0])
 		+ node->datalen + node->childlen;
 
-	if (domain_is_unprivileged(conn) && data.dsize >= quota_max_entry_size)
-		goto error;
-
-	add_change_node(conn, node, false);
-	wrl_apply_debit_direct(conn);
+	if (domain_is_unprivileged(conn) &&
+	    data.dsize >= quota_max_entry_size) {
+		errno = ENOSPC;
+		return errno;
+	}
 
 	data.dptr = talloc_size(node, data.dsize);
 	hdr = (void *)data.dptr;
@@ -471,14 +447,22 @@ static int write_node(struct connection *conn, struct node *node)
 	memcpy(p, node->children, node->childlen);
 
 	/* TDB should set errno, but doesn't even set ecode AFAICT. */
-	if (tdb_store(tdb_context(conn), key, data, TDB_REPLACE) != 0) {
-		corrupt(conn, "Write of %s failed", key.dptr);
-		goto error;
+	if (tdb_store(tdb_ctx, *key, data, TDB_REPLACE) != 0) {
+		corrupt(conn, "Write of %s failed", key->dptr);
+		errno = EIO;
+		return errno;
 	}
 	return 0;
- error:
-	errno = ENOSPC;
-	return errno;
+}
+
+static int write_node(struct connection *conn, struct node *node)
+{
+	TDB_DATA key;
+
+	if (access_node(conn, node, NODE_ACCESS_WRITE, &key))
+		return errno;
+
+	return write_node_raw(conn, &key, node);
 }
 
 static enum xs_perm_type perm_for_conn(struct connection *conn,
@@ -900,24 +884,18 @@ static int do_read(struct connection *conn, struct buffered_data *in)
 	return 0;
 }
 
-static void delete_node_single(struct connection *conn, struct node *node,
-			       bool changed)
+static void delete_node_single(struct connection *conn, struct node *node)
 {
 	TDB_DATA key;
 
-	key.dptr = (void *)node->name;
-	key.dsize = strlen(node->name);
+	if (access_node(conn, node, NODE_ACCESS_DELETE, &key))
+		return;
 
-	if (tdb_delete(tdb_context(conn), key) != 0) {
+	if (tdb_delete(tdb_ctx, key) != 0) {
 		corrupt(conn, "Could not delete '%s'", node->name);
 		return;
 	}
 
-	if (changed) {
-		add_change_node(conn, node, true);
-		wrl_apply_debit_direct(conn);
-	}
-
 	domain_entry_dec(conn, node);
 }
 
@@ -965,7 +943,6 @@ static struct node *construct_node(struct connection *conn, const void *ctx,
 	node = talloc(ctx, struct node);
 	if (!node)
 		goto nomem;
-	node->tdb = tdb_context(conn);
 	node->name = talloc_strdup(node, name);
 	if (!node->name)
 		goto nomem;
@@ -1002,7 +979,7 @@ static int destroy_node(void *_node)
 	key.dptr = (void *)node->name;
 	key.dsize = strlen(node->name);
 
-	tdb_delete(node->tdb, key);
+	tdb_delete(tdb_ctx, key);
 	return 0;
 }
 
@@ -1095,8 +1072,7 @@ static int do_mkdir(struct connection *conn, struct buffered_data *in)
 	return 0;
 }
 
-static void delete_node(struct connection *conn, struct node *node,
-			bool changed)
+static void delete_node(struct connection *conn, struct node *node)
 {
 	unsigned int i;
 	char *name;
@@ -1104,7 +1080,7 @@ static void delete_node(struct connection *conn, struct node *node,
 	/* Delete self, then delete children.  If we crash, then the worst
 	   that can happen is the children will continue to take up space, but
 	   will otherwise be unreachable. */
-	delete_node_single(conn, node, changed);
+	delete_node_single(conn, node);
 
 	/* Delete children, too. */
 	for (i = 0; i < node->childlen; i += strlen(node->children+i) + 1) {
@@ -1114,7 +1090,7 @@ static void delete_node(struct connection *conn, struct node *node,
 				       node->children + i);
 		child = name ? read_node(conn, node, name) : NULL;
 		if (child) {
-			delete_node(conn, child, false);
+			delete_node(conn, child);
 		}
 		else {
 			trace("delete_node: Error deleting child '%s/%s'!\n",
@@ -1177,7 +1153,7 @@ static int _rm(struct connection *conn, const void *ctx, struct node *node,
 	if (delete_child(conn, parent, basename(name)))
 		return EINVAL;
 
-	delete_node(conn, node, true);
+	delete_node(conn, node);
 	return 0;
 }
 
@@ -1617,7 +1593,7 @@ static char *child_name(const char *s1, const char *s2)
 }
 
 
-static int remember_string(struct hashtable *hash, const char *str)
+int remember_string(struct hashtable *hash, const char *str)
 {
 	char *k = malloc(strlen(str) + 1);
 
@@ -1737,6 +1713,7 @@ static int clean_store_(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA val,
 			void *private)
 {
 	struct hashtable *reachable = private;
+	char *slash;
 	char * name = talloc_strndup(NULL, key.dptr, key.dsize);
 
 	if (!name) {
@@ -1744,6 +1721,11 @@ static int clean_store_(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA val,
 		return 1;
 	}
 
+	if (name[0] != '/') {
+		slash = strchr(name, '/');
+		if (slash)
+			*slash = 0;
+	}
 	if (!hashtable_search(reachable, name)) {
 		log("clean_store: '%s' is orphaned!", name);
 		if (recovery) {
@@ -1779,7 +1761,8 @@ void check_store(void)
 	}
 
 	log("Checking store ...");
-	if (!check_store_(root, reachable))
+	if (!check_store_(root, reachable) &&
+	    !check_transactions(reachable))
 		clean_store(reachable);
 	log("Checking store complete.");
 
@@ -1790,7 +1773,7 @@ void check_store(void)
 
 
 /* Something is horribly wrong: check the store. */
-static void corrupt(struct connection *conn, const char *fmt, ...)
+void corrupt(struct connection *conn, const char *fmt, ...)
 {
 	va_list arglist;
 	char *str;
tools/xenstore/xenstored_core.h +11 -9
index 0580827..3d7eb91 100644
@@ -32,6 +32,7 @@
 #include "xenstore_lib.h"
 #include "list.h"
 #include "tdb.h"
+#include "hashtable.h"
 
 /* DEFAULT_BUFFER_SIZE should be large enough for each errno string. */
 #define DEFAULT_BUFFER_SIZE 16
@@ -113,14 +114,12 @@ extern struct list_head connections;
 struct node {
 	const char *name;
 
-	/* Database I came from */
-	TDB_CONTEXT *tdb;
-
 	/* Parent (optional) */
 	struct node *parent;
 
 	/* Generation count. */
 	uint64_t generation;
+#define NO_GENERATION ~((uint64_t)0)
 
 	/* Permissions. */
 	unsigned int num_perms;
@@ -151,20 +150,18 @@ void send_ack(struct connection *conn, enum xsd_sockmsg_type type);
 /* Canonicalize this path if possible. */
 char *canonicalize(struct connection *conn, const void *ctx, const char *node);
 
+/* Write a node to the tdb data base. */
+int write_node_raw(struct connection *conn, TDB_DATA *key, struct node *node);
+
 /* Get this node, checking we have permissions. */
 struct node *get_node(struct connection *conn,
 		      const void *ctx,
 		      const char *name,
 		      enum xs_perm_type perm);
 
-/* Get TDB context for this connection */
-TDB_CONTEXT *tdb_context(struct connection *conn);
-
-/* Replace the tdb: required for transaction code */
-bool replace_tdb(const char *newname, TDB_CONTEXT *newtdb);
-
 struct connection *new_connection(connwritefn_t *write, connreadfn_t *read);
 void check_store(void);
+void corrupt(struct connection *conn, const char *fmt, ...);
 
 /* Is this a valid node name? */
 bool is_valid_nodename(const char *node);
@@ -179,9 +176,12 @@ void close_log(void);
 
 extern char *tracefile;
 extern int tracefd;
+
+extern TDB_CONTEXT *tdb_ctx;
 extern int dom0_domid;
 extern int dom0_event;
 extern int priv_domid;
+extern int quota_nb_entry_per_domain;
 
 /* Map the kernel's xenstore page. */
 void *xenbus_map(void);
@@ -208,6 +208,8 @@ void init_pipe(int reopen_log_pipe[2]);
 
 xengnttab_handle **xgt_handle;
 
+int remember_string(struct hashtable *hash, const char *str);
+
 #endif /* _XENSTORED_CORE_H */
 
 /*
tools/xenstore/xenstored_domain.c +20 -4
index 6af219e..4edd14e 100644
@@ -268,9 +268,15 @@ bool domain_can_read(struct connection *conn)
 	return (intf->req_cons != intf->req_prod);
 }
 
+static bool domid_is_unprivileged(unsigned int domid)
+{
+	return domid != 0 && domid != priv_domid;
+}
+
 bool domain_is_unprivileged(struct connection *conn)
 {
-	return (conn && conn->domain && conn->domain->domid != 0 && conn->domain->domid != priv_domid);
+	return conn && conn->domain &&
+	       domid_is_unprivileged(conn->domain->domid);
 }
 
 bool domain_can_write(struct connection *conn)
@@ -699,13 +705,23 @@ void domain_entry_dec(struct connection *conn, struct node *node)
 	}
 }
 
-void domain_entry_fix(unsigned int domid, int num)
+int domain_entry_fix(unsigned int domid, int num, bool update)
 {
 	struct domain *d;
+	int cnt;
 
 	d = find_domain_by_domid(domid);
-	if (d && ((d->nbentry += num) < 0))
-		d->nbentry = 0;
+	if (!d)
+		return 0;
+
+	cnt = d->nbentry + num;
+	if (cnt < 0)
+		cnt = 0;
+
+	if (update)
+		d->nbentry = cnt;
+
+	return domid_is_unprivileged(domid) ? cnt : 0;
 }
 
 int domain_entry(struct connection *conn)
tools/xenstore/xenstored_domain.h +1 -1
index 4aa80db..56ae015 100644
@@ -59,7 +59,7 @@ bool domain_is_unprivileged(struct connection *conn);
 /* Quota manipulation */
 void domain_entry_inc(struct connection *conn, struct node *);
 void domain_entry_dec(struct connection *conn, struct node *);
-void domain_entry_fix(unsigned int domid, int num);
+int domain_entry_fix(unsigned int domid, int num, bool update);
 int domain_entry(struct connection *conn);
 void domain_watch_inc(struct connection *conn);
 void domain_watch_dec(struct connection *conn);
tools/xenstore/xenstored_transaction.c +370 -73

546 lines not on this page · raw message

tools/xenstore/xenstored_transaction.h +13 -5
index aeeac3d..3386bac 100644
@@ -19,6 +19,12 @@
 #define _XENSTORED_TRANSACTION_H
 #include "xenstored_core.h"
 
+enum node_access_type {
+    NODE_ACCESS_READ,
+    NODE_ACCESS_WRITE,
+    NODE_ACCESS_DELETE
+};
+
 struct transaction;
 
 int do_transaction_start(struct connection *conn, struct buffered_data *node);
@@ -30,13 +36,15 @@ struct transaction *transaction_lookup(struct connection *conn, uint32_t id);
 void transaction_entry_inc(struct transaction *trans, unsigned int domid);
 void transaction_entry_dec(struct transaction *trans, unsigned int domid);
 
-/* This node was changed. */
-void add_change_node(struct connection *conn, struct node *node,
-                     bool recurse);
+/* This node was accessed. */
+int access_node(struct connection *conn, struct node *node,
+                enum node_access_type type, TDB_DATA *key);
 
-/* Return tdb context to use for this connection. */
-TDB_CONTEXT *tdb_transaction_context(struct transaction *trans);
+/* Prepend the transaction to name if appropriate. */
+int transaction_prepend(struct connection *conn, const char *name,
+                        TDB_DATA *key);
 
 void conn_delete_all_transactions(struct connection *conn);
+int check_transactions(struct hashtable *hash);
 
 #endif /* _XENSTORED_TRANSACTION_H */
Signature · 7 lines
2.10.2


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw

Another stupid question below.

Quoted 21 lines · Juergen Gross
tools/xenstore/xenstored_transaction.c +19 -1
-struct changed_node
+/*
+ * Some notes regarding detection and handling of transaction conflicts:
+ *
+ * Basic source of reference is the 'generation' count. Each writing access
+ * (either normal write or in a transaction) to the tdb data base will set
+ * the node specific generation count to the global generation count.
+ * For being able to identify a transaction the transaction specific generation
+ * count is initialized with the global generation count when starting the
+ * transaction.
+ * Each time the global generation count is copied to either a node or a
+ * transaction it is incremented. This ensures all nodes and/or transactions
+ * are having a unique generation count.
+ *
+ * Transaction conflicts are detected by checking the generation count of all
+ * nodes read in the transaction to match with the generation count in the
+ * global data base at the end of the transaction. Nodes which have been
+ * modified in the transaction don't have to be checked to match even if they
+ * have been read, as the modified node will be globally visible after the
+ * succeeded transaction possibly overwriting another modification which may

tools/xenstore/xenstored_transaction.c line 67

Quoted 10 lines
tools/xenstore/xenstored_transaction.c +10 -0
+ * have occurred concurrent to the transaction.
+ *
+ * Examples:
+ * ---------
+ * The following notation is used:
+ * I:      initial state
+ * G       global generation count
+ * g(X)    generation count of node X
+ * G(1)    generation count of transaction 1
+ * g(1:Y)  saved generation count of node Y in transaction 1

Assuming this is recorded in accessed_node, can you point me to where about in the code this is implemented? I looked at access_node but that only records generation for read.

Quoted 8 lines

+ * TA1: operation in transaction 1
+ * X=1:X replace global node X with transaction 1 specific value of X
+ *
+ * 1. Simple transaction doing: read node A, write node B

+ *    I: g(A) = 1, g(B) = 2, G = 3
+ *    Start transaction 1: G(1) = 3, G = 4
+ *    TA1: read node A:    g(1:A) = 1
+ *    TA1: write node B:   g(1:B) = 4, G = 5

Specifically, here you mention write type also records generation count.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#2 lore raw
Quoted 30 lines · Wei Liu

Another stupid question below.

Quoted 27 lines · Juergen Gross
tools/xenstore/xenstored_transaction.c +25 -1
-struct changed_node
+/*
+ * Some notes regarding detection and handling of transaction conflicts:
+ *
+ * Basic source of reference is the 'generation' count. Each writing access
+ * (either normal write or in a transaction) to the tdb data base will set
+ * the node specific generation count to the global generation count.
+ * For being able to identify a transaction the transaction specific generation
+ * count is initialized with the global generation count when starting the
+ * transaction.
+ * Each time the global generation count is copied to either a node or a
+ * transaction it is incremented. This ensures all nodes and/or transactions
+ * are having a unique generation count.
+ *
+ * Transaction conflicts are detected by checking the generation count of all
+ * nodes read in the transaction to match with the generation count in the
+ * global data base at the end of the transaction. Nodes which have been
+ * modified in the transaction don't have to be checked to match even if they
+ * have been read, as the modified node will be globally visible after the
+ * succeeded transaction possibly overwriting another modification which may
+ * have occurred concurrent to the transaction.
+ *
+ * Examples:
+ * ---------
+ * The following notation is used:
+ * I:      initial state
Quoted 8 lines
Quoted 4 lines
+ * G       global generation count
+ * g(X)    generation count of node X
+ * G(1)    generation count of transaction 1
+ * g(1:Y)  saved generation count of node Y in transaction 1

Assuming this is recorded in accessed_node, can you point me to where about in the code this is implemented? I looked at access_node but that only records generation for read.

It is in the node itself stored in the data base.

Quoted 10 lines
Quoted 8 lines

+ * TA1: operation in transaction 1
+ * X=1:X replace global node X with transaction 1 specific value of X
+ *
+ * 1. Simple transaction doing: read node A, write node B

+ *    I: g(A) = 1, g(B) = 2, G = 3
+ *    Start transaction 1: G(1) = 3, G = 4
+ *    TA1: read node A:    g(1:A) = 1
+ *    TA1: write node B:   g(1:B) = 4, G = 5

Specifically, here you mention write type also records generation count.

In the end the generation count of a node modified by a transaction isn't important for the transaction.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw
Quoted 40 lines · Juergen Gross
Quoted 30 lines · Wei Liu

Another stupid question below.

Quoted 27 lines · Juergen Gross
tools/xenstore/xenstored_transaction.c +25 -1
-struct changed_node
+/*
+ * Some notes regarding detection and handling of transaction conflicts:
+ *
+ * Basic source of reference is the 'generation' count. Each writing access
+ * (either normal write or in a transaction) to the tdb data base will set
+ * the node specific generation count to the global generation count.
+ * For being able to identify a transaction the transaction specific generation
+ * count is initialized with the global generation count when starting the
+ * transaction.
+ * Each time the global generation count is copied to either a node or a
+ * transaction it is incremented. This ensures all nodes and/or transactions
+ * are having a unique generation count.
+ *
+ * Transaction conflicts are detected by checking the generation count of all
+ * nodes read in the transaction to match with the generation count in the
+ * global data base at the end of the transaction. Nodes which have been
+ * modified in the transaction don't have to be checked to match even if they
+ * have been read, as the modified node will be globally visible after the
+ * succeeded transaction possibly overwriting another modification which may
+ * have occurred concurrent to the transaction.
+ *
+ * Examples:
+ * ---------
+ * The following notation is used:
+ * I:      initial state
Quoted 8 lines
Quoted 4 lines
+ * G       global generation count
+ * g(X)    generation count of node X
+ * G(1)    generation count of transaction 1
+ * g(1:Y)  saved generation count of node Y in transaction 1

Assuming this is recorded in accessed_node, can you point me to where about in the code this is implemented? I looked at access_node but that only records generation for read.

Quoted 2 lines

It is in the node itself stored in the data base.

Right, then ...

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

+ * TA1: operation in transaction 1
+ * X=1:X replace global node X with transaction 1 specific value of X
+ *
+ * 1. Simple transaction doing: read node A, write node B

+ *    I: g(A) = 1, g(B) = 2, G = 3
+ *    Start transaction 1: G(1) = 3, G = 4
+ *    TA1: read node A:    g(1:A) = 1
+ *    TA1: write node B:   g(1:B) = 4, G = 5

I suggest updating places like g(1:B) = 4 to g(B) = 4 to match the code.

I will continue my review.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by on v5 3/4
#6 lore raw
In reply to Juergen Gross
Quoted 27 lines · Juergen Gross

The handling of transactions in xenstored is rather clumsy today:

- Each transaction in progress is keeping a local copy of the complete xenstore data base
- A transaction will fail as soon as any node is being modified outside the transaction

This is leading to a very bad behavior in case of a large xenstore. Memory consumption of xenstored is much higher than necessary and with many domains up transactions failures will be more and more common.

Instead of keeping a complete copy of the data base for each transaction store the transaction data in the same data base as the normal xenstore entries prepended with the transaction in the single nodes either read or modified. At the end of the transaction walk through all nodes accessed and check for conflicting modifications. In case no conflicts are found write all modified nodes to the data base without transaction identifier.

Following tests have been performed:
- create/destroy of various domains, including HVM with ioemu-stubdom (xenstored and xenstore-stubdom)
- multiple concurrent runs of xs-test over several minutes (xenstored and xenstore-stubdom)
- test for memory leaks of xenstored by dumping talloc reports before and after the tests

Quoted 1 line

With the suggestion to update the comment taken care of:

Given this is rather complex code it would be helpful to have a second opinion.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#4 lore raw
In reply to Wei Liu
Quoted 56 lines · Wei Liu
Quoted 40 lines · Juergen Gross
Quoted 30 lines · Wei Liu

Another stupid question below.

Quoted 27 lines · Juergen Gross
tools/xenstore/xenstored_transaction.c +25 -1
-struct changed_node
+/*
+ * Some notes regarding detection and handling of transaction conflicts:
+ *
+ * Basic source of reference is the 'generation' count. Each writing access
+ * (either normal write or in a transaction) to the tdb data base will set
+ * the node specific generation count to the global generation count.
+ * For being able to identify a transaction the transaction specific generation
+ * count is initialized with the global generation count when starting the
+ * transaction.
+ * Each time the global generation count is copied to either a node or a
+ * transaction it is incremented. This ensures all nodes and/or transactions
+ * are having a unique generation count.
+ *
+ * Transaction conflicts are detected by checking the generation count of all
+ * nodes read in the transaction to match with the generation count in the
+ * global data base at the end of the transaction. Nodes which have been
+ * modified in the transaction don't have to be checked to match even if they
+ * have been read, as the modified node will be globally visible after the
+ * succeeded transaction possibly overwriting another modification which may
+ * have occurred concurrent to the transaction.
+ *
+ * Examples:
+ * ---------
+ * The following notation is used:
+ * I:      initial state
Quoted 8 lines
Quoted 4 lines
+ * G       global generation count
+ * g(X)    generation count of node X
+ * G(1)    generation count of transaction 1
+ * g(1:Y)  saved generation count of node Y in transaction 1

Assuming this is recorded in accessed_node, can you point me to where about in the code this is implemented? I looked at access_node but that only records generation for read.

Quoted 2 lines

It is in the node itself stored in the data base.

Right, then ...

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

+ * TA1: operation in transaction 1
+ * X=1:X replace global node X with transaction 1 specific value of X
+ *
+ * 1. Simple transaction doing: read node A, write node B

+ *    I: g(A) = 1, g(B) = 2, G = 3
+ *    Start transaction 1: G(1) = 3, G = 4
+ *    TA1: read node A:    g(1:A) = 1
+ *    TA1: write node B:   g(1:B) = 4, G = 5
Quoted 1 line

I suggest updating places like g(1:B) = 4 to g(B) = 4 to match the code.

No, as during the transaction only the node with the transaction prepended is being stored in the data base. It isn't visible outside the transaction until the transaction has been committed.

So the notation isn't reflecting where the generation count is stored, but only that it is specific to the transaction/node pair.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#5 lore raw
Quoted 57 lines · Juergen Gross
Quoted 56 lines · Wei Liu
Quoted 40 lines · Juergen Gross
Quoted 30 lines · Wei Liu

Another stupid question below.

Quoted 27 lines · Juergen Gross
tools/xenstore/xenstored_transaction.c +25 -1
-struct changed_node
+/*
+ * Some notes regarding detection and handling of transaction conflicts:
+ *
+ * Basic source of reference is the 'generation' count. Each writing access
+ * (either normal write or in a transaction) to the tdb data base will set
+ * the node specific generation count to the global generation count.
+ * For being able to identify a transaction the transaction specific generation
+ * count is initialized with the global generation count when starting the
+ * transaction.
+ * Each time the global generation count is copied to either a node or a
+ * transaction it is incremented. This ensures all nodes and/or transactions
+ * are having a unique generation count.
+ *
+ * Transaction conflicts are detected by checking the generation count of all
+ * nodes read in the transaction to match with the generation count in the
+ * global data base at the end of the transaction. Nodes which have been
+ * modified in the transaction don't have to be checked to match even if they
+ * have been read, as the modified node will be globally visible after the
+ * succeeded transaction possibly overwriting another modification which may
+ * have occurred concurrent to the transaction.
+ *
+ * Examples:
+ * ---------
+ * The following notation is used:
+ * I:      initial state
Quoted 8 lines
Quoted 4 lines
+ * G       global generation count
+ * g(X)    generation count of node X
+ * G(1)    generation count of transaction 1
+ * g(1:Y)  saved generation count of node Y in transaction 1

Assuming this is recorded in accessed_node, can you point me to where about in the code this is implemented? I looked at access_node but that only records generation for read.

Quoted 2 lines

It is in the node itself stored in the data base.

Right, then ...

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

+ * TA1: operation in transaction 1
+ * X=1:X replace global node X with transaction 1 specific value of X
+ *
+ * 1. Simple transaction doing: read node A, write node B

+ *    I: g(A) = 1, g(B) = 2, G = 3
+ *    Start transaction 1: G(1) = 3, G = 4
+ *    TA1: read node A:    g(1:A) = 1
+ *    TA1: write node B:   g(1:B) = 4, G = 5
Quoted 6 lines
Quoted 1 line

I suggest updating places like g(1:B) = 4 to g(B) = 4 to match the code.

No, as during the transaction only the node with the transaction prepended is being stored in the data base. It isn't visible outside the transaction until the transaction has been committed.

Hmm... yes, that's true.

Quoted 3 lines

So the notation isn't reflecting where the generation count is stored, but only that it is specific to the transaction/node pair.

OK.

Wei.

Quoted 2 lines

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel