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

Fetch only the recent commits when cloning a remote Git repository for mirroring #808

Merged
merged 4 commits into from
Mar 6, 2023

Conversation

thachlp
Copy link
Member

@thachlp thachlp commented Feb 21, 2023

Motivation

From jgit 6.3.x we can limit the fetch graph by setDepth, it will help improve performance.

Modification

  • Add new module server-jgit6 for jgit 6.x version.
  • Abstract GitWithAuth for support GitWithAuth5 and GitWithAuth6.
  • Add a new class GitWithAuth5 that implements GitWithAuth with jGit5.
  • Add a new class GitWithAuth6 that implements GitWithAuth with jGit6.
  • Adding an abstract method GitWithAuth.fetch(int depth) for adapting jgit update.

Result

  • We have jgit 6.x with performance improvement running on jre 11 and jgit 5.x for jre 8.

@CLAassistant
Copy link

CLAassistant commented Feb 21, 2023

CLA assistant check
All committers have signed the CLA.

@thachlp thachlp marked this pull request as draft February 21, 2023 04:40
@trustin
Copy link
Member

trustin commented Feb 22, 2023

As you told me via chat, jgit requires Java 11+. Central Dogma builds everything with Java 8, and thus we get compilation errors.

To fix this, we need to update the Java version from 8 to 11, but we cannot update the client library's Java version just yet, because many users are still using Java 8.

What's tricky about the upgrade is that our users sometimes pull in Central Dogma server as a dependency for testing purposes. We can't force them to upgrade their tests to Java 11.

Therefore, I'd like to suggest the following workaround:

  • Keep jGit version at 5.x
  • Call setDepth() using reflection.
    • If setDepth() method is not available, log a debug message.
  • Override the jGit version in the dependencies section of server/build.gradle only when rootProject.ext.testJavaVersion >= 11, e.g.
    dependencies {
      ...
      if (rootProject.ext.testJavaVersion >= 11) {
        testImplementation("....:jgit") {
          version {
              strictly "6.x.y"
          }
        }
      }
      ...
    }
  • See if your JUnit test is run with jGit 6, not 5.

What do you think?

@trustin
Copy link
Member

trustin commented Feb 23, 2023

I heard from @minwoox et al that there might be a few more breaking changes between jGit 5 and 6. Those changes are basically package renaming. Please let me know if you ever encounter such compilation or runtime error. We'll need to use reflection again there as well.

@minwoox
Copy link
Member

minwoox commented Feb 23, 2023

There were two classes when I was creating the PR: https://github.com/line/centraldogma/pull/702/files#diff-858d35514fceb503e11dca2402c0c61a0d21b4f3481d6955ba5af10391b069e7R44

We probably need two separate classes (e.g. GitWithAuthJGit5, GitWithAuthJGit6) and call them depending on the jGit version.

@thachlp
Copy link
Member Author

thachlp commented Feb 23, 2023

I heard from @minwoox et al that there might be a few more breaking changes between jGit 5 and 6. Those changes are basically package renaming. Please let me know if you ever encounter such compilation or runtime error. We'll need to use reflection again there as well.

Thanks @minwoox, yes @trustin, there are 2 classes I have updated in this pr too, I am dealing with it.

server-jgit6/build.gradle Outdated Show resolved Hide resolved
@trustin
Copy link
Member

trustin commented Feb 28, 2023

  1. Could you also try running GitWithAuthTest with the system properties explained here? https://github.com/trustin/centraldogma/blob/e93bc5a04eb3d38a0f315d9c5fdb0db3b0af1f52/it/src/test/java/com/linecorp/centraldogma/it/mirror/git/GitMirrorAuthTest.java#L65-L78 I already gave you the read permission to the test repository, so it should just work.
  2. Please add the test case that makes sure setDepth works as expected.

@codecov
Copy link

codecov bot commented Feb 28, 2023

Codecov Report

Patch coverage: 31.64% and project coverage change: -0.16 ⚠️

Comparison is base (6f13d12) 65.66% compared to head (25414f7) 65.50%.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #808      +/-   ##
============================================
- Coverage     65.66%   65.50%   -0.16%     
- Complexity     3292     3293       +1     
============================================
  Files           351      353       +2     
  Lines         13751    13796      +45     
  Branches       1491     1492       +1     
