/
PartialIndexRebuilderIT.java
879 lines (826 loc) · 47.4 KB
/
PartialIndexRebuilderIT.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.phoenix.end2end.index;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTableInterface;
import org.apache.hadoop.hbase.client.Mutation;
import org.apache.hadoop.hbase.coprocessor.ObserverContext;
import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
import org.apache.hadoop.hbase.coprocessor.SimpleRegionObserver;
import org.apache.hadoop.hbase.regionserver.MiniBatchOperationInProgress;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.phoenix.end2end.BaseUniqueNamesOwnClusterIT;
import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
import org.apache.phoenix.query.ConnectionQueryServices;
import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.query.QueryServicesOptions;
import org.apache.phoenix.schema.PIndexState;
import org.apache.phoenix.schema.PMetaData;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTableKey;
import org.apache.phoenix.schema.TableNotFoundException;
import org.apache.phoenix.util.EnvironmentEdge;
import org.apache.phoenix.util.EnvironmentEdgeManager;
import org.apache.phoenix.util.IndexScrutiny;
import org.apache.phoenix.util.IndexUtil;
import org.apache.phoenix.util.MetaDataUtil;
import org.apache.phoenix.util.ReadOnlyProps;
import org.apache.phoenix.util.Repeat;
import org.apache.phoenix.util.RunUntilFailure;
import org.apache.phoenix.util.SchemaUtil;
import org.apache.phoenix.util.TestUtil;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import com.google.common.collect.Maps;
@RunWith(RunUntilFailure.class)
public class PartialIndexRebuilderIT extends BaseUniqueNamesOwnClusterIT {
private static final Random RAND = new Random(5);
private static final int WAIT_AFTER_DISABLED = 5000;
@BeforeClass
public static void doSetup() throws Exception {
Map<String, String> serverProps = Maps.newHashMapWithExpectedSize(10);
serverProps.put(QueryServices.INDEX_FAILURE_HANDLING_REBUILD_ATTRIB, Boolean.TRUE.toString());
serverProps.put(QueryServices.INDEX_FAILURE_HANDLING_REBUILD_INTERVAL_ATTRIB, "2000");
serverProps.put(QueryServices.INDEX_REBUILD_DISABLE_TIMESTAMP_THRESHOLD, "120000"); // give up rebuilding after 2 minutes
serverProps.put(QueryServices.INDEX_FAILURE_HANDLING_REBUILD_OVERLAP_FORWARD_TIME_ATTRIB, Long.toString(WAIT_AFTER_DISABLED));
setUpTestDriver(new ReadOnlyProps(serverProps.entrySet().iterator()), ReadOnlyProps.EMPTY_PROPS);
}
private static void mutateRandomly(final String fullTableName, final int nThreads, final int nRows, final int nIndexValues, final int batchSize, final CountDownLatch doneSignal) {
Runnable[] runnables = new Runnable[nThreads];
for (int i = 0; i < nThreads; i++) {
runnables[i] = new Runnable() {
@Override
public void run() {
try {
Connection conn = DriverManager.getConnection(getUrl());
for (int i = 0; i < 3000; i++) {
boolean isNull = RAND.nextBoolean();
int randInt = RAND.nextInt() % nIndexValues;
int pk = Math.abs(RAND.nextInt()) % nRows;
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES (" + pk + ", 0, " + (isNull ? null : randInt) + ")");
if ((i % batchSize) == 0) {
conn.commit();
}
}
conn.commit();
for (int i = 0; i < 3000; i++) {
int pk = Math.abs(RAND.nextInt()) % nRows;
conn.createStatement().execute("DELETE FROM " + fullTableName + " WHERE k1= " + pk + " AND k2=0");
if (i % batchSize == 0) {
conn.commit();
}
}
conn.commit();
for (int i = 0; i < 3000; i++) {
int randInt = RAND.nextInt() % nIndexValues;
int pk = Math.abs(RAND.nextInt()) % nRows;
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES (" + pk + ", 0, " + randInt + ")");
if ((i % batchSize) == 0) {
conn.commit();
}
}
conn.commit();
} catch (SQLException e) {
throw new RuntimeException(e);
} finally {
doneSignal.countDown();
}
}
};
}
for (int i = 0; i < nThreads; i++) {
Thread t = new Thread(runnables[i]);
t.start();
}
}
@Test
@Repeat(5)
public void testConcurrentUpsertsWithRebuild() throws Throwable {
int nThreads = 5;
final int batchSize = 200;
final int nRows = 51;
final int nIndexValues = 23;
final String schemaName = "";
final String tableName = generateUniqueName();
final String indexName = generateUniqueName();
final String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
final String fullIndexName = SchemaUtil.getTableName(schemaName, indexName);
Connection conn = DriverManager.getConnection(getUrl());
HTableInterface metaTable = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES);
conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k1 INTEGER NOT NULL, k2 INTEGER NOT NULL, v1 INTEGER, CONSTRAINT pk PRIMARY KEY (k1,k2)) STORE_NULLS=true, VERSIONS=1");
conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullTableName + "(v1)");
final CountDownLatch doneSignal1 = new CountDownLatch(nThreads);
mutateRandomly(fullTableName, nThreads, nRows, nIndexValues, batchSize, doneSignal1);
assertTrue("Ran out of time", doneSignal1.await(120, TimeUnit.SECONDS));
IndexUtil.updateIndexState(fullIndexName, EnvironmentEdgeManager.currentTimeMillis(), metaTable, PIndexState.DISABLE);
do {
final CountDownLatch doneSignal2 = new CountDownLatch(nThreads);
mutateRandomly(fullTableName, nThreads, nRows, nIndexValues, batchSize, doneSignal2);
assertTrue("Ran out of time", doneSignal2.await(500, TimeUnit.SECONDS));
} while (!TestUtil.checkIndexState(conn, fullIndexName, PIndexState.ACTIVE, 0L));
long actualRowCount = IndexScrutiny.scrutinizeIndex(conn, fullTableName, fullIndexName);
assertEquals(nRows, actualRowCount);
}
private static boolean mutateRandomly(Connection conn, String fullTableName, int nRows) throws Exception {
return mutateRandomly(conn, fullTableName, nRows, false, null);
}
private static boolean hasInactiveIndex(PMetaData metaCache, PTableKey key) throws TableNotFoundException {
PTable table = metaCache.getTableRef(key).getTable();
for (PTable index : table.getIndexes()) {
if (index.getIndexState() == PIndexState.ACTIVE) {
return true;
}
}
return false;
}
private static boolean hasDisabledIndex(PMetaData metaCache, PTableKey key) throws TableNotFoundException {
PTable table = metaCache.getTableRef(key).getTable();
for (PTable index : table.getIndexes()) {
if (index.getIndexState() == PIndexState.DISABLE) {
return true;
}
}
return false;
}
private static boolean mutateRandomly(Connection conn, String fullTableName, int nRows, boolean checkForInactive, String fullIndexName) throws SQLException, InterruptedException {
PTableKey key = new PTableKey(null,fullTableName);
PMetaData metaCache = conn.unwrap(PhoenixConnection.class).getMetaDataCache();
boolean hasInactiveIndex = false;
int batchSize = 200;
if (checkForInactive) {
batchSize = 3;
}
for (int i = 0; i < 10000; i++) {
int pk = Math.abs(RAND.nextInt()) % nRows;
int v1 = Math.abs(RAND.nextInt()) % nRows;
int v2 = Math.abs(RAND.nextInt()) % nRows;
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES(" + pk + "," + v1 + "," + v2 + ")");
if (i % batchSize == 0) {
conn.commit();
if (checkForInactive) {
if (hasInactiveIndex(metaCache, key)) {
checkForInactive = false;
hasInactiveIndex = true;
batchSize = 200;
}
}
}
}
conn.commit();
for (int i = 0; i < 10000; i++) {
int pk = Math.abs(RAND.nextInt()) % nRows;
conn.createStatement().execute("DELETE FROM " + fullTableName + " WHERE k= " + pk);
if (i % batchSize == 0) {
conn.commit();
if (checkForInactive) {
if (hasInactiveIndex(metaCache, key)) {
checkForInactive = false;
hasInactiveIndex = true;
batchSize = 200;
}
}
}
}
conn.commit();
for (int i = 0; i < 10000; i++) {
int pk = Math.abs(RAND.nextInt()) % nRows;
int v1 = Math.abs(RAND.nextInt()) % nRows;
int v2 = Math.abs(RAND.nextInt()) % nRows;
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES(" + pk + "," + v1 + "," + v2 + ")");
if (i % batchSize == 0) {
conn.commit();
if (checkForInactive) {
if (hasInactiveIndex(metaCache, key)) {
checkForInactive = false;
hasInactiveIndex = true;
batchSize = 200;
}
}
}
}
conn.commit();
return hasInactiveIndex;
}
@Test
public void testCompactionDuringRebuild() throws Throwable {
String schemaName = generateUniqueName();
String tableName = generateUniqueName();
String indexName1 = generateUniqueName();
String indexName2 = generateUniqueName();
final String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
String fullIndexName1 = SchemaUtil.getTableName(schemaName, indexName1);
String fullIndexName2 = SchemaUtil.getTableName(schemaName, indexName2);
final MyClock clock = new MyClock(1000);
// Use our own clock to prevent race between partial rebuilder and compaction
EnvironmentEdgeManager.injectEdge(clock);
try (Connection conn = DriverManager.getConnection(getUrl())) {
conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k INTEGER PRIMARY KEY, v1 INTEGER, v2 INTEGER) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true, GUIDE_POSTS_WIDTH=1000");
clock.time += 100;
conn.createStatement().execute("CREATE INDEX " + indexName1 + " ON " + fullTableName + " (v1) INCLUDE (v2)");
clock.time += 100;
conn.createStatement().execute("CREATE INDEX " + indexName2 + " ON " + fullTableName + " (v2) INCLUDE (v1)");
clock.time += 100;
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES(1, 2, 3)");
conn.commit();
clock.time += 100;
long disableTS = EnvironmentEdgeManager.currentTimeMillis();
HTableInterface metaTable = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES);
IndexUtil.updateIndexState(fullIndexName1, disableTS, metaTable, PIndexState.DISABLE);
IndexUtil.updateIndexState(fullIndexName2, disableTS, metaTable, PIndexState.DISABLE);
clock.time += 100;
TestUtil.doMajorCompaction(conn, fullIndexName1);
clock.time += 100;
assertTrue(TestUtil.checkIndexState(conn, fullIndexName1, PIndexState.DISABLE, 0L));
assertFalse(TestUtil.checkIndexState(conn, fullIndexName2, PIndexState.DISABLE, 0L));
TestUtil.doMajorCompaction(conn, fullTableName);
clock.time += 100;
assertTrue(TestUtil.checkIndexState(conn, fullIndexName2, PIndexState.DISABLE, 0L));
} finally {
EnvironmentEdgeManager.injectEdge(null);
}
}
@Test
@Repeat(5)
public void testDeleteAndUpsertAfterFailure() throws Throwable {
final int nRows = 10;
String schemaName = generateUniqueName();
String tableName = generateUniqueName();
String indexName = generateUniqueName();
final String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
String fullIndexName = SchemaUtil.getTableName(schemaName, indexName);
try (Connection conn = DriverManager.getConnection(getUrl())) {
conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k INTEGER PRIMARY KEY, v1 INTEGER, v2 INTEGER) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true");
conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullTableName + " (v1) INCLUDE (v2)");
mutateRandomly(conn, fullTableName, nRows);
long disableTS = EnvironmentEdgeManager.currentTimeMillis();
HTableInterface metaTable = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES);
IndexUtil.updateIndexState(fullIndexName, disableTS, metaTable, PIndexState.DISABLE);
mutateRandomly(conn, fullTableName, nRows);
TestUtil.waitForIndexRebuild(conn, fullIndexName, PIndexState.ACTIVE);
long actualRowCount = IndexScrutiny.scrutinizeIndex(conn, fullTableName, fullIndexName);
assertEquals(nRows,actualRowCount);
}
}
@Test
public void testWriteWhileRebuilding() throws Throwable {
final int nRows = 10;
String schemaName = generateUniqueName();
String tableName = generateUniqueName();
String indexName = generateUniqueName();
final String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
final String fullIndexName = SchemaUtil.getTableName(schemaName, indexName);
try (Connection conn = DriverManager.getConnection(getUrl())) {
conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k INTEGER PRIMARY KEY, v1 INTEGER, v2 INTEGER) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true");
conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullTableName + " (v1) INCLUDE (v2)");
mutateRandomly(conn, fullTableName, nRows);
HTableInterface metaTable = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES);
final boolean[] hasInactiveIndex = new boolean[1];
final CountDownLatch doneSignal = new CountDownLatch(1);
Runnable r = new Runnable() {
@Override
public void run() {
try (Connection conn = DriverManager.getConnection(getUrl())) {
hasInactiveIndex[0] = mutateRandomly(conn, fullTableName, nRows, true, fullIndexName);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
doneSignal.countDown();
}
}
};
Thread t = new Thread(r);
t.setDaemon(true);
t.start();
long disableTS = EnvironmentEdgeManager.currentTimeMillis();
IndexUtil.updateIndexState(fullIndexName, disableTS, metaTable, PIndexState.DISABLE);
TestUtil.waitForIndexRebuild(conn, fullIndexName, PIndexState.ACTIVE);
doneSignal.await(60, TimeUnit.SECONDS);
assertTrue(hasInactiveIndex[0]);
TestUtil.dumpIndexStatus(conn, fullIndexName);
long actualRowCount = IndexScrutiny.scrutinizeIndex(conn, fullTableName, fullIndexName);
assertEquals(nRows,actualRowCount);
}
}
@Test
public void testMultiVersionsAfterFailure() throws Throwable {
String schemaName = generateUniqueName();
String tableName = generateUniqueName();
String indexName = generateUniqueName();
String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
String fullIndexName = SchemaUtil.getTableName(schemaName, indexName);
try (Connection conn = DriverManager.getConnection(getUrl())) {
conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v VARCHAR) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true");
conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullTableName + " (v)");
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','bb')");
conn.commit();
long disableTS = EnvironmentEdgeManager.currentTimeMillis();
HTableInterface metaTable = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES);
IndexUtil.updateIndexState(fullIndexName, disableTS, metaTable, PIndexState.DISABLE);
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','ccc')");
conn.commit();
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','dddd')");
conn.commit();
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','eeeee')");
conn.commit();
TestUtil.waitForIndexRebuild(conn, fullIndexName, PIndexState.ACTIVE);
IndexScrutiny.scrutinizeIndex(conn, fullTableName, fullIndexName);
}
}
@Test
public void testUpsertNullAfterFailure() throws Throwable {
String schemaName = generateUniqueName();
String tableName = generateUniqueName();
String indexName = generateUniqueName();
String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
String fullIndexName = SchemaUtil.getTableName(schemaName, indexName);
try (Connection conn = DriverManager.getConnection(getUrl())) {
conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v VARCHAR) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true");
conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullTableName + " (v)");
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','a')");
conn.commit();
long disableTS = EnvironmentEdgeManager.currentTimeMillis();
HTableInterface metaTable = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES);
IndexUtil.updateIndexState(fullIndexName, disableTS, metaTable, PIndexState.DISABLE);
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a',null)");
conn.commit();
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','bb')");
conn.commit();
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','ccc')");
conn.commit();
TestUtil.waitForIndexRebuild(conn, fullIndexName, PIndexState.ACTIVE);
IndexScrutiny.scrutinizeIndex(conn, fullTableName, fullIndexName);
}
}
@Test
public void testUpsertNullTwiceAfterFailure() throws Throwable {
String schemaName = generateUniqueName();
String tableName = generateUniqueName();
String indexName = generateUniqueName();
String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
String fullIndexName = SchemaUtil.getTableName(schemaName, indexName);
try (Connection conn = DriverManager.getConnection(getUrl())) {
conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v VARCHAR) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true");
conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullTableName + " (v)");
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a',null)");
conn.commit();
long disableTS = EnvironmentEdgeManager.currentTimeMillis();
HTableInterface metaTable = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES);
IndexUtil.updateIndexState(fullIndexName, disableTS, metaTable, PIndexState.DISABLE);
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','bb')");
conn.commit();
conn.createStatement().execute("DELETE FROM " + fullTableName);
conn.commit();
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a',null)");
conn.commit();
TestUtil.waitForIndexRebuild(conn, fullIndexName, PIndexState.ACTIVE);
IndexScrutiny.scrutinizeIndex(conn, fullTableName, fullIndexName);
}
}
@Test
public void testDeleteAfterFailure() throws Throwable {
String schemaName = generateUniqueName();
String tableName = generateUniqueName();
String indexName = generateUniqueName();
String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
String fullIndexName = SchemaUtil.getTableName(schemaName, indexName);
try (Connection conn = DriverManager.getConnection(getUrl())) {
conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v VARCHAR) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true");
conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullTableName + " (v)");
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a',null)");
conn.commit();
long disableTS = EnvironmentEdgeManager.currentTimeMillis();
HTableInterface metaTable = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES);
IndexUtil.updateIndexState(fullIndexName, disableTS, metaTable, PIndexState.DISABLE);
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','b')");
conn.commit();
conn.createStatement().execute("DELETE FROM " + fullTableName);
conn.commit();
TestUtil.waitForIndexRebuild(conn, fullIndexName, PIndexState.ACTIVE);
IndexScrutiny.scrutinizeIndex(conn, fullTableName, fullIndexName);
}
}
@Test
public void testDeleteBeforeFailure() throws Throwable {
String schemaName = generateUniqueName();
String tableName = generateUniqueName();
String indexName = generateUniqueName();
String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
String fullIndexName = SchemaUtil.getTableName(schemaName, indexName);
try (Connection conn = DriverManager.getConnection(getUrl())) {
conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v VARCHAR) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true");
conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullTableName + " (v)");
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a',null)");
conn.commit();
conn.createStatement().execute("DELETE FROM " + fullTableName);
conn.commit();
long disableTS = EnvironmentEdgeManager.currentTimeMillis();
HTableInterface metaTable = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES);
IndexUtil.updateIndexState(fullIndexName, disableTS, metaTable, PIndexState.DISABLE);
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','b')");
conn.commit();
TestUtil.waitForIndexRebuild(conn, fullIndexName, PIndexState.ACTIVE);
IndexScrutiny.scrutinizeIndex(conn, fullTableName, fullIndexName);
}
}
private static class MyClock extends EnvironmentEdge {
public volatile long time;
public MyClock (long time) {
this.time = time;
}
@Override
public long currentTime() {
return time;
}
}
@Test
public void testMultiValuesAtSameTS() throws Throwable {
String schemaName = generateUniqueName();
String tableName = generateUniqueName();
String indexName = generateUniqueName();
final String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
final String fullIndexName = SchemaUtil.getTableName(schemaName, indexName);
final MyClock clock = new MyClock(1000);
EnvironmentEdgeManager.injectEdge(clock);
try (Connection conn = DriverManager.getConnection(getUrl())) {
conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v VARCHAR) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true");
clock.time += 100;
conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullTableName + " (v)");
clock.time += 100;
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','a')");
conn.commit();
clock.time += 100;
HTableInterface metaTable = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES);
IndexUtil.updateIndexState(fullIndexName, clock.currentTime(), metaTable, PIndexState.DISABLE);
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','bb')");
conn.commit();
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','ccc')");
conn.commit();
clock.time += 1000;
advanceClockUntilPartialRebuildStarts(fullIndexName, clock);
TestUtil.waitForIndexRebuild(conn, fullIndexName, PIndexState.ACTIVE);
clock.time += 100;
IndexScrutiny.scrutinizeIndex(conn, fullTableName, fullIndexName);
} finally {
EnvironmentEdgeManager.injectEdge(null);
}
}
@Test
public void testSeparateTimeBatchesRequired() throws Throwable {
String schemaName = generateUniqueName();
String tableName = generateUniqueName();
String indexName = generateUniqueName();
final String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
final String fullIndexName = SchemaUtil.getTableName(schemaName, indexName);
PTableKey key = new PTableKey(null,fullTableName);
final MyClock clock = new MyClock(1000);
EnvironmentEdgeManager.injectEdge(clock);
try (Connection conn = DriverManager.getConnection(getUrl())) {
PMetaData metaCache = conn.unwrap(PhoenixConnection.class).getMetaDataCache();
conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true");
clock.time += 100;
conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullTableName + " (v1, v2)");
clock.time += 100;
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','a','0')");
conn.commit();
clock.time += 100;
HTableInterface metaTable = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES);
IndexUtil.updateIndexState(fullIndexName, 0L, metaTable, PIndexState.DISABLE);
clock.time += 100;
long disableTime = clock.currentTime();
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('b','bb', '11')");
conn.commit();
clock.time += 100;
assertTrue(hasDisabledIndex(metaCache, key));
assertEquals(2,TestUtil.getRowCount(conn, fullTableName));
assertEquals(1,TestUtil.getRowCount(conn, fullIndexName));
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','ccc','0')");
conn.commit();
clock.time += 100;
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','a')");
conn.commit();
clock.time += 100;
IndexUtil.updateIndexState(fullIndexName, disableTime, metaTable, PIndexState.DISABLE);
clock.time += 100;
advanceClockUntilPartialRebuildStarts(fullIndexName, clock);
TestUtil.waitForIndexRebuild(conn, fullIndexName, PIndexState.ACTIVE);
clock.time += 100;
IndexScrutiny.scrutinizeIndex(conn, fullTableName, fullIndexName);
} finally {
EnvironmentEdgeManager.injectEdge(null);
}
}
@Test
public void testMultiValuesWhenDisableAndInactive() throws Throwable {
String schemaName = generateUniqueName();
String tableName = generateUniqueName();
String indexName = generateUniqueName();
final String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
final String fullIndexName = SchemaUtil.getTableName(schemaName, indexName);
PTableKey key = new PTableKey(null,fullTableName);
final MyClock clock = new MyClock(1000);
EnvironmentEdgeManager.injectEdge(clock);
try (Connection conn = DriverManager.getConnection(getUrl())) {
PMetaData metaCache = conn.unwrap(PhoenixConnection.class).getMetaDataCache();
conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR, v3 VARCHAR) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true");
clock.time += 100;
conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullTableName + " (v1, v2) INCLUDE (v3)");
clock.time += 100;
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','a','0','x')");
conn.commit();
clock.time += 100;
try (HTableInterface metaTable = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES)) {
// By using an INDEX_DISABLE_TIMESTAMP of 0, we prevent the partial index rebuilder from triggering
IndexUtil.updateIndexState(fullIndexName, 0L, metaTable, PIndexState.DISABLE);
clock.time += 100;
long disableTime = clock.currentTime();
// Set some values while index disabled
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('b','bb', '11','yy')");
conn.commit();
clock.time += 100;
assertTrue(hasDisabledIndex(metaCache, key));
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','ccc','222','zzz')");
conn.commit();
clock.time += 100;
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','dddd','3333','zzzz')");
conn.commit();
clock.time += 100;
// Will cause partial index rebuilder to be triggered
IndexUtil.updateIndexState(fullIndexName, disableTime, metaTable, PIndexState.DISABLE);
}
final CountDownLatch doneSignal = new CountDownLatch(1);
advanceClockUntilPartialRebuildStarts(fullIndexName, clock, doneSignal);
doneSignal.await(30, TimeUnit.SECONDS);
// Set some values while index is in INACTIVE state
clock.time += 100;
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','eeeee','44444','zzzzz')");
conn.commit();
clock.time += 100;
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','fffff','55555','zzzzzz')");
conn.commit();
clock.time += WAIT_AFTER_DISABLED;
// Enough time has passed, so rebuild will start now
TestUtil.waitForIndexRebuild(conn, fullIndexName, PIndexState.ACTIVE);
clock.time += 100;
IndexScrutiny.scrutinizeIndex(conn, fullTableName, fullIndexName);
} finally {
EnvironmentEdgeManager.injectEdge(null);
}
}
private final static CountDownLatch WAIT_FOR_REBUILD_TO_START = new CountDownLatch(1);
private final static CountDownLatch WAIT_FOR_INDEX_WRITE = new CountDownLatch(1);
@Test
public void testDisableIndexDuringRebuild() throws Throwable {
String schemaName = generateUniqueName();
String tableName = generateUniqueName();
String indexName = generateUniqueName();
final String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
final String fullIndexName = SchemaUtil.getTableName(schemaName, indexName);
PTableKey key = new PTableKey(null,fullTableName);
final MyClock clock = new MyClock(1000);
EnvironmentEdgeManager.injectEdge(clock);
try (Connection conn = DriverManager.getConnection(getUrl())) {
PMetaData metaCache = conn.unwrap(PhoenixConnection.class).getMetaDataCache();
conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR, v3 VARCHAR) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true");
clock.time += 100;
conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullTableName + " (v1, v2) INCLUDE (v3)");
clock.time += 100;
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','a','0','x')");
conn.commit();
clock.time += 100;
try (HTableInterface metaTable = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES)) {
// By using an INDEX_DISABLE_TIMESTAMP of 0, we prevent the partial index rebuilder from triggering
IndexUtil.updateIndexState(fullIndexName, 0L, metaTable, PIndexState.DISABLE);
clock.time += 100;
long disableTime = clock.currentTime();
// Set some values while index disabled
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('b','bb', '11','yy')");
conn.commit();
clock.time += 100;
assertTrue(hasDisabledIndex(metaCache, key));
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','ccc','222','zzz')");
conn.commit();
clock.time += 100;
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','dddd','3333','zzzz')");
conn.commit();
clock.time += 100;
// Will cause partial index rebuilder to be triggered
IndexUtil.updateIndexState(fullIndexName, disableTime, metaTable, PIndexState.DISABLE);
final CountDownLatch doneSignal = new CountDownLatch(1);
advanceClockUntilPartialRebuildStarts(fullIndexName, clock, doneSignal);
// Set some values while index is in INACTIVE state
clock.time += 100;
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','eeeee','44444','zzzzz')");
conn.commit();
clock.time += 100;
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','fffff','55555','zzzzzz')");
conn.commit();
doneSignal.await(30, TimeUnit.SECONDS);
// Install coprocessor that will simulate an index write failure during index rebuild
TestUtil.addCoprocessor(conn,fullIndexName,WriteFailingRegionObserver.class);
clock.time += WAIT_AFTER_DISABLED;
doneSignal.await(30, TimeUnit.SECONDS);
WAIT_FOR_REBUILD_TO_START.await(30, TimeUnit.SECONDS);
// By using an INDEX_DISABLE_TIMESTAMP of 0, we prevent the partial index rebuilder from triggering
IndexUtil.updateIndexState(fullIndexName, 0L, metaTable, PIndexState.DISABLE);
clock.time += 100;
disableTime = clock.currentTime();
// Set some values while index disabled
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('b','bbbbb', '11','yy')");
conn.commit();
clock.time += 100;
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','cccccc','222','zzz')");
conn.commit();
clock.time += 100;
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','ddddddd','3333','zzzz')");
conn.commit();
clock.time += 100;
// Simulates another write failure. Should cause current run of rebuilder to fail and retry again later
IndexUtil.updateIndexState(fullIndexName, disableTime, metaTable, PIndexState.DISABLE);
removeWriteFailingCoprocessor(conn,fullIndexName);
WAIT_FOR_INDEX_WRITE.countDown();
}
// Original rebuilder should have failed
advanceClockUntilPartialRebuildStarts(fullIndexName, clock);
clock.time += WAIT_AFTER_DISABLED * 2;
// Enough time has passed, so rebuild will start now
TestUtil.waitForIndexRebuild(conn, fullIndexName, PIndexState.ACTIVE);
clock.time += 100;
IndexScrutiny.scrutinizeIndex(conn, fullTableName, fullIndexName);
} finally {
EnvironmentEdgeManager.injectEdge(null);
}
}
@Test
public void testDeleteAndUpsertValuesAtSameTS1() throws Throwable {
String schemaName = generateUniqueName();
String tableName = generateUniqueName();
String indexName = generateUniqueName();
final String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
final String fullIndexName = SchemaUtil.getTableName(schemaName, indexName);
final MyClock clock = new MyClock(1000);
EnvironmentEdgeManager.injectEdge(clock);
try (Connection conn = DriverManager.getConnection(getUrl())) {
conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v VARCHAR) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true");
clock.time += 100;
conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullTableName + " (v)");
clock.time += 100;
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','a')");
conn.commit();
clock.time += 100;
HTableInterface metaTable = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES);
IndexUtil.updateIndexState(fullIndexName, clock.currentTime(), metaTable, PIndexState.DISABLE);
conn.createStatement().execute("DELETE FROM " + fullTableName + " WHERE k='a'");
conn.commit();
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','ccc')");
conn.commit();
clock.time += 1000;
advanceClockUntilPartialRebuildStarts(fullIndexName, clock);
TestUtil.waitForIndexRebuild(conn, fullIndexName, PIndexState.ACTIVE);
clock.time += 100;
IndexScrutiny.scrutinizeIndex(conn, fullTableName, fullIndexName);
} finally {
EnvironmentEdgeManager.injectEdge(null);
}
}
@Test
public void testDeleteAndUpsertValuesAtSameTS2() throws Throwable {
String schemaName = generateUniqueName();
String tableName = generateUniqueName();
String indexName = generateUniqueName();
final String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
final String fullIndexName = SchemaUtil.getTableName(schemaName, indexName);
final MyClock clock = new MyClock(1000);
EnvironmentEdgeManager.injectEdge(clock);
try (Connection conn = DriverManager.getConnection(getUrl())) {
conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v VARCHAR) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true");
clock.time += 100;
conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullTableName + " (v)");
clock.time += 100;
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','a')");
conn.commit();
clock.time += 100;
HTableInterface metaTable = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES);
IndexUtil.updateIndexState(fullIndexName, clock.currentTime(), metaTable, PIndexState.DISABLE);
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','ccc')");
conn.commit();
conn.createStatement().execute("DELETE FROM " + fullTableName + " WHERE k='a'");
conn.commit();
clock.time += 1000;
advanceClockUntilPartialRebuildStarts(fullIndexName, clock);
TestUtil.waitForIndexRebuild(conn, fullIndexName, PIndexState.ACTIVE);
clock.time += 100;
IndexScrutiny.scrutinizeIndex(conn, fullTableName, fullIndexName);
} finally {
EnvironmentEdgeManager.injectEdge(null);
}
}
@Test
public void testRegionsOnlineCheck() throws Throwable {
String schemaName = generateUniqueName();
String tableName = generateUniqueName();
final String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
PTableKey key = new PTableKey(null,fullTableName);
try (Connection conn = DriverManager.getConnection(getUrl())) {
PMetaData metaCache = conn.unwrap(PhoenixConnection.class).getMetaDataCache();
conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY)");
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a')");
conn.commit();
Configuration conf = conn.unwrap(PhoenixConnection.class).getQueryServices().getConfiguration();
PTable table = metaCache.getTableRef(key).getTable();
assertTrue(MetaDataUtil.tableRegionsOnline(conf, table));
try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
admin.disableTable(fullTableName);
assertFalse(MetaDataUtil.tableRegionsOnline(conf, table));
admin.enableTable(fullTableName);
}
assertTrue(MetaDataUtil.tableRegionsOnline(conf, table));
}
}
private static void advanceClockUntilPartialRebuildStarts(final String fullIndexName, final MyClock clock) throws InterruptedException {
final CountDownLatch doneSignal = new CountDownLatch(1);
advanceClockUntilPartialRebuildStarts(fullIndexName, clock, doneSignal);
clock.time += WAIT_AFTER_DISABLED + 1000;
doneSignal.await(30, TimeUnit.SECONDS);
}
private static void advanceClockUntilPartialRebuildStarts(final String fullIndexName, final MyClock clock, final CountDownLatch doneSignal) {
Runnable r = new Runnable() {
@Override
public void run() {
try (Connection conn = DriverManager.getConnection(getUrl())) {
int nTries = 10;
while (--nTries >0 && !TestUtil.checkIndexState(conn, fullIndexName, PIndexState.INACTIVE, null)) {
Thread.sleep(1000);
clock.time += 1000;
}
doneSignal.countDown();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
Thread t = new Thread(r);
t.setDaemon(true);
t.start();
}
private static void removeWriteFailingCoprocessor(Connection conn, String tableName) throws Exception {
ConnectionQueryServices services = conn.unwrap(PhoenixConnection.class).getQueryServices();
HTableDescriptor descriptor = services.getTableDescriptor(Bytes.toBytes(tableName));
descriptor.removeCoprocessor(WriteFailingRegionObserver.class.getName());
int numTries = 10;
try (HBaseAdmin admin = services.getAdmin()) {
admin.modifyTable(Bytes.toBytes(tableName), descriptor);
while (!admin.getTableDescriptor(Bytes.toBytes(tableName)).equals(descriptor)
&& numTries > 0) {
numTries--;
if (numTries == 0) {
throw new Exception(
"Check to detect if delaying co-processor was removed failed after "
+ numTries + " retries.");
}
Thread.sleep(1000);
}
}
}
public static class WriteFailingRegionObserver extends SimpleRegionObserver {
@Override
public void postBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c, MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException {
WAIT_FOR_REBUILD_TO_START.countDown();
try {
WAIT_FOR_INDEX_WRITE.await(30, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Thread.interrupted();
throw new IOException(e);
}
}
}
}