java.lang.Object
org.apache.hadoop.hdfs.server.federation.store.records.BaseRecord
All Implemented Interfaces:
Comparable<BaseRecord>
Direct Known Subclasses:
DisabledNameservice, MembershipState, MembershipStats, MountTable, RouterState, StateStoreVersion

public abstract class BaseRecord extends Object implements Comparable<BaseRecord>
Abstract base of a data record in the StateStore. All StateStore records are derived from this class. Data records are persisted in the data store and are identified by their primary key. Each data record contains:
  • A primary key consisting of a combination of record data fields.
  • A modification date.
  • A creation date.
  • Field Details

  • Constructor Details

    • BaseRecord

      public BaseRecord()
  • Method Details

    • setDateModified

      public abstract void setDateModified(long time)
      Set the modification time for the record.
      Parameters:
      time - Modification time of the record.
    • getDateModified

      public abstract long getDateModified()
      Get the modification time for the record.
      Returns:
      Modification time of the record.
    • setDateCreated

      public abstract void setDateCreated(long time)
      Set the creation time for the record.
      Parameters:
      time - Creation time of the record.
    • getDateCreated

      public abstract long getDateCreated()
      Get the creation time for the record.
      Returns:
      Creation time of the record
    • getExpirationMs

      public abstract long getExpirationMs()
      Get the expiration time for the record.
      Returns:
      Expiration time for the record.
    • isExpired

      public boolean isExpired()
      Check if this record is expired. The default is false. Override for customized behavior.
      Returns:
      True if the record is expired.
    • getDeletionMs

      public long getDeletionMs()
      Get the deletion time for the expired record. The default is disabled. Override for customized behavior.
      Returns:
      Deletion time for the expired record.
    • getPrimaryKeys

      public abstract Map<String,String> getPrimaryKeys()
      Map of primary key names to values for the record. The primary key can be a combination of 1-n different State Store serialized values.
      Returns:
      Map of key/value pairs that constitute this object's primary key.
    • init

      public void init()
      Initialize the object.
    • getPrimaryKey

      public String getPrimaryKey()
      Join the primary keys into one single primary key.
      Returns:
      A string that is guaranteed to be unique amongst all records of this type.
    • hasOtherFields

      @VisibleForTesting public boolean hasOtherFields()
      If the record has fields others than the primary keys. This is used by TestStateStoreDriverBase to skip the modification check.
      Returns:
      If the record has more fields.
    • generateMashupKey

      protected static String generateMashupKey(Map<String,String> keys)
      Generates a cache key from a map of values.
      Parameters:
      keys - Map of values.
      Returns:
      String mashup of key values.
    • like

      public boolean like(BaseRecord other)
      Check if this record matches a partial record.
      Parameters:
      other - Partial record.
      Returns:
      If this record matches.
    • equals

      public boolean equals(Object obj)
      Override equals check to use primary key(s) for comparison.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Override hash code to use primary key(s) for comparison.
      Overrides:
      hashCode in class Object
    • compareTo

      public int compareTo(BaseRecord record)
      Specified by:
      compareTo in interface Comparable<BaseRecord>
    • checkExpired

      public boolean checkExpired(long currentTime)
      Called when the modification time and current time is available, checks for expirations.
      Parameters:
      currentTime - The current timestamp in ms from the data store, to be compared against the modification and creation dates of the object.
      Returns:
      boolean True if the record has been updated and should be committed to the data store. Override for customized behavior.
    • shouldBeDeleted

      public boolean shouldBeDeleted(long currentTime)
      Called when this record is expired and expired deletion is enabled, checks for the deletion. If an expired record exists beyond the deletion time, it should be deleted.
      Parameters:
      currentTime - The current timestamp in ms from the data store, to be compared against the modification and creation dates of the object.
      Returns:
      boolean True if the record has been updated and should be deleted from the data store.
    • validate

      public void validate()
      Validates the record. Called when the record is created, populated from the state store, and before committing to the state store. If validate failed, there throws an exception.
    • toString

      public String toString()
      Overrides:
      toString in class Object