1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 package org.apache.hadoop.hbase.replication;
19
20 import java.util.UUID;
21 import org.apache.hadoop.hbase.Cell;
22 import org.apache.hadoop.hbase.CellUtil;
23 import org.apache.hadoop.hbase.classification.InterfaceAudience;
24 import org.apache.hadoop.hbase.wal.WAL;
25
26 /**
27 * A dummy {@link ReplicationEndpoint} that replicates nothing.
28 * <p/>
29 * Mainly used by ITBLL to check whether all the entries in WAL files are fine, since for normal
30 * case, we will only read the WAL files when there are region servers crash and we need to split
31 * the log, but for replication we will read all the entries and pass them to the
32 * {@link ReplicationEndpoint}, so setting up a replication peer can help finding out whether there
33 * are broken entries in WAL files.
34 */
35 @InterfaceAudience.Private
36 public class VerifyWALEntriesReplicationEndpoint extends BaseReplicationEndpoint {
37
38 @Override
39 public boolean canReplicateToSameCluster() {
40 return true;
41 }
42
43 @Override
44 public UUID getPeerUUID() {
45 return ctx.getClusterId();
46 }
47
48 @Override
49 public WALEntryFilter getWALEntryfilter() {
50 return null;
51 }
52
53 private void checkCell(Cell cell) {
54 // check whether all the fields are fine
55 CellUtil.cloneRow(cell);
56 CellUtil.cloneFamily(cell);
57 CellUtil.cloneQualifier(cell);
58 CellUtil.cloneValue(cell);
59 }
60
61 @Override
62 public boolean replicate(ReplicateContext replicateContext) {
63 for (WAL.Entry entry : replicateContext.getEntries()) {
64 for (Cell cell: entry.getEdit().getCells()) {
65 checkCell(cell);
66 }
67 }
68 return true;
69 }
70
71 @Override
72 protected void doStart() {
73 notifyStarted();
74 }
75
76 @Override
77 protected void doStop() {
78 notifyStopped();
79 }
80 }