dovecot-2.1: stats: Fixes to handling per-command stats updates.

dovecot at dovecot.org dovecot at dovecot.org
Sat Mar 10 15:53:55 EET 2012


details:   http://hg.dovecot.org/dovecot-2.1/rev/96ad6da5c902
changeset: 14284:96ad6da5c902
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Mar 10 15:53:39 2012 +0200
description:
stats: Fixes to handling per-command stats updates.

diffstat:

 src/plugins/imap-stats/imap-stats-plugin.c |   9 ++-
 src/stats/mail-command.c                   |  67 ++++++++++++++++++++---------
 2 files changed, 51 insertions(+), 25 deletions(-)

diffs (128 lines):

diff -r 00887de4ad32 -r 96ad6da5c902 src/plugins/imap-stats/imap-stats-plugin.c
--- a/src/plugins/imap-stats/imap-stats-plugin.c	Sat Mar 10 15:44:27 2012 +0200
+++ b/src/plugins/imap-stats/imap-stats-plugin.c	Sat Mar 10 15:53:39 2012 +0200
@@ -56,7 +56,6 @@
 	struct mail_stats stats, pre_trans_stats, trans_stats;
 	unsigned int args_pos = 0;
 	string_t *str;
-	bool done;
 
 	if (scmd == NULL)
 		return;
@@ -76,11 +75,13 @@
 	str_append(str, "UPDATE-CMD\t");
 	str_append(str, guid_128_to_string(suser->session_guid));
 
-	done = cmd->state == CLIENT_COMMAND_STATE_DONE;
-	str_printfa(str, "\t%u\t%d\t", scmd->id, done);
+	str_printfa(str, "\t%u\t", scmd->id);
+	if (cmd->state == CLIENT_COMMAND_STATE_DONE)
+		str_append_c(str, 'd');
 	if (scmd->continued)
+		str_append_c(str, 'c');
+	else {
 		str_append_c(str, '\t');
-	else {
 		str_append(str, cmd->name);
 		str_append_c(str, '\t');
 		args_pos = str_len(str);
diff -r 00887de4ad32 -r 96ad6da5c902 src/stats/mail-command.c
--- a/src/stats/mail-command.c	Sat Mar 10 15:44:27 2012 +0200
+++ b/src/stats/mail-command.c	Sat Mar 10 15:53:39 2012 +0200
@@ -100,11 +100,12 @@
 	struct mail_command *cmd;
 	struct mail_stats stats, diff_stats;
 	const char *error;
-	unsigned int cmd_id;
-	bool done;
+	unsigned int i, cmd_id;
+	bool done = FALSE, continued = FALSE;
 
-	/* <session guid> <cmd id> <done> <name> <args> [key=value ..] */
-	if (str_array_length(args) < 4) {
+	/* <session guid> <cmd id> [d] <name> <args> [key=value ..]
+	   <session guid> <cmd id> c[d] [key=value ..] */
+	if (str_array_length(args) < 3) {
 		*error_r = "UPDATE-CMD: Too few parameters";
 		return -1;
 	}
@@ -115,38 +116,62 @@
 		*error_r = "UPDATE-CMD: Invalid command id";
 		return -1;
 	}
-	if (strcmp(args[2], "0") != 0 &&
-	    strcmp(args[2], "1") != 0) {
-		*error_r = "UPDATE-CMD: Invalid done parameter";
-		return -1;
-	}
-	done = args[2][0] == '1';
-	if (mail_stats_parse(args+5, &stats, error_r) < 0) {
-		*error_r = t_strconcat("UPDATE-CMD: ", *error_r, NULL);
-		return -1;
+	for (i = 0; args[2][i] != '\0'; i++) {
+		switch (args[2][i]) {
+		case 'd':
+			done = TRUE;
+			break;
+		case 'c':
+			continued = TRUE;
+			break;
+		default:
+			*error_r = "UPDATE-CMD: Invalid flags parameter";
+			return -1;
+		}
 	}
 
 	cmd = mail_command_find(session, cmd_id);
-	if (cmd == NULL) {
+	if (!continued) {
+		/* new command */
+		if (cmd != NULL) {
+			*error_r = "UPDATE-CMD: Duplicate new command id";
+			return -1;
+		}
+		if (str_array_length(args) < 5) {
+			*error_r = "UPDATE-CMD: Too few parameters";
+			return -1;
+		}
 		cmd = mail_command_add(session, args[3], args[4]);
 		cmd->id = cmd_id;
-		cmd->stats = stats;
 
+		session->highest_cmd_id =
+			I_MAX(session->highest_cmd_id, cmd_id);
 		session->num_cmds++;
 		session->user->num_cmds++;
 		session->user->domain->num_cmds++;
 		if (session->ip != NULL)
 			session->ip->num_cmds++;
+		args += 5;
 	} else {
-		if (!mail_stats_diff(&cmd->stats, &stats, &diff_stats,
-				     &error)) {
-			*error_r = t_strconcat("UPDATE-CMD: stats shrank: ",
-					       error, NULL);
-			return -1;
+		if (cmd == NULL) {
+			/* already expired command, ignore */
+			i_warning("UPDATE-CMD: Already expired");
+			return 0;
 		}
+		args += 3;
 		cmd->last_update = ioloop_timeval;
-		mail_stats_add(&cmd->stats, &diff_stats);
 	}
+	if (mail_stats_parse(args, &stats, error_r) < 0) {
+		*error_r = t_strconcat("UPDATE-CMD: ", *error_r, NULL);
+		return -1;
+	}
+	if (!mail_stats_diff(&cmd->stats, &stats, &diff_stats, &error)) {
+		*error_r = t_strconcat("UPDATE-CMD: stats shrank: ",
+				       error, NULL);
+		return -1;
+	}
+	mail_stats_add(&cmd->stats, &diff_stats);
+
 	if (done) {
 		cmd->id = 0;
 		mail_command_unref(&cmd);


More information about the dovecot-cvs mailing list