#51258 Issue 51121 - Remove hardcoded changelog file name
Closed 2 years ago by spichugi. Opened 2 years ago by mreynolds.
mreynolds/389-ds-base issue51121  into  master

@@ -99,6 +99,7 @@ 

      /* cleanup config */

      changelog5_config_cleanup();

  }

+ 

  static int

  _cl5_upgrade_replica_config(Replica *replica, changelog5Config *config)

  {
@@ -119,13 +120,11 @@ 

          slapi_entry_add_string(config_entry, CONFIG_CHANGELOG_MAXAGE_ATTRIBUTE, config->maxAge);

      }

      if (config->trimInterval != CHANGELOGDB_TRIM_INTERVAL) {

-         /* char *interval = slapi_ch_smprintf("%ld", config->trimInterval); */

          slapi_entry_add_string(config_entry, CONFIG_CHANGELOG_TRIM_ATTRIBUTE, gen_duration(config->trimInterval));

      }

  

      /* if changelog encryption is enabled then in the upgrade mode all backends will have 

       * an encrypted changelog, store the encryption attrs */

- 

      if (config->encryptionAlgorithm) {

          slapi_entry_add_string(config_entry, CONFIG_CHANGELOG_ENCRYPTION_ALGORITHM, config->encryptionAlgorithm);

          slapi_entry_add_string(config_entry, CONFIG_CHANGELOG_SYMMETRIC_KEY, config->symmetricKey);
@@ -134,36 +133,43 @@ 

  

      return rc;

  }

+ 

  static int

  _cl5_upgrade_replica(Replica *replica, void *arg)

  {

-     int rc = 0;

      changelog5Config *config = (changelog5Config *)arg;

+     const char *replName = replica_get_name(replica);

+     char *replGen = replica_get_generation(replica);

+     char *oldFile = slapi_ch_smprintf("%s/%s_%s.db", config->dir, replName, replGen);

+     char *newFile = NULL;

+     char *instancedir = NULL;

+     int rc = 0;

  

-     /* Move existing database file to backend */

-     char *replGen = replica_get_generation (replica);

-     const char *replName = replica_get_name (replica);

-     char *oldFile = slapi_ch_smprintf("%s/%s_%s.db",

-                                        config->dir, replName, replGen);

-     slapi_ch_free_string(&replGen);

      if (PR_Access(oldFile, PR_ACCESS_EXISTS) == PR_SUCCESS) {

          Slapi_Backend *be = slapi_be_select(replica_get_root(replica));

-         char *instancedir;

-         slapi_back_get_info(be, BACK_INFO_INSTANCE_DIR, (void **)&instancedir);

-         char *newFile = slapi_ch_smprintf("%s/changelog.db", instancedir);

+         char *cl_filename;

  

+         slapi_back_get_info(be, BACK_INFO_INSTANCE_DIR, (void **)&instancedir);

+         slapi_back_get_info(be, BACK_INFO_CLDB_FILENAME, (void **)&cl_filename);

+         newFile = slapi_ch_smprintf("%s/%s", instancedir, cl_filename);

          rc = slapi_back_ctrl_info(be, BACK_INFO_DBENV_CLDB_UPGRADE, oldFile);

          slapi_log_err(SLAPI_LOG_INFO, repl_plugin_name_cl,

-                       "_cl5_upgrade_replica: moving file (%s) to (%s) %s\n",

+                       "_cl5_upgrade_replica: moving changelog file (%s) to (%s) %s\n",

                        oldFile, newFile, rc?"failed":"succeeded");

-         slapi_ch_free_string(&instancedir);

      }

  

      /* Move changelog config to backend config */

      rc = _cl5_upgrade_replica_config(replica, config);

  

+     /* Cleanup */

+     slapi_ch_free_string(&instancedir);

+     slapi_ch_free_string(&oldFile);

+     slapi_ch_free_string(&newFile);

+     slapi_ch_free_string(&replGen);

+ 

      return rc;

  }

+ 

  static int

  _cl5_upgrade_removedir(char *path)

  {
@@ -198,6 +204,7 @@ 

      rval += PR_RmDir(path);

      return rval;

  }

