@@ -60,13 +60,32 @@ public class TestCatalogJanitorCluster {
60
60
private static final TableName T1 = TableName .valueOf ("t1" );
61
61
private static final TableName T2 = TableName .valueOf ("t2" );
62
62
private static final TableName T3 = TableName .valueOf ("t3" );
63
+ private static final TableName T4 = TableName .valueOf ("t4" );
64
+ private static final TableName T5 = TableName .valueOf ("t5" );
63
65
64
66
@ Before
65
67
public void before () throws Exception {
66
68
TEST_UTIL .startMiniCluster ();
67
69
TEST_UTIL .createMultiRegionTable (T1 , new byte [][] {HConstants .CATALOG_FAMILY });
68
70
TEST_UTIL .createMultiRegionTable (T2 , new byte [][] {HConstants .CATALOG_FAMILY });
69
71
TEST_UTIL .createMultiRegionTable (T3 , new byte [][] {HConstants .CATALOG_FAMILY });
72
+
73
+ final byte [][] keysForT4 = {
74
+ Bytes .toBytes ("aa" ),
75
+ Bytes .toBytes ("bb" ),
76
+ Bytes .toBytes ("cc" ),
77
+ Bytes .toBytes ("dd" )
78
+ };
79
+
80
+ TEST_UTIL .createTable (T4 , HConstants .CATALOG_FAMILY , keysForT4 );
81
+
82
+ final byte [][] keysForT5 = {
83
+ Bytes .toBytes ("bb" ),
84
+ Bytes .toBytes ("cc" ),
85
+ Bytes .toBytes ("dd" )
86
+ };
87
+
88
+ TEST_UTIL .createTable (T5 , HConstants .CATALOG_FAMILY , keysForT5 );
70
89
}
71
90
72
91
@ After
@@ -141,7 +160,7 @@ public void testConsistency() throws IOException {
141
160
emptyInfoServerPut .addColumn (MetaTableAccessor .getCatalogFamily (),
142
161
MetaTableAccessor .getServerColumn (0 ), Bytes .toBytes ("" ));
143
162
MetaTableAccessor .putsToMetaTable (TEST_UTIL .getConnection (), Arrays .asList (emptyInfoServerPut ));
144
- gc = janitor .scan ();
163
+ janitor .scan ();
145
164
report = janitor .getLastReport ();
146
165
assertEquals (0 , report .getUnknownServers ().size ());
147
166
// Mke an empty regioninfo in t1.
@@ -150,9 +169,56 @@ public void testConsistency() throws IOException {
150
169
pEmptyRI .addColumn (MetaTableAccessor .getCatalogFamily (),
151
170
MetaTableAccessor .getRegionInfoColumn (), HConstants .EMPTY_BYTE_ARRAY );
152
171
MetaTableAccessor .putsToMetaTable (TEST_UTIL .getConnection (), Arrays .asList (pEmptyRI ));
153
- gc = janitor .scan ();
172
+ janitor .scan ();
154
173
report = janitor .getLastReport ();
155
174
assertEquals (1 , report .getEmptyRegionInfo ().size ());
175
+
176
+ int holesReported = report .getHoles ().size ();
177
+ int overlapsReported = report .getOverlaps ().size ();
178
+
179
+ // Test the case for T4
180
+ // r1: [aa, bb), r2: [cc, dd), r3: [a, cc)
181
+ // Make sure only overlaps and no holes are reported.
182
+ List <RegionInfo > t4Ris = MetaTableAccessor .getTableRegions (TEST_UTIL .getConnection (), T4 );
183
+ // delete the region [bb, cc)
184
+ MetaTableAccessor .deleteRegionInfo (TEST_UTIL .getConnection (), t4Ris .get (2 ));
185
+
186
+ // add a new region [a, cc)
187
+ RegionInfo newRiT4 = RegionInfoBuilder .newBuilder (T4 ).
188
+ setStartKey ("a" .getBytes ()).
189
+ setEndKey ("cc" .getBytes ()).build ();
190
+ Put putForT4 = MetaTableAccessor .makePutFromRegionInfo (newRiT4 , System .currentTimeMillis ());
191
+ MetaTableAccessor .putsToMetaTable (TEST_UTIL .getConnection (), Arrays .asList (putForT4 ));
192
+
193
+ janitor .scan ();
194
+ report = janitor .getLastReport ();
195
+ // there is no new hole reported, 2 more overLaps added.
196
+ assertEquals (holesReported , report .getHoles ().size ());
197
+ assertEquals (overlapsReported + 2 , report .getOverlaps ().size ());
198
+
199
+ holesReported = report .getHoles ().size ();
200
+ overlapsReported = report .getOverlaps ().size ();
201
+
202
+ // Test the case for T5
203
+ // r0: [, bb), r1: [a, g), r2: [bb, cc), r3: [dd, )
204
+ // Make sure only overlaps and no holes are reported.
205
+ List <RegionInfo > t5Ris = MetaTableAccessor .getTableRegions (TEST_UTIL .getConnection (), T5 );
206
+ // delete the region [cc, dd)
207
+ MetaTableAccessor .deleteRegionInfo (TEST_UTIL .getConnection (), t5Ris .get (2 ));
208
+
209
+ // add a new region [a, g)
210
+ RegionInfo newRiT5 = RegionInfoBuilder .newBuilder (T5 ).
211
+ setStartKey ("a" .getBytes ()).
212
+ setEndKey ("g" .getBytes ()).build ();
213
+ Put putForT5 = MetaTableAccessor .makePutFromRegionInfo (newRiT5 , System .currentTimeMillis ());
214
+ MetaTableAccessor .putsToMetaTable (TEST_UTIL .getConnection (), Arrays .asList (putForT5 ));
215
+
216
+ janitor .scan ();
217
+ report = janitor .getLastReport ();
218
+ // there is no new hole reported, 3 more overLaps added.
219
+ // ([a, g), [, bb)), ([a, g), [bb, cc)), ([a, g), [dd, ))
220
+ assertEquals (holesReported , report .getHoles ().size ());
221
+ assertEquals (overlapsReported + 3 , report .getOverlaps ().size ());
156
222
}
157
223
158
224
/**
0 commit comments