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 13493 - Automatic git cache maintenance #1277

Draft
wants to merge 143 commits into
base: master
Choose a base branch
from

Conversation

Hrushi20
Copy link

@Hrushi20 Hrushi20 commented May 31, 2022

JENKINS-13493 - Automatic git cache maintenance

This PR adds git maintenance to the Jenkins controller to optimize the git caches on the controller.

Please refer to Project Page for reference and design:
https://www.jenkins.io/projects/gsoc/2022/projects/automatic-git-cache-maintenance/

Checklist

  • I have read the CONTRIBUTING doc
  • I have referenced the Jira issue related to my changes in one or more commit messages
  • I have added tests that verify my changes
  • Unit tests pass locally with my changes
  • I have added documentation as necessary
  • No Javadoc warnings were introduced with my changes
  • No spotbugs warnings were introduced with my changes
  • Documentation in README has been updated as necessary
  • Online help has been added and reviewed for any new or modified fields
  • I have interactively tested my changes
  • Any dependent changes have been merged and published in upstream modules (like git-client-plugin)

Types of changes

  • New feature (non-breaking change which adds functionality)

@github-actions github-actions bot added the dependencies Dependency related change label May 31, 2022
@github-actions github-actions bot added the test label Jun 8, 2022
@Hrushi20 Hrushi20 closed this Jun 10, 2022
@Hrushi20 Hrushi20 reopened this Jun 12, 2022
@Hrushi20
Copy link
Author

Thank You @MarkEWaite for fixing those tests.

