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.wal;
019
020import org.apache.hadoop.hbase.HBaseInterfaceAudience;
021import org.apache.hadoop.hbase.HConstants;
022import org.apache.hadoop.hbase.TableName;
023import org.apache.hadoop.hbase.regionserver.SequenceId;
024import org.apache.hadoop.hbase.util.Bytes;
025import org.apache.yetus.audience.InterfaceAudience;
026
027import java.util.ArrayList;
028import java.util.Collections;
029import java.util.HashMap;
030import java.util.List;
031import java.util.Map;
032import java.util.UUID;
033
034
035/**
036 * Key for WAL Entry.
037 * Read-only. No Setters. For limited audience such as Coprocessors.
038 */
039@InterfaceAudience.LimitedPrivate({HBaseInterfaceAudience.REPLICATION,
040    HBaseInterfaceAudience.COPROC})
041public interface WALKey extends SequenceId, Comparable<WALKey> {
042  /**
043   * Unmodifiable empty list of UUIDs.
044   */
045  List<UUID> EMPTY_UUIDS = Collections.unmodifiableList(new ArrayList<UUID>());
046
047  default long estimatedSerializedSizeOf() {
048    return 0;
049  }
050
051  /**
052   * @return encoded region name
053   */
054  byte[] getEncodedRegionName();
055
056  /**
057   * @return table name
058   */
059  TableName getTableName();
060
061  /**
062   * @return the write time
063   */
064  long getWriteTime();
065
066  /**
067   * @return The nonce group
068   */
069  default long getNonceGroup() {
070    return HConstants.NO_NONCE;
071  }
072
073  /**
074   * @return The nonce
075   */
076  default long getNonce() {
077    return HConstants.NO_NONCE;
078  }
079
080  UUID getOriginatingClusterId();
081
082  /**
083   * Return a positive long if current WALKeyImpl is created from a replay edit; a replay edit is an
084   * edit that came in when replaying WALs of a crashed server.
085   * @return original sequence number of the WALEdit
086   */
087  long getOrigLogSeqNum();
088
089  /**
090   * Produces a string map for this key. Useful for programmatic use and
091   * manipulation of the data stored in an WALKeyImpl, for example, printing
092   * as JSON.
093   *
094   * @return a Map containing data from this key
095   */
096  default Map<String, Object> toStringMap() {
097    Map<String, Object> stringMap = new HashMap<>();
098    stringMap.put("table", getTableName());
099    stringMap.put("region", Bytes.toStringBinary(getEncodedRegionName()));
100    stringMap.put("sequence", getSequenceId());
101    return stringMap;
102  }
103}