============================================
+ Hits           9029     9037       +8     
- Misses         3876     3909      +33     
- Partials        846      850       +4     
Impacted Files Coverage Δ
...traldogma/server/internal/mirror/Git5WithAuth.java 0.00% <0.00%> (ø)
...traldogma/server/internal/mirror/Git6WithAuth.java 43.75% <43.75%> (ø)
...centraldogma/server/internal/mirror/GitMirror.java 80.58% <71.42%> (-0.69%) ⬇️
...ntraldogma/server/internal/mirror/GitWithAuth.java 63.63% <100.00%> (+6.73%) ⬆️
...ient/armeria/legacy/LegacyCentralDogmaBuilder.java 81.48% <0.00%> (-3.71%) ⬇️
...centraldogma/server/internal/api/WatchService.java 76.27% <0.00%> (-3.39%) ⬇️
.../linecorp/centraldogma/client/AbstractWatcher.java 78.66% <0.00%> (+1.33%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@thachlp thachlp requested review from trustin and removed request for ikhoon, jrhee17 and minwoox March 1, 2023 10:19
@thachlp thachlp marked this pull request as ready for review March 2, 2023 10:17
@trustin
Copy link
Member

trustin commented Mar 2, 2023

So far so good! Could you:

  • Update dist/build.gradle so we use jGit6 in our tarball distribution?
    • Add evaluationDependsOn(':server-jgit6')
    • Add the following to task copyLib:
      from project(':server-jgit6').configurations.runtimeClasspath
      from project(':server-jgit6').tasks.jar
      
  • Remove the draft status from this pull request; and
  • Update the pull request subject and content?

@trustin trustin requested review from jrhee17 and ikhoon March 2, 2023 10:24
@trustin trustin added this to the 0.60.2 milestone Mar 2, 2023
@thachlp thachlp changed the title issue_801 Fetch only the recent commits when cloning a remote Git repository for mirroring Mar 2, 2023
@trustin
Copy link
Member

trustin commented Mar 2, 2023

Oh and please make sure the distribution directory (dist/build/dist/lib) populated by ./gradlew :dist:distDir contains the jgit 6 JAR file.

@thachlp
Copy link
Member Author

thachlp commented Mar 2, 2023

please make sure the distribution directory (dist/build/dist/lib) populated by ./gradlew :dist:distDir contains the jgit 6 JAR file.

OK, how can I do this?

Comment on lines 1 to 5
java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we set the Java version java11 flag instead which will automatically set the compile target version https://github.com/line/gradle-scripts#setting-a-target-version-with-the-javad-flag

Copy link
Contributor

@ikhoon ikhoon Mar 2, 2023

Choose a reason for hiding this comment

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

You need to update master branch first and refer to the following link as an example.
https://github.com/line/armeria/blob/ab7488bafc2912445f026fb6d02420f134937073/settings.gradle#L28

Copy link
Member Author

Choose a reason for hiding this comment

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

Hello, what do you mean about update master branch first, you mean create another pull request? I guess I need to update on /setting.gradle in this branch?

Copy link
Member

Choose a reason for hiding this comment

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

It looks like we can't use java11 flag in this case because other non-java11 modules optionally depends on it, e.g. :it and :dist.

Copy link
Member

Choose a reason for hiding this comment

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

I guess he meant doing git merge master in this PR. I did it for you 😉

Copy link
Contributor

Choose a reason for hiding this comment

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

It is likely we can fix buildJdkVersion to 17 and run tests with 8, 11, 17 to take advantage of javaN flag.

./gradlew test -PbuildJdkVersion=17 -PtestJavaVersion=8

Let me update actions_build.yml and gradle scripts and push them to this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Great! Thank you

@thachlp thachlp requested review from ikhoon and trustin and removed request for trustin, jrhee17 and ikhoon March 2, 2023 14:18
@ikhoon
Copy link
Contributor

ikhoon commented Mar 3, 2023

@thachlp Could you resolve the conflicts?

@thachlp
Copy link
Member Author

thachlp commented Mar 3, 2023

@thachlp Could you resolve the conflicts?

sure

@thachlp thachlp requested review from trustin and removed request for ikhoon March 3, 2023 07:21
Copy link
Member

@trustin trustin left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@ikhoon ikhoon left a comment

Choose a reason for hiding this comment

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

Thanks, @thachlp! 🚀🥳

Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

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

Looks good, left some minor comments/questions

@thachlp thachlp requested a review from jrhee17 March 3, 2023 09:25
Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

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

Verified the flaky tests CI job passes in my local. Thanks @thachlp ! 🙇 👍 🚀

@trustin trustin added this pull request to the merge queue Mar 6, 2023
Merged via the queue into line:master with commit 79221af Mar 6, 2023
@trustin trustin mentioned this pull request Mar 8, 2023
@thachlp thachlp deleted the issue_801 branch March 24, 2023 09:22
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.

Fetch only the recent commits when cloning a remote Git repository for mirroring
6 participants