tds/src/main/java/thredds/core/ConfigCatalogInitialization.java
public synchronized boolean reread(ReadMode readMode, boolean isStartup) {
    readNow = System.currentTimeMillis();
    logCatalogInit.info("=========================================================================================\n"+
                    "ConfigCatalogInitialization readMode={} isStartup={}", readMode, isStartup);
    catPathMap = new HashSet<>();
    fcNameMap = new HashMap<>();
    if (ccc != null) ccc.invalidateAll(); // remove anything in cache
    if (fcCache != null) fcCache.invalidateAll(); // remove anything in cache

    if (!isStartup && readMode == ReadMode.always) trackerNumber++;  // must write a new database if TDS is already running and rereading all
    if (!isDebugMode || this.datasetTracker == null)
      this.datasetTracker = new DatasetTrackerChronicle(trackerDir, maxDatasets, trackerNumber);

    boolean databaseAlreadyExists = datasetTracker.exists(); // detect if tracker database exists
    if (!databaseAlreadyExists) {
      readMode = ReadMode.always;
      logCatalogInit.info("ConfigCatalogInitializion datasetTracker database does not exist, set readMode to=" + readMode);
    }

    if (this.callback == null)
      this.callback = new StatCallback(readMode);

    // going to reread global services
    allowedServices.clearGlobalServices();

    switch (readMode) {
      case always:
        // if the database already exists, we need to close it
        // before we reinit
        if (databaseAlreadyExists) {
          logCatalogInit.info("ConfigCatalogInitializion datasetTracker database already exists - closing it before reinitialization.");
          try {
            this.datasetTracker.close();
          } catch (IOException e) {
            logCatalogInit.error("There was an error closing the datasetTracker database.", e);
          }
          this.datasetTracker.reinit();
        }
        this.catalogTracker = new CatalogTracker(trackerDir, true, numberCatalogs, nextCatId);
        this.dataRootTracker = new DataRootTracker(trackerDir, true, callback);
        this.dataRootPathMatcher = new DataRootPathMatcher(ccc, dataRootTracker);  // starting over
        readRootCatalogs(readMode);
        break;

      case check:
        this.catalogTracker = new CatalogTracker(trackerDir, false, numberCatalogs, nextCatId);        // use existing catalog list
        this.dataRootTracker = new DataRootTracker(trackerDir, false, callback);      // use existing data roots
        this.dataRootPathMatcher = new DataRootPathMatcher(ccc, dataRootTracker);
        readRootCatalogs(readMode);           // read just roots to get global services
        checkExistingCatalogs(readMode);
        break;

      case triggerOnly:
        this.catalogTracker = new CatalogTracker(trackerDir, false, numberCatalogs, nextCatId);               // use existing catalog list
        this.dataRootTracker = new DataRootTracker(trackerDir, false, callback);             // use existing data roots
        this.dataRootPathMatcher = new DataRootPathMatcher(ccc, dataRootTracker);
        readRootCatalogs(readMode);           // read just roots to get global services
        break;
    }

    numberCatalogs = catalogTracker.size();
    nextCatId = catalogTracker.getNextCatId();
    if (prefs != null) {
      prefs.putLong("trackerNumber", trackerNumber);
      prefs.putLong("nextCatId", nextCatId);
      prefs.putInt("numberCatalogs", numberCatalogs);
    }
    callback.finish();
    logCatalogInit.info("\nConfigCatalogInitializion stats\n" + callback);

    try {
      datasetTracker.save();
      catalogTracker.save();
      dataRootTracker.save();
    } catch (IOException e) {
      // e.printStackTrace();
      logCatalogInit.error("datasetTracker.save() failed", e);
    }

    // heres where we may be doing a switcheroo in a running TDS
    if (dataRootManager != null)
      dataRootManager.setDataRootPathMatcher(dataRootPathMatcher);
    if (datasetManager != null)
      datasetManager.setDatasetTracker(datasetTracker);

    // cleanup old version of the database
    if (!isStartup && readMode == ReadMode.always) {
      DatasetTrackerChronicle.cleanupBefore(trackerDir, trackerNumber);
    }

    long took = System.currentTimeMillis() - readNow;
    logCatalogInit.info("ConfigCatalogInitializion finished took={} msecs", took);

    // cleanup
    catPathMap = null;
    fcNameMap = null;
    catalogTracker = null;

    return true; // ok
  }
