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
[JENKINS-30424] Move build.save to the migration thread #8
Conversation
…save the build before it is loaded)
This pull request originates from a CloudBees employee. At CloudBees, we require that all pull requests be reviewed by other CloudBees employees before we seek to have the change accepted. If you want to learn more about our process please see this explanation. |
@@ -38,4 +41,18 @@ public void remove(Run run) throws IOException { | |||
public String get(Run thing) { | |||
return Id.getId((Actionable) thing); | |||
} | |||
|
|||
private void saveIfNeeded(Run run) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method name seems clear, but a javadoc will be nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's private so Javadocs are not really useful. There are some inline comments inside for developers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not know this measure to add javadoc
LGTM |
@@ -71,7 +71,7 @@ public void onAttached(Run<?, ?> r) { | |||
// NO-OP | |||
} | |||
|
|||
/** | |||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could revert.
🐝, kudos on finding a way to reproduce this in a test. |
|
||
public void onLoad(Run<?, ?> r) { | ||
try { | ||
Thread.sleep(1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sleeping in tests isn't generally a good idea, ca. A wait/semaphore be used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't think about it. It would be far more complex than this.
What's exactly wrong with Thread.sleep
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see how sleeping indefinitely (inside a loop) is a bad thing, but this seems fine to me, even if I don't know why it's there (mimic a load delay or something?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's simulating a load delay (which is what causes the original issue actually).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, having looked at the test code I can now see why you're using the 1s delay. I can see now that this could (potentially) cause some flaky test behaviour, but I guess @amuniz is the one to decide if that's realistically possible or not. If it is possible it should be easy to fix by adding a flag on LongLoadingAction
that gets toggled once the test is where it needs to be, telling LongLoadingAction.onLoad
that it's ok to finish now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The question is what happens if the machine running the test is heavily loaded. If that causes a test failure when the code is good, that is a problem. If it just causes the test to pass even when the code regressed, that is OK, since this will not usually happen and we will find the failure soon.
1075b13
to
1ad1a6f
Compare
// Save the run here so its storage is updated (after being migrated in Id.onLoad(Run)) | ||
run.save(); | ||
} catch (IOException e) { | ||
LOGGER.log(Level.WARNING, "Can not save build {0} on job {1}", new Object[] { run.getNumber(), job.getName() }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about including the IOException
in the log?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not like to pollute the logs with stacktraces, since if this migration fails it will be addressed later by Id.onLoad
on demand.
Moreover, all Level.WARNING
logs in this plugin are not printing stacktraces, I don't want to break predefined style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐜 This exception would be unexpected and logging it would probably be wise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other loggers should log the message. If not please raise another jira
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
🐝 |
🐝 |
It appears this solves another test failure in unique-id that periodically shows up if you're unlucky in threading. This will be very helpful in clearing our compat failures. |
@reviewbybees done |
🐝 |
[JENKINS-30424] Move build.save to the migration thread
JENKINS-30424
Move build.save to the migration thread (avoiding to save the build before it is loaded), and keep the save on
Id.onLoad
but limit its effect if the migration thread did not finish yet.Test added. Confirmed the test failing with current master with the following exception (and working after this fix):
@reviewbybees (esp. @jtnord)