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 2019/06/15 16:22:53 UTC

[trafficserver] 23/23: Step 23: Renames Rollback object -> FileManager consistently

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

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

commit e5e90741657f99611b76d8d81c0115b3683c2200
Author: Leif Hedstrom <zw...@apache.org>
AuthorDate: Thu Jun 13 10:20:32 2019 -0600

    Step 23: Renames Rollback object -> FileManager consistently
    
    I think as a future project, eliminating ConfigManager completely would be
    worthwhile, incorporating all functionality into FileManager.
---
 doc/admin-guide/monitoring/error-messages.en.rst   |  5 +--
 .../admin-guide/monitoring/error-messages.en.po    |  4 +-
 mgmt/ConfigManager.cc                              | 27 +++++------
 mgmt/ConfigManager.h                               | 26 +++++------
 mgmt/FileManager.cc                                | 52 +++++++++++-----------
 mgmt/FileManager.h                                 | 18 ++++----
 mgmt/LocalManager.cc                               |  4 +-
 7 files changed, 66 insertions(+), 70 deletions(-)

diff --git a/doc/admin-guide/monitoring/error-messages.en.rst b/doc/admin-guide/monitoring/error-messages.en.rst
index e7e4ba9..71cc2ba 100644
--- a/doc/admin-guide/monitoring/error-messages.en.rst
+++ b/doc/admin-guide/monitoring/error-messages.en.rst
@@ -78,11 +78,11 @@ Process Warnings
 Alarm Messages
 ==============
 
-``[Rollback::Rollback] Config file is read-only: <filename>``
+``[ConfigManager::ConfigManager] Config file is read-only: <filename>``
    Go to the Traffic Server ``config`` directory and check the
    indicated file permissions; change if necessary.
 
-``[Rollback::Rollback] Unable to read or write config file <filename>``
+``[ConfigManager::ConfigManager] Unable to read or write config file <filename>``
    Go to the Traffic Server ``config`` directory and make sure the
    indicated file exists. Check permissions and modify if necessary.
 
@@ -311,4 +311,3 @@ with corresponding HTTP response codes and customizable files.
    Cannot perform your request for the document ``URL`` because the
    protocol scheme is unknown.
    ``request#scheme_unsupported``
-
diff --git a/doc/locale/ja/LC_MESSAGES/admin-guide/monitoring/error-messages.en.po b/doc/locale/ja/LC_MESSAGES/admin-guide/monitoring/error-messages.en.po
index c0fa265..0000fb2 100644
--- a/doc/locale/ja/LC_MESSAGES/admin-guide/monitoring/error-messages.en.po
+++ b/doc/locale/ja/LC_MESSAGES/admin-guide/monitoring/error-messages.en.po
@@ -185,7 +185,7 @@ msgid "Alarm Messages"
 msgstr ""
 
 #: ../../../admin-guide/monitoring/error-messages.en.rst:92
-msgid "``[Rollback::Rollback] Config file is read-only: <filename>``"
+msgid "``[ConfigManager::ConfigManager] Config file is read-only: <filename>``"
 msgstr ""
 
 #: ../../../admin-guide/monitoring/error-messages.en.rst:91
@@ -199,7 +199,7 @@ msgstr ""
 
 #: ../../../admin-guide/monitoring/error-messages.en.rst:96
 msgid ""
-"``[Rollback::Rollback] Unable to read or write config file <filename>``"
+"``[ConfigManager::ConfigManager] Unable to read or write config file <filename>``"
 msgstr ""
 
 #: ../../../admin-guide/monitoring/error-messages.en.rst:95
