-
Notifications
You must be signed in to change notification settings - Fork 119
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
Provide a way to remove old commits #681
Open
minwoox
wants to merge
19
commits into
line:main
Choose a base branch
from
minwoox:GitV2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b38014d
Provide a way to remove old commits
minwoox 9d5e250
WIP
minwoox c0bafb3
Add tests
minwoox 2f8e107
Fix test
minwoox 96fd44c
Close repo in test
minwoox e0a78f8
Address comments by @ikhoon
minwoox d241167
Merge branch 'master' into GitV2
minwoox 1c5185a
WIP
minwoox 7b21b1a
Introduce CreateRollingRepository command to create the rolling repos…
minwoox 958e7a9
Fix NonNullByDefault
minwoox cd622e4
WIP
minwoox 9fef35d
Address the comment by @jrhee17 and @ikhoon
minwoox a40a22d
Remove unused import
minwoox 23e329b
Merge branch 'master' into GitV2
minwoox ec5de1d
Fix test
minwoox b5f739f
Merge branch 'main' into GitV2
minwoox 02bcfe1
Merge branch 'main' into GitV2
minwoox 433dcb8
Refine
minwoox 84cb6cd
Merge branch 'main' into GitV2
minwoox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
common/src/main/java/com/linecorp/centraldogma/common/RolledRevisionAccessException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2018 LINE Corporation | ||
* | ||
* LINE Corporation licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package com.linecorp.centraldogma.common; | ||
|
||
/** | ||
* A {@link RevisionNotFoundException} that is raised when attempted to access a removed revision | ||
* by rolling repository. | ||
*/ | ||
public class RolledRevisionAccessException extends RevisionNotFoundException { | ||
|
||
private static final long serialVersionUID = -8291795114909224145L; | ||
|
||
/** | ||
* Creates a new instance. | ||
*/ | ||
public RolledRevisionAccessException(String message) { | ||
super(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
server/src/main/java/com/linecorp/centraldogma/server/CommitRetentionConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright 2021 LINE Corporation | ||
* | ||
* LINE Corporation licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package com.linecorp.centraldogma.server; | ||
|
||
import static com.google.common.base.MoreObjects.firstNonNull; | ||
import static com.google.common.base.MoreObjects.toStringHelper; | ||
import static com.google.common.base.Preconditions.checkArgument; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import com.cronutils.model.Cron; | ||
import com.cronutils.model.CronType; | ||
import com.cronutils.model.definition.CronDefinitionBuilder; | ||
import com.cronutils.parser.CronParser; | ||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import com.linecorp.centraldogma.server.storage.repository.Repository; | ||
|
||
/** | ||
* A configuration for retaining commits in a {@link Repository}. | ||
*/ | ||
public final class CommitRetentionConfig { | ||
|
||
// TODO(minwoox): Make this configurable. | ||
// The minimum of minRetentionCommits | ||
private static final int MINIMUM_MINIMUM_RETENTION_COMMITS = 5000; | ||
|
||
private static final String DEFAULT_SCHEDULE = "0 0 * * * ?"; // Every day | ||
private static final CronParser cronParser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor( | ||
CronType.QUARTZ)); | ||
|
||
private final int minRetentionCommits; | ||
private final int minRetentionDays; | ||
private final Cron schedule; | ||
|
||
/** | ||
* Creates a new instance. | ||
*/ | ||
@JsonCreator | ||
public CommitRetentionConfig(@JsonProperty("minRetentionCommits") int minRetentionCommits, | ||
@JsonProperty("minRetentionDays") int minRetentionDays, | ||
@JsonProperty("schedule") @Nullable String schedule) { | ||
checkArgument(minRetentionCommits == 0 || minRetentionCommits >= MINIMUM_MINIMUM_RETENTION_COMMITS, | ||
"minRetentionCommits: %s (expected: 0 || >= %s)", | ||
minRetentionCommits, MINIMUM_MINIMUM_RETENTION_COMMITS); | ||
checkArgument(minRetentionDays >= 0, | ||
"minRetentionDays: %s (expected: >= 0)", minRetentionDays); | ||
this.minRetentionCommits = minRetentionCommits; | ||
this.minRetentionDays = minRetentionDays; | ||
this.schedule = cronParser.parse(firstNonNull(schedule, DEFAULT_SCHEDULE)); | ||
} | ||
|
||
/** | ||
* Returns the minimum number of commits that a {@link Repository} should retain. {@code 0} means that | ||
* commits are not removed. | ||
*/ | ||
public int minRetentionCommits() { | ||
return minRetentionCommits; | ||
} | ||
|
||
/** | ||
* Returns the minimum number of days of a commit that a {@link Repository} should retain. | ||
*/ | ||
public int minRetentionDays() { | ||
return minRetentionDays; | ||
} | ||
|
||
/** | ||
* Returns the schedule of the job that removes old commits. | ||
*/ | ||
public Cron schedule() { | ||
return schedule; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return toStringHelper(this).add("minRetentionCommits", minRetentionCommits) | ||
.add("minRetentionDays", minRetentionDays) | ||
.add("schedule", schedule) | ||
.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Question) isn't it possible for
minRetentionDays
to be 0?