jerryshao commented on code in PR #14954:
URL: https://github.com/apache/gravitino/pull/14954#discussion_r4558835264
##########
core/src/main/java/org/apache/gravitino/catalog/SchemaOperationDispatcher.java:
##########
@@ -426,6 +434,9 @@ public Schema alterSchema(NameIdentifier ident,
SchemaChange... changes)
.build()),
"UPDATE",
schemaId);
+ // A null result is logged, and the entity may still reference the
released secrets.
+ secretManager.commitSecrets(
+ updatedSchemaEntity == null ? preparedSecrets.withoutReleased()
: preparedSecrets);
Review Comment:
In the external-schema path the catalog alter has already committed, so if
store.update throws on the line above, the written versions are neither
committed nor rolled back. The new versions leak and the secret keeps its old
value while the catalog has the new URN; wrap the update so a failure rolls
back the written versions.
##########
core/src/main/java/org/apache/gravitino/secret/SecretManager.java:
##########
@@ -323,6 +324,171 @@ public void rollbackSecrets(List<SecretMaterial>
secretMaterials) {
deleteSecrets(urns);
}
+ /**
+ * Makes the versions an alter wrote current and deletes the versions it
replaced.
+ *
+ * <p>Call only after the entity alter committed. Failures are logged and do
not fail the
+ * committed alter. If making a written version current fails, the version
that was current before
+ * it is not deleted and the written version stays in the provider; running
the same change again
+ * writes and promotes a new version.
+ *
+ * @param prepared secrets prepared by a {@code
SecretAlterChanges.prepare*Changes} method
+ */
+ public void commitSecrets(PreparedSecrets prepared) {
+ Preconditions.checkArgument(prepared != null, "prepared must not be null");
+ for (PreparedSecrets.WrittenVersion written : prepared.written()) {
+ // Without a previous version the write already made the new version
current.
+ if (written.previousId() == null) {
+ continue;
+ }
+ SecretUrn urn = written.version().urn();
+ SecretProvider provider;
+ try {
+ provider = registry.getProvider(urn.providerName());
+ provider.promoteSecretVersion(urn, written.version().id());
+ } catch (RuntimeException e) {
+ LOG.error(
+ "Failed to make version {} of secret {} current after the alter
committed; the"
Review Comment:
If promoting the new version fails, the alter is reported as successful but
readSecret still returns the old value, and the new version is never deleted.
Consider retrying or surfacing the failure, and at least delete the unpromoted
version, so callers are not silently left with a stale secret.
--
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]