@MarkEWaite MarkEWaite changed the title Jenkins 13493 Jenkins 13493 - Automatic git cache maintenance Jun 20, 2022
@Hrushi20 Hrushi20 closed this Jun 26, 2022
@Hrushi20 Hrushi20 reopened this Jun 26, 2022
@Hrushi20 Hrushi20 closed this Jul 8, 2022
@Hrushi20 Hrushi20 reopened this Jul 8, 2022
@@ -1253,6 +1274,7 @@ protected static File getCacheDir(String cacheEntry, boolean createDirectory) {
if (!cacheDir.isDirectory()) {
if (createDirectory) {
boolean ok = cacheDir.mkdirs();
cacheEntries.add(cacheEntry);
Copy link
Contributor

Choose a reason for hiding this comment

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

would this not add invalid cache directory entry to the static map?

Suggested change
cacheEntries.add(cacheEntry);
if (ok) {
cacheEntries.add(cacheEntry);
} else {
LOGGER.log(Level.WARNING, "Failed mkdirs of {0}", cacheDir);
}

Copy link
Author

Choose a reason for hiding this comment

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

Fixed this issue. Thank You. My apologies for not observing it.


public static String checkSanity(String cron) throws ANTLRException {
try {
CronTab cronTab = new CronTab(cron.trim());
Copy link
Contributor

Choose a reason for hiding this comment

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

can the input string cron ever be null? It could be a potential NPE.

Copy link
Author

Choose a reason for hiding this comment

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

The cron string will not be null. If the user leave the text field blank in the UI, an empty string is passed to this method.

Copy link
Contributor

Choose a reason for hiding this comment

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

Needs a NonNull annotation to declare to spotbugs that the argument should never be allowed to be null.


lock.lock();
LOGGER.log(Level.FINE, "Cache " + cacheFile.getName() + " locked.");
executeMaintenanceTask(gitClient, taskType);
Copy link
Contributor

Choose a reason for hiding this comment

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

I have some concerns over this locking mechanism.

  • running a git maintenance task can be time intensive, locking a thread while others are waiting to acquire the lock might increase the number of waiting threads (need to take a jvm thread dump to analyse and confirm this)
  • we should try to reduce the scope of locking instead of locking the whole git maintenance process, i.e, identify the operations that need locking and only apply it conditionally
  • another strategy to use locks, lock.tryLock(time interval). This allows the waiting threads to wait for a certain time and move on if the subjected lock to be acquired is not free.


List<Task> configuredTasks = config.getMaintenanceTasks();
addTasksToQueue(configuredTasks);
// Option of Using the same thread for executing more maintenance task, or create a new thread the next minute and execute the maintenance task.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is interesting, would like to discuss this more in our weekly sync.

@MarkEWaite MarkEWaite added enhancement Improvement or new feature and removed dependencies Dependency related change test labels Sep 3, 2022
@github-actions github-actions bot added dependencies Dependency related change test labels Sep 3, 2022
pom.xml Outdated
Comment on lines 130 to 134
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.19</version>
</dependency>
Copy link
Contributor

Choose a reason for hiding this comment

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

The xstream API is already provided by Jenkins core without requiring the inclusion of a dependency. This needs to be removed. It causes several additional transitive dependencies to be included that should not be in the git plugin.

Suggested change
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.19</version>
</dependency>


public static String checkSanity(String cron) throws ANTLRException {
try {
CronTab cronTab = new CronTab(cron.trim());
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs a NonNull annotation to declare to spotbugs that the argument should never be allowed to be null.

@@ -0,0 +1,3 @@
<div>
Copy link
Contributor

Choose a reason for hiding this comment

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

@MarkEWaite needs to find the technique to add the help icon to the user interface. Users will expect to view help for the various maintenance commands.

@MarkEWaite
Copy link
Contributor

@Hrushi20 it appears there are testing failing in the CI job that were not failing before. I'm on vacation and won't be able to investigate for several weeks. If you have time over the next few weeks, it would be very nice if you could investigate the test failures.

@Hrushi20
Copy link
Author

Hrushi20 commented Oct 24, 2022

Sure @MarkEWaite I'll look into it. Enjoy your vacation.

@Hrushi20
Copy link
Author

Hrushi20 commented Oct 25, 2022

Hello @MarkEWaite, I have gone through the failed tests. I realized that the below code is not creating a cache on the Jenkins controller.

        sampleRepo1.init();
        sampleRepo1.git("checkout", "-b", "bug/JENKINS-42817");
        sampleRepo1.write("file", "modified");
        sampleRepo1.git("commit", "--all", "--message=dev");

        SCMFileSystem fs = SCMFileSystem.of(j.createFreeStyleProject(), new GitSCM(GitSCM.createRepoList(sampleRepo1.toString(), null), Collections.singletonList(new BranchSpec("*/bug/JENKINS-42817")), null, null, Collections.emptyList()));

Before I could access the caches, but now I am not able to create caches.
Also, Java 8 clears all the tests. Java 11 and Java 17 fails this test.

Is there a way to create a MultibranchPipeline so that it handle creating the caches.

@Hrushi20
Copy link
Author

Hello @MarkEWaite, can you help me fix these failing tests. The problem I am facing right now is that I am not able to create fake caches during tests.

@MarkEWaite
Copy link
Contributor

Hello @MarkEWaite, can you help me fix these failing tests. The problem I am facing right now is that I am not able to create fake caches during tests.

I won't be able to help with these tests until after I've completed the release of git client plugin 4.0.0 and git plugin 5.0.0. Those releases are getting all the time that I can allocate to the git plugin and git client plugin.

@github-actions github-actions bot removed the test label Jul 30, 2023
@Hrushi20
Copy link
Author

Hrushi20 commented Jul 30, 2023

Hey @MarkEWaite, incremental repack is failing. I'm getting task timeout error. Can you help me with that. I fixed all the other tests. Looking forward to getting this feature merged.

Hrushi20 and others added 26 commits December 10, 2023 12:49
remove unwanted test
Provided by Jenkins core, no need for a separate dependency.

Cause several other transitive dependencies to be included unnecessarily.
Let spotbugs help with checks for null pointer exceptions
See CONTRIBUTING file for rationale
Provides maintenance API
Signed-off-by: Hrushi20 <hrushikesh20thegreat@gmail.com>
Signed-off-by: Hrushi20 <hrushikesh20thegreat@gmail.com>
Signed-off-by: Hrushi20 <hrushikesh20thegreat@gmail.com>
Signed-off-by: Hrushi20 <hrushikesh20thegreat@gmail.com>
@Hrushi20
Copy link
Author

Hey @MarkEWaite, I've fixed all the Unit test Issues. I ran a git rebase and the code is up to date with latest master. There are 2 spotbug issues, I am facing. Should I use the Spotbug flag to neglect such an issue? Looking forward to getting this merged.

@Hrushi20
Copy link
Author

Hrushi20 commented Feb 3, 2024

Hey @MarkEWaite, can we get this code merged?

@MarkEWaite MarkEWaite removed the dependencies Dependency related change label Apr 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement or new feature
Projects
None yet
3 participants