trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jplev...@apache.org
Subject svn commit: r903893 - in /incubator/trafficserver/traffic/branches/dev/iocore/cache: CacheDir.cc P_CacheDir.h P_CacheInternal.h
Date Wed, 27 Jan 2010 22:38:22 GMT
Author: jplevyak
Date: Wed Jan 27 22:38:21 2010
New Revision: 903893

URL: http://svn.apache.org/viewvc?rev=903893&view=rev
Log:
TS-74: fixup Cache_dir regression test

Modified:
    incubator/trafficserver/traffic/branches/dev/iocore/cache/CacheDir.cc
    incubator/trafficserver/traffic/branches/dev/iocore/cache/P_CacheDir.h
    incubator/trafficserver/traffic/branches/dev/iocore/cache/P_CacheInternal.h

Modified: incubator/trafficserver/traffic/branches/dev/iocore/cache/CacheDir.cc
URL: http://svn.apache.org/viewvc/incubator/trafficserver/traffic/branches/dev/iocore/cache/CacheDir.cc?rev=903893&r1=903892&r2=903893&view=diff
==============================================================================
--- incubator/trafficserver/traffic/branches/dev/iocore/cache/CacheDir.cc (original)
+++ incubator/trafficserver/traffic/branches/dev/iocore/cache/CacheDir.cc Wed Jan 27 22:38:21
2010
@@ -24,7 +24,7 @@
 
 #include "P_Cache.h"
 
-#define LOOP_CHECK_MODE
+// #define LOOP_CHECK_MODE 1
 #ifdef LOOP_CHECK_MODE
 #define DIR_LOOP_THRESHOLD	      1000
 #endif
@@ -287,8 +287,10 @@
   Dir *e = b;
   int i = 0;
   Dir *seg = dir_segment(s, d);
+#ifdef LOOP_CHECK_MODE
   if (dir_bucket_loop_fix(b, s, d))
     return 1;
+#endif
   while (e) {
     i++;
     if (i > 100)
@@ -305,7 +307,6 @@
   Debug("cache_check_dir", "inside check dir");
   for (s = 0; s < d->segments; s++) {
     Dir *seg = dir_segment(s, d);
-    ink_debug_assert(dir_bucket_loop_check(dir_from_offset(d->header->freelist[s],
seg), seg));
     for (i = 0; i < d->buckets; i++) {
       Dir *b = dir_bucket(i, seg);
       if (!(dir_bucket_length(b, s, d) >= 0)) return 0;
@@ -364,7 +365,9 @@
 {
   Dir *e = b, *p = NULL;
   Dir *seg = dir_segment(s, part);
+#ifdef LOOP_CHECK_MODE
   int loop_count = 0;
+#endif
   do {
 #ifdef LOOP_CHECK_MODE
     loop_count++;
@@ -560,13 +563,13 @@
             // for the same document and so the collision stat
             // may not accurately reflect the number of documents
             // having the same first_key
-            Debug("cache_stats", "Incrementing dir collisions");
+            DDebug("cache_stats", "Incrementing dir collisions");
             CACHE_INC_DIR_COLLISIONS(d->mutex);
           }
           goto Lcont;
         }
         if (dir_valid(d, e)) {
-          Debug("dir_probe_hit", "found %X %X part %d bucket %d  boffset %d", key->word(0),
key->word(1), d->fd, b, (int) dir_offset(e));
+          DDebug("dir_probe_hit", "found %X %X part %d bucket %d  boffset %d", key->word(0),
key->word(1), d->fd, b, (int) dir_offset(e));
           dir_assign(result, e);
           *last_collision = e;
           ink_assert(dir_offset(e) * INK_BLOCK_SIZE < d->len);
@@ -577,18 +580,18 @@
           continue;
         }
       } else
-        Debug("dir_probe_tag", "tag mismatch %X %X vs expected %X", e, dir_tag(e), key->word(3));
+        DDebug("dir_probe_tag", "tag mismatch %X %X vs expected %X", e, dir_tag(e), key->word(3));
     Lcont:
       p = e;
       e = next_dir(e, seg);
     } while (e);
   if (collision) {              // last collision no longer in the list, retry
-    Debug("cache_stats", "Incrementing dir collisions");
+    DDebug("cache_stats", "Incrementing dir collisions");
     CACHE_INC_DIR_COLLISIONS(d->mutex);
     collision = NULL;
     goto Lagain;
   }
-  Debug("dir_probe_miss", "missed %X %X on part %d bucket %d at %X", key->word(0), key->word(1),
d->fd, b, (long) seg);
+  DDebug("dir_probe_miss", "missed %X %X on part %d bucket %d at %X", key->word(0), key->word(1),
d->fd, b, (long) seg);
   CHECK_DIR(d);
   return 0;
 }
