You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jp...@apache.org on 2014/01/24 02:15:08 UTC

git commit: TS-2526: remove the g_stats_snap_fpath global variable

Updated Branches:
  refs/heads/master c2434df8c -> 5b163671c


TS-2526: remove the g_stats_snap_fpath global variable


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/5b163671
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/5b163671
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/5b163671

Branch: refs/heads/master
Commit: 5b163671cd1412b1a7bd6084e14539200634a43e
Parents: c2434df
Author: James Peach <jp...@apache.org>
Authored: Wed Jan 22 12:16:56 2014 -0800
Committer: James Peach <jp...@apache.org>
Committed: Thu Jan 23 17:12:45 2014 -0800

----------------------------------------------------------------------
 CHANGES                  |  2 ++
 lib/records/I_RecCore.h  |  4 ++++
 lib/records/P_RecCore.cc |  8 +++++---
 lib/records/P_RecCore.h  |  3 ---
 lib/records/RecCore.cc   | 13 ++++++++++---
 mgmt/LocalManager.cc     |  8 ++------
 6 files changed, 23 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/5b163671/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 162e255..a24e138 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,8 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache Traffic Server 4.2.0
 
+  *) [TS-2526] Remove the g_stats_snap_fpath global variable.
+
   *) [TS-2525] Remove restrictions on outbound transparency with SSL.
 
   *) [TS-2425] Update to TS-2261 for loading plugins as root

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/5b163671/lib/records/I_RecCore.h
----------------------------------------------------------------------
diff --git a/lib/records/I_RecCore.h b/lib/records/I_RecCore.h
index 4b3088c..424b1c2 100644
--- a/lib/records/I_RecCore.h
+++ b/lib/records/I_RecCore.h
@@ -62,6 +62,10 @@ char * RecConfigReadLogDir();
 // value, NULL is returned. The caller MUST release the result with ats_free().
 char * RecConfigReadConfigPath(const char * file_variable, const char * default_value = NULL);
 
+// Return a copy of the persistent stats file. This is $RUNTIMEDIR/records.snap.
+// The caller MUST release the result with ats_free().
+char * RecConfigReadPersistentStatsPath();
+
 // Test whether the named configuration value is overridden by an environment variable. Return either
 // the overridden value, or the original value. Caller MUST NOT free the result.
 const char * RecConfigOverrideFromEnvironment(const char * name, const char * value);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/5b163671/lib/records/P_RecCore.cc
----------------------------------------------------------------------
diff --git a/lib/records/P_RecCore.cc b/lib/records/P_RecCore.cc
index f176192..2be8116 100644
--- a/lib/records/P_RecCore.cc
+++ b/lib/records/P_RecCore.cc
@@ -531,11 +531,12 @@ RecReadStatsFile()
   RecRecord *r;
   RecMessage *m;
   RecMessageItr itr;
+  xptr<char> snap_fpath(RecConfigReadPersistentStatsPath());
 
   // lock our hash table
   ink_rwlock_wrlock(&g_records_rwlock);
 
