Skip to content

Commit

Permalink
Merge branch 'V23_8-HTCONDOR-2448-condor-history-remote-honor-forward…
Browse files Browse the repository at this point in the history
…s-search' into main
  • Loading branch information
timtheisen committed May 17, 2024
2 parents 738eabe + 3cedf34 commit afd2af8
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 63 deletions.
4 changes: 3 additions & 1 deletion docs/version-history/lts-versions-23-0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ Release Notes:

New Features:

- None.
- *condor_history* will now pass along the ``-forwards`` and ``-scanlimit``
flags when doing a remote history query.
:jira:`2448`

Bugs Fixed:

Expand Down
2 changes: 2 additions & 0 deletions src/condor_tests/test_condor_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def __init__(self, cmd, exp_out=[], header=[]):
"remote_clust.proc" : TestReqs("condor_history 5.3 -name TEST_SCHEDD@", ["5.3"], STD_HEADER),
"remote_match" : TestReqs("condor_history 5 -name TEST_SCHEDD@ -limit 2", ["5.4","5.3"], STD_HEADER),
"remote_since" : TestReqs("condor_history -name TEST_SCHEDD@ -since 4.0", ["4.1","5.0","5.1","5.2","5.3","5.4"], STD_HEADER),
"remote_forwards" : TestReqs("condor_history 2 -forwards -scanlimit 4 -name TEST_SCHEDD@", ["2.0","2.1","2.2"], STD_HEADER),
"remote_scanlimit" : TestReqs("condor_history -scanlimit 2 -name TEST_SCHEDD@", ["5.3","5.4"], STD_HEADER),
"remote_constraint" : TestReqs("condor_history -const CustAttr=!=UNDEFINED -name TEST_SCHEDD@", ["3.0"], STD_HEADER),
# Note: remote_epochs default type is EPOCH ads so query should return the first 3 ads marked as EPOCH in their banners
"remote_epochs" : TestReqs("condor_history -epochs -const IsEpoch=!=UNDEFINED -match 3 -name TEST_SCHEDD@", ["5.0","7.0","8.0"], STD_HEADER),
Expand Down
86 changes: 25 additions & 61 deletions src/condor_tools/history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,7 @@ main(int argc, const char* argv[])
"Error: Argument -forwards cannot be combined with -since.\n");
exit(1);
}
if ( ! writetosocket) {
backwards=FALSE;
}
backwards=FALSE;
hasForwards = true;
}

Expand Down Expand Up @@ -881,6 +879,8 @@ static void readHistoryRemote(classad::ExprTree *constraintExpr, bool want_start
bool want_streamresults = streamresults_specified ? streamresults : true;
ad.InsertAttr("StreamResults", want_streamresults);
}
if ( ! backwards) { ad.InsertAttr("HistoryReadForwards", true); }
if (maxAds >= 0) { ad.InsertAttr("ScanLimit", maxAds); }
// only 8.5.6 and later will honor this, older schedd's will just ignore it
if (sinceExpr) ad.Insert("Since", sinceExpr);
// we may or may not be able to do the projection, we will decide after knowing the daemon version
Expand Down Expand Up @@ -1191,6 +1191,8 @@ static bool checkMatchJobIdsFound(BannerInfo &banner, ClassAd *ad = NULL, bool o
return false;
}

static bool printJobIfConstraint(ClassAd &ad, const char* constraint, ExprTree *constraintExpr, BannerInfo& banner);

// Read the history from a single file and print it out.
static void readHistoryFromFileOld(const char *JobHistoryFileName, const char* constraint, ExprTree *constraintExpr)
{
Expand Down Expand Up @@ -1256,66 +1258,22 @@ static void readHistoryFromFileOld(const char *JobHistoryFileName, const char* c
}
continue;
}
if (!constraint || constraint[0]=='\0' || EvalExprBool(ad, constraintExpr)) {
if (longformat) {
if( use_xml ) {
fPrintAdAsXML(stdout, *ad, projection.empty() ? NULL : &projection);
} else if ( use_json ) {
if ( printCount != 0 ) {
printf(",\n");
}
fPrintAdAsJson(stdout, *ad, projection.empty() ? NULL : &projection, false);
} else if ( use_json_lines ) {
fPrintAdAsJson(stdout, *ad, projection.empty() ? NULL : &projection, true);
}
else {
fPrintAd(stdout, *ad, false, projection.empty() ? NULL : &projection);
}
printf("\n");
} else {
if (customFormat) {
mask.display(stdout, ad);
} else {
displayJobShort(ad);
}
}

printCount++;
matchCount++; // if control reached here, match has occured

if (specifiedMatch > 0) { // User specified a match number
if (matchCount == specifiedMatch) { // Found n number of matches, cleanup
if (ad) {
delete ad;
ad = NULL;
}

fclose(LogFile);
return;
}
}
}
BannerInfo ad_info;
parseBanner(ad_info, banner);
bool done = printJobIfConstraint(*ad, constraint, constraintExpr, ad_info);

