MCPcopy
hub / github.com/NVIDIA/aistore / LoadConfig

Function LoadConfig

cmn/config.go:1693–1786  ·  view source on GitHub ↗

is called at startup

(globalConfPath, localConfPath, daeRole string, config *Config)

Source from the content-addressed store, hash-verified

1691
1692// is called at startup
1693func LoadConfig(globalConfPath, localConfPath, daeRole string, config *Config) error {
1694 debug.Assert(globalConfPath != "" && localConfPath != "")
1695 GCO.SetInitialGconfPath(globalConfPath)
1696
1697 // first, local config
1698 if _, err := jsp.LoadMeta(localConfPath, &config.LocalConfig); err != nil {
1699 return fmt.Errorf("failed to load plain-text local config %q: %v", localConfPath, err)
1700 }
1701 glog.SetLogDir(config.LogDir)
1702
1703 // Global (aka Cluster) config
1704 // Normally, when the node is being deployed the very first time the last updated version
1705 // of the config doesn't exist.
1706 // In this case, we load the initial plain-text global config from the command-line/environment
1707 // specified `globalConfPath`.
1708 // Once started, the node then always relies on the last updated version stored in a binary
1709 // form (in accordance with the associated ClusterConfig.JspOpts()).
1710 globalFpath := filepath.Join(config.ConfigDir, fname.GlobalConfig)
1711 if _, err := jsp.LoadMeta(globalFpath, &config.ClusterConfig); err != nil {
1712 const txt = "load global config"
1713 if os.IsNotExist(err) {
1714 const itxt = "load initial global config"
1715 // initial (plain-text)
1716 glog.Warningf("%s %q", itxt, globalConfPath)
1717 _, err = jsp.Load(globalConfPath, &config.ClusterConfig, jsp.Plain())
1718 if err != nil {
1719 return fmt.Errorf("failed to %s %q: %v", itxt, globalConfPath, err)
1720 }
1721 debug.Assert(config.Version == 0)
1722 globalFpath = globalConfPath
1723 } else if _, ok := err.(*jsp.ErrUnsupportedMetaVersion); ok {
1724 glog.Warningf("failed to %s - trying the previous meta-version v%d", txt, v1MetaverConfig)
1725 errOld := loadClusterConfigV1(globalFpath, config)
1726 if errOld != nil {
1727 return fmt.Errorf("failed to %s %q: [%v] [%v]", txt, globalFpath, err, errOld)
1728 }
1729 debug.Assert(config.Version > 0 && config.UUID != "")
1730
1731 // rewrite with the current meta-version
1732 if errSav := jsp.SaveMeta(globalFpath, &config.ClusterConfig, nil); errSav != nil {
1733 return fmt.Errorf("failed to %s %q: [%v] [%v]", txt, globalFpath, err, errSav)
1734 }
1735 glog.Warningf("backward compatibility: saved %s meta-version v%d => v%d",
1736 &config.ClusterConfig, v1MetaverConfig, MetaverConfig)
1737 } else {
1738 // otherwise
1739 return fmt.Errorf("failed to %s %q: %v", txt, globalConfPath, err)
1740 }
1741 } else {
1742 debug.Assert(config.Version > 0 && config.UUID != "")
1743 }
1744
1745 // readonly config which can be updated but
1746 // for the change to take an effect the cluster (or the node) must be restarted
1747 Features = config.Features
1748 Timeout.setReadOnly(config)
1749
1750 config.SetRole(daeRole)

Callers 3

TestConfigTestEnvFunction · 0.92
TestConfigFSPathsFunction · 0.92
initDaemonFunction · 0.92

Calls 15

AssertFunction · 0.92
LoadMetaFunction · 0.92
SetLogDirFunction · 0.92
WarningfFunction · 0.92
LoadFunction · 0.92
PlainFunction · 0.92
SaveMetaFunction · 0.92
CreateDirFunction · 0.92
InfofFunction · 0.92
loadClusterConfigV1Function · 0.85
handleOverrideConfigFunction · 0.85
SetLogLevelFunction · 0.85

Tested by 2

TestConfigTestEnvFunction · 0.74
TestConfigFSPathsFunction · 0.74