public synchronized boolean reread(ReadMode readMode, boolean isStartup) {
    readNow = System.currentTimeMillis();
    logCatalogInit.info("=========================================================================================\n"+
                    "ConfigCatalogInitialization readMode={} isStartup={}", readMode, isStartup);
    catPathMap = new HashSet<>();
    fcNameMap = new HashMap<>();
    if (ccc != null) ccc.invalidateAll(); // remove anything in cache
    if (fcCache != null) fcCache.invalidateAll(); // remove anything in cache

    if (!isStartup && readMode == ReadMode.always) trackerNumber++;  // must write a new database if TDS is already running and rereading all
    if (!isDebugMode || this.datasetTracker == null)
      this.datasetTracker = new DatasetTrackerChronicle(trackerDir, maxDatasets, trackerNumber);

    boolean databaseAlreadyExists = datasetTracker.exists(); // detect if tracker database exists
    if (!databaseAlreadyExists) {
      readMode = ReadMode.always;
      logCatalogInit.info("ConfigCatalogInitializion datasetTracker database does not exist, set readMode to=" + readMode);
    }

    if (this.callback == null)
      this.callback = new StatCallback(readMode);

    // going to reread global services
    allowedServices.clearGlobalServices();

    switch (readMode) {
      case always:
        // if the database already exists, we need to close it
        // before we reinit
        if (databaseAlreadyExists) {
          logCatalogInit.info("ConfigCatalogInitializion datasetTracker database already exists - closing it before reinitialization.");
          try {
            this.datasetTracker.close();
          } catch (IOException e) {
            logCatalogInit.error("There was an error closing the datasetTracker database.", e);
          }
          this.datasetTracker.reinit();
        }
        this.catalogTracker = new CatalogTracker(trackerDir, true, numberCatalogs, nextCatId);
        this.dataRootTracker = new DataRootTracker(trackerDir, true, callback);
        this.dataRootPathMatcher = new DataRootPathMatcher(ccc, dataRootTracker);  // starting over
        readRootCatalogs(readMode);
        break;

      case check:
        this.catalogTracker = new CatalogTracker(trackerDir, false, numberCatalogs, nextCatId);        // use existing catalog list
        this.dataRootTracker = new DataRootTracker(trackerDir, false, callback);      // use existing data roots
        this.dataRootPathMatcher = new DataRootPathMatcher(ccc, dataRootTracker);
        readRootCatalogs(readMode);           // read just roots to get global services
        checkExistingCatalogs(readMode);
        break;

      case triggerOnly:
        this.catalogTracker = new CatalogTracker(trackerDir, false, numberCatalogs, nextCatId);               // use existing catalog list
        this.dataRootTracker = new DataRootTracker(trackerDir, false, callback);             // use existing data roots
        this.dataRootPathMatcher = new DataRootPathMatcher(ccc, dataRootTracker);
        readRootCatalogs(readMode);           // read just roots to get global services
        break;
    }

    numberCatalogs = catalogTracker.size();
    nextCatId = catalogTracker.getNextCatId();
    if (prefs != null) {
      prefs.putLong("trackerNumber", trackerNumber);
      prefs.putLong("nextCatId", nextCatId);
      prefs.putInt("numberCatalogs", numberCatalogs);
    }
    callback.finish();
    logCatalogInit.info("\nConfigCatalogInitializion stats\n" + callback);

    try {
      datasetTracker.save();
      catalogTracker.save();
      dataRootTracker.save();
    } catch (IOException e) {
      // e.printStackTrace();
      logCatalogInit.error("datasetTracker.save() failed", e);
    }

    // heres where we may be doing a switcheroo in a running TDS
    if (dataRootManager != null)
      dataRootManager.setDataRootPathMatcher(dataRootPathMatcher);
    if (datasetManager != null)
      datasetManager.setDatasetTracker(datasetTracker);

    // cleanup old version of the database
    if (!isStartup && readMode == ReadMode.always) {
      DatasetTrackerChronicle.cleanupBefore(trackerDir, trackerNumber);
    }

    long took = System.currentTimeMillis() - readNow;
    logCatalogInit.info("ConfigCatalogInitializion finished took={} msecs", took);

    // cleanup
    catPathMap = null;
    fcNameMap = null;
    catalogTracker = null;

    return true; // ok
  }
called from init() and from trigger controller