LuciferYang commented on code in PR #14954:
URL: https://github.com/apache/gravitino/pull/14954#discussion_r4560567510


##########
core/src/main/java/org/apache/gravitino/secret/SecretManager.java:
##########
@@ -323,6 +324,209 @@ 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 and the 
provider then reports it as
+   * current, the previous version is deleted; otherwise the written version 
is deleted. If the
+   * current version cannot be looked up, both versions are kept. 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 = null;
+      try {
+        provider = registry.getProvider(urn.providerName());
+        provider.promoteSecretVersion(urn, written.version().id());

Review Comment:
   Yes, it's intended. When promote runs, the entity alter has already 
committed, possibly with other changes in the same batch, so an error would 
report a failure for a change that took effect. Alter responses carry only the 
code and the altered entity, and the client methods return just the entity, so 
a warning needs an API change I'd keep out of this PR. The in-memory provider 
fails promote only when the written version is already gone, so retrying in 
`commitSecrets` would fail the same way. The ERROR log names the secret and the 
version, and running the same change again writes and promotes a new version. I 
can open a follow-up issue if you'd like the response to report it.



-- 
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]

Reply via email to