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

[JENKINS-30424] Move build.save to the migration thread #8

Merged
merged 5 commits into from Oct 23, 2015

Conversation

amuniz
Copy link
Member

@amuniz amuniz commented Oct 21, 2015

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):

Exception in thread "unique-id background migration thread" org.jenkinsci.plugins.uniqueid.impl.IdStoreMigratorV1ToV2$IDStoreMigrationException: Failure whilst migrating folderWithID » jobWithID #2
    at org.jenkinsci.plugins.uniqueid.impl.IdStoreMigratorV1ToV2.migrate(IdStoreMigratorV1ToV2.java:100)
    at org.jenkinsci.plugins.uniqueid.impl.Id.onLoad(Id.java:78)
    at hudson.model.Run.onLoad(Run.java:345)
    at org.jenkinsci.plugins.uniqueid.impl.LongLoadingBuild.onLoad(LongLoadingBuild.java:29)
    at hudson.model.RunMap.retrieve(RunMap.java:223)
    at hudson.model.RunMap.retrieve(RunMap.java:59)
    at jenkins.model.lazy.AbstractLazyLoadRunMap.load(AbstractLazyLoadRunMap.java:687)
    at jenkins.model.lazy.AbstractLazyLoadRunMap.load(AbstractLazyLoadRunMap.java:670)
    at jenkins.model.lazy.AbstractLazyLoadRunMap.all(AbstractLazyLoadRunMap.java:622)
    at jenkins.model.lazy.AbstractLazyLoadRunMap.entrySet(AbstractLazyLoadRunMap.java:277)
    at java.util.AbstractMap$2$1.<init>(AbstractMap.java:389)
    at java.util.AbstractMap$2.iterator(AbstractMap.java:388)
    at hudson.util.RunList.iterator(RunList.java:97)
    at org.jenkinsci.plugins.uniqueid.impl.IdStoreMigratorV1ToV2$RunIDMigrationThread.run(IdStoreMigratorV1ToV2.java:134)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
    at org.jenkinsci.plugins.uniqueid.impl.LongLoadingBuild.save(LongLoadingBuild.java:23)
    at org.jenkinsci.plugins.uniqueid.impl.RunIdStore.remove(RunIdStore.java:33)

@reviewbybees (esp. @jtnord)

@ghost
Copy link

ghost commented Oct 21, 2015

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 {
Copy link

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.

Copy link
Member Author

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.

Copy link

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

@recena
Copy link

recena commented Oct 21, 2015

LGTM

@@ -71,7 +71,7 @@ public void onAttached(Run<?, ?> r) {
// NO-OP
}

/**
/**
Copy link
Member

Choose a reason for hiding this comment

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

Could revert.

@jglick
Copy link
Member

jglick commented Oct 21, 2015

🐝, kudos on finding a way to reproduce this in a test.


public void onLoad(Run<?, ?> r) {
try {
Thread.sleep(1000);
Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member

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?).

Copy link
Member Author

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).

Copy link
Member

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.

Copy link
Member

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.

@amuniz amuniz force-pushed the JENKINS-30424 branch 2 times, most recently from 1075b13 to 1ad1a6f Compare October 22, 2015 08:02
@amuniz
Copy link
Member Author

amuniz commented Oct 22, 2015

@jglick @jtnord comments addressed.

// 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() });
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough.

Copy link
Member

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.

Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

@tfennelly
Copy link
Member

🐝

@jglick
Copy link
Member

jglick commented Oct 22, 2015

🐝

@kwhetstone
Copy link

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.

@amuniz
Copy link
Member Author

amuniz commented Oct 23, 2015

@reviewbybees done

@stephenc
Copy link
Member

🐝

stephenc added a commit that referenced this pull request Oct 23, 2015
[JENKINS-30424] Move build.save to the migration thread
@stephenc stephenc merged commit 62ae665 into jenkinsci:master Oct 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants