1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.hadoop.hbase.regionserver;
22
23 import com.google.common.collect.ImmutableList;
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26
27 import org.apache.hadoop.conf.Configuration;
28 import org.apache.hadoop.fs.Path;
29 import org.apache.hadoop.hbase.HBaseConfiguration;
30 import org.apache.hadoop.hbase.HRegionInfo;
31 import org.apache.hadoop.hbase.HTableDescriptor;
32 import org.apache.hadoop.hbase.KeyValue;
33 import org.apache.hadoop.hbase.Coprocessor;
34 import org.apache.hadoop.hbase.CoprocessorEnvironment;
35 import org.apache.hadoop.hbase.HConstants;
36 import org.apache.hadoop.hbase.client.*;
37 import org.apache.hadoop.hbase.coprocessor.*;
38 import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
39 import org.apache.hadoop.hbase.filter.WritableByteArrayComparable;
40 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
41 import org.apache.hadoop.hbase.ipc.CoprocessorProtocol;
42 import org.apache.hadoop.hbase.regionserver.wal.HLogKey;
43 import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
44 import org.apache.hadoop.hbase.util.Bytes;
45 import org.apache.hadoop.util.StringUtils;
46
47 import java.io.IOException;
48 import java.util.*;
49 import java.util.regex.Matcher;
50
51
52
53
54
55 public class RegionCoprocessorHost
56 extends CoprocessorHost<RegionCoprocessorHost.RegionEnvironment> {
57
58 private static final Log LOG = LogFactory.getLog(RegionCoprocessorHost.class);
59
60
61
62
63 static class RegionEnvironment extends CoprocessorHost.Environment
64 implements RegionCoprocessorEnvironment {
65
66 private HRegion region;
67 private RegionServerServices rsServices;
68
69
70
71
72
73
74 public RegionEnvironment(final Coprocessor impl, final int priority,
75 final int seq, final Configuration conf, final HRegion region,
76 final RegionServerServices services) {
77 super(impl, priority, seq, conf);
78 this.region = region;
79 this.rsServices = services;
80 }
81
82
83 @Override
84 public HRegion getRegion() {
85 return region;
86 }
87
88
89 @Override
90 public RegionServerServices getRegionServerServices() {
91 return rsServices;
92 }
93
94 public void shutdown() {
95 super.shutdown();
96 }
97 }
98
99
100 RegionServerServices rsServices;
101
102 HRegion region;
103
104
105
106
107
108
109
110 public RegionCoprocessorHost(final HRegion region,
111 final RegionServerServices rsServices, final Configuration conf) {
112 this.rsServices = rsServices;
113 this.region = region;
114 this.pathPrefix = this.region.getRegionNameAsString().replace(',', '_');
115
116
117 loadSystemCoprocessors(conf, REGION_COPROCESSOR_CONF_KEY);
118
119
120 if (!HTableDescriptor.isMetaTable(region.getRegionInfo().getTableName())) {
121 loadSystemCoprocessors(conf, USER_REGION_COPROCESSOR_CONF_KEY);
122 }
123
124
125 loadTableCoprocessors(conf);
126 }
127
128 void loadTableCoprocessors(final Configuration conf) {
129
130
131 List<RegionEnvironment> configured = new ArrayList<RegionEnvironment>();
132 for (Map.Entry<ImmutableBytesWritable,ImmutableBytesWritable> e:
133 region.getTableDesc().getValues().entrySet()) {
134 String key = Bytes.toString(e.getKey().get()).trim();
135 String spec = Bytes.toString(e.getValue().get()).trim();
136 if (HConstants.CP_HTD_ATTR_KEY_PATTERN.matcher(key).matches()) {
137
138 try {
139 Matcher matcher = HConstants.CP_HTD_ATTR_VALUE_PATTERN.matcher(spec);
140 if (matcher.matches()) {
141
142
143 Path path = matcher.group(1).trim().isEmpty() ?
144 null : new Path(matcher.group(1).trim());
145 String className = matcher.group(2).trim();
146 int priority = matcher.group(3).trim().isEmpty() ?
147 Coprocessor.PRIORITY_USER : Integer.valueOf(matcher.group(3));
148 String cfgSpec = null;
149 try {
150 cfgSpec = matcher.group(4);
151 } catch (IndexOutOfBoundsException ex) {
152
153 }
154 if (cfgSpec != null) {
155 cfgSpec = cfgSpec.substring(cfgSpec.indexOf('|') + 1);
156 Configuration newConf = HBaseConfiguration.create(conf);
157 Matcher m = HConstants.CP_HTD_ATTR_VALUE_PARAM_PATTERN.matcher(cfgSpec);
158 while (m.find()) {
159 newConf.set(m.group(1), m.group(2));
160 }
161 configured.add(load(path, className, priority, newConf));
162 } else {
163 configured.add(load(path, className, priority, conf));
164 }
165 LOG.info("Load coprocessor " + className + " from HTD of " +
166 Bytes.toString(region.getTableDesc().getName()) +
167 " successfully.");
168 } else {
169 throw new RuntimeException("specification does not match pattern");
170 }
171 } catch (Exception ex) {
172 LOG.warn("attribute '" + key +
173 "' has invalid coprocessor specification '" + spec + "'");
174 LOG.warn(StringUtils.stringifyException(ex));
175 }
176 }
177 }
178
179 coprocessors.addAll(configured);
180 }
181
182 @Override
183 public RegionEnvironment createEnvironment(Class<?> implClass,
184 Coprocessor instance, int priority, int seq, Configuration conf) {
185
186
187
188
189
190 for (Class c : implClass.getInterfaces()) {
191 if (CoprocessorProtocol.class.isAssignableFrom(c)) {
192 region.registerProtocol(c, (CoprocessorProtocol)instance);
193 break;
194 }
195 }
196 return new RegionEnvironment(instance, priority, seq, conf, region,
197 rsServices);
198 }
199
200 @Override
201 protected void abortServer(final CoprocessorEnvironment env, final Throwable e) {
202 abortServer("regionserver", rsServices, env, e);
203 }
204
205
206
207
208
209
210
211
212
213
214
215
216 private void handleCoprocessorThrowableNoRethrow(
217 final CoprocessorEnvironment env, final Throwable e) {
218 try {
219 handleCoprocessorThrowable(env,e);
220 } catch (IOException ioe) {
221
222 LOG.warn("handleCoprocessorThrowable() threw an IOException while attempting to handle Throwable " + e
223 + ". Ignoring.",e);
224 }
225 }
226
227
228
229
230 public void preOpen() {
231 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
232 for (RegionEnvironment env: coprocessors) {
233 if (env.getInstance() instanceof RegionObserver) {
234 ctx = ObserverContext.createAndPrepare(env, ctx);
235 try {
236 ((RegionObserver)env.getInstance()).preOpen(ctx);
237 } catch (Throwable e) {
238 handleCoprocessorThrowableNoRethrow(env, e);
239 }
240 if (ctx.shouldComplete()) {
241 break;
242 }
243 }
244 }
245 }
246
247
248
249
250 public void postOpen() {
251 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
252 for (RegionEnvironment env: coprocessors) {
253 if (env.getInstance() instanceof RegionObserver) {
254 ctx = ObserverContext.createAndPrepare(env, ctx);
255 try {
256 ((RegionObserver)env.getInstance()).postOpen(ctx);
257 } catch (Throwable e) {
258 handleCoprocessorThrowableNoRethrow(env, e);
259 }
260 if (ctx.shouldComplete()) {
261 break;
262 }
263 }
264 }
265 }
266
267
268
269
270
271 public void preClose(boolean abortRequested) {
272 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
273 for (RegionEnvironment env: coprocessors) {
274 if (env.getInstance() instanceof RegionObserver) {
275 ctx = ObserverContext.createAndPrepare(env, ctx);
276 try {
277 ((RegionObserver)env.getInstance()).preClose(ctx, abortRequested);
278 } catch (Throwable e) {
279 handleCoprocessorThrowableNoRethrow(env, e);
280 }
281 }
282 }
283 }
284
285
286
287
288
289 public void postClose(boolean abortRequested) {
290 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
291 for (RegionEnvironment env: coprocessors) {
292 if (env.getInstance() instanceof RegionObserver) {
293 ctx = ObserverContext.createAndPrepare(env, ctx);
294 try {
295 ((RegionObserver)env.getInstance()).postClose(ctx, abortRequested);
296 } catch (Throwable e) {
297 handleCoprocessorThrowableNoRethrow(env, e);
298 }
299
300 }
301 shutdown(env);
302 }
303 }
304
305
306
307
308
309
310
311
312 public boolean preCompactSelection(Store store, List<StoreFile> candidates) {
313 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
314 boolean bypass = false;
315 for (RegionEnvironment env: coprocessors) {
316 if (env.getInstance() instanceof RegionObserver) {
317 ctx = ObserverContext.createAndPrepare(env, ctx);
318 ((RegionObserver)env.getInstance()).preCompactSelection(
319 ctx, store, candidates);
320 bypass |= ctx.shouldBypass();
321 if (ctx.shouldComplete()) {
322 break;
323 }
324 }
325 }
326 return bypass;
327 }
328
329
330
331
332
333
334
335 public void postCompactSelection(Store store,
336 ImmutableList<StoreFile> selected) {
337 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
338 for (RegionEnvironment env: coprocessors) {
339 if (env.getInstance() instanceof RegionObserver) {
340 ctx = ObserverContext.createAndPrepare(env, ctx);
341 try {
342 ((RegionObserver)env.getInstance()).postCompactSelection(
343 ctx, store, selected);
344 } catch (Throwable e) {
345 handleCoprocessorThrowableNoRethrow(env,e);
346 }
347 if (ctx.shouldComplete()) {
348 break;
349 }
350 }
351 }
352 }
353
354
355
356
357
358
359 public InternalScanner preCompact(Store store, InternalScanner scanner) {
360 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
361 boolean bypass = false;
362 for (RegionEnvironment env: coprocessors) {
363 if (env.getInstance() instanceof RegionObserver) {
364 ctx = ObserverContext.createAndPrepare(env, ctx);
365 try {
366 scanner = ((RegionObserver)env.getInstance()).preCompact(
367 ctx, store, scanner);
368 } catch (Throwable e) {
369 handleCoprocessorThrowableNoRethrow(env,e);
370 }
371 bypass |= ctx.shouldBypass();
372 if (ctx.shouldComplete()) {
373 break;
374 }
375 }
376 }
377 return bypass ? null : scanner;
378 }
379
380
381
382
383
384
385 public void postCompact(Store store, StoreFile resultFile) {
386 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
387 for (RegionEnvironment env: coprocessors) {
388 if (env.getInstance() instanceof RegionObserver) {
389 ctx = ObserverContext.createAndPrepare(env, ctx);
390 try {
391 ((RegionObserver)env.getInstance()).postCompact(ctx, store, resultFile);
392 } catch (Throwable e) {
393 handleCoprocessorThrowableNoRethrow(env, e);
394 }
395 if (ctx.shouldComplete()) {
396 break;
397 }
398 }
399 }
400 }
401
402
403
404
405 public void preFlush() {
406 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
407 for (RegionEnvironment env: coprocessors) {
408 if (env.getInstance() instanceof RegionObserver) {
409 ctx = ObserverContext.createAndPrepare(env, ctx);
410 try {
411 ((RegionObserver)env.getInstance()).preFlush(ctx);
412 } catch (Throwable e) {
413 handleCoprocessorThrowableNoRethrow(env, e);
414 }
415 if (ctx.shouldComplete()) {
416 break;
417 }
418 }
419 }
420 }
421
422
423
424
425 public void postFlush() {
426 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
427 for (RegionEnvironment env: coprocessors) {
428 if (env.getInstance() instanceof RegionObserver) {
429 ctx = ObserverContext.createAndPrepare(env, ctx);
430 try {
431 ((RegionObserver)env.getInstance()).postFlush(ctx);
432 } catch (Throwable e) {
433 handleCoprocessorThrowableNoRethrow(env, e);
434 }
435 if (ctx.shouldComplete()) {
436 break;
437 }
438 }
439 }
440 }
441
442
443
444
445 public void preSplit() {
446 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
447 for (RegionEnvironment env: coprocessors) {
448 if (env.getInstance() instanceof RegionObserver) {
449 ctx = ObserverContext.createAndPrepare(env, ctx);
450 try {
451 ((RegionObserver)env.getInstance()).preSplit(ctx);
452 } catch (Throwable e) {
453 handleCoprocessorThrowableNoRethrow(env, e);
454 }
455 if (ctx.shouldComplete()) {
456 break;
457 }
458 }
459 }
460 }
461
462
463
464
465
466
467 public void postSplit(HRegion l, HRegion r) {
468 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
469 for (RegionEnvironment env: coprocessors) {
470 if (env.getInstance() instanceof RegionObserver) {
471 ctx = ObserverContext.createAndPrepare(env, ctx);
472 try {
473 ((RegionObserver)env.getInstance()).postSplit(ctx, l, r);
474 } catch (Throwable e) {
475 handleCoprocessorThrowableNoRethrow(env, e);
476 }
477 if (ctx.shouldComplete()) {
478 break;
479 }
480 }
481 }
482 }
483
484
485
486
487
488
489
490
491
492
493 public boolean preGetClosestRowBefore(final byte[] row, final byte[] family,
494 final Result result) throws IOException {
495 boolean bypass = false;
496 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
497 for (RegionEnvironment env: coprocessors) {
498 if (env.getInstance() instanceof RegionObserver) {
499 ctx = ObserverContext.createAndPrepare(env, ctx);
500 try {
501 ((RegionObserver)env.getInstance()).preGetClosestRowBefore(ctx, row,
502 family, result);
503 } catch (Throwable e) {
504 handleCoprocessorThrowable(env, e);
505 }
506 bypass |= ctx.shouldBypass();
507 if (ctx.shouldComplete()) {
508 break;
509 }
510 }
511 }
512 return bypass;
513 }
514
515
516
517
518
519
520
521 public void postGetClosestRowBefore(final byte[] row, final byte[] family,
522 final Result result) throws IOException {
523 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
524 for (RegionEnvironment env: coprocessors) {
525 if (env.getInstance() instanceof RegionObserver) {
526 ctx = ObserverContext.createAndPrepare(env, ctx);
527 try {
528 ((RegionObserver)env.getInstance()).postGetClosestRowBefore(ctx, row,
529 family, result);
530 } catch (Throwable e) {
531 handleCoprocessorThrowable(env, e);
532 }
533 if (ctx.shouldComplete()) {
534 break;
535 }
536 }
537 }
538 }
539
540
541
542
543
544
545 public boolean preGet(final Get get, final List<KeyValue> results)
546 throws IOException {
547 boolean bypass = false;
548 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
549 for (RegionEnvironment env: coprocessors) {
550 if (env.getInstance() instanceof RegionObserver) {
551 ctx = ObserverContext.createAndPrepare(env, ctx);
552 try {
553 ((RegionObserver)env.getInstance()).preGet(ctx, get, results);
554 } catch (Throwable e) {
555 handleCoprocessorThrowable(env, e);
556 }
557 bypass |= ctx.shouldBypass();
558 if (ctx.shouldComplete()) {
559 break;
560 }
561 }
562 }
563 return bypass;
564 }
565
566
567
568
569
570
571 public void postGet(final Get get, final List<KeyValue> results)
572 throws IOException {
573 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
574 for (RegionEnvironment env: coprocessors) {
575 if (env.getInstance() instanceof RegionObserver) {
576 ctx = ObserverContext.createAndPrepare(env, ctx);
577 try {
578 ((RegionObserver)env.getInstance()).postGet(ctx, get, results);
579 } catch (Throwable e) {
580 handleCoprocessorThrowable(env, e);
581 }
582 if (ctx.shouldComplete()) {
583 break;
584 }
585 }
586 }
587 }
588
589
590
591
592
593
594
595 public Boolean preExists(final Get get) throws IOException {
596 boolean bypass = false;
597 boolean exists = false;
598 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
599 for (RegionEnvironment env: coprocessors) {
600 if (env.getInstance() instanceof RegionObserver) {
601 ctx = ObserverContext.createAndPrepare(env, ctx);
602 try {
603 exists = ((RegionObserver)env.getInstance()).preExists(ctx, get, exists);
604 } catch (Throwable e) {
605 handleCoprocessorThrowable(env, e);
606 }
607 bypass |= ctx.shouldBypass();
608 if (ctx.shouldComplete()) {
609 break;
610 }
611 }
612 }
613 return bypass ? exists : null;
614 }
615
616
617
618
619
620
621
622 public boolean postExists(final Get get, boolean exists)
623 throws IOException {
624 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
625 for (RegionEnvironment env: coprocessors) {
626 if (env.getInstance() instanceof RegionObserver) {
627 ctx = ObserverContext.createAndPrepare(env, ctx);
628 try {
629 exists = ((RegionObserver)env.getInstance()).postExists(ctx, get, exists);
630 } catch (Throwable e) {
631 handleCoprocessorThrowable(env, e);
632 }
633 if (ctx.shouldComplete()) {
634 break;
635 }
636 }
637 }
638 return exists;
639 }
640
641
642
643
644
645
646
647
648 public boolean prePut(Put put, WALEdit edit,
649 final boolean writeToWAL) throws IOException {
650 boolean bypass = false;
651 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
652 for (RegionEnvironment env: coprocessors) {
653 if (env.getInstance() instanceof RegionObserver) {
654 ctx = ObserverContext.createAndPrepare(env, ctx);
655 try {
656 ((RegionObserver)env.getInstance()).prePut(ctx, put, edit, writeToWAL);
657 } catch (Throwable e) {
658 handleCoprocessorThrowable(env, e);
659 }
660 bypass |= ctx.shouldBypass();
661 if (ctx.shouldComplete()) {
662 break;
663 }
664 }
665 }
666 return bypass;
667 }
668
669
670
671
672
673
674
675 public void postPut(Put put, WALEdit edit,
676 final boolean writeToWAL) throws IOException {
677 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
678 for (RegionEnvironment env: coprocessors) {
679 if (env.getInstance() instanceof RegionObserver) {
680 ctx = ObserverContext.createAndPrepare(env, ctx);
681 try {
682 ((RegionObserver)env.getInstance()).postPut(ctx, put, edit, writeToWAL);
683 } catch (Throwable e) {
684 handleCoprocessorThrowable(env, e);
685 }
686 if (ctx.shouldComplete()) {
687 break;
688 }
689 }
690 }
691 }
692
693
694
695
696
697
698
699
700 public boolean preDelete(Delete delete, WALEdit edit,
701 final boolean writeToWAL) throws IOException {
702 boolean bypass = false;
703 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
704 for (RegionEnvironment env: coprocessors) {
705 if (env.getInstance() instanceof RegionObserver) {
706 ctx = ObserverContext.createAndPrepare(env, ctx);
707 try {
708 ((RegionObserver)env.getInstance()).preDelete(ctx, delete, edit, writeToWAL);
709 } catch (Throwable e) {
710 handleCoprocessorThrowable(env, e);
711 }
712 bypass |= ctx.shouldBypass();
713 if (ctx.shouldComplete()) {
714 break;
715 }
716 }
717 }
718 return bypass;
719 }
720
721
722
723
724
725
726
727 public void postDelete(Delete delete, WALEdit edit,
728 final boolean writeToWAL) throws IOException {
729 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
730 for (RegionEnvironment env: coprocessors) {
731 if (env.getInstance() instanceof RegionObserver) {
732 ctx = ObserverContext.createAndPrepare(env, ctx);
733 try {
734 ((RegionObserver)env.getInstance()).postDelete(ctx, delete, edit, writeToWAL);
735 } catch (Throwable e) {
736 handleCoprocessorThrowable(env, e);
737 }
738 if (ctx.shouldComplete()) {
739 break;
740 }
741 }
742 }
743 }
744
745
746
747
748
749
750
751
752
753
754
755
756 public Boolean preCheckAndPut(final byte [] row, final byte [] family,
757 final byte [] qualifier, final CompareOp compareOp,
758 final WritableByteArrayComparable comparator, Put put)
759 throws IOException {
760 boolean bypass = false;
761 boolean result = false;
762 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
763 for (RegionEnvironment env: coprocessors) {
764 if (env.getInstance() instanceof RegionObserver) {
765 ctx = ObserverContext.createAndPrepare(env, ctx);
766 try {
767 result = ((RegionObserver)env.getInstance()).preCheckAndPut(ctx, row, family,
768 qualifier, compareOp, comparator, put, result);
769 } catch (Throwable e) {
770 handleCoprocessorThrowable(env, e);
771 }
772
773
774 bypass |= ctx.shouldBypass();
775 if (ctx.shouldComplete()) {
776 break;
777 }
778 }
779 }
780 return bypass ? result : null;
781 }
782
783
784
785
786
787
788
789
790
791
792 public boolean postCheckAndPut(final byte [] row, final byte [] family,
793 final byte [] qualifier, final CompareOp compareOp,
794 final WritableByteArrayComparable comparator, final Put put,
795 boolean result)
796 throws IOException {
797 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
798 for (RegionEnvironment env: coprocessors) {
799 if (env.getInstance() instanceof RegionObserver) {
800 ctx = ObserverContext.createAndPrepare(env, ctx);
801 try {
802 result = ((RegionObserver)env.getInstance()).postCheckAndPut(ctx, row,
803 family, qualifier, compareOp, comparator, put, result);
804 } catch (Throwable e) {
805 handleCoprocessorThrowable(env, e);
806 }
807 if (ctx.shouldComplete()) {
808 break;
809 }
810 }
811 }
812 return result;
813 }
814
815
816
817
818
819
820
821
822
823
824
825
826 public Boolean preCheckAndDelete(final byte [] row, final byte [] family,
827 final byte [] qualifier, final CompareOp compareOp,
828 final WritableByteArrayComparable comparator, Delete delete)
829 throws IOException {
830 boolean bypass = false;
831 boolean result = false;
832 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
833 for (RegionEnvironment env: coprocessors) {
834 if (env.getInstance() instanceof RegionObserver) {
835 ctx = ObserverContext.createAndPrepare(env, ctx);
836 try {
837 result = ((RegionObserver)env.getInstance()).preCheckAndDelete(ctx, row,
838 family, qualifier, compareOp, comparator, delete, result);
839 } catch (Throwable e) {
840 handleCoprocessorThrowable(env, e);
841 }
842 bypass |= ctx.shouldBypass();
843 if (ctx.shouldComplete()) {
844 break;
845 }
846 }
847 }
848 return bypass ? result : null;
849 }
850
851
852
853
854
855
856
857
858
859
860 public boolean postCheckAndDelete(final byte [] row, final byte [] family,
861 final byte [] qualifier, final CompareOp compareOp,
862 final WritableByteArrayComparable comparator, final Delete delete,
863 boolean result)
864 throws IOException {
865 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
866 for (RegionEnvironment env: coprocessors) {
867 if (env.getInstance() instanceof RegionObserver) {
868 ctx = ObserverContext.createAndPrepare(env, ctx);
869 try {
870 result = ((RegionObserver)env.getInstance())
871 .postCheckAndDelete(ctx, row, family, qualifier, compareOp,
872 comparator, delete, result);
873 } catch (Throwable e) {
874 handleCoprocessorThrowable(env, e);
875 }
876 if (ctx.shouldComplete()) {
877 break;
878 }
879 }
880 }
881 return result;
882 }
883
884
885
886
887
888
889
890
891
892
893
894 public Long preIncrementColumnValue(final byte [] row, final byte [] family,
895 final byte [] qualifier, long amount, final boolean writeToWAL)
896 throws IOException {
897 boolean bypass = false;
898 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
899 for (RegionEnvironment env: coprocessors) {
900 if (env.getInstance() instanceof RegionObserver) {
901 ctx = ObserverContext.createAndPrepare(env, ctx);
902 try {
903 amount = ((RegionObserver)env.getInstance()).preIncrementColumnValue(ctx,
904 row, family, qualifier, amount, writeToWAL);
905 } catch (Throwable e) {
906 handleCoprocessorThrowable(env, e);
907 }
908 bypass |= ctx.shouldBypass();
909 if (ctx.shouldComplete()) {
910 break;
911 }
912 }
913 }
914 return bypass ? amount : null;
915 }
916
917
918
919
920
921
922
923
924
925
926
927 public long postIncrementColumnValue(final byte [] row, final byte [] family,
928 final byte [] qualifier, final long amount, final boolean writeToWAL,
929 long result) throws IOException {
930 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
931 for (RegionEnvironment env: coprocessors) {
932 if (env.getInstance() instanceof RegionObserver) {
933 ctx = ObserverContext.createAndPrepare(env, ctx);
934 try {
935 result = ((RegionObserver)env.getInstance()).postIncrementColumnValue(ctx,
936 row, family, qualifier, amount, writeToWAL, result);
937 } catch (Throwable e) {
938 handleCoprocessorThrowable(env, e);
939 }
940 if (ctx.shouldComplete()) {
941 break;
942 }
943 }
944 }
945 return result;
946 }
947
948
949
950
951
952
953
954 public Result preIncrement(Increment increment)
955 throws IOException {
956 boolean bypass = false;
957 Result result = new Result();
958 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
959 for (RegionEnvironment env: coprocessors) {
960 if (env.getInstance() instanceof RegionObserver) {
961 ctx = ObserverContext.createAndPrepare(env, ctx);
962 try {
963 ((RegionObserver)env.getInstance()).preIncrement(ctx, increment, result);
964 } catch (Throwable e) {
965 handleCoprocessorThrowable(env, e);
966 }
967 bypass |= ctx.shouldBypass();
968 if (ctx.shouldComplete()) {
969 break;
970 }
971 }
972 }
973 return bypass ? result : null;
974 }
975
976
977
978
979
980
981 public void postIncrement(final Increment increment, Result result)
982 throws IOException {
983 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
984 for (RegionEnvironment env: coprocessors) {
985 if (env.getInstance() instanceof RegionObserver) {
986 ctx = ObserverContext.createAndPrepare(env, ctx);
987 try {
988 ((RegionObserver)env.getInstance()).postIncrement(ctx, increment, result);
989 } catch (Throwable e) {
990 handleCoprocessorThrowable(env, e);
991 }
992 if (ctx.shouldComplete()) {
993 break;
994 }
995 }
996 }
997 }
998
999
1000
1001
1002
1003
1004
1005 public RegionScanner preScannerOpen(Scan scan) throws IOException {
1006 boolean bypass = false;
1007 RegionScanner s = null;
1008 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
1009 for (RegionEnvironment env: coprocessors) {
1010 if (env.getInstance() instanceof RegionObserver) {
1011 ctx = ObserverContext.createAndPrepare(env, ctx);
1012 try {
1013 s = ((RegionObserver)env.getInstance()).preScannerOpen(ctx, scan, s);
1014 } catch (Throwable e) {
1015 handleCoprocessorThrowable(env, e);
1016 }
1017 bypass |= ctx.shouldBypass();
1018 if (ctx.shouldComplete()) {
1019 break;
1020 }
1021 }
1022 }
1023 return bypass ? s : null;
1024 }
1025
1026
1027
1028
1029
1030
1031
1032 public RegionScanner postScannerOpen(final Scan scan, RegionScanner s)
1033 throws IOException {
1034 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
1035 for (RegionEnvironment env: coprocessors) {
1036 if (env.getInstance() instanceof RegionObserver) {
1037 ctx = ObserverContext.createAndPrepare(env, ctx);
1038 try {
1039 s = ((RegionObserver)env.getInstance()).postScannerOpen(ctx, scan, s);
1040 } catch (Throwable e) {
1041 handleCoprocessorThrowable(env, e);
1042 }
1043 if (ctx.shouldComplete()) {
1044 break;
1045 }
1046 }
1047 }
1048 return s;
1049 }
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059 public Boolean preScannerNext(final InternalScanner s,
1060 final List<Result> results, int limit) throws IOException {
1061 boolean bypass = false;
1062 boolean hasNext = false;
1063 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
1064 for (RegionEnvironment env: coprocessors) {
1065 if (env.getInstance() instanceof RegionObserver) {
1066 ctx = ObserverContext.createAndPrepare(env, ctx);
1067 try {
1068 hasNext = ((RegionObserver)env.getInstance()).preScannerNext(ctx, s, results,
1069 limit, hasNext);
1070 } catch (Throwable e) {
1071 handleCoprocessorThrowable(env, e);
1072 }
1073 bypass |= ctx.shouldBypass();
1074 if (ctx.shouldComplete()) {
1075 break;
1076 }
1077 }
1078 }
1079 return bypass ? hasNext : null;
1080 }
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090 public boolean postScannerNext(final InternalScanner s,
1091 final List<Result> results, final int limit, boolean hasMore)
1092 throws IOException {
1093 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
1094 for (RegionEnvironment env: coprocessors) {
1095 if (env.getInstance() instanceof RegionObserver) {
1096 ctx = ObserverContext.createAndPrepare(env, ctx);
1097 try {
1098 hasMore = ((RegionObserver)env.getInstance()).postScannerNext(ctx, s,
1099 results, limit, hasMore);
1100 } catch (Throwable e) {
1101 handleCoprocessorThrowable(env, e);
1102 }
1103 if (ctx.shouldComplete()) {
1104 break;
1105 }
1106 }
1107 }
1108 return hasMore;
1109 }
1110
1111
1112
1113
1114
1115
1116 public boolean preScannerClose(final InternalScanner s)
1117 throws IOException {
1118 boolean bypass = false;
1119 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
1120 for (RegionEnvironment env: coprocessors) {
1121 if (env.getInstance() instanceof RegionObserver) {
1122 ctx = ObserverContext.createAndPrepare(env, ctx);
1123 try {
1124 ((RegionObserver)env.getInstance()).preScannerClose(ctx, s);
1125 } catch (Throwable e) {
1126 handleCoprocessorThrowable(env, e);
1127 }
1128 bypass |= ctx.shouldBypass();
1129 if (ctx.shouldComplete()) {
1130 break;
1131 }
1132 }
1133 }
1134 return bypass;
1135 }
1136
1137
1138
1139
1140
1141 public void postScannerClose(final InternalScanner s)
1142 throws IOException {
1143 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
1144 for (RegionEnvironment env: coprocessors) {
1145 if (env.getInstance() instanceof RegionObserver) {
1146 ctx = ObserverContext.createAndPrepare(env, ctx);
1147 try {
1148 ((RegionObserver)env.getInstance()).postScannerClose(ctx, s);
1149 } catch (Throwable e) {
1150 handleCoprocessorThrowable(env, e);
1151 }
1152 if (ctx.shouldComplete()) {
1153 break;
1154 }
1155 }
1156 }
1157 }
1158
1159
1160
1161
1162
1163
1164
1165
1166 public boolean preWALRestore(HRegionInfo info, HLogKey logKey,
1167 WALEdit logEdit) throws IOException {
1168 boolean bypass = false;
1169 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
1170 for (RegionEnvironment env: coprocessors) {
1171 if (env.getInstance() instanceof RegionObserver) {
1172 ctx = ObserverContext.createAndPrepare(env, ctx);
1173 try {
1174 ((RegionObserver)env.getInstance()).preWALRestore(ctx, info, logKey,
1175 logEdit);
1176 } catch (Throwable e) {
1177 handleCoprocessorThrowable(env, e);
1178 }
1179 bypass |= ctx.shouldBypass();
1180 if (ctx.shouldComplete()) {
1181 break;
1182 }
1183 }
1184 }
1185 return bypass;
1186 }
1187
1188
1189
1190
1191
1192
1193
1194 public void postWALRestore(HRegionInfo info, HLogKey logKey,
1195 WALEdit logEdit) throws IOException {
1196 ObserverContext<RegionCoprocessorEnvironment> ctx = null;
1197 for (RegionEnvironment env: coprocessors) {
1198 if (env.getInstance() instanceof RegionObserver) {
1199 ctx = ObserverContext.createAndPrepare(env, ctx);
1200 try {
1201 ((RegionObserver)env.getInstance()).postWALRestore(ctx, info,
1202 logKey, logEdit);
1203 } catch (Throwable e) {
1204 handleCoprocessorThrowable(env, e);
1205 }
1206 if (ctx.shouldComplete()) {
1207 break;
1208 }
1209 }
1210 }
1211 }
1212 }