-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure that content IDs are unique in a Nessie repository
Nessie content IDs are random IDs, but we do not guarantee that those are actually really unique. This change adds a new object type to ensure that a generated ID is unique by leveraging existing functionality of the `Persist` framework that already provides "`INSERT IF NOT EXIST`" guarantees. New content IDs from this change on are now verified. This change does not include functionality to automatically add already existing content-IDs. IMHO it is probably okay for now given the practically non-existing probability of content-ID conflicts.
- Loading branch information
Showing
16 changed files
with
257 additions
and
6 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
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
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
62 changes: 62 additions & 0 deletions
62
...common/src/main/java/org/projectnessie/versioned/storage/common/objtypes/UniqueIdObj.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,62 @@ | ||
/* | ||
* 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.versioned.storage.common.objtypes; | ||
|
||
import static org.projectnessie.versioned.storage.common.objtypes.Hashes.uniqueIdHash; | ||
|
||
import javax.annotation.Nullable; | ||
import org.immutables.value.Value; | ||
import org.projectnessie.versioned.storage.common.logic.ReferenceLogic; | ||
import org.projectnessie.versioned.storage.common.persist.Obj; | ||
import org.projectnessie.versioned.storage.common.persist.ObjId; | ||
import org.projectnessie.versioned.storage.common.persist.ObjType; | ||
import org.projectnessie.versioned.storage.common.persist.Persist; | ||
|
||
/** | ||
* Describes the <em>internal</em> state of a reference when it has been created, managed by {@link | ||
* ReferenceLogic} implementations, not available/tracked for transactional {@link Persist} | ||
* instances. | ||
*/ | ||
@Value.Immutable | ||
public interface UniqueIdObj extends Obj { | ||
|
||
@Override | ||
default ObjType type() { | ||
return ObjType.UNIQUE; | ||
} | ||
|
||
@Override | ||
@Value.Parameter(order = 1) | ||
@Nullable | ||
@jakarta.annotation.Nullable | ||
ObjId id(); | ||
|
||
/** The "ID space", for example {@code content-id}. */ | ||
@Value.Parameter(order = 2) | ||
String space(); | ||
|
||
/** The value of the ID within the {@link #space()}. */ | ||
@Value.Parameter(order = 3) | ||
String value(); | ||
|
||
static UniqueIdObj uniqueId(ObjId id, String space, String value) { | ||
return ImmutableUniqueIdObj.of(id, space, value); | ||
} | ||
|
||
static UniqueIdObj uniqueId(String space, String value) { | ||
return uniqueId(uniqueIdHash(space, value), space, value); | ||
} | ||
} |
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.