21
21
import com .starrocks .catalog .HiveTable ;
22
22
import com .starrocks .catalog .PrimitiveType ;
23
23
import com .starrocks .catalog .ScalarType ;
24
+ <<<<<<< HEAD
25
+ =======
26
+ import com .starrocks .catalog .Type ;
27
+ import com .starrocks .common .Config ;
28
+ >>>>>>> d24c364da6 ([Enhancement ] invalidate table cache after hive table do not need to refresh by ConnectorTableMetadataProcessor (#37549 ))
24
29
import com .starrocks .connector .MetastoreType ;
25
30
import com .starrocks .connector .PartitionUtil ;
26
31
import com .starrocks .connector .exception .StarRocksConnectorException ;
@@ -44,7 +49,7 @@ public class CachingHiveMetastoreTest {
44
49
private HiveMetaClient client ;
45
50
private HiveMetastore metastore ;
46
51
private ExecutorService executor ;
47
- private long expireAfterWriteSec = 10 ;
52
+ private long expireAfterWriteSec = 30 ;
48
53
private long refreshAfterWriteSec = -1 ;
49
54
50
55
@ Before
@@ -166,6 +171,49 @@ public void testRefreshTableSync() {
166
171
Assert .assertEquals (1 , cachingHiveMetastore .tableNameLockMap .size ());
167
172
}
168
173
174
+ @ Test
175
+ public void testRefreshTableBackground () throws InterruptedException {
176
+ CachingHiveMetastore cachingHiveMetastore = new CachingHiveMetastore (
177
+ metastore , executor , expireAfterWriteSec , refreshAfterWriteSec , 1000 , false );
178
+ Assert .assertFalse (cachingHiveMetastore .tableNameLockMap .containsKey (
179
+ HiveTableName .of ("db1" , "tbl1" )));
180
+ try {
181
+ // mock query table tbl1
182
+ List <String > partitionNames = cachingHiveMetastore .getPartitionKeysByValue ("db1" , "tbl1" ,
183
+ HivePartitionValue .ALL_PARTITION_VALUES );
184
+ cachingHiveMetastore .getPartitionsByNames ("db1" ,
185
+ "tbl1" , partitionNames );
186
+ // put table tbl1 in table cache
187
+ cachingHiveMetastore .refreshTable ("db1" , "tbl1" , true );
188
+ } catch (Exception e ) {
189
+ Assert .fail ();
190
+ }
191
+ Assert .assertTrue (cachingHiveMetastore .isTablePresent (HiveTableName .of ("db1" , "tbl1" )));
192
+
193
+ try {
194
+ cachingHiveMetastore .refreshTableBackground ("db1" , "tbl1" , true );
195
+ } catch (Exception e ) {
196
+ Assert .fail ();
197
+ }
198
+ // not skip refresh table, table cache still exist
199
+ Assert .assertTrue (cachingHiveMetastore .isTablePresent (HiveTableName .of ("db1" , "tbl1" )));
200
+ // sleep 1s, background refresh table will be skipped
201
+ Thread .sleep (1000 );
202
+ long oldValue = Config .background_refresh_metadata_time_secs_since_last_access_secs ;
203
+ // not refresh table, just skip refresh table
204
+ Config .background_refresh_metadata_time_secs_since_last_access_secs = 0 ;
205
+
206
+ try {
207
+ cachingHiveMetastore .refreshTableBackground ("db1" , "tbl1" , true );
208
+ } catch (Exception e ) {
209
+ Assert .fail ();
210
+ } finally {
211
+ Config .background_refresh_metadata_time_secs_since_last_access_secs = oldValue ;
212
+ }
213
+ // table cache will be removed because of skip refresh table
214
+ Assert .assertFalse (cachingHiveMetastore .isTablePresent (HiveTableName .of ("db1" , "tbl1" )));
215
+ }
216
+
169
217
@ Test
170
218
public void testRefreshHiveView () {
171
219
CachingHiveMetastore cachingHiveMetastore = new CachingHiveMetastore (
0 commit comments