You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2018/06/04 08:56:57 UTC

[trafficserver] branch 8.0.x updated: Correct the number of available disk shows in fatal message

This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a commit to branch 8.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/8.0.x by this push:
     new 21d09d2  Correct the number of available disk shows in fatal message
21d09d2 is described below

commit 21d09d259b5135080485cf33cf4706aba98f9bef
Author: Oknet Xu <xu...@skyguard.com.cn>
AuthorDate: Sat Jun 2 15:13:42 2018 +0800

    Correct the number of available disk shows in fatal message
    
    (cherry picked from commit b375d166ec54b0523320059dbb31185d06302d9e)
---
 iocore/cache/Cache.cc | 180 +++++++++++++++++++++++---------------------------
 1 file changed, 84 insertions(+), 96 deletions(-)

diff --git a/iocore/cache/Cache.cc b/iocore/cache/Cache.cc
index 5c085e6..1e06c58 100644
--- a/iocore/cache/Cache.cc
+++ b/iocore/cache/Cache.cc
@@ -752,115 +752,103 @@ CacheProcessor::diskInitialized()
   int n_init    = ink_atomic_increment(&initialize_disk, 1);
   int bad_disks = 0;
   int res       = 0;
-  if (n_init == gndisks - 1) {
-    int i;
-    for (i = 0; i < gndisks; i++) {
-      if (DISK_BAD(gdisks[i])) {
-        bad_disks++;
-      }
-    }
-
-    if (bad_disks != 0) {
-      // Check if this is a fatal error
-      if (this->waitForCache() == 3 || (bad_disks == gndisks && this->waitForCache() == 2)) {
-        // This could be passed off to @c cacheInitialized (as with volume config problems) but I think
-        // the more specific error message here is worth the extra code.
-        CacheProcessor::initialized = CACHE_INIT_FAILED;
-        if (cb_after_init) {
-          cb_after_init();
-        }
-        Fatal("Cache initialization failed - only %d of %d disks were available.", gndisks, theCacheStore.n_disks_in_config);
-      }
+  int i;
 
-      // still good, create a new array to hold the valid disks.
-      CacheDisk **p_good_disks;
-      if ((gndisks - bad_disks) > 0) {
-        p_good_disks = (CacheDisk **)ats_malloc((gndisks - bad_disks) * sizeof(CacheDisk *));
-      } else {
-        p_good_disks = nullptr;
-      }
+  // Wait for all the cache disks are initialized
+  if (n_init != gndisks - 1) {
+    return;
+  }
 
-      int insert_at = 0;
-      for (i = 0; i < gndisks; i++) {
-        if (DISK_BAD(gdisks[i])) {
-          delete gdisks[i];
-          continue;
-        }
-        if (p_good_disks != nullptr) {
-          p_good_disks[insert_at++] = gdisks[i];
-        }
+  // Check and remove bad disks from gdisks[]
+  for (i = 0; i < gndisks; i++) {
+    if (DISK_BAD(gdisks[i])) {
+      delete gdisks[i];
+      gdisks[i] = nullptr;
+      bad_disks++;
+    } else if (bad_disks > 0) {
+      gdisks[i - bad_disks] = gdisks[i];
+      gdisks[i]             = nullptr;
+    }
+  }
+  if (bad_disks > 0) {
+    // Update the number of available cache disks
+    gndisks -= bad_disks;
+    // Check if this is a fatal error
+    if (this->waitForCache() == 3 || (0 == gndisks && this->waitForCache() == 2)) {
+      // This could be passed off to @c cacheInitialized (as with volume config problems) but I think
+      // the more specific error message here is worth the extra code.
+      CacheProcessor::initialized = CACHE_INIT_FAILED;
+      if (cb_after_init) {
+        cb_after_init();
       }
-      ats_free(gdisks);
-      gdisks  = p_good_disks;
-      gndisks = gndisks - bad_disks;
+      Fatal("Cache initialization failed - only %d of %d disks were available.", gndisks, theCacheStore.n_disks_in_config);
     }
+  }
 
-    /* Practically just took all bad_disks offline so update the stats. */
-    RecSetGlobalRawStatSum(cache_rsb, cache_span_offline_stat, bad_disks);
-    RecIncrGlobalRawStat(cache_rsb, cache_span_failing_stat, -bad_disks);
-    RecSetGlobalRawStatSum(cache_rsb, cache_span_online_stat, gndisks);
+  /* Practically just took all bad_disks offline so update the stats. */
+  RecSetGlobalRawStatSum(cache_rsb, cache_span_offline_stat, bad_disks);
+  RecIncrGlobalRawStat(cache_rsb, cache_span_failing_stat, -bad_disks);
+  RecSetGlobalRawStatSum(cache_rsb, cache_span_online_stat, gndisks);
 
-    /* create the cachevol list only if num volumes are greater
-       than 0. */
-    if (config_volumes.num_volumes == 0) {
-      /* if no volumes, default to just an http cache */
-      res = cplist_reconfigure();
-    } else {
-      // else
-      /* create the cachevol list. */
-      cplist_init();
-      /* now change the cachevol list based on the config file */
-      res = cplist_reconfigure();
-    }
-
-    if (res == -1) {
-      /* problems initializing the volume.config. Punt */
-      gnvol = 0;
-      cacheInitialized();
-      return;
-    } else {
-      CacheVol *cp = cp_list.head;
-      for (; cp; cp = cp->link.next) {
-        cp->vol_rsb = RecAllocateRawStatBlock((int)cache_stat_count);
-        char vol_stat_str_prefix[256];
-        snprintf(vol_stat_str_prefix, sizeof(vol_stat_str_prefix), "proxy.process.cache.volume_%d", cp->vol_number);
-        register_cache_stats(cp->vol_rsb, vol_stat_str_prefix);
-      }
-    }
+  /* create the cachevol list only if num volumes are greater than 0. */
+  if (config_volumes.num_volumes == 0) {
+    /* if no volumes, default to just an http cache */
+    res = cplist_reconfigure();
+  } else {
+    // else
+    /* create the cachevol list. */
+    cplist_init();
+    /* now change the cachevol list based on the config file */
+    res = cplist_reconfigure();
+  }
 
-    gvol = (Vol **)ats_malloc(gnvol * sizeof(Vol *));
-    memset(gvol, 0, gnvol * sizeof(Vol *));
+  if (res == -1) {
+    /* problems initializing the volume.config. Punt */
     gnvol = 0;
-    for (i = 0; i < gndisks; i++) {
-      CacheDisk *d = gdisks[i];
-      if (is_debug_tag_set("cache_hosting")) {
-        int j;
-        Debug("cache_hosting", "Disk: %d:%s: Vol Blocks: %u: Free space: %" PRIu64, i, d->path, d->header->num_diskvol_blks,
-              d->free_space);
-        for (j = 0; j < (int)d->header->num_volumes; j++) {
-          Debug("cache_hosting", "\tVol: %d Size: %" PRIu64, d->disk_vols[j]->vol_number, d->disk_vols[j]->size);
-        }
-        for (j = 0; j < (int)d->header->num_diskvol_blks; j++) {
-          Debug("cache_hosting", "\tBlock No: %d Size: %" PRIu64 " Free: %u", d->header->vol_info[j].number,
-                d->header->vol_info[j].len, d->header->vol_info[j].free);
-        }
+    cacheInitialized();
+    return;
+  } else {
+    CacheVol *cp = cp_list.head;
+    for (; cp; cp = cp->link.next) {
+      cp->vol_rsb = RecAllocateRawStatBlock((int)cache_stat_count);
+      char vol_stat_str_prefix[256];
+      snprintf(vol_stat_str_prefix, sizeof(vol_stat_str_prefix), "proxy.process.cache.volume_%d", cp->vol_number);
+      register_cache_stats(cp->vol_rsb, vol_stat_str_prefix);
+    }
+  }
+
+  gvol = (Vol **)ats_malloc(gnvol * sizeof(Vol *));
+  memset(gvol, 0, gnvol * sizeof(Vol *));
+  gnvol = 0;
+  for (i = 0; i < gndisks; i++) {
+    CacheDisk *d = gdisks[i];
+    if (is_debug_tag_set("cache_hosting")) {
+      int j;
+      Debug("cache_hosting", "Disk: %d:%s: Vol Blocks: %u: Free space: %" PRIu64, i, d->path, d->header->num_diskvol_blks,
+            d->free_space);
+      for (j = 0; j < (int)d->header->num_volumes; j++) {
+        Debug("cache_hosting", "\tVol: %d Size: %" PRIu64, d->disk_vols[j]->vol_number, d->disk_vols[j]->size);
       }
-      if (!check) {
-        d->sync();
+      for (j = 0; j < (int)d->header->num_diskvol_blks; j++) {
+        Debug("cache_hosting", "\tBlock No: %d Size: %" PRIu64 " Free: %u", d->header->vol_info[j].number,
+              d->header->vol_info[j].len, d->header->vol_info[j].free);
       }
     }
-    if (config_volumes.num_volumes == 0) {
-      theCache         = new Cache();
-      theCache->scheme = CACHE_HTTP_TYPE;
-      theCache->open(clear, fix);
-      return;
-    }
-    if (config_volumes.num_http_volumes != 0) {
-      theCache         = new Cache();
-      theCache->scheme = CACHE_HTTP_TYPE;
-      theCache->open(clear, fix);
+    if (!check) {
+      d->sync();
     }
   }
+  if (config_volumes.num_volumes == 0) {
+    theCache         = new Cache();
+    theCache->scheme = CACHE_HTTP_TYPE;
+    theCache->open(clear, fix);
+    return;
+  }
+  if (config_volumes.num_http_volumes != 0) {
+    theCache         = new Cache();
+    theCache->scheme = CACHE_HTTP_TYPE;
+    theCache->open(clear, fix);
+  }
 }
 
 void

-- 
To stop receiving notification emails like this one, please contact
zwoop@apache.org.