Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HPCC-33120 Add daliadmin cleangenerateddlls utility command. #19357

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -3424,4 +3425,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 @@ -96,5 +96,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 @@ -582,6 +583,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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NB: sneaking this fix in (TRACE_HASH off by default).
Can separate into separate PR ..

#endif
}

Expand Down
Loading