]> git.sur5r.net Git - bacula/bacula/commitdiff
- Optimize File pruning to eliminate one database call.
authorKern Sibbald <kern@sibbald.com>
Sat, 7 May 2005 10:43:02 +0000 (10:43 +0000)
committerKern Sibbald <kern@sibbald.com>
Sat, 7 May 2005 10:43:02 +0000 (10:43 +0000)
- Fix bug that prevented File pruning from working.
- Implement a cstrlen() which returns the character
  length of a UTF-8 string.

git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2002 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/cats/sql_list.c
bacula/src/dird/sql_cmds.c
bacula/src/dird/ua_prune.c
bacula/src/lib/bsys.c
bacula/src/lib/protos.h

index b512b1c6559ab1a079aa882c3b3f2a1e31bbac4f..0abc749d5ec6add8bdfc1af5d035928abc0ae856 100644 (file)
@@ -106,7 +106,7 @@ db_list_client_records(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *sendit, void *ctx,
    db_lock(mdb);
    if (type == VERT_LIST) {
       Mmsg(mdb->cmd, "SELECT ClientId,Name,Uname,AutoPrune,FileRetention,"
-         "FileRetention,JobRetention "
+         "JobRetention "
          "FROM Client ORDER BY ClientId");
    } else {
       Mmsg(mdb->cmd, "SELECT ClientId,Name,FileRetention,JobRetention "
index fd300924910455d4724177a8bfa3594441f737dc..9a2a5aa3f4efdbe74d0753dc68eb7845e4d0a913 100644 (file)
@@ -47,7 +47,6 @@ const char *client_backups =
 
 /* ====== ua_prune.c */
 
-const char *cnt_File     = "SELECT count(*) FROM File WHERE JobId=%s";
 const char *del_File     = "DELETE FROM File WHERE JobId=%s";
 const char *upd_Purged   = "UPDATE Job Set PurgedFiles=1 WHERE JobId=%s";
 const char *cnt_DelCand  = "SELECT count(*) FROM DelCandidates";
index 239424993bf344bb51ca2453afb2492c75bbb729..d992987aa2fb3d3c05f655577d9b2a4ee9662da4 100644 (file)
@@ -246,7 +246,7 @@ int prune_files(UAContext *ua, CLIENT *client)
 
    /* Select Jobs -- for counting */
    Mmsg(query, select_job, edit_uint64(now - period, ed1), 
-        edit_int64(cr.ClientId, ed1));
+        edit_int64(cr.ClientId, ed2));
    Dmsg1(050, "select sql=%s\n", query);
    if (!db_sql_query(ua->db, query, file_count_handler, (void *)&del)) {
       if (ua->verbose) {
@@ -276,12 +276,7 @@ int prune_files(UAContext *ua, CLIENT *client)
    db_sql_query(ua->db, query, file_delete_handler, (void *)&del);
 
    for (i=0; i < del.num_ids; i++) {
-      struct s_count_ctx cnt;
       Dmsg1(050, "Delete JobId=%u\n", del.JobId[i]);
-      Mmsg(query, cnt_File, edit_int64(del.JobId[i], ed1));
-      cnt.count = 0;
-      db_sql_query(ua->db, query, count_handler, (void *)&cnt);
-      del.tot_ids += cnt.count;
       Mmsg(query, del_File, edit_int64(del.JobId[i], ed1));
       db_sql_query(ua->db, query, NULL, (void *)NULL);
       /*
@@ -294,10 +289,9 @@ int prune_files(UAContext *ua, CLIENT *client)
       db_sql_query(ua->db, query, NULL, (void *)NULL);
       Dmsg1(050, "Del sql=%s\n", query);
    }
-   edit_uint64_with_commas(del.tot_ids, ed1);
-   edit_uint64_with_commas(del.num_ids, ed2);
-   bsendmsg(ua, _("Pruned %s Files from %s Jobs for client %s from catalog.\n"),
-      ed1, ed2, client->hdr.name);
+   edit_uint64_with_commas(del.num_ids, ed1);
+   bsendmsg(ua, _("Pruned Files from %s Jobs for client %s from catalog.\n"),
+      ed1, client->hdr.name);
 
 bail_out:
    db_unlock(ua->db);
index 5bf1a8098c882610a1cf7bac24d5c133267eff4a..8b640dd0ba76db9f3d325590b729f26d812dc09f 100644 (file)
@@ -118,6 +118,57 @@ char *bstrncat(char *dest, POOL_MEM &src, int maxlen)
    return dest;
 }
 
+/*
+ * Get character length of UTF-8 string
+ *
+ * Valid UTF-8 codes
+ * U-00000000 - U-0000007F: 0xxxxxxx 
+ * U-00000080 - U-000007FF: 110xxxxx 10xxxxxx 
+ * U-00000800 - U-0000FFFF: 1110xxxx 10xxxxxx 10xxxxxx 
+ * U-00010000 - U-001FFFFF: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx 
+ * U-00200000 - U-03FFFFFF: 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 
+ * U-04000000 - U-7FFFFFFF: 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
+ */
+int cstrlen(const char *str)
+{
+   uint8_t *p = (uint8_t *)str;
+   int len = 0;
+   while (*p) {
+      if ((*p & 0xC0) != 0xC0) {
+         p++;
+         len++;
+         continue;
+      }
+      if ((*p & 0xD0) == 0xC0) {
+         p += 2;
+         len++;
+         continue;
+      }
+      if ((*p & 0xF0) == 0xD0) {
+         p += 3;
+         len++;
+         continue;
+      }
+      if ((*p & 0xF8) == 0xF0) {
+         p += 4;
+         len++;
+         continue;
+      }
+      if ((*p & 0xFC) == 0xF8) {
+         p += 5;
+         len++;
+         continue;
+      }
+      if ((*p & 0xFE) == 0xFC) {
+         p += 6;
+         len++;
+         continue;
+      }
+      p++;                      /* Shouln't get here but must advance */
+   }
+   return len;
+}
+
 
 
 #ifndef DEBUG
index 6941263c4d85829fcdef82786f92465765e6e721..ab636cc971c8d0a8df991047dedc179839b41f1b 100644 (file)
@@ -43,6 +43,7 @@ char     *bstrncpy               (char *dest, const char *src, int maxlen);
 char     *bstrncpy               (char *dest, POOL_MEM &src, int maxlen);
 char     *bstrncat               (char *dest, const char *src, int maxlen);
 char     *bstrncat               (char *dest, POOL_MEM &src, int maxlen);
+int       cstrlen                (const char *str);
 void     *b_malloc               (const char *file, int line, size_t size);
 #ifndef DEBUG
 void     *bmalloc                (size_t size);