-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Record previous HEADs of named references (#7607)
Persisted `Reference`s now keep a history of previous HEADs, limited in size and age, defaults to up to 20 elementa with a maximum age of 300 seconds. Exposes a new Nessie-API V2 endpoint to retrieve the status of a reference. The returned information contains a consistency status of the HEAD commit, the recorded recent HEADs and, if requested, a combined status for the recent commits in the commit log. This change also ensures that a "broken" reference can be re-assigned to another existing commit, and that it can be deleted.
- Loading branch information
Showing
61 changed files
with
3,065 additions
and
67 deletions.
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
39 changes: 39 additions & 0 deletions
39
api/client/src/main/java/org/projectnessie/client/api/ReferenceHistoryBuilder.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,39 @@ | ||
/* | ||
* Copyright (C) 2023 Dremio | ||
* | ||
* Licensed 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 | ||
* | ||
* http://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 org.projectnessie.client.api; | ||
|
||
import javax.annotation.Nullable; | ||
import javax.validation.constraints.NotNull; | ||
import javax.validation.constraints.Pattern; | ||
import org.projectnessie.error.NessieNotFoundException; | ||
import org.projectnessie.model.ReferenceHistoryResponse; | ||
import org.projectnessie.model.Validation; | ||
|
||
public interface ReferenceHistoryBuilder { | ||
ReferenceHistoryBuilder refName( | ||
@NotNull | ||
@jakarta.validation.constraints.NotNull | ||
@Pattern(regexp = Validation.REF_NAME_REGEX, message = Validation.REF_NAME_MESSAGE) | ||
@jakarta.validation.constraints.Pattern( | ||
regexp = Validation.REF_NAME_REGEX, | ||
message = Validation.REF_NAME_MESSAGE) | ||
String refName); | ||
|
||
ReferenceHistoryBuilder headCommitsToScan( | ||
@Nullable @jakarta.annotation.Nullable Integer headCommitsToScan); | ||
|
||
ReferenceHistoryResponse get() throws NessieNotFoundException; | ||
} |
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
57 changes: 57 additions & 0 deletions
57
api/client/src/main/java/org/projectnessie/client/rest/v2/HttpReferenceHistory.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,57 @@ | ||
/* | ||
* Copyright (C) 2020 Dremio | ||
* | ||
* Licensed 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 | ||
* | ||
* http://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 org.projectnessie.client.rest.v2; | ||
|
||
import org.projectnessie.client.api.ReferenceHistoryBuilder; | ||
import org.projectnessie.client.http.HttpClient; | ||
import org.projectnessie.error.NessieNotFoundException; | ||
import org.projectnessie.model.ReferenceHistoryResponse; | ||
|
||
final class HttpReferenceHistory implements ReferenceHistoryBuilder { | ||
|
||
private final HttpClient client; | ||
|
||
HttpReferenceHistory(HttpClient client) { | ||
this.client = client; | ||
} | ||
|
||
private String refName; | ||
private Integer headCommitsToScan; | ||
|
||
@Override | ||
public ReferenceHistoryBuilder refName(String refName) { | ||
this.refName = refName; | ||
return this; | ||
} | ||
|
||
@Override | ||
public ReferenceHistoryBuilder headCommitsToScan(Integer headCommitsToScan) { | ||
this.headCommitsToScan = headCommitsToScan; | ||
return this; | ||
} | ||
|
||
@Override | ||
public ReferenceHistoryResponse get() throws NessieNotFoundException { | ||
return client | ||
.newRequest() | ||
.path("trees/{ref}/recent-changes") | ||
.queryParam("scan-commits", headCommitsToScan) | ||
.resolveTemplate("ref", refName) | ||
.unwrap(NessieNotFoundException.class) | ||
.get() | ||
.readEntity(ReferenceHistoryResponse.class); | ||
} | ||
} |
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
79 changes: 79 additions & 0 deletions
79
api/model/src/main/java/org/projectnessie/api/v2/params/ReferenceHistoryParams.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,79 @@ | ||
/* | ||
* Copyright (C) 2022 Dremio | ||
* | ||
* Licensed 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 | ||
* | ||
* http://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 org.projectnessie.api.v2.params; | ||
|
||
import static org.projectnessie.api.v2.doc.ApiDoc.REF_GET_PARAMETER_DESCRIPTION; | ||
|
||
import javax.annotation.Nullable; | ||
import javax.validation.constraints.NotNull; | ||
import javax.validation.constraints.Pattern; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.QueryParam; | ||
import org.eclipse.microprofile.openapi.annotations.media.ExampleObject; | ||
import org.eclipse.microprofile.openapi.annotations.parameters.Parameter; | ||
import org.immutables.builder.Builder.Constructor; | ||
import org.projectnessie.model.Validation; | ||
|
||
public class ReferenceHistoryParams { | ||
|
||
@Parameter( | ||
description = REF_GET_PARAMETER_DESCRIPTION, | ||
examples = {@ExampleObject(ref = "ref"), @ExampleObject(ref = "refDefault")}) | ||
@PathParam("ref") | ||
@jakarta.ws.rs.PathParam("ref") | ||
@NotNull | ||
@jakarta.validation.constraints.NotNull | ||
@Pattern(regexp = Validation.REF_NAME_PATH_REGEX, message = Validation.REF_NAME_MESSAGE) | ||
@jakarta.validation.constraints.Pattern( | ||
regexp = Validation.REF_NAME_PATH_REGEX, | ||
message = Validation.REF_NAME_MESSAGE) | ||
private String ref; | ||
|
||
@Parameter( | ||
description = | ||
"Optional parameter, specifies the number of commits to scan from the reference's current HEAD, " | ||
+ "limited to the given amount of commits. Default is to not scan the commit log. The server " | ||
+ "may impose a hard limit on the amount of commits from the commit log.") | ||
@QueryParam("scan-commits") | ||
@jakarta.ws.rs.QueryParam("scan-commits") | ||
@Nullable | ||
@jakarta.annotation.Nullable | ||
private Integer headCommitsToScan; | ||
|
||
public ReferenceHistoryParams() {} | ||
|
||
@Constructor | ||
ReferenceHistoryParams( | ||
@NotNull @jakarta.validation.constraints.NotNull String ref, | ||
@Nullable @jakarta.annotation.Nullable Integer headCommitsToScan) { | ||
this.ref = ref; | ||
this.headCommitsToScan = headCommitsToScan; | ||
} | ||
|
||
@Nullable | ||
@jakarta.annotation.Nullable | ||
public Integer headCommitsToScan() { | ||
return headCommitsToScan; | ||
} | ||
|
||
public String getRef() { | ||
return ref; | ||
} | ||
|
||
public static ReferenceHistoryParamsBuilder builder() { | ||
return new ReferenceHistoryParamsBuilder(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
api/model/src/main/java/org/projectnessie/model/CommitConsistency.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,35 @@ | ||
/* | ||
* Copyright (C) 2023 Dremio | ||
* | ||
* Licensed 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 | ||
* | ||
* http://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 org.projectnessie.model; | ||
|
||
public enum CommitConsistency { | ||
// NOTE: the order of the values represents the "health" of a commit, best to worst. | ||
|
||
/** Consistency was not checked. */ | ||
NOT_CHECKED, | ||
/** The commit object, its index information and all reachable content is present. */ | ||
COMMIT_CONSISTENT, | ||
/** | ||
* The commit object is present and its index is accessible, but some content reachable from the | ||
* commit is not present. | ||
*/ | ||
COMMIT_CONTENT_INCONSISTENT, | ||
/** | ||
* The commit is inconsistent in a way that makes it impossible to access the commit, for example | ||
* if the commit object itself or its index information is missing. | ||
*/ | ||
COMMIT_INCONSISTENT | ||
} |
Oops, something went wrong.