@@ -637,7 +640,7 @@
   dir_assign_data(e, to_part);
   dir_set_tag(e, key->word(2));
   ink_assert(part_offset(d, e) < (d->skip + d->len));
-  Debug("dir_insert",
+  DDebug("dir_insert",
         "insert %X %X into part %d bucket %d at %X tag %X %X boffset %d",
         (long) e, key->word(0), d->fd, bi, (long) e, key->word(1), dir_tag(e), (int)
dir_offset(e));
   CHECK_DIR(d);
@@ -657,8 +660,10 @@
   Dir *b = dir_bucket(bi, seg);
   unsigned int t = DIR_MASK_TAG(key->word(2));
   int res = 1;
+#ifdef LOOP_CHECK_MODE
   int loop_count = 0;
   bool loop_possible = true;
+#endif
   Part *part = d;
   CHECK_DIR(d);
 
@@ -709,7 +714,7 @@
   dir_assign_data(e, dir);
   dir_set_tag(e, t);
   ink_assert(part_offset(d, e) < d->skip + d->len);
-  Debug("dir_overwrite",
+  DDebug("dir_overwrite",
         "overwrite %X %X into part %d bucket %d at %X tag %X %X boffset %d",
         (long) e, key->word(0), d->fd, bi, (long) e, t, dir_tag(e), (int) dir_offset(e));
   CHECK_DIR(d);
@@ -725,7 +730,9 @@
   int b = key->word(1) % d->buckets;
   Dir *seg = dir_segment(s, d);
   Dir *e = NULL, *p = NULL;
+#ifdef LOOP_CHECK_MODE
   int loop_count = 0;
+#endif
   Part *part = d;
   CHECK_DIR(d);
 
@@ -764,7 +771,7 @@
     if (b->evac_frags.key == *key) {
       if (dir_valid(d, &b->new_dir)) {
         *result = b->new_dir;
-        Debug("dir_lookaside", "probe %X success", key->word(0));
+        DDebug("dir_lookaside", "probe %X success", key->word(0));
         if (eblock)
           *eblock = b;
         return 1;
@@ -772,7 +779,7 @@
     }
     b = b->link.next;
   }
-  Debug("dir_lookaside", "probe %X failed", key->word(0));
+  DDebug("dir_lookaside", "probe %X failed", key->word(0));
   return 0;
 }
 
@@ -780,7 +787,7 @@
 dir_lookaside_insert(EvacuationBlock *eblock, Part *d, Dir *to)
 {
   CacheKey *key = &eblock->evac_frags.earliest_key;
-  Debug("dir_lookaside", "insert %X %X, offset %d phase %d", key->word(0), key->word(1),
(int) dir_offset(to), (int) dir_phase(to));
+  DDebug("dir_lookaside", "insert %X %X, offset %d phase %d", key->word(0), key->word(1),
(int) dir_offset(to), (int) dir_phase(to));
   ink_debug_assert(d->mutex->thread_holding == this_ethread());
   int i = key->word(3) % LOOKASIDE_SIZE;
   EvacuationBlock *b = new_EvacuationBlock(d->mutex->thread_holding);
@@ -803,7 +810,7 @@
   while (b) {
     if (b->evac_frags.key == *key) {
       int res = dir_overwrite(key, d, &b->new_dir, &b->dir, false);
-      Debug("dir_lookaside", "fixup %X %X offset %d phase %d %d",
+      DDebug("dir_lookaside", "fixup %X %X offset %d phase %d %d",
             key->word(0), key->word(1), dir_offset(&b->new_dir), dir_phase(&b->new_dir),
res);
       d->ram_cache.fixup(key, 0, dir_offset(&b->dir), 0, dir_offset(&b->new_dir));
       d->lookaside[i].remove(b);
@@ -822,7 +829,7 @@
     }
     b = b->link.next;
   }
-  Debug("dir_lookaside", "fixup %X %X failed", key->word(0), key->word(1));
+  DDebug("dir_lookaside", "fixup %X %X failed", key->word(0), key->word(1));
   return 0;
 }
 
@@ -835,7 +842,7 @@
     while (b) {
       if (!dir_valid(d, &b->new_dir)) {
         EvacuationBlock *nb = b->link.next;
-        Debug("dir_lookaside", "cleanup %X %X cleaned up", 
+        DDebug("dir_lookaside", "cleanup %X %X cleaned up", 
               b->evac_frags.earliest_key.word(0), b->evac_frags.earliest_key.word(1));
         d->lookaside[i].remove(b);
         free_CacheVC(b->earliest_evacuator);
@@ -857,7 +864,7 @@
   EvacuationBlock *b = d->lookaside[i].head;
   while (b) {
     if (b->evac_frags.key == *key) {
-      Debug("dir_lookaside", "remove %X %X offset %d phase %d",
+      DDebug("dir_lookaside", "remove %X %X offset %d phase %d",
             key->word(0), key->word(1), dir_offset(&b->new_dir), dir_phase(&b->new_dir));
       d->lookaside[i].remove(b);
       free_EvacuationBlock(b, d->mutex->thread_holding);
@@ -865,7 +872,7 @@
     }
     b = b->link.next;
   }
-  Debug("dir_lookaside", "remove %X %X failed", key->word(0), key->word(1));
+  DDebug("dir_lookaside", "remove %X %X failed", key->word(0), key->word(1));
   return;
 }
 
@@ -894,7 +901,6 @@
 inku64
 dir_entries_used(Part *d)
 {
-
   inku64 full = 0;
   inku64 sfull = 0;
   for (int s = 0; s < d->segments; full += sfull, s++) {
@@ -909,7 +915,6 @@
       while (e) {
         if (dir_offset(e))
           sfull++;
-
         e = next_dir(e, seg);
         if (!e)
           break;
@@ -1310,7 +1315,7 @@
     ink_release_assert(e);
     e = next_dir(e, seg);
   }
-  dir_next(e) = dir_to_offset(e, seg);
+  dir_set_next(e, dir_to_offset(e, seg));
 }
 
 EXCLUSIVE_REGRESSION_TEST(Cache_dir) (RegressionTest *t, int atype, int *status) {
@@ -1405,18 +1410,19 @@
   }
 
 
-  Dir *last_collision = 0, *seg1 = 0;
+  Dir dir1;
   int s1, b1;
 
   rprintf(t, "corrupt_bucket test\n");
   for (int ntimes = 0; ntimes < 10; ntimes++) {
+#ifdef LOOP_CHECK_MODE
     // dir_probe in bucket with loop
     rand_CacheKey(&key, thread->mutex);
     s1 = key.word(0) % d->segments;
     b1 = key.word(1) % d->buckets;
     dir_corrupt_bucket(dir_bucket(b1, dir_segment(s1, d)), s1, d);
     dir_insert(&key, d, &dir);
-    last_collision = 0;
+    Dir *last_collision = 0;
     dir_probe(&key, d, &dir, &last_collision);
 
 
@@ -1434,7 +1440,7 @@
     b1 = key.word(1) % d->buckets;
     CacheKey key1;
     key1.b[1] = 127;
-    Dir dir1 = dir;
+    dir1 = dir;
     dir_set_offset(&dir1, 23);
     dir_insert(&key1, d, &dir1);
     dir_insert(&key, d, &dir);
@@ -1453,7 +1459,7 @@
 
     rand_CacheKey(&key, thread->mutex);
     s1 = key.word(0) % d->segments;
-    seg1 = dir_segment(s1, d);
+    Dir *seg1 = dir_segment(s1, d);
     // dir_freelist_length in freelist with loop
     dir_corrupt_bucket(dir_from_offset(d->header->freelist[s], seg1), s1, d);
     dir_freelist_length(d, s1);
@@ -1464,17 +1470,23 @@
     // dir_bucket_length in bucket with loop
     dir_corrupt_bucket(dir_bucket(b1, dir_segment(s1, d)), s1, d);
     dir_bucket_length(dir_bucket(b1, dir_segment(s1, d)), s1, d);
-
-    // this assert by design
+    if (!check_dir(d))
+      ret = REGRESSION_TEST_FAILED;
+#else
+    // test corruption detection
     rand_CacheKey(&key, thread->mutex);
     s1 = key.word(0) % d->segments;
     b1 = key.word(1) % d->buckets;
 
-    dir_corrupt_bucket(dir_bucket(b1, dir_segment(3, d)), 3, d);
-    dir_corrupt_bucket(dir_bucket(b1, dir_segment(7, d)), 7, d);
-    dir_corrupt_bucket(dir_bucket(b1, dir_segment(17, d)), 17, d);
+    dir_insert(&key, d, &dir1);
+    dir_insert(&key, d, &dir1);
+    dir_insert(&key, d, &dir1);
+    dir_insert(&key, d, &dir1);
+    dir_insert(&key, d, &dir1);
+    dir_corrupt_bucket(dir_bucket(b1, dir_segment(s1, d)), s1, d);
     if (check_dir(d))
       ret = REGRESSION_TEST_FAILED;
+#endif
   }
   part_dir_clear(d);
   *status = ret;

Modified: incubator/trafficserver/traffic/branches/dev/iocore/cache/P_CacheDir.h
URL: http://svn.apache.org/viewvc/incubator/trafficserver/traffic/branches/dev/iocore/cache/P_CacheDir.h?rev=903893&r1=903892&r2=903893&view=diff
==============================================================================
--- incubator/trafficserver/traffic/branches/dev/iocore/cache/P_CacheDir.h (original)
+++ incubator/trafficserver/traffic/branches/dev/iocore/cache/P_CacheDir.h Wed Jan 27 22:38:21
2010
@@ -235,7 +235,7 @@
 
   Link<OpenDirEntry> link;
 
-  int wait(CacheVC * c, int msec);
+  int wait(CacheVC *c, int msec);
 
   bool has_multiple_writers()
   {
@@ -248,10 +248,10 @@
   Queue<CacheVC> delayed_readers;
   DLL<OpenDirEntry> bucket[OPEN_DIR_BUCKETS];
 
-  int open_write(CacheVC * c, int allow_if_writers, int max_writers);
-  int close_write(CacheVC * c);
-  OpenDirEntry *open_read(INK_MD5 * key);
-  int signal_readers(int event, Event * e);
+  int open_write(CacheVC *c, int allow_if_writers, int max_writers);
+  int close_write(CacheVC *c);
+  OpenDirEntry *open_read(INK_MD5 *key);
+  int signal_readers(int event, Event *e);
 
   OpenDir();
 };
@@ -264,7 +264,7 @@
   int writepos;
   AIOCallbackInternal io;
   Event *trigger;
-  int mainEvent(int event, Event * e);
+  int mainEvent(int event, Event *e);
   void aio_write(int fd, char *b, int n, ink_off_t o);
 
   CacheSync():Continuation(new_ProxyMutex()), part(0), buf(0), buflen(0), writepos(0), trigger(0)
@@ -275,26 +275,26 @@
 
 // Global Functions
 
-void part_init_dir(Part * d);
+void part_init_dir(Part *d);
 int dir_token_probe(CacheKey *, Part *, Dir *);
 int dir_probe(CacheKey *, Part *, Dir *, Dir **);
-int dir_insert(CacheKey * key, Part * d, Dir * to_part);
-int dir_overwrite(CacheKey * key, Part * d, Dir * to_part, Dir * overwrite, bool must_overwrite
= true);
-int dir_delete(CacheKey * key, Part * d, Dir * del);
-int dir_lookaside_probe(CacheKey * key, Part * d, Dir * result, EvacuationBlock ** eblock);
-int dir_lookaside_insert(EvacuationBlock * b, Part * d, Dir * to);
-int dir_lookaside_fixup(CacheKey * key, Part * d);
-void dir_lookaside_cleanup(Part * d);
-void dir_lookaside_remove(CacheKey * key, Part * d);
-void dir_free_entry(Dir * e, int s, Part * d);
+int dir_insert(CacheKey *key, Part *d, Dir *to_part);
+int dir_overwrite(CacheKey *key, Part *d, Dir *to_part, Dir *overwrite, bool must_overwrite
= true);
+int dir_delete(CacheKey *key, Part *d, Dir *del);
+int dir_lookaside_probe(CacheKey *key, Part *d, Dir *result, EvacuationBlock ** eblock);
+int dir_lookaside_insert(EvacuationBlock *b, Part *d, Dir *to);
+int dir_lookaside_fixup(CacheKey *key, Part *d);
+void dir_lookaside_cleanup(Part *d);
+void dir_lookaside_remove(CacheKey *key, Part *d);
+void dir_free_entry(Dir *e, int s, Part *d);
 void dir_sync_init();
-int check_dir(Part * d);
-void dir_clean_part(Part * d);
-void dir_clear_range(ink_off_t start, ink_off_t end, Part * d);
-int dir_segment_accounted(int s, Part * d, int offby = 0,
+int check_dir(Part *d);
+void dir_clean_part(Part *d);
+void dir_clear_range(ink_off_t start, ink_off_t end, Part *d);
+int dir_segment_accounted(int s, Part *d, int offby = 0,
                           int *free = 0, int *used = 0,
                           int *empty = 0, int *valid = 0, int *agg_valid = 0, int *avg_size
= 0);
-inku64 dir_entries_used(Part * d);
+inku64 dir_entries_used(Part *d);
 void sync_cache_dir_on_shutdown();
 
 // Global Data
@@ -303,16 +303,16 @@
 
 // Inline Funtions
 
-#define dir_in_seg(_s, _i) ((Dir*)(((char*)(_s)) + (SIZEOF_DIR * (_i))))
+#define dir_in_seg(_s, _i) ((Dir*)(((char*)(_s)) + (SIZEOF_DIR *(_i))))
 
 inline bool
-dir_compare_tag(Dir * e, CacheKey * key)
+dir_compare_tag(Dir *e, CacheKey *key)
 {
   return (dir_tag(e) == DIR_MASK_TAG(key->word(2)));
 }
 
 inline Dir *
-dir_from_offset(int i, Dir * seg)
+dir_from_offset(int i, Dir *seg)
 {
 #if DIR_DEPTH < 5
   if (!i)
@@ -324,13 +324,13 @@
 #endif
 }
 inline Dir *
-next_dir(Dir * d, Dir * seg)
+next_dir(Dir *d, Dir *seg)
 {
   int i = dir_next(d);
   return dir_from_offset(i, seg);
 }
 inline int
-dir_to_offset(Dir * d, Dir * seg)
+dir_to_offset(Dir *d, Dir *seg)
 {
 #if DIR_DEPTH < 5
   return (((char*)d) - ((char*)seg))/SIZEOF_DIR;
@@ -341,12 +341,12 @@
 #endif
 }
 inline Dir *
-dir_bucket(int b, Dir * seg)
+dir_bucket(int b, Dir *seg)
 {
   return dir_in_seg(seg, b * DIR_DEPTH);
 }
 inline Dir *
-dir_bucket_row(Dir * b, int i)
+dir_bucket_row(Dir *b, int i)
 {
   return dir_in_seg(b, i);
 }

Modified: incubator/trafficserver/traffic/branches/dev/iocore/cache/P_CacheInternal.h
URL: http://svn.apache.org/viewvc/incubator/trafficserver/traffic/branches/dev/iocore/cache/P_CacheInternal.h?rev=903893&r1=903892&r2=903893&view=diff
==============================================================================
--- incubator/trafficserver/traffic/branches/dev/iocore/cache/P_CacheInternal.h (original)
+++ incubator/trafficserver/traffic/branches/dev/iocore/cache/P_CacheInternal.h Wed Jan 27
22:38:21 2010
@@ -52,6 +52,12 @@
 #endif
 #endif
 
+#ifdef DEBUG
+#define DDebug Debug
+#else
+#define DDebug if (0) dummy_debug
+#endif
+
 #define AIO_SOFT_FAILURE                -100000
 // retry read from writer delay
 #define WRITER_RETRY_DELAY  HRTIME_MSECONDS(50)



Mime
View raw message