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

[ML] Fail start up if state is missing #4

Merged
merged 3 commits into from
Feb 23, 2018
Merged

[ML] Fail start up if state is missing #4

merged 3 commits into from
Feb 23, 2018

Conversation

davidkyle
Copy link
Member

Fail restoring job if state input stream is empty.

If the restore state argument is passed to autodetect then a state input stream is created and it is an error if that stream contains no state.

" - ignoring it as current state version is " <<
model::CAnomalyDetector::STATE_VERSION);

// This counts as successful restoration
return true;
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this one should stay as it is, otherwise we can never ever bump the model state version.

However, there is another problem here. If the job is doing categorization as well as anomaly detection then the stream will be incorrectly positioned if we simply return here, so in the case where the model state version has been bumped but the categorizer state version hasn't the categorizer restoration will fail with a horrible error. (Simply returning dates back to when we used to run completely separate searches against ES to get the different state types.) It needs to read and discard the old model state leaving the stream positioned at the start of the categorizer state. I'm happy to leave this problem for a followup PR, as it's not possible to hit it until we eventually bump the state version, so you could just add a TODO for it.

fieldConfig.initFromClause(clauses);
model::CAnomalyDetectorModelConfig modelConfig =
model::CAnomalyDetectorModelConfig::defaultConfig(BUCKET_SIZE);
std::stringstream outputStrm;
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use ostringstream as it's only for output.

// This is not an error if no data has been persisted
return true;
LOG_ERROR("Expected persisted state but no state exists");
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

The same change is also needed on line 282 of CFieldDataTyper.cc.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@@ -888,8 +888,8 @@ bool CAnomalyJob::restoreState(core::CDataSearcher &restoreSearcher,

if (strm->fail())
{
// This is not fatal - we just didn't find the given document number
return true;
// This is fatal. If the stream exists and has failed then state is missing
Copy link
Contributor

Choose a reason for hiding this comment

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

I think eof is a special case of fail, so in the case where there are no state documents at all this will trigger instead of the eof check in the method below. So it's probably worth adding LOG_ERROR("Expected persisted state but no state exists"); here too, so we get an error logged in both cases.

Copy link
Member Author

Choose a reason for hiding this comment

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

This if before anything has been read from the stream so eof will not be set. Considering bad is checked above this is very unlikely to fail but it does need a log message

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, good point. I don't think this can happen for our named pipe restoration, as we'll fail earlier on if the named pipe doesn't exist.

Copy link
Contributor

@droberts195 droberts195 left a comment

Choose a reason for hiding this comment

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

I noticed a few minor nits but LGTM when they're fixed.

//!
//! DESCRIPTION:\n
//! CDataSearcher that returns an empty stream.
//!
Copy link
Contributor

Choose a reason for hiding this comment

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

The Doxygen comment should go above the class CEmptySearcher line.

//!
//! DESCRIPTION:\n
//! CDataSearcher that returns an empty stream.
//!
Copy link
Contributor

Choose a reason for hiding this comment

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

The Doxygen comment should go above the class CEmptySearcher line.

@@ -308,7 +309,14 @@ bool CFieldDataTyper::restoreState(core::CDataSearcher &restoreSearcher,

bool CFieldDataTyper::acceptRestoreTraverser(core::CStateRestoreTraverser &traverser)
{
if (traverser.name() == VERSION_TAG)
std::string firstFieldName(traverser.name());
Copy link
Contributor

Choose a reason for hiding this comment

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

There's no need to copy here - you can just keep a reference:

const std::string &firstFieldName = traverser.name();

@davidkyle davidkyle merged commit daac9e8 into elastic:master Feb 23, 2018
@davidkyle davidkyle deleted the fail-missing-state branch February 23, 2018 17:03
davidkyle added a commit that referenced this pull request Feb 25, 2018
* Fail start up if state is missing

* Fail categorizer restore if state is missing
@sophiec20 sophiec20 changed the title Fail start up if state is missing [ML] Fail start up if state is missing Mar 28, 2018
@sophiec20 sophiec20 added the :ml label Apr 4, 2018
droberts195 pushed a commit that referenced this pull request Apr 23, 2018
* Fail start up if state is missing

* Fail categorizer restore if state is missing
droberts195 pushed a commit that referenced this pull request Apr 23, 2018
* Fail start up if state is missing

* Fail categorizer restore if state is missing
@lcawl lcawl added the >bug label Jun 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants