@@ -81,8 +81,13 @@ public void setUp() throws IOException {
81
81
82
82
private TableDescriptor getTableDesc (TableName tableName , int regionReplication ,
83
83
byte []... families ) {
84
- TableDescriptorBuilder builder =
85
- TableDescriptorBuilder .newBuilder (tableName ).setRegionReplication (regionReplication );
84
+ return getTableDesc (tableName , regionReplication , false , families );
85
+ }
86
+
87
+ private TableDescriptor getTableDesc (TableName tableName , int regionReplication , boolean readOnly ,
88
+ byte []... families ) {
89
+ TableDescriptorBuilder builder = TableDescriptorBuilder .newBuilder (tableName )
90
+ .setRegionReplication (regionReplication ).setReadOnly (readOnly );
86
91
Arrays .stream (families ).map (family -> ColumnFamilyDescriptorBuilder .newBuilder (family )
87
92
.setMaxVersions (Integer .MAX_VALUE ).build ()).forEachOrdered (builder ::setColumnFamily );
88
93
return builder .build ();
@@ -235,4 +240,47 @@ public void testIsStale() throws IOException {
235
240
// expected
236
241
}
237
242
}
243
+
244
+ @ Test
245
+ public void testRefreshReadOnlyTable () throws IOException {
246
+ int period = 0 ;
247
+ byte [][] families = new byte [][] { Bytes .toBytes ("cf" ) };
248
+ byte [] qf = Bytes .toBytes ("cq" );
249
+
250
+ HRegionServer regionServer = mock (HRegionServer .class );
251
+ List <HRegion > regions = new ArrayList <>();
252
+ when (regionServer .getOnlineRegionsLocalContext ()).thenReturn (regions );
253
+ when (regionServer .getConfiguration ()).thenReturn (TEST_UTIL .getConfiguration ());
254
+
255
+ TableDescriptor htd = getTableDesc (TableName .valueOf (name .getMethodName ()), 2 , families );
256
+ HRegion primary = initHRegion (htd , HConstants .EMPTY_START_ROW , HConstants .EMPTY_END_ROW , 0 );
257
+ HRegion replica1 = initHRegion (htd , HConstants .EMPTY_START_ROW , HConstants .EMPTY_END_ROW , 1 );
258
+ regions .add (primary );
259
+ regions .add (replica1 );
260
+
261
+ StorefileRefresherChore chore =
262
+ new StorefileRefresherChore (period , false , regionServer , new StoppableImplementation ());
263
+
264
+ // write some data to primary and flush
265
+ putData (primary , 0 , 100 , qf , families );
266
+ primary .flush (true );
267
+ verifyData (primary , 0 , 100 , qf , families );
268
+
269
+ verifyDataExpectFail (replica1 , 0 , 100 , qf , families );
270
+ chore .chore ();
271
+ verifyData (replica1 , 0 , 100 , qf , families );
272
+
273
+ // write some data to primary and flush before refresh the store files for the replica
274
+ putData (primary , 100 , 100 , qf , families );
275
+ primary .flush (true );
276
+ verifyData (primary , 0 , 200 , qf , families );
277
+
278
+ // then the table is set to readonly
279
+ htd = getTableDesc (TableName .valueOf (name .getMethodName ()), 2 , true , families );
280
+ primary .setTableDescriptor (htd );
281
+ replica1 .setTableDescriptor (htd );
282
+
283
+ chore .chore (); // we cannot refresh the store files
284
+ verifyDataExpectFail (replica1 , 100 , 100 , qf , families );
285
+ }
238
286
}
0 commit comments