001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.replication;
019
020import org.apache.hadoop.hbase.HBaseInterfaceAudience;
021import org.apache.hadoop.hbase.wal.WAL.Entry;
022import org.apache.yetus.audience.InterfaceAudience;
023
024/**
025 * Base class for {@link WALEntryFilter}, store the necessary common properties like
026 * {@link #serial}.
027 * <p>
028 * Why need to treat serial replication specially:
029 * <p>
030 * Under some special cases, we may filter out some entries but we still need to record the last
031 * pushed sequence id for these entries. For example, when we setup a bidirection replication A
032 * &lt;-&gt; B, if we write to both cluster A and cluster B, cluster A will not replicate the
033 * entries which are replicated from cluster B, which means we may have holes in the replication
034 * sequence ids. So if the region is closed abnormally, i.e, we do not have a close event for the
035 * region, and before the closing, we have some entries from cluster B, then the replication from
036 * cluster A to cluster B will be stuck if we do not record the last pushed sequence id of these
037 * entries because we will find out that the previous sequence id range will never finish. So we
038 * need to record the sequence id for these entries so the last pushed sequence id can reach the
039 * region barrier.
040 * @see <a href="https://issues.apache.org/jira/browse/HBASE-29463">HBASE-29463</a>
041 */
042@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.REPLICATION)
043public abstract class WALEntryFilterBase implements WALEntryFilter {
044
045  protected boolean serial;
046
047  @Override
048  public void setSerial(boolean serial) {
049    this.serial = serial;
050  }
051
052  /**
053   * Call this method when you do not need to replicate the entry.
054   * <p>
055   * For serial replication, since still need to WALKey for recording progress, we clear all the
056   * cells of the WALEdit. For normal replication, we just return null.
057   */
058  protected final Entry clearOrNull(Entry entry) {
059    if (serial) {
060      entry.getEdit().getCells().clear();
061      return entry;
062    } else {
063      return null;
064    }
065  }
066}