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   * Retained for backwards compatibility with K/V indexer
063   * @deprecated Use {@link #getTableName()} instead
064   * @return table name
065   */
066  @Deprecated
067  default TableName getTablename() {
068    return getTableName();
069  }
070
071  /**
072   * @return the write time
073   */
074  long getWriteTime();
075
076  /**
077   * @return The nonce group
078   */
079  default long getNonceGroup() {
080    return HConstants.NO_NONCE;
081  }
082
083  /**
084   * @return The nonce
085   */
086  default long getNonce() {
087    return HConstants.NO_NONCE;
088  }
089
090  UUID getOriginatingClusterId();
091
092  /**
093   * Return a positive long if current WALKeyImpl is created from a replay edit; a replay edit is an
094   * edit that came in when replaying WALs of a crashed server.
095   * @return original sequence number of the WALEdit
096   */
097  long getOrigLogSeqNum();
098
099  /**
100   * Produces a string map for this key. Useful for programmatic use and
101   * manipulation of the data stored in an WALKeyImpl, for example, printing
102   * as JSON.
103   *
104   * @return a Map containing data from this key
105   */
106  default Map<String, Object> toStringMap() {
107    Map<String, Object> stringMap = new HashMap<>();
108    stringMap.put("table", getTableName());
109    stringMap.put("region", Bytes.toStringBinary(getEncodedRegionName()));
110    stringMap.put("sequence", getSequenceId());
111    return stringMap;
112  }
113}