+ 

  static int

  _cl5_upgrade_removeconfig(void)

  {

@@ -118,6 +118,10 @@ 

  #define BDB_RDNFORMAT_VERSION "3"            /* rdn-format version (by default, 0) */

  #define BDB_DNFORMAT          "dn-4514"      /* DN format RFC 4514 compliant */

  #define BDB_DNFORMAT_VERSION  "1"            /* DN format version */

+ #define BDB_CL_FILENAME       "changelog.db"

+ 

+ #define LMDB_IMPL             "lmdb"

+ #define LMDB_CL_FILENAME      "changelog.mdb"

  

  #define DBVERSION_NEWIDL 0x1

  #define DBVERSION_RDNFORMAT 0x2
@@ -645,6 +649,10 @@ 

   */

  /* allow conf w/o CONFIG_FLAG_ALLOW_RUNNING_CHANGE to be updated */

  #define LI_FORCE_MOD_CONFIG 0x10

+ #define LI_BDB_IMPL         0x20

+ #define LI_LMDB_IMPL        0x40

+ 

+ #define LI_DEFAULT_IMPL_FLAG  LI_BDB_IMPL /* the default is BDB for now */

  

  /* Structure used to hold stuff for the lifetime of an LDAP transaction */

  /* If we do clever stuff like LDAP transactions, we'll need a stack of TXN ID's */

@@ -4264,7 +4264,7 @@ 

          if (pEnv &&

              /* PL_strcmp takes NULL arg */

              (PL_strcmp(LDBM_FILENAME_SUFFIX, strrchr(direntry->name, '.')) == 0)) {

-             if (strcmp(direntry->name, "changelog.db") == 0) {

+             if (strcmp(direntry->name, BDB_CL_FILENAME) == 0) {

                  /* do not delete the changelog, if it no longer

                   * matches the database it will be recreated later

                   */
@@ -6002,6 +6002,11 @@ 

          }

          break;

      }

+     case BACK_INFO_CLDB_FILENAME: {

+         *(char **)info = BDB_CL_FILENAME;

+         rc = 0;

+         break;

+     }

      default:

          break;

      }
@@ -6074,7 +6079,7 @@ 

              if (priv && priv->dblayer_env) {

                  char *instancedir;

                  slapi_back_get_info(be, BACK_INFO_INSTANCE_DIR, (void **)&instancedir);

-                 char *path = slapi_ch_smprintf("%s/changelog.db", instancedir);

+                 char *path = slapi_ch_smprintf("%s/%s", instancedir, BDB_CL_FILENAME);

                  db->close(db, 0);

                  rc = bdb_db_remove_ex((bdb_db_env *)priv->dblayer_env, path, NULL, PR_TRUE);

                  inst->inst_changelog = NULL;
@@ -6086,16 +6091,20 @@ 

      case BACK_INFO_DBENV_CLDB_UPGRADE: {

          struct ldbminfo *li = (struct ldbminfo *)be->be_database->plg_private;

          char *oldFile = (char *)info;

+ 

          if (li) {

              dblayer_private *priv = (dblayer_private *)li->li_dblayer_private;

              if (priv && priv->dblayer_env) {

                  DB_ENV *pEnv = ((bdb_db_env *)priv->dblayer_env)->bdb_DB_ENV;

                  if (pEnv) {

                      char *instancedir;

+                     char *newFile;

+ 

                      slapi_back_get_info(be, BACK_INFO_INSTANCE_DIR, (void **)&instancedir);

-                     char *newFile = slapi_ch_smprintf("%s/changelog.db", instancedir);

+                     newFile = slapi_ch_smprintf("%s/%s", instancedir, BDB_CL_FILENAME);

                      rc = pEnv->dbrename(pEnv, 0, oldFile, 0, newFile, 0);

                      slapi_ch_free_string(&instancedir);

+                     slapi_ch_free_string(&newFile);

                      bdb_force_logrenewal(li);

                  }

              }

@@ -283,6 +283,15 @@ 

      if (apply) {

          slapi_ch_free((void **)&(li->li_backend_implement));

          li->li_backend_implement = slapi_ch_strdup((char *)value);

+         /* Set a flag that we can efficiently check which backend

+          * implementation we are using */

+         if (strcasecmp(li->li_backend_implement, BDB_IMPL) == 0) {

+             li->li_flags |= LI_BDB_IMPL;

+         } else if (strcasecmp(li->li_backend_implement, LMDB_IMPL) == 0) {

+             li->li_flags |= LI_LMDB_IMPL;

+         } else {

+             li->li_flags |= LI_DEFAULT_IMPL_FLAG;

+         }

      }

  

      return retval;

@@ -7721,7 +7721,7 @@ 

  /**

   * Get backend info based upon cmd

   *

-  * \param be Backend from which the infomation will be retrieved

+  * \param be Backend from which the information will be retrieved

   * \param cmd macro to specify the information type

   * \param info pointer to store the information

   * \return \c 0 if the operation was successful
@@ -7787,7 +7787,8 @@ 

      BACK_INFO_INDEX_KEY,           /* Get the status of a key in an index */

      BACK_INFO_DB_DIRECTORY,        /* Get the db directory */

      BACK_INFO_DBHOME_DIRECTORY,    /* Get the dbhome directory */

-     BACK_INFO_IS_ENTRYRDN          /* Get the flag for entryrdn */

+     BACK_INFO_IS_ENTRYRDN,         /* Get the flag for entryrdn */

+     BACK_INFO_CLDB_FILENAME        /* Get the backend replication changelog name */

  };

  

  struct _back_info_index_key

Bug Description:

There are several places in the code where the new changelog name is just a hardcoded string. So if the name changes we will have many places that need to be updated.

Fix Description:

Use a "define" for the file name in the bdb code, and in the changelog get get the filename from backend ldbminfo.

Also extended the ldbminfo flags to include the backend implementation. This will be used as we start to need a way to detect what database backend is in use.

relates: https://pagure.io/389-ds-base/issue/51121

Seems pretty reasonable to me :) Ack

rebased onto e8f0692

2 years ago

Pull-Request has been merged by mreynolds

2 years ago

389-ds-base is moving from Pagure to Github. This means that new issues and pull requests
will be accepted only in 389-ds-base's github repository.

This pull request has been cloned to Github as issue and is available here:
- https://github.com/389ds/389-ds-base/issues/4311

If you want to continue to work on the PR, please navigate to the github issue,
download the patch from the attachments and file a new pull request.

Thank you for understanding. We apologize for all inconvenience.

Pull-Request has been closed by spichugi

2 years ago