Skip to content

Commit

Permalink
Fix problems with hostgroups modifying global config
Browse files Browse the repository at this point in the history
Signed-off-by: Gavin Halliday <[email protected]>
  • Loading branch information
ghalliday committed Dec 17, 2024
1 parent 849d415 commit 5240339
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
5 changes: 3 additions & 2 deletions dali/base/dadfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10756,10 +10756,11 @@ class CInitGroups

void constructStorageGroups(bool force, StringBuffer &messages)
{
Owned<IPropertyTree> storage = getGlobalConfigSP()->getPropTree("storage");
Owned<IPropertyTree> globalConfig = getGlobalConfig();
Owned<IPropertyTree> storage = globalConfig->getPropTree("storage");
if (storage)
{
normalizeHostGroups();
normalizeHostGroups(globalConfig);

Owned<IPropertyTreeIterator> planes = storage->getElements("planes");
ForEach(*planes)
Expand Down
2 changes: 1 addition & 1 deletion dali/base/dafdesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3786,7 +3786,7 @@ static void doInitializeStorageGroups(bool createPlanesFromGroups, IPropertyTree
}

//Ensure that host groups that are defined in terms of other host groups are expanded out so they have an explicit list of hosts
normalizeHostGroups();
normalizeHostGroups(newGlobalConfiguration);

//The following can be removed once the storage planes have better integration
setupContainerizedStorageLocations();
Expand Down
18 changes: 14 additions & 4 deletions dali/base/dameta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
#include "dautils.hpp"


// Expand indirect hostGroups so each hostGroups has an expanded list of host names
void normalizeHostGroups()
//Expand indirect hostGroups so each hostGroups has an expanded list of host names
//This function cannot use (directly or indirectly) getGlobalConfig(), because it may be called when creating
//a new config.
void normalizeHostGroups(IPropertyTree * globalConfig)
{
Owned<IPropertyTreeIterator> hostGroupIter = getGlobalConfigSP()->getElements("storage/hostGroups");
Owned<IPropertyTreeIterator> hostGroupIter = globalConfig->getElements("storage/hostGroups");
//Process the groups in order - so that multiple levels of indirection are supported
ForEach (*hostGroupIter)
{
Expand All @@ -33,7 +35,15 @@ void normalizeHostGroups()
{
const char * name = cur.queryProp("@name");
const char * baseGroup = cur.queryProp("@hostGroup");
Owned<IPropertyTree> match = getHostGroup(baseGroup, true);
if (!baseGroup)
throw makeStringExceptionV(-1, "HostGroup %s with no hosts does not have a base hostgroup", name ? name : "<null>");

//Cannot call getHostGroup() because that uses getGlobalConfig()
VStringBuffer xpath("storage/hostGroups[@name='%s']", baseGroup);
IPropertyTree * match = globalConfig->queryPropTree(xpath);
if (!match)
throw makeStringExceptionV(-1, "No entry found for hostGroup: '%s'", baseGroup);

StringArray hosts;
Owned<IPropertyTreeIterator> hostIter = match->getElements("hosts");
ForEach (*hostIter)
Expand Down
2 changes: 1 addition & 1 deletion dali/base/dameta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ constexpr ResolveOptions operator &(ResolveOptions l, ResolveOptions r) { return
*/

extern da_decl IPropertyTree * resolveLogicalFilenameFromDali(const char * filename, IUserDescriptor * user, ResolveOptions options);
extern da_decl void normalizeHostGroups(); // Expand indirect hostGroups so each hostGroups has an expanded list of host names
extern da_decl void normalizeHostGroups(IPropertyTree * globalConfig); // Expand indirect hostGroups so each hostGroups has an expanded list of host names

#endif
5 changes: 3 additions & 2 deletions dali/base/dautils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ bool getPlaneHost(StringBuffer &host, IPropertyTree *plane, unsigned which)
if (!hostGroup)
return false;

if (which >= hostGroup->getCount("hosts"))
throw makeStringException(0, "getPlaneHost: index out of range");
unsigned maxHosts = hostGroup->getCount("hosts");
if (which >= maxHosts)
throw makeStringExceptionV(0, "getPlaneHost: index %u out of range 1..%u", which, maxHosts);
VStringBuffer xpath("hosts[%u]", which+1); // which is 0 based
host.append(hostGroup->queryProp(xpath));
return true;
Expand Down

0 comments on commit 5240339

Please sign in to comment.