Bladeren bron

mtree: store reload count and timestamp for trees

- print these details via mi/rpc summary command
- count is not stored when reload many tables from one table (cannot
  easily get reference to the previous loaded tree structure)
Daniel-Constantin Mierla 11 jaren geleden
bovenliggende
commit
731685fc58
3 gewijzigde bestanden met toevoegingen van 27 en 0 verwijderingen
  1. 2 0
      modules/mtree/mtree.c
  2. 2 0
      modules/mtree/mtree.h
  3. 23 0
      modules/mtree/mtree_mod.c

+ 2 - 0
modules/mtree/mtree.c

@@ -26,6 +26,7 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
+#include <time.h>
 
 #include "../../dprint.h"
 #include "../../mem/shm_mem.h"
@@ -112,6 +113,7 @@ m_tree_t* mt_init_tree(str* tname, str *dbtable, int type, int multi)
 
 	pt->type = type;
 	pt->multi = multi;
+	pt->reload_time = (unsigned int)time(NULL);
 	pt->tname.s = (char*)shm_malloc((1+tname->len)*sizeof(char));
 	if(pt->tname.s==NULL)
 	{

+ 2 - 0
modules/mtree/mtree.h

@@ -72,6 +72,8 @@ typedef struct _m_tree
 	unsigned int nrnodes;
 	unsigned int nritems;
 	unsigned int memsize;
+	unsigned int reload_count;
+	unsigned int reload_time;
 	mt_node_t *head;
 	struct _m_tree *next;
 } m_tree_t;

+ 23 - 0
modules/mtree/mtree_mod.c

@@ -24,6 +24,7 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
+#include <time.h>
 
 #include "../../lib/srdb1/db_op.h"
 #include "../../lib/kmi/mi.h"
@@ -530,6 +531,8 @@ static int mt_load_db(m_tree_t *pt)
 	new_tree.nrnodes = 0;
 	new_tree.nritems = 0;
 	new_tree.memsize = 0;
+	new_tree.reload_count++;
+	new_tree.reload_time = (unsigned int)time(NULL);
 
 
 	if (mt_dbf.use_table(db_con, &old_tree->dbtable) < 0)
@@ -1012,6 +1015,16 @@ struct mi_root* mt_mi_summary(struct mi_root* cmd_tree, void* param)
 				val.s, val.len);
 		if(attr == NULL)
 			goto error;
+		val.s = int2str((int)pt->reload_count, &val.len);
+		attr = add_mi_attr(node, MI_DUP_VALUE, "RELOADCOUNT", 11,
+				val.s, val.len);
+		if(attr == NULL)
+			goto error;
+		val.s = int2str((int)pt->reload_time, &val.len);
+		attr = add_mi_attr(node, MI_DUP_VALUE, "RELOADTIME", 10,
+				val.s, val.len);
+		if(attr == NULL)
+			goto error;
 
 		pt = pt->next;
 	}
@@ -1086,6 +1099,16 @@ void rpc_mtree_summary(rpc_t* rpc, void* c)
 				rpc->fault(c, 500, "Internal error adding items");
 				return;
 			}
+			if(rpc->struct_add(ih, "d", "reload_count",
+						(int)pt->reload_count) < 0 ) {
+				rpc->fault(c, 500, "Internal error adding items");
+				return;
+			}
+			if(rpc->struct_add(ih, "d", "reload_time",
+						(int)pt->reload_time) < 0 ) {
+				rpc->fault(c, 500, "Internal error adding items");
+				return;
+			}
 		}
 		pt = pt->next;
 	}