-
Notifications
You must be signed in to change notification settings - Fork 116
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
base: main
Are you sure you want to change the base?
Changes from all commits
b38014d
9d5e250
c0bafb3
2f8e107
96fd44c
e0a78f8
d241167
1c5185a
7b21b1a
958e7a9
cd622e4
9fef35d
a40a22d
23e329b
ec5de1d
b5f739f
02bcfe1
433dcb8
84cb6cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||
} | ||
} |
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)); | ||
} | ||
Check warning on line 65 in server/src/main/java/com/linecorp/centraldogma/server/CommitRetentionConfig.java
|
||
|
||
/** | ||
* 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(); | ||
Check warning on line 94 in server/src/main/java/com/linecorp/centraldogma/server/CommitRetentionConfig.java
|
||
} | ||
} |
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?