@@ -154,7 +154,6 @@ public class FileStoreCommitImpl implements FileStoreCommit {
154154 @ Nullable private Long strictModeLastSafeSnapshot ;
155155 private final InternalRowPartitionComputer partitionComputer ;
156156 private final boolean rowTrackingEnabled ;
157- private final boolean isPkTable ;
158157 private final boolean deletionVectorsEnabled ;
159158 private final IndexFileHandler indexFileHandler ;
160159
@@ -194,7 +193,6 @@ public FileStoreCommitImpl(
194193 long commitMaxRetryWait ,
195194 @ Nullable Long strictModeLastSafeSnapshot ,
196195 boolean rowTrackingEnabled ,
197- boolean isPkTable ,
198196 boolean deletionVectorsEnabled ,
199197 IndexFileHandler indexFileHandler ) {
200198 this .snapshotCommit = snapshotCommit ;
@@ -240,7 +238,6 @@ public FileStoreCommitImpl(
240238 this .statsFileHandler = statsFileHandler ;
241239 this .bucketMode = bucketMode ;
242240 this .rowTrackingEnabled = rowTrackingEnabled ;
243- this .isPkTable = isPkTable ;
244241 this .deletionVectorsEnabled = deletionVectorsEnabled ;
245242 this .indexFileHandler = indexFileHandler ;
246243 }
@@ -728,23 +725,23 @@ private void collectChanges(
728725 .forEach (m -> appendChangelog .add (makeEntry (FileKind .ADD , commitMessage , m )));
729726 commitMessage
730727 .newFilesIncrement ()
731- .newIndexFiles ()
728+ .deletedIndexFiles ()
732729 .forEach (
733730 m ->
734731 appendIndexFiles .add (
735732 new IndexManifestEntry (
736- FileKind .ADD ,
733+ FileKind .DELETE ,
737734 commitMessage .partition (),
738735 commitMessage .bucket (),
739736 m )));
740737 commitMessage
741738 .newFilesIncrement ()
742- .deletedIndexFiles ()
739+ .newIndexFiles ()
743740 .forEach (
744741 m ->
745742 appendIndexFiles .add (
746743 new IndexManifestEntry (
747- FileKind .DELETE ,
744+ FileKind .ADD ,
748745 commitMessage .partition (),
749746 commitMessage .bucket (),
750747 m )));
@@ -766,23 +763,23 @@ private void collectChanges(
766763 .forEach (m -> compactChangelog .add (makeEntry (FileKind .ADD , commitMessage , m )));
767764 commitMessage
768765 .compactIncrement ()
769- .newIndexFiles ()
766+ .deletedIndexFiles ()
770767 .forEach (
771768 m ->
772769 compactIndexFiles .add (
773770 new IndexManifestEntry (
774- FileKind .ADD ,
771+ FileKind .DELETE ,
775772 commitMessage .partition (),
776773 commitMessage .bucket (),
777774 m )));
778775 commitMessage
779776 .compactIncrement ()
780- .deletedIndexFiles ()
777+ .newIndexFiles ()
781778 .forEach (
782779 m ->
783780 compactIndexFiles .add (
784781 new IndexManifestEntry (
785- FileKind .DELETE ,
782+ FileKind .ADD ,
786783 commitMessage .partition (),
787784 commitMessage .bucket (),
788785 m )));
@@ -1419,7 +1416,7 @@ private void noConflictsOrFail(
14191416 List <IndexManifestEntry > deltaIndexEntries ,
14201417 CommitKind commitKind ) {
14211418 String baseCommitUser = snapshot .commitUser ();
1422- if (checkForDeletionVector (commitKind )) {
1419+ if (checkForDeletionVector ()) {
14231420 // Enrich dvName in fileEntry to checker for base ADD dv and delta DELETE dv.
14241421 // For example:
14251422 // If the base file is <ADD baseFile1, ADD dv1>,
@@ -1443,52 +1440,72 @@ private void noConflictsOrFail(
14431440 List <SimpleFileEntry > allEntries = new ArrayList <>(baseEntries );
14441441 allEntries .addAll (deltaEntries );
14451442
1446- if (commitKind != CommitKind .OVERWRITE ) {
1447- // total buckets within the same partition should remain the same
1448- Map <BinaryRow , Integer > totalBuckets = new HashMap <>();
1449- for (SimpleFileEntry entry : allEntries ) {
1450- if (entry .totalBuckets () <= 0 ) {
1451- continue ;
1452- }
1453-
1454- if (!totalBuckets .containsKey (entry .partition ())) {
1455- totalBuckets .put (entry .partition (), entry .totalBuckets ());
1456- continue ;
1457- }
1458-
1459- int old = totalBuckets .get (entry .partition ());
1460- if (old == entry .totalBuckets ()) {
1461- continue ;
1462- }
1463-
1464- Pair <RuntimeException , RuntimeException > conflictException =
1465- createConflictException (
1466- "Total buckets of partition "
1467- + entry .partition ()
1468- + " changed from "
1469- + old
1470- + " to "
1471- + entry .totalBuckets ()
1472- + " without overwrite. Give up committing." ,
1473- baseCommitUser ,
1474- baseEntries ,
1475- deltaEntries ,
1476- null );
1477- LOG .warn ("" , conflictException .getLeft ());
1478- throw conflictException .getRight ();
1479- }
1480- }
1443+ checkBucketKeepSame (baseEntries , deltaEntries , commitKind , allEntries , baseCommitUser );
14811444
1445+ Function <Throwable , RuntimeException > conflictException =
1446+ conflictException (baseCommitUser , baseEntries , deltaEntries );
14821447 Collection <SimpleFileEntry > mergedEntries ;
14831448 try {
14841449 // merge manifest entries and also check if the files we want to delete are still there
14851450 mergedEntries = FileEntry .mergeEntries (allEntries );
14861451 } catch (Throwable e ) {
1487- throw conflictException (commitUser , baseEntries , deltaEntries ).apply (e );
1452+ throw conflictException .apply (e );
1453+ }
1454+
1455+ checkNoDeleteInMergedEntries (mergedEntries , conflictException );
1456+ checkKeyRangeNoConflicts (baseEntries , deltaEntries , mergedEntries , baseCommitUser );
1457+ }
1458+
1459+ private void checkBucketKeepSame (
1460+ List <SimpleFileEntry > baseEntries ,
1461+ List <SimpleFileEntry > deltaEntries ,
1462+ CommitKind commitKind ,
1463+ List <SimpleFileEntry > allEntries ,
1464+ String baseCommitUser ) {
1465+ if (commitKind == CommitKind .OVERWRITE ) {
1466+ return ;
14881467 }
14891468
1490- assertNoDelete (mergedEntries , conflictException (commitUser , baseEntries , deltaEntries ));
1469+ // total buckets within the same partition should remain the same
1470+ Map <BinaryRow , Integer > totalBuckets = new HashMap <>();
1471+ for (SimpleFileEntry entry : allEntries ) {
1472+ if (entry .totalBuckets () <= 0 ) {
1473+ continue ;
1474+ }
1475+
1476+ if (!totalBuckets .containsKey (entry .partition ())) {
1477+ totalBuckets .put (entry .partition (), entry .totalBuckets ());
1478+ continue ;
1479+ }
1480+
1481+ int old = totalBuckets .get (entry .partition ());
1482+ if (old == entry .totalBuckets ()) {
1483+ continue ;
1484+ }
1485+
1486+ Pair <RuntimeException , RuntimeException > conflictException =
1487+ createConflictException (
1488+ "Total buckets of partition "
1489+ + entry .partition ()
1490+ + " changed from "
1491+ + old
1492+ + " to "
1493+ + entry .totalBuckets ()
1494+ + " without overwrite. Give up committing." ,
1495+ baseCommitUser ,
1496+ baseEntries ,
1497+ deltaEntries ,
1498+ null );
1499+ LOG .warn ("" , conflictException .getLeft ());
1500+ throw conflictException .getRight ();
1501+ }
1502+ }
14911503
1504+ private void checkKeyRangeNoConflicts (
1505+ List <SimpleFileEntry > baseEntries ,
1506+ List <SimpleFileEntry > deltaEntries ,
1507+ Collection <SimpleFileEntry > mergedEntries ,
1508+ String baseCommitUser ) {
14921509 // fast exit for file store without keys
14931510 if (keyComparator == null ) {
14941511 return ;
@@ -1548,26 +1565,11 @@ private Function<Throwable, RuntimeException> conflictException(
15481565 };
15491566 }
15501567
1551- private boolean checkForDeletionVector (CommitKind commitKind ) {
1552- if (!deletionVectorsEnabled ) {
1553- return false ;
1554- }
1555-
1556- // todo: Add them once contains DELETE type.
1557- // PK table's compact dv index only contains ADD type, skip conflict detection.
1558- if (isPkTable && commitKind == CommitKind .COMPACT ) {
1559- return false ;
1560- }
1561-
1562- // Non-PK table's hash fixed bucket mode only contains ADD type, skip conflict detection.
1563- if (!isPkTable && bucketMode .equals (BucketMode .HASH_FIXED )) {
1564- return false ;
1565- }
1566-
1567- return true ;
1568+ private boolean checkForDeletionVector () {
1569+ return deletionVectorsEnabled && bucketMode .equals (BucketMode .BUCKET_UNAWARE );
15681570 }
15691571
1570- private void assertNoDelete (
1572+ private void checkNoDeleteInMergedEntries (
15711573 Collection <SimpleFileEntry > mergedEntries ,
15721574 Function <Throwable , RuntimeException > exceptionFunction ) {
15731575 try {
0 commit comments