-  if ((m = RecMessageReadFromDisk(g_stats_snap_fpath)) != NULL) {
+  if ((m = RecMessageReadFromDisk(snap_fpath)) != NULL) {
     if (RecMessageUnmarshalFirst(m, &itr, &r) != REC_ERR_FAIL) {
       do {
         if ((r->name == NULL) || (!strlen(r->name)))
@@ -562,6 +563,7 @@ RecSyncStatsFile()
   RecMessage *m;
   int i, num_records;
   bool sync_to_disk;
+  xptr<char> snap_fpath(RecConfigReadPersistentStatsPath());
 
   /*
    * g_mode_type should be initialized by
@@ -585,8 +587,8 @@ RecSyncStatsFile()
       rec_mutex_release(&(r->lock));
     }
     if (sync_to_disk) {
-      RecDebug(DL_Note, "Writing '%s' [%d bytes]", g_stats_snap_fpath, m->o_write - m->o_start + sizeof(RecMessageHdr));
-      RecMessageWriteToDisk(m, g_stats_snap_fpath);
+      RecDebug(DL_Note, "Writing '%s' [%d bytes]", (const char *)snap_fpath, m->o_write - m->o_start + sizeof(RecMessageHdr));
+      RecMessageWriteToDisk(m, snap_fpath);
     }
     RecMessageFree(m);
   }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/5b163671/lib/records/P_RecCore.h
----------------------------------------------------------------------
diff --git a/lib/records/P_RecCore.h b/lib/records/P_RecCore.h
index f0335b9..63109f6 100644
--- a/lib/records/P_RecCore.h
+++ b/lib/records/P_RecCore.h
@@ -49,9 +49,6 @@ extern LLQ *g_rec_config_contents_llq;
 extern InkHashTable *g_rec_config_contents_ht;
 extern ink_mutex g_rec_config_lock;
 
-// stats.snap items
-extern const char *g_stats_snap_fpath;
-
 //-------------------------------------------------------------------------
 // Initialization
 //-------------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/5b163671/lib/records/RecCore.cc
----------------------------------------------------------------------
diff --git a/lib/records/RecCore.cc b/lib/records/RecCore.cc
index 532aecc..484a9c6 100644
--- a/lib/records/RecCore.cc
+++ b/lib/records/RecCore.cc
@@ -36,7 +36,6 @@ InkHashTable *g_records_ht = NULL;
 ink_rwlock g_records_rwlock;
 int g_num_records = 0;
 
-const char *g_stats_snap_fpath = NULL;
 int g_num_update[RECT_MAX];
 
 RecTree *g_records_tree = NULL;
@@ -177,8 +176,6 @@ RecCoreInit(RecModeT mode_type, Diags *_diags)
   }
   // read stats
   if ((mode_type == RECM_SERVER) || (mode_type == RECM_STAND_ALONE)) {
-    xptr<char> rundir(RecConfigReadRuntimeDir());
-    g_stats_snap_fpath = Layout::relative_to(rundir, REC_RAW_STATS_FILE);
     RecReadStatsFile();
   }
   // read configs
@@ -1111,6 +1108,16 @@ RecConfigReadConfigPath(const char * file_variable, const char * default_value)
 }
 
 //-------------------------------------------------------------------------
+// RecConfigReadPersistentStatsPath
+//-------------------------------------------------------------------------
+char *
+RecConfigReadPersistentStatsPath()
+{
+  xptr<char> rundir(RecConfigReadRuntimeDir());
+  return Layout::relative_to(rundir, REC_RAW_STATS_FILE);
+}
+
+//-------------------------------------------------------------------------
 // REC_SignalManager (TS)
 //-------------------------------------------------------------------------
 #if defined (REC_BUILD_MGMT)

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/5b163671/mgmt/LocalManager.cc
----------------------------------------------------------------------
diff --git a/mgmt/LocalManager.cc b/mgmt/LocalManager.cc
index 898e87c..2bc67ad 100644
--- a/mgmt/LocalManager.cc
+++ b/mgmt/LocalManager.cc
@@ -124,8 +124,6 @@ LocalManager::rollLogFiles()
 void
 LocalManager::clearStats(const char *name)
 {
-  char *statsPath;
-
   // Clear our records and then send the signal.  There is a race condition
   //  here where our stats could get re-updated from the proxy
   //  before the proxy clears them, but this should be rare.
@@ -146,14 +144,12 @@ LocalManager::clearStats(const char *name)
   //   that operation works even when the proxy is off
   //
   if (this->proxy_running == 0) {
-    xptr<char> rundir(RecConfigReadRuntimeDir());
-    statsPath = Layout::relative_to(rundir, REC_RAW_STATS_FILE);
+    xptr<char> statsPath(RecConfigReadPersistentStatsPath());
     if (unlink(statsPath) < 0) {
       if (errno != ENOENT) {
-        mgmt_log(stderr, "[LocalManager::clearStats] Unlink of %s failed : %s\n", REC_RAW_STATS_FILE, strerror(errno));
+        mgmt_log(stderr, "[LocalManager::clearStats] Unlink of %s failed : %s\n", (const char *)statsPath, strerror(errno));
       }
     }
-    ats_free(statsPath);
   }
 }
 


Re: git commit: TS-2526: remove the g_stats_snap_fpath global variable

Posted by James Peach <jp...@apache.org>.
On Jan 24, 2014, at 12:19 AM, Leif Hedstrom <zw...@apache.org> wrote:

> 
> On Jan 24, 2014, at 2:15 AM, jpeach@apache.org wrote:
> 
>> Updated Branches:
>> refs/heads/master c2434df8c -> 5b163671c
>> 
>> 
>> TS-2526: remove the g_stats_snap_fpath global variable
> 
> 
> I agree with the addition of RecConfigReadPersistentStatsPath(), that’s nice, but is it really that important to get rid of a global at the expense of allocating memory, creating the (same) path, and then free memory every time we want / need this path string?

It seemed like this was used infrequently enough to make it worth it in exchange for removing a global ...

J

Re: git commit: TS-2526: remove the g_stats_snap_fpath global variable

Posted by Bahram Akhundov <de...@hotmail.de>.
Hi Leif :)
what are so panic ?)

gr33tz...





Am 24.01.2014 12:19, schrieb Leif Hedstrom:
> On Jan 24, 2014, at 2:15 AM, jpeach@apache.org wrote:
>
>> Updated Branches:
>>   refs/heads/master c2434df8c -> 5b163671c
>>
>>
>> TS-2526: remove the g_stats_snap_fpath global variable
>
> I agree with the addition of RecConfigReadPersistentStatsPath(), that’s nice, but is it really that important to get rid of a global at the expense of allocating memory, creating the (same) path, and then free memory every time we want / need this path string?
>
> — Leif
>
>
>


Re: git commit: TS-2526: remove the g_stats_snap_fpath global variable

Posted by Leif Hedstrom <zw...@apache.org>.
On Jan 24, 2014, at 2:15 AM, jpeach@apache.org wrote:

> Updated Branches:
>  refs/heads/master c2434df8c -> 5b163671c
> 
> 
> TS-2526: remove the g_stats_snap_fpath global variable


I agree with the addition of RecConfigReadPersistentStatsPath(), that’s nice, but is it really that important to get rid of a global at the expense of allocating memory, creating the (same) path, and then free memory every time we want / need this path string?

— Leif