LuciferYang commented on code in PR #14926:
URL: https://github.com/apache/gravitino/pull/14926#discussion_r4546643007
##########
core/src/main/java/org/apache/gravitino/secret/SecretManager.java:
##########
@@ -484,23 +547,56 @@ public String alterSetProperty(
}
/**
- * Deletes write-through secret if owned by this entity; removes key from
properties.
+ * Collects a write-through secret for post-commit deletion and removes the
key from properties.
*
* @param properties mutable properties map updated as changes are applied
* @param entityType {@code catalog}, {@code schema}, or {@code fileset}
* @param entityId stable numeric entity id
* @param property property key to remove
+ * @param replacedVersions list that receives the current version to delete
after commit
*/
public void alterRemoveProperty(
- Map<String, String> properties, String entityType, long entityId, String
property) {
+ Map<String, String> properties,
+ String entityType,
+ long entityId,
+ String property,
+ List<SecretVersion> replacedVersions) {
Preconditions.checkArgument(StringUtils.isNotBlank(property), "property
must not be blank");
String current = properties.get(property);
if (SecretPropertyUtils.isWriteThroughForEntity(property, current,
entityType, entityId)) {
- deleteSecretsFromProperties(Map.of(property, current));
+ collectCurrentVersion(SecretUrn.parse(current), replacedVersions);
}
properties.remove(property);
}
+ private void collectCurrentVersion(SecretUrn urn, List<SecretVersion>
replacedVersions) {
+ String version =
registry.getProvider(urn.providerName()).currentSecretVersion(urn);
Review Comment:
Rotating, `setProperty` and removing a write-through secret now look up its
current version first (`collectCurrentVersion`), and that throws `Secret not
found` when the URN has no material. So an entity whose material is gone can no
longer be repaired or cleaned up: a same-provider rebind, `setProperty` or
`removeProperty` on that key fails on every retry. That covers every
write-through secret after a restart with the in-memory provider, material
deleted outside Gravitino, and entities already left dangling by #13439. This
is the Fork CI failure in `testCatalogManageableWhenSecretMissing`; on main the
rebind overwrote the URN and the remove was best effort.
When there is no current version, collect nothing. A remove then has nothing
to delete, and for a rebind or `setProperty` the new version can simply become
current, which `writeSecretVersion` already does when the URN is empty.
##########
core/src/main/java/org/apache/gravitino/secret/SecretManager.java:
##########
@@ -385,47 +435,58 @@ public String alterSetSecretBinding(
long entityId,
String property,
SecretBinding binding,
- List<SecretMaterial> written) {
+ List<SecretMaterial> written,
+ List<SecretVersion> pendingVersions,
+ List<SecretVersion> replacedVersions,
+ List<SecretUrn> replacedUrns) {
Preconditions.checkArgument(StringUtils.isNotBlank(property), "property
must not be blank");
Preconditions.checkArgument(binding != null, "binding must not be null");
SecretPropertyUtils.validateAlterSecretBindingPlaintext(binding.plaintext());
Map<String, SecretBinding> bindings = ImmutableMap.of(property, binding);
List<SecretUrn> urns = buildSecretBindingUrns(entityType, entityId,
bindings);
- String newUrn = urns.get(0).toString();
+ SecretUrn newUrn = urns.get(0);
String current = properties.get(property);
- if (current != null
- && !current.equals(newUrn)
- && SecretPropertyUtils.isWriteThroughForEntity(property, current,
entityType, entityId)) {
- deleteSecretsFromProperties(Map.of(property, current));
+ if (SecretPropertyUtils.isWriteThroughForEntity(property, current,
entityType, entityId)) {
Review Comment:
The bookkeeping is decided per change from the batch-local properties map,
so a batch that touches one key twice gets the wrong commit or rollback. After
`removeProperty(P)` or `setSecretReference(P)`, a same-provider
`setSecretBinding(P)` no longer sees P's URN and takes the first-bind branch:
`writeSecret` makes the new value current during prepare, and a failed alter's
`rollbackSecrets` deletes the whole URN, old version included, while the entity
still points at it.
Two shapes go wrong even when the alter succeeds. `[setSecretReference(P),
setSecretBinding(P, same provider)]` leaves P's final URN in `replacedUrns`, so
`commit()` deletes the secret the entity references. `[setSecretBinding(P),
removeProperty(P)]` deletes only the old version, so the removed plaintext
stays readable.
Same-key batches aren't rejected
(`testRemoveAndRebindKeepsRewrittenSecretAfterCommit` uses one). Could the
actions be derived per key from the batch's start and end values instead?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]