-
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
Ensure that content IDs are unique in a Nessie repository #7757
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
81 changes: 81 additions & 0 deletions
81
...java/org/projectnessie/versioned/storage/cassandra/serializers/UniqueIdObjSerializer.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,81 @@ | ||
/* | ||
* 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.versioned.storage.cassandra.serializers; | ||
|
||
import static org.projectnessie.versioned.storage.cassandra.CassandraConstants.INSERT_OBJ_PREFIX; | ||
import static org.projectnessie.versioned.storage.cassandra.CassandraConstants.INSERT_OBJ_VALUES; | ||
import static org.projectnessie.versioned.storage.cassandra.CassandraConstants.STORE_OBJ_SUFFIX; | ||
import static org.projectnessie.versioned.storage.common.objtypes.UniqueIdObj.uniqueId; | ||
|
||
import com.datastax.oss.driver.api.core.cql.BoundStatementBuilder; | ||
import com.datastax.oss.driver.api.core.cql.Row; | ||
import com.google.common.collect.ImmutableSet; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import org.projectnessie.versioned.storage.cassandra.CqlColumn; | ||
import org.projectnessie.versioned.storage.cassandra.CqlColumnType; | ||
import org.projectnessie.versioned.storage.common.exceptions.ObjTooLargeException; | ||
import org.projectnessie.versioned.storage.common.objtypes.UniqueIdObj; | ||
import org.projectnessie.versioned.storage.common.persist.ObjId; | ||
|
||
public class UniqueIdObjSerializer implements ObjSerializer<UniqueIdObj> { | ||
|
||
public static final ObjSerializer<UniqueIdObj> INSTANCE = new UniqueIdObjSerializer(); | ||
|
||
private static final CqlColumn COL_UNIQUE_SPACE = new CqlColumn("u_space", CqlColumnType.VARCHAR); | ||
private static final CqlColumn COL_UNIQUE_VALUE = new CqlColumn("u_value", CqlColumnType.VARCHAR); | ||
|
||
private static final Set<CqlColumn> COLS = ImmutableSet.of(COL_UNIQUE_SPACE, COL_UNIQUE_VALUE); | ||
|
||
private static final String INSERT_CQL = | ||
INSERT_OBJ_PREFIX | ||
+ COLS.stream().map(CqlColumn::name).collect(Collectors.joining(",")) | ||
+ INSERT_OBJ_VALUES | ||
+ COLS.stream().map(c -> ":" + c.name()).collect(Collectors.joining(",")) | ||
+ ")"; | ||
|
||
private static final String STORE_CQL = INSERT_CQL + STORE_OBJ_SUFFIX; | ||
|
||
private UniqueIdObjSerializer() {} | ||
|
||
@Override | ||
public Set<CqlColumn> columns() { | ||
return COLS; | ||
} | ||
|
||
@Override | ||
public String insertCql(boolean upsert) { | ||
return upsert ? INSERT_CQL : STORE_CQL; | ||
} | ||
|
||
@SuppressWarnings("ResultOfMethodCallIgnored") | ||
@Override | ||
public void serialize( | ||
UniqueIdObj obj, | ||
BoundStatementBuilder stmt, | ||
int incrementalIndexLimit, | ||
int maxSerializedIndexSize) | ||
throws ObjTooLargeException { | ||
stmt.setString(COL_UNIQUE_SPACE.name(), obj.space()); | ||
stmt.setString(COL_UNIQUE_VALUE.name(), obj.value()); | ||
} | ||
|
||
@Override | ||
public UniqueIdObj deserialize(Row row, ObjId id) { | ||
return uniqueId( | ||
id, row.getString(COL_UNIQUE_SPACE.name()), row.getString(COL_UNIQUE_VALUE.name())); | ||
} | ||
} |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The javadoc seems to refer to |
||
* ReferenceLogic} implementations, not available/tracked for transactional {@link Persist} | ||
* instances. | ||
*/ | ||
@Value.Immutable | ||
public interface UniqueIdObj extends Obj { | ||
|
||
@Override | ||
default ObjType type() { | ||
return StandardObjType.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
Oops, something went wrong.
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.
One general remark: wouldn't it be simpler to model the value as an opaque byte array? It seems we could save some conversions to and from string in the common case where the value is an UUID.