Skip to content

Commit

Permalink
HPCC-33120 Add daliadmin cleangenerateddlls utility command.
Browse files Browse the repository at this point in the history
daliadmin <daliip> cleangenerateddlls [dryrun] [nobackup]

The command will scan workunits and generated dll meta data,
and remove all unrefenced generated dlls.

Signed-off-by: Jake Smith <[email protected]>
  • Loading branch information
jakesmith committed Dec 17, 2024
1 parent 20adacd commit 961c09e
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
73 changes: 73 additions & 0 deletions dali/daliadmin/daadmin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
############################################################################## */

#include <unordered_map>
#include <unordered_set>
#include <string>

#include "platform.h"
Expand Down Expand Up @@ -3499,4 +3500,76 @@ void cleanJobQueues(bool dryRun)
}
}

void cleanGeneratedDlls(bool dryRun, bool backup)
{
PROGLOG("Gathering workunits for referencd generated dlls");
CCycleTimer timer;
Owned<IRemoteConnection> conn = querySDS().connect("/", myProcessSession(), 0, SDS_LOCK_TIMEOUT);
if (!conn)
{
WARNLOG("Failed to connect to /WorkUnits");
return;
}
IPropertyTree *root = conn->queryRoot();
IPropertyTree *wuidsTree = root->queryPropTree("WorkUnits");
if (!wuidsTree)
{
PROGLOG("No WorkUnits found");
return;
}
Owned<IPropertyTreeIterator> wuidIter = wuidsTree->getElements("*");
std::unordered_set<std::string> referencedGDlls;
ForEach(*wuidIter)
{
IPropertyTree &wuid = wuidIter->query();
Owned<IPropertyTreeIterator> gdIter = wuid.getElements("Query/Associated/File[@type='dll']");
ForEach(*gdIter)
{
IPropertyTree &gd = gdIter->query();
const char *fullPath = gd.queryProp("@filename");
const char *filename = pathTail(fullPath);
if (filename)
referencedGDlls.emplace(filename);
}
}
PROGLOG("Found %u workunits that reference generated dlls, took: %u ms", (unsigned)referencedGDlls.size(), timer.elapsedMs());
PROGLOG("Scanning GeneratedDlls");
timer.reset();
IPropertyTree *generatedDllsTree = root->queryPropTree("GeneratedDlls");
if (!generatedDllsTree)
{
PROGLOG("No GeneratedDlls found");
return;
}
std::vector<IPropertyTree *> gDllsToRemove;
unsigned totalGDlls = 0;
Owned<IPropertyTreeIterator> gDlls = generatedDllsTree->getElements("*");
ForEach(*gDlls)
{
++totalGDlls;
IPropertyTree &gDll = gDlls->query();
const char *name = gDll.queryProp("@name");
if (referencedGDlls.find(name) == referencedGDlls.end())
gDllsToRemove.push_back(&gDll);
}
PROGLOG("Found %u GeneratedDlls, %u not referenced, took: %u ms", totalGDlls, (unsigned)gDllsToRemove.size(), timer.elapsedMs());
if (!dryRun)
{
if (backup)
{
StringBuffer bakName;
Owned<IFileIO> iFileIO = createUniqueFile(NULL, "daliadmin_generateddlls", "bak", bakName);
if (!iFileIO)
throw makeStringException(0, "Failed to create backup file");
PROGLOG("Saving backup of GeneratedDlls to %s", bakName.str());
saveXML(*iFileIO, generatedDllsTree, 2);
}
PROGLOG("Deleting %u unreferenced GeneratedDlls", (unsigned)gDllsToRemove.size());
timer.reset();
for (auto &item: gDllsToRemove)
generatedDllsTree->removeTree(item);
PROGLOG("Removed %u unreferenced GeneratedDlls, took: %u ms", (unsigned)gDllsToRemove.size(), timer.elapsedMs());
}
}

} // namespace daadmin
1 change: 1 addition & 0 deletions dali/daliadmin/daadmin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,6 @@ extern DALIADMIN_API void daliping(const char *dalis, unsigned connecttime, unsi
extern DALIADMIN_API void validateStore(bool fix, bool deleteFiles, bool verbose);
extern DALIADMIN_API void removeOrphanedGlobalVariables(bool dryrun, bool reconstruct);
extern DALIADMIN_API void cleanJobQueues(bool dryRun);
extern DALIADMIN_API void cleanGeneratedDlls(bool dryRun, bool backup);

} // namespace daadmin
15 changes: 15 additions & 0 deletions dali/daliadmin/daliadmin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void usage(const char *exe)
printf(" auditlog <fromdate> <todate> <match>\n");
printf(" cleanglobalwuid [dryrun] [noreconstruct]\n");
printf(" cleanjobqueues [dryrun]\n");
printf(" cleangenerateddlls [dryrun] [nobackup]\n");
printf(" clusterlist <mask> -- list clusters (mask optional)\n");
printf(" coalesce -- force transaction coalesce\n");
printf(" dalilocks [ <ip-pattern> ] [ files ] -- get all locked files/xpaths\n");
Expand Down Expand Up @@ -597,6 +598,20 @@ int main(int argc, const char* argv[])
bool dryRun = np>0 && strieq("dryrun", params.item(1));
cleanJobQueues(dryRun);
}
else if (strieq(cmd, "cleangenerateddlls"))
{
bool dryRun = false;
bool backup = true; // default
for (unsigned i=1; i<params.ordinality(); i++)
{
const char *param = params.item(i);
if (strieq("dryrun", param))
dryRun = true;
else if (strieq("nobackup", param))
backup = false;
}
cleanGeneratedDlls(dryRun, backup);
}
else if (strieq(cmd, "remotetest"))
remoteTest(params.item(1), true);
else
Expand Down
1 change: 1 addition & 0 deletions system/jlib/jsuperhash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ void SuperHashTable::init(unsigned initsize)
#ifdef TRACE_HASH
search_tot = 0;
search_num = 0;
search_max = 0;
#endif
}

Expand Down

0 comments on commit 961c09e

Please sign in to comment.