LuciferYang commented on code in PR #14954:
URL: https://github.com/apache/gravitino/pull/14954#discussion_r4559924514
##########
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:
Done in dbe07bc4c: after a failed promote, `commitSecrets` asks the provider
for the current version. If the new version is current (a remote promote can
time out after taking effect), the previous version is deleted; otherwise the
new one is. If the lookup also fails, both are kept. The `promoteSecretVersion`
Javadoc now states the contract this relies on. I left retries to the provider,
which knows which errors are transient; the in-memory one only fails for an
unknown version. The alter still succeeds: the entity alter has already
committed, so an error would report a change that took effect, and retrying a
batch with a rename fails because the old name is gone. An ERROR is logged, and
running the same change again writes and promotes a new version.
--
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]