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