singhpk234 commented on code in PR #18489:
URL: https://github.com/apache/iceberg/pull/18489#discussion_r4626463437


##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java:
##########
@@ -213,22 +212,16 @@ the table key parameter (along with existing snapshots) 
in the file, making the
               ? Integer.parseInt(dekLengthFromHMS)
               : TableProperties.ENCRYPTION_DEK_LENGTH_DEFAULT;
 
-      encryptedKeys =
-          Optional.ofNullable(current().encryptionKeys())
-              .map(Lists::newLinkedList)
-              .orElseGet(Lists::newLinkedList);
-
-      // Active transactions may still need keys that are not in committed 
metadata.
-      if (encryptionManager != null) {
-        Set<String> keyIdsFromMetadata =
-            
encryptedKeys.stream().map(EncryptedKey::keyId).collect(Collectors.toSet());
-
-        for (EncryptedKey keyFromEM : 
EncryptionUtil.encryptionKeys(encryptionManager).values()) {
-          if (!keyIdsFromMetadata.contains(keyFromEM.keyId())) {
-            encryptedKeys.add(keyFromEM);
-          }
-        }
-      }
+      // Open transactions may still need keys that are not in committed 
metadata. After an
+      // earlier refresh discarded the manager, those keys are only in 
encryptedKeys.
+      Iterable<EncryptedKey> knownKeys =

Review Comment:
   minor : how about activeKeys ? 



##########
spark/v4.0/spark/src/test/java/org/apache/iceberg/spark/sql/TestTableEncryption.java:
##########
@@ -185,6 +185,29 @@ void transactionCanReadAfterTableRefresh() {
     assertThat(currentDataFiles(table)).hasSize(dataFiles.size() + 1);
   }
 
+  @TestTemplate
+  void transactionCanReadAfterMetadataCommits() {
+    validationCatalog.initialize(catalogName, catalogConfig);
+    Table table = validationCatalog.loadTable(tableIdent);
+    List<DataFile> dataFiles = currentDataFiles(table);
+    DataFile file = dataFiles.get(0);
+
+    Transaction transaction = table.newTransaction();
+    transaction.newFastAppend().appendFile(file).commit();
+
+    // Commit twice to check that the transaction's keys survive back-to-back 
refreshes.
+    table.updateProperties().set("prop", "first").commit();
+    table.updateProperties().set("prop", "second").commit();
+
+    
assertThat(SnapshotChanges.builderFor(transaction.table()).build().addedDataFiles())
+        .extracting(DataFile::location)
+        .containsExactly(file.location());

Review Comment:
   what is assertion buying us ? 



##########
spark/v4.0/spark/src/test/java/org/apache/iceberg/spark/sql/TestTableEncryption.java:
##########
@@ -185,6 +185,29 @@ void transactionCanReadAfterTableRefresh() {
     assertThat(currentDataFiles(table)).hasSize(dataFiles.size() + 1);
   }
 
+  @TestTemplate
+  void transactionCanReadAfterMetadataCommits() {
+    validationCatalog.initialize(catalogName, catalogConfig);
+    Table table = validationCatalog.loadTable(tableIdent);
+    List<DataFile> dataFiles = currentDataFiles(table);
+    DataFile file = dataFiles.get(0);
+
+    Transaction transaction = table.newTransaction();
+    transaction.newFastAppend().appendFile(file).commit();
+
+    // Commit twice to check that the transaction's keys survive back-to-back 
refreshes.
+    table.updateProperties().set("prop", "first").commit();
+    table.updateProperties().set("prop", "second").commit();

Review Comment:
   can we more comments ? 
   
   for example first commit sets encryptionManager = null, but encryptionKeys 
at this point still tracks the active ML key 
   second one since encryption manager is null, encryptionKeys from transaction 
is not propagated, just table's current key survive ...
   
   then transaction commit and in the commit we see ML key has been lost ? 
   



##########
spark/v4.0/spark/src/test/java/org/apache/iceberg/spark/sql/TestTableEncryption.java:
##########
@@ -185,6 +185,29 @@ void transactionCanReadAfterTableRefresh() {
     assertThat(currentDataFiles(table)).hasSize(dataFiles.size() + 1);
   }
 
+  @TestTemplate
+  void transactionCanReadAfterMetadataCommits() {
+    validationCatalog.initialize(catalogName, catalogConfig);
+    Table table = validationCatalog.loadTable(tableIdent);
+    List<DataFile> dataFiles = currentDataFiles(table);
+    DataFile file = dataFiles.get(0);
+
+    Transaction transaction = table.newTransaction();
+    transaction.newFastAppend().appendFile(file).commit();

Review Comment:
   we are appending the same file again ? 



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to