diff --git a/mgmt/ConfigManager.cc b/mgmt/ConfigManager.cc
index 4b53cb4..e5ffa73 100644
--- a/mgmt/ConfigManager.cc
+++ b/mgmt/ConfigManager.cc
@@ -1,6 +1,6 @@
 /** @file
 
-  This file contains code for class to allow rollback of configuration files
+  This file contains code for class to allow management of configuration files
 
   @section license License
 
@@ -42,20 +42,16 @@
 #define TS_ARCHIVE_STAT_MTIME(t) ((t).st_mtime * 1000000000)
 #endif
 
-// Error Strings
-const char *RollbackStrings[] = {"Rollback Ok", "File was not found", "Version was out of date", "System Call Error",
-                                 "Invalid Version - Version Numbers Must Increase"};
-
-Rollback::Rollback(const char *fileName_, const char *configName_, bool root_access_needed_, Rollback *parentRollback_)
-  : root_access_needed(root_access_needed_), parentRollback(parentRollback_)
+ConfigManager::ConfigManager(const char *fileName_, const char *configName_, bool root_access_needed_, ConfigManager *parentConfig_)
+  : root_access_needed(root_access_needed_), parentConfig(parentConfig_)
 {
   ExpandingArray existVer(25, true); // Existing versions
   struct stat fileInfo;
   ink_assert(fileName_ != nullptr);
 
   // parent must not also have a parent
-  if (parentRollback) {
-    ink_assert(parentRollback->parentRollback == nullptr);
+  if (parentConfig) {
+    ink_assert(parentConfig->parentConfig == nullptr);
   }
 
   // Copy the file name.
@@ -68,26 +64,27 @@ Rollback::Rollback(const char *fileName_, const char *configName_, bool root_acc
   //
   if (statFile(&fileInfo) < 0) {
     // If we can't find an active version because there is none we have a hard failure.
-    mgmt_fatal(0, "[RollBack::Rollback] Unable to find configuration file %s.\n\tStat failed : %s\n", fileName, strerror(errno));
+    mgmt_fatal(0, "[ConfigManager::ConfigManager] Unable to find configuration file %s.\n\tStat failed : %s\n", fileName,
+               strerror(errno));
 
   } else {
     fileLastModified = TS_ARCHIVE_STAT_MTIME(fileInfo);
   }
 }
 
-Rollback::~Rollback()
+ConfigManager::~ConfigManager()
 {
   ats_free(fileName);
 }
 
 //
 //
-// int Rollback::statFile()
+// int ConfigManager::statFile()
 //
 //  A wrapper for stat()
 //
 int
-Rollback::statFile(struct stat *buf)
+ConfigManager::statFile(struct stat *buf)
 {
   int statResult;
   std::string sysconfdir(RecConfigReadConfigDir());
@@ -98,12 +95,12 @@ Rollback::statFile(struct stat *buf)
   return statResult;
 }
 
-// bool Rollback::checkForUserUpdate()
+// bool ConfigManager::checkForUserUpdate()
 //
 //  Called to check if the file has been changed  by the user.
 //  Timestamps are compared to see if a change occurred
 bool
-Rollback::checkForUserUpdate()
+ConfigManager::checkForUserUpdate()
 {
   struct stat fileInfo;
   bool result;
diff --git a/mgmt/ConfigManager.h b/mgmt/ConfigManager.h
index f118e89..d27aed1 100644
--- a/mgmt/ConfigManager.h
+++ b/mgmt/ConfigManager.h
@@ -1,6 +1,6 @@
 /** @file
 
-  Interface for class to allow rollback of configuration files
+  Interface for class to allow management of configuration files
 
   @section license License
 
@@ -32,7 +32,7 @@ class TextBuffer;
 class ExpandingArray;
 
 //
-//  class Rollback
+//  class ConfigManager
 //
 //  public functions
 //
@@ -45,12 +45,12 @@ class ExpandingArray;
 //
 //  statFile(struct stat*) - a wrapper for stat(), using layout engine
 //
-class Rollback
+class ConfigManager
 {
 public:
   // fileName_ should be rooted or a base file name.
-  Rollback(const char *fileName_, const char *configName_, bool root_access_needed, Rollback *parentRollback);
-  ~Rollback();
+  ConfigManager(const char *fileName_, const char *configName_, bool root_access_needed, ConfigManager *parentConfig_);
+  ~ConfigManager();
 
   // Manual take out of lock required
   void
@@ -82,15 +82,15 @@ public:
   }
 
   bool
-  isChildRollback() const
+  isChildManaged() const
   {
-    return parentRollback != nullptr;
+    return parentConfig != nullptr;
   }
 
-  Rollback *
-  getParentRollback() const
+  ConfigManager *
+  getParentConfig() const
   {
-    return parentRollback;
+    return parentConfig;
   }
 
   bool
@@ -102,8 +102,8 @@ public:
   FileManager *configFiles = nullptr; // Manager to notify on an update.
 
   // noncopyable
-  Rollback(const Rollback &) = delete;
-  Rollback &operator=(const Rollback &) = delete;
+  ConfigManager(const ConfigManager &) = delete;
+  ConfigManager &operator=(const ConfigManager &) = delete;
 
 private:
   int statFile(struct stat *buf);
@@ -112,6 +112,6 @@ private:
   char *fileName;
   char *configName;
   bool root_access_needed;
-  Rollback *parentRollback;
+  ConfigManager *parentConfig;
   time_t fileLastModified = 0;
 };
diff --git a/mgmt/FileManager.cc b/mgmt/FileManager.cc
index fc1d068..d409045 100644
--- a/mgmt/FileManager.cc
+++ b/mgmt/FileManager.cc
@@ -82,9 +82,9 @@ FileManager::registerCallback(FileCallbackFunc func)
 }
 
 // void FileManager::addFile(char* fileName, const configFileInfo* file_info,
-//  Rollback* parentRollback)
+//  ConfigManager* parentConfig)
 //
-//  for the baseFile, creates a Rollback object for it
+//  for the baseFile, creates a ConfigManager object for it
 //
 //  if file_info is not null, a WebFileEdit object is also created for
 //    the file
@@ -92,34 +92,34 @@ FileManager::registerCallback(FileCallbackFunc func)
 //  Pointers to the new objects are stored in the bindings hashtable
 //
 void
-FileManager::addFile(const char *fileName, const char *configName, bool root_access_needed, Rollback *parentRollback)
+FileManager::addFile(const char *fileName, const char *configName, bool root_access_needed, ConfigManager *parentConfig)
 {
   ink_mutex_acquire(&accessLock);
-  addFileHelper(fileName, configName, root_access_needed, parentRollback);
+  addFileHelper(fileName, configName, root_access_needed, parentConfig);
   ink_mutex_release(&accessLock);
 }
 
 // caller must hold the lock
 void
-FileManager::addFileHelper(const char *fileName, const char *configName, bool root_access_needed, Rollback *parentRollback)
+FileManager::addFileHelper(const char *fileName, const char *configName, bool root_access_needed, ConfigManager *parentConfig)
 {
   ink_assert(fileName != nullptr);
 
-  Rollback *rb    = new Rollback(fileName, configName, root_access_needed, parentRollback);
-  rb->configFiles = this;
+  ConfigManager *rb = new ConfigManager(fileName, configName, root_access_needed, parentConfig);
+  rb->configFiles   = this;
 
   bindings.emplace(rb->getFileName(), rb);
 }
 
-// bool FileManager::getRollbackObj(char* fileName, Rollback** rbPtr)
+// bool FileManager::getConfigManagerObj(char* fileName, ConfigManager** rbPtr)
 //
-//  Sets rbPtr to the rollback object associated
+//  Sets rbPtr to the ConfigManager object associated
 //    with the passed in fileName.
 //
 //  If there is no binding, false is returned
 //
 bool
-FileManager::getRollbackObj(const char *fileName, Rollback **rbPtr)
+FileManager::getConfigObj(const char *fileName, ConfigManager **rbPtr)
 {
   ink_mutex_acquire(&accessLock);
   auto it    = bindings.find(fileName);
@@ -132,7 +132,7 @@ FileManager::getRollbackObj(const char *fileName, Rollback **rbPtr)
 
 // bool FileManager::fileChanged(const char* fileName)
 //
-//  Called by the Rollback class whenever a config has changed
+//  Called by the ConfigManager class whenever a config has changed
 //     Initiates callbacks
 //
 //
@@ -159,7 +159,7 @@ FileManager::fileChanged(const char *fileName, const char *configName)
 // void FileManger::rereadConfig()
 //
 //   Iterates through the list of managed files and
-//     calls Rollback::checkForUserUpdate on them
+//     calls ConfigManager::checkForUserUpdate on them
 //
 //   although it is tempting, DO NOT CALL FROM SIGNAL HANDLERS
 //      This function is not Async-Signal Safe.  It
@@ -167,10 +167,10 @@ FileManager::fileChanged(const char *fileName, const char *configName)
 void
 FileManager::rereadConfig()
 {
-  Rollback *rb;
+  ConfigManager *rb;
 
-  std::vector<Rollback *> changedFiles;
-  std::vector<Rollback *> parentFileNeedChange;
+  std::vector<ConfigManager *> changedFiles;
+  std::vector<ConfigManager *> parentFileNeedChange;
   size_t n;
   ink_mutex_acquire(&accessLock);
   for (auto &&it : bindings) {
@@ -179,25 +179,25 @@ FileManager::rereadConfig()
     // happen at all...
     if (rb->checkForUserUpdate()) {
       changedFiles.push_back(rb);
-      if (rb->isChildRollback()) {
-        if (std::find(parentFileNeedChange.begin(), parentFileNeedChange.end(), rb->getParentRollback()) ==
+      if (rb->isChildManaged()) {
+        if (std::find(parentFileNeedChange.begin(), parentFileNeedChange.end(), rb->getParentConfig()) ==
             parentFileNeedChange.end()) {
-          parentFileNeedChange.push_back(rb->getParentRollback());
+          parentFileNeedChange.push_back(rb->getParentConfig());
         }
       }
     }
   }
 
-  std::vector<Rollback *> childFileNeedDelete;
+  std::vector<ConfigManager *> childFileNeedDelete;
   n = changedFiles.size();
   for (size_t i = 0; i < n; i++) {
-    if (changedFiles[i]->isChildRollback()) {
+    if (changedFiles[i]->isChildManaged()) {
       continue;
     }
     // for each parent file, if it is changed, then delete all its children
     for (auto &&it : bindings) {
       rb = it.second;
-      if (rb->getParentRollback() == changedFiles[i]) {
+      if (rb->getParentConfig() == changedFiles[i]) {
         if (std::find(childFileNeedDelete.begin(), childFileNeedDelete.end(), rb) == childFileNeedDelete.end()) {
           childFileNeedDelete.push_back(rb);
         }
@@ -231,7 +231,7 @@ FileManager::rereadConfig()
 bool
 FileManager::isConfigStale()
 {
-  Rollback *rb;
+  ConfigManager *rb;
   bool stale = false;
 
   ink_mutex_acquire(&accessLock);
@@ -249,15 +249,15 @@ FileManager::isConfigStale()
 
 // void configFileChild(const char *parent, const char *child)
 //
-// Add child to the bindings with parentRollback
+// Add child to the bindings with parentConfig
 void
 FileManager::configFileChild(const char *parent, const char *child)
 {
-  Rollback *parentRollback = nullptr;
+  ConfigManager *parentConfig = nullptr;
   ink_mutex_acquire(&accessLock);
   if (auto it = bindings.find(parent); it != bindings.end()) {
-    parentRollback = it->second;
-    addFileHelper(child, "", parentRollback->rootAccessNeeded(), parentRollback);
+    parentConfig = it->second;
+    addFileHelper(child, "", parentConfig->rootAccessNeeded(), parentConfig);
   }
   ink_mutex_release(&accessLock);
 }
diff --git a/mgmt/FileManager.h b/mgmt/FileManager.h
index ea45500..dfc59cf 100644
--- a/mgmt/FileManager.h
+++ b/mgmt/FileManager.h
@@ -29,7 +29,7 @@
 #include <unordered_map>
 
 class ExpandingArray;
-class Rollback;
+class ConfigManager;
 
 typedef void (*FileCallbackFunc)(char *, char *);
 
@@ -49,11 +49,11 @@ enum lockAction_t {
 //  public functions:
 //
 //  addFile(char*, char *, configFileInfo*) - adds a new config file to be
-//       managed.  A rollback object is created for the file.
+//       managed.  A ConfigManager object is created for the file.
 //       if the file_info ptr is not NULL, a WebFileEdit object
 //       is also created
 //
-//  getRollbckObj(char* , RollbackPtr**) - sets *rbPtr to Rollback
+//  getRollbckObj(char* , ConfigManagerPtr**) - sets *rbPtr to ConfigManager
 //       object bound to fileName.  Returns true if there is
 //       a binding and false otherwise
 //
@@ -64,9 +64,9 @@ enum lockAction_t {
 //  registerCallback(FileCallbackFunc) - registers a callback function
 //       which will get called every time a managed file changes.  The
 //       callback function should NOT use the calling thread to
-//       access any Rollback objects or block for a long time
+//       access any ConfigManager objects or block for a long time
 //
-//  fileChanged(const char* fileName, const char *configName) - called by Rollback objects
+//  fileChanged(const char* fileName, const char *configName) - called by ConfigManager objects
 //       when their contents change.  Triggers callbacks to FileCallbackFuncs
 //
 //  isConfigStale() - returns whether the in-memory files might be stale
@@ -80,8 +80,8 @@ class FileManager
 public:
   FileManager();
   ~FileManager();
-  void addFile(const char *fileName, const char *configName, bool root_access_needed, Rollback *parentRollback = nullptr);
-  bool getRollbackObj(const char *fileName, Rollback **rbPtr);
+  void addFile(const char *fileName, const char *configName, bool root_access_needed, ConfigManager *parentConfig = nullptr);
+  bool getConfigObj(const char *fileName, ConfigManager **rbPtr);
   void registerCallback(FileCallbackFunc func);
   void fileChanged(const char *fileName, const char *configName);
   void rereadConfig();
@@ -92,8 +92,8 @@ private:
   ink_mutex accessLock; // Protects bindings hashtable
   ink_mutex cbListLock; // Protects the CallBack List
   DLL<callbackListable> cblist;
-  std::unordered_map<std::string_view, Rollback *> bindings;
-  void addFileHelper(const char *fileName, const char *configName, bool root_access_needed, Rollback *parentRollback);
+  std::unordered_map<std::string_view, ConfigManager *> bindings;
+  void addFileHelper(const char *fileName, const char *configName, bool root_access_needed, ConfigManager *parentConfig);
 };
 
 void initializeRegistry(); // implemented in AddConfigFilesHere.cc
diff --git a/mgmt/LocalManager.cc b/mgmt/LocalManager.cc
index 058b782..2a0d3d7 100644
--- a/mgmt/LocalManager.cc
+++ b/mgmt/LocalManager.cc
@@ -606,7 +606,7 @@ LocalManager::sendMgmtMsgToProcesses(MgmtMessageHdr *mh)
   case MGMT_EVENT_CONFIG_FILE_UPDATE:
     bool found;
     char *fname = nullptr;
-    Rollback *rb;
+    ConfigManager *rb;
     char *data_raw;
 
     data_raw = (char *)mh + sizeof(MgmtMessageHdr);
@@ -619,7 +619,7 @@ LocalManager::sendMgmtMsgToProcesses(MgmtMessageHdr *mh)
       mgmt_log("[LocalManager:sendMgmtMsgToProcesses] Unknown file change: '%s'\n", data_raw);
     }
     ink_assert(found);
-    if (!(fname && configFiles && configFiles->getRollbackObj(fname, &rb)) &&
+    if (!(fname && configFiles && configFiles->getConfigObj(fname, &rb)) &&
         (strcmp(data_raw, "proxy.config.body_factory.template_sets_dir") != 0) &&
         (strcmp(data_raw, "proxy.config.ssl.server.ticket_key.filename") != 0)) {
       mgmt_fatal(0, "[LocalManager::sendMgmtMsgToProcesses] "