1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.hadoop.hbase.regionserver.wal;
23
24 import java.io.IOException;
25
26 import org.apache.hadoop.hbase.Coprocessor;
27 import org.apache.hadoop.hbase.HRegionInfo;
28 import org.apache.hadoop.hbase.coprocessor.*;
29 import org.apache.hadoop.conf.Configuration;
30
31
32
33
34
35 public class WALCoprocessorHost
36 extends CoprocessorHost<WALCoprocessorHost.WALEnvironment> {
37
38
39
40
41 static class WALEnvironment extends CoprocessorHost.Environment
42 implements WALCoprocessorEnvironment {
43
44 private HLog wal;
45
46 @Override
47 public HLog getWAL() {
48 return wal;
49 }
50
51
52
53
54
55
56
57
58
59 public WALEnvironment(Class<?> implClass, final Coprocessor impl,
60 final int priority, final int seq, final Configuration conf,
61 final HLog hlog) {
62 super(impl, priority, seq, conf);
63 this.wal = hlog;
64 }
65 }
66
67 HLog wal;
68
69
70
71
72
73 public WALCoprocessorHost(final HLog log, final Configuration conf) {
74 this.wal = log;
75
76 loadSystemCoprocessors(conf, WAL_COPROCESSOR_CONF_KEY);
77 }
78
79 @Override
80 public WALEnvironment createEnvironment(final Class<?> implClass,
81 final Coprocessor instance, final int priority, final int seq,
82 final Configuration conf) {
83 return new WALEnvironment(implClass, instance, priority, seq, conf,
84 this.wal);
85 }
86
87
88
89
90
91
92
93
94 public boolean preWALWrite(HRegionInfo info, HLogKey logKey, WALEdit logEdit)
95 throws IOException {
96 boolean bypass = false;
97 ObserverContext<WALCoprocessorEnvironment> ctx = null;
98 for (WALEnvironment env: coprocessors) {
99 if (env.getInstance() instanceof
100 org.apache.hadoop.hbase.coprocessor.WALObserver) {
101 ctx = ObserverContext.createAndPrepare(env, ctx);
102 ((org.apache.hadoop.hbase.coprocessor.WALObserver)env.getInstance()).
103 preWALWrite(ctx, info, logKey, logEdit);
104 bypass |= ctx.shouldBypass();
105 if (ctx.shouldComplete()) {
106 break;
107 }
108 }
109 }
110 return bypass;
111 }
112
113
114
115
116
117
118
119 public void postWALWrite(HRegionInfo info, HLogKey logKey, WALEdit logEdit)
120 throws IOException {
121 ObserverContext<WALCoprocessorEnvironment> ctx = null;
122 for (WALEnvironment env: coprocessors) {
123 if (env.getInstance() instanceof
124 org.apache.hadoop.hbase.coprocessor.WALObserver) {
125 ctx = ObserverContext.createAndPrepare(env, ctx);
126 ((org.apache.hadoop.hbase.coprocessor.WALObserver)env.getInstance()).
127 postWALWrite(ctx, info, logKey, logEdit);
128 if (ctx.shouldComplete()) {
129 break;
130 }
131 }
132 }
133 }
134 }