if (cluster > 0) { //User specified cluster or cluster.proc.
BannerInfo ad_info;
parseBanner(ad_info, banner);
if (checkMatchJobIdsFound(ad_info, ad)) { //Check if all possible matches have been found
if (ad) {
delete ad;
ad = NULL;
}
fclose(LogFile);
return;
}
if (ad) {
delete ad;
ad = nullptr;
}

if(ad) {
delete ad;
ad = NULL;
}
}
fclose(LogFile);
return;
if (done || (specifiedMatch > 0 && matchCount >= specifiedMatch) || (maxAds > 0 && adCount >= maxAds)) {
break;
}
}
fclose(LogFile);
return;
}

// return true if p1 starts with p2
Expand Down Expand Up @@ -1403,11 +1361,16 @@ static void printJobIfConstraint(std::vector<std::string> & exprs, const char* c
}
exprs.pop_back();
}
printJobIfConstraint(ad, constraint, constraintExpr, banner);
}

static bool printJobIfConstraint(ClassAd &ad, const char* constraint, ExprTree *constraintExpr, BannerInfo& banner)
{
++adCount;

if (sinceExpr && EvalExprBool(&ad, sinceExpr)) {
maxAds = adCount; // this will force us to stop scanning
return;
return true;
}

if (!constraint || constraint[0]=='\0' || EvalExprBool(&ad, constraintExpr)) {
Expand All @@ -1417,9 +1380,10 @@ static void printJobIfConstraint(std::vector<std::string> & exprs, const char* c
if (cluster > 0) { //User specified cluster or cluster.proc.
if (checkMatchJobIdsFound(banner, &ad)) { //Check if all possible ads have been displayed
maxAds = adCount;
return;
return true;
}
}
return false;
}

static void printJobAds(ClassAdList & jobs)
Expand Down
21 changes: 20 additions & 1 deletion src/condor_utils/history_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ int HistoryHelperQueue::command_handler(int cmd, Stream* stream)
streamresults = false;
}

bool searchForwards;
if ( ! queryAd.EvaluateAttrBool("HistoryReadForwards", searchForwards)) { searchForwards = false; }

std::string scanLimit;
if (queryAd.EvaluateAttr("ScanLimit", value) && value.IsIntegerValue()) {
unparser.Unparse(scanLimit, value);
}

std::string record_src;
queryAd.EvaluateAttrString(ATTR_HISTORY_RECORD_SOURCE, record_src);

Expand All @@ -129,13 +137,17 @@ int HistoryHelperQueue::command_handler(int cmd, Stream* stream)
HistoryHelperState state(stream_shared, requirements_str, since_str, proj_str, match_limit, record_src);
state.m_streamresults = streamresults;
state.m_searchdir = searchDir;
state.m_searchForwards = searchForwards;
state.m_scanLimit = scanLimit;
state.m_adTypeFilter = ad_type_filter;
m_queue.push_back(state);
return KEEP_STREAM;
} else {
HistoryHelperState state(*stream, requirements_str, since_str, proj_str, match_limit, record_src);
state.m_streamresults = streamresults;
state.m_searchdir = searchDir;
state.m_searchForwards = searchForwards;
state.m_scanLimit = scanLimit;
state.m_adTypeFilter = ad_type_filter;
return launcher(state);
}
Expand Down Expand Up @@ -195,8 +207,15 @@ int HistoryHelperQueue::launcher(const HistoryHelperState &state) {
args.AppendArg("-match");
args.AppendArg(state.MatchCount());
}
if (state.m_searchForwards) {
args.AppendArg("-forwards");
}
args.AppendArg("-scanlimit");
args.AppendArg(std::to_string(param_integer("HISTORY_HELPER_MAX_HISTORY", 50000)));
if (state.m_scanLimit.empty()) {
args.AppendArg(std::to_string(param_integer("HISTORY_HELPER_MAX_HISTORY", 50000)));
} else {
args.AppendArg(state.m_scanLimit);
}
if ( ! state.Since().empty()) {
args.AppendArg("-since");
args.AppendArg(state.Since());
Expand Down
2 changes: 2 additions & 0 deletions src/condor_utils/history_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ class HistoryHelperState
const std::string & MatchCount() const { return m_match; }
const std::string & RecordSrc() const { return m_recordSrc; }
std::string m_adTypeFilter{};
std::string m_scanLimit{};
bool m_streamresults{false};
bool m_searchdir{false};
bool m_searchForwards{false};

private:
Stream *m_stream_ptr;
Expand Down

0 comments on commit afd2af8

Please sign in to comment.