@@ -816,7 +816,7 @@ public void testSnapshotPartitionLoadUsesCapturedAuthenticatorAndProjectionGener
816816 try (MockedStatic <IcebergUtils > icebergUtils = Mockito .mockStatic (
817817 IcebergUtils .class , Mockito .CALLS_REAL_METHODS )) {
818818 icebergUtils .when (() -> IcebergUtils .loadPartitionInfo (
819- tableIdentity , cache , "ice.db.tbl" , projectionTable , 11L , 3L , capturedAuthenticator , true , false ))
819+ "ice.db.tbl" , projectionTable , 11L , 3L , capturedAuthenticator , true , false ))
820820 .thenReturn (IcebergPartitionInfo .empty ());
821821 icebergUtils .when (() -> IcebergUtils .getNameMapping (projectionTable ))
822822 .thenReturn (Optional .empty ());
@@ -829,10 +829,10 @@ public void testSnapshotPartitionLoadUsesCapturedAuthenticatorAndProjectionGener
829829 null , false , capturedAuthenticator , true , false );
830830
831831 icebergUtils .verify (() -> IcebergUtils .loadPartitionInfo (
832- tableIdentity , cache , "ice.db.tbl" , projectionTable , 11L , 3L , capturedAuthenticator , true , false ), Mockito .never ());
832+ "ice.db.tbl" , projectionTable , 11L , 3L , capturedAuthenticator , true , false ), Mockito .never ());
833833 value .getPartitionInfo ();
834834 icebergUtils .verify (() -> IcebergUtils .loadPartitionInfo (
835- tableIdentity , cache , "ice.db.tbl" , projectionTable , 11L , 3L , capturedAuthenticator , true , false ));
835+ "ice.db.tbl" , projectionTable , 11L , 3L , capturedAuthenticator , true , false ));
836836 icebergUtils .verify (() -> IcebergUtils .isValidRelatedTable (projectionTable ));
837837 Mockito .verify (dorisTable , Mockito .never ()).isValidRelatedTable ();
838838 } finally {
@@ -867,9 +867,8 @@ private void assertMvBulkPartitionSnapshotsReuseUnadmittedView(Map<String, Strin
867867 ExecutionAuthenticator authenticator = new ExecutionAuthenticator () {};
868868 try (MockedStatic <IcebergUtils > utils = Mockito .mockStatic (IcebergUtils .class , Mockito .CALLS_REAL_METHODS )) {
869869 utils .when (() -> IcebergUtils .isValidRelatedTable (Mockito .any (Table .class ))).thenReturn (true );
870- utils .when (() -> IcebergUtils .loadPartitionInfo (Mockito .eq (identity ), Mockito .same (cache ),
871- Mockito .eq ("ice.db.tbl" ), Mockito .any (Table .class ), Mockito .anyLong (), Mockito .anyLong (),
872- Mockito .same (authenticator ), Mockito .eq (false ), Mockito .eq (false )))
870+ utils .when (() -> IcebergUtils .loadPartitionInfo (Mockito .eq ("ice.db.tbl" ), Mockito .any (Table .class ),
871+ Mockito .anyLong (), Mockito .anyLong (), Mockito .same (authenticator ), Mockito .eq (false ), Mockito .eq (false )))
873872 .thenAnswer (call -> {
874873 loads .incrementAndGet ();
875874 return info ;
@@ -957,9 +956,8 @@ public void testOldPartitionLoadsCannotRepublishAfterTableReplacement() throws E
957956 ExecutionAuthenticator authenticator = new ExecutionAuthenticator () {};
958957 try (MockedStatic <IcebergUtils > utils = Mockito .mockStatic (IcebergUtils .class , Mockito .CALLS_REAL_METHODS )) {
959958 utils .when (() -> IcebergUtils .isValidRelatedTable (Mockito .any (Table .class ))).thenReturn (true );
960- utils .when (() -> IcebergUtils .loadPartitionInfo (Mockito .eq (identity ), Mockito .same (cache ),
961- Mockito .eq ("ice.db.tbl" ), Mockito .any (Table .class ), Mockito .anyLong (), Mockito .anyLong (),
962- Mockito .same (authenticator ), Mockito .eq (false ), Mockito .eq (false )))
959+ utils .when (() -> IcebergUtils .loadPartitionInfo (Mockito .eq ("ice.db.tbl" ), Mockito .any (Table .class ),
960+ Mockito .anyLong (), Mockito .anyLong (), Mockito .same (authenticator ), Mockito .eq (false ), Mockito .eq (false )))
963961 .thenAnswer (call -> {
964962 loads .incrementAndGet ();
965963 if (replaceDuringLoad .getAndSet (false )) {
@@ -1058,6 +1056,83 @@ private IcebergSnapshotCacheValue partitionProjectionForTest(IcebergExternalMeta
10581056 retainedTable , retainedTable , null , false , authenticator , false , false );
10591057 }
10601058
1059+ @ Test
1060+ public void testLazyPartitionLoadSurvivesCatalogReset () throws Exception {
1061+ assertRetainedPartitionLoadAfterReset (false , false );
1062+ }
1063+
1064+ @ Test
1065+ public void testPartitionProjectionCreatedAfterCatalogReset () throws Exception {
1066+ assertRetainedPartitionLoadAfterReset (true , false );
1067+ }
1068+
1069+ @ Test
1070+ public void testSessionPartitionProjectionNeedsNoCatalogCacheGroup () throws Exception {
1071+ assertRetainedPartitionLoadAfterReset (true , true );
1072+ }
1073+
1074+ private void assertRetainedPartitionLoadAfterReset (boolean resetBeforeProjection , boolean sessionCatalog )
1075+ throws Exception {
1076+ ExecutorService executor = Executors .newSingleThreadExecutor ();
1077+ IcebergExternalMetaCache cache = new IcebergExternalMetaCache (executor );
1078+ NameMapping identity = NameMapping .createForTest (1L , "db" , "tbl" );
1079+ IcebergExternalTable dorisTable = partitionConsumerForTest (identity );
1080+ Schema schema = new Schema (Types .NestedField .optional (1 , "dt" , Types .DateType .get ()));
1081+ PartitionSpec spec = PartitionSpec .builderFor (schema ).day ("dt" ).build ();
1082+ String location = temporaryFolder .newFolder ("retained-partition-reset" ).toURI ().toString ();
1083+ Table table = new HadoopTables (new Configuration ()).create (schema , spec , location );
1084+ PartitionData partition = new PartitionData (spec .rawPartitionType ());
1085+ partition .set (0 , 19724 );
1086+ table .newFastAppend ().appendFile (DataFiles .builder (spec )
1087+ .withPath (location + "/data/old.parquet" ).withPartition (partition )
1088+ .withFileSizeInBytes (10 ).withRecordCount (1 ).build ()).commit ();
1089+ AtomicInteger authenticatedCalls = new AtomicInteger ();
1090+ ExecutionAuthenticator captured = new ExecutionAuthenticator () {
1091+ @ Override
1092+ public <T > T execute (Callable <T > action ) throws Exception {
1093+ authenticatedCalls .incrementAndGet ();
1094+ return action .call ();
1095+ }
1096+ };
1097+ IcebergTableCacheValue generation = new IcebergTableCacheValue (table );
1098+ try (IcebergTableCacheValue .Lease retained = generation .tryAcquire ();
1099+ MockedStatic <IcebergUtils > utils = Mockito .mockStatic (IcebergUtils .class , Mockito .CALLS_REAL_METHODS )) {
1100+ Assert .assertNotNull (retained );
1101+ utils .when (() -> IcebergUtils .useSessionCatalog (dorisTable )).thenReturn (sessionCatalog );
1102+ if (!sessionCatalog ) {
1103+ cache .initCatalog (1L , Collections .emptyMap ());
1104+ cache .entry (1L , IcebergExternalMetaCache .ENTRY_TABLE ,
1105+ NameMapping .class , IcebergTableCacheValue .class )
1106+ .put (identity , generation );
1107+ if (resetBeforeProjection ) {
1108+ cache .invalidateCatalog (1L );
1109+ }
1110+ }
1111+ IcebergSnapshotCacheValue projection = partitionProjectionForTest (
1112+ cache , dorisTable , retained .getIcebergTable (), captured );
1113+ Assert .assertEquals ("partition enumeration remains lazy" , 0 , authenticatedCalls .get ());
1114+ if (!resetBeforeProjection ) {
1115+ cache .invalidateCatalog (1L );
1116+ }
1117+ IcebergPartitionInfo info = projection .getPartitionInfo ();
1118+ Assert .assertEquals (1 , info .getNameToPartitionItem ().size ());
1119+ Assert .assertEquals (1 , info .getNameToIcebergPartition ().size ());
1120+ Assert .assertEquals (table .currentSnapshot ().snapshotId (),
1121+ info .getNameToIcebergPartition ().values ().iterator ().next ().getLastSnapshotId ());
1122+ Assert .assertTrue (authenticatedCalls .get () > 0 );
1123+ Mockito .verify (dorisTable .getCatalog (), Mockito .never ()).getExecutionAuthenticator ();
1124+ // Retired work must not populate the next catalog generation's budgeted entries.
1125+ cache .initCatalog (1L , Collections .emptyMap ());
1126+ Assert .assertNull (cache .entry (1L , IcebergExternalMetaCache .ENTRY_PARTITION ,
1127+ IcebergSnapshotEntryKey .class , IcebergPartitionInfo .class )
1128+ .peekIfPresent (IcebergSnapshotEntryKey .tryCreate (identity , table ).get ()));
1129+ } finally {
1130+ cache .close ();
1131+ generation .retire ();
1132+ executor .shutdownNow ();
1133+ }
1134+ }
1135+
10611136 @ Test
10621137 public void testPartitionViewLoadsOncePerPhysicalGenerationAndRefreshInvalidatesIt () throws Exception {
10631138 ExecutorService executor = Executors .newSingleThreadExecutor ();
@@ -1083,9 +1158,8 @@ public void testPartitionViewLoadsOncePerPhysicalGenerationAndRefreshInvalidates
10831158 loader .setAccessible (true );
10841159 try (MockedStatic <IcebergUtils > utils = Mockito .mockStatic (IcebergUtils .class , Mockito .CALLS_REAL_METHODS )) {
10851160 utils .when (() -> IcebergUtils .isValidRelatedTable (Mockito .any (Table .class ))).thenReturn (true );
1086- utils .when (() -> IcebergUtils .loadPartitionInfo (Mockito .eq (identity ), Mockito .same (cache ),
1087- Mockito .eq ("ice.db.tbl" ), Mockito .any (Table .class ), Mockito .anyLong (), Mockito .anyLong (),
1088- Mockito .same (authenticator ), Mockito .eq (false ), Mockito .eq (false )))
1161+ utils .when (() -> IcebergUtils .loadPartitionInfo (Mockito .eq ("ice.db.tbl" ), Mockito .any (Table .class ),
1162+ Mockito .anyLong (), Mockito .anyLong (), Mockito .same (authenticator ), Mockito .eq (false ), Mockito .eq (false )))
10891163 .thenAnswer (call -> {
10901164 loads .incrementAndGet ();
10911165 return IcebergPartitionInfo .empty ();
0 commit comments