Class BaseRecord
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
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancheckExpired(long currentTime) Called when the modification time and current time is available, checks for expirations.intcompareTo(BaseRecord record) booleanOverride equals check to use primary key(s) for comparison.protected static StringgenerateMashupKey(Map<String, String> keys) Generates a cache key from a map of values.abstract longGet the creation time for the record.abstract longGet the modification time for the record.longGet the deletion time for the expired record.abstract longGet the expiration time for the record.Join the primary keys into one single primary key.Map of primary key names to values for the record.inthashCode()Override hash code to use primary key(s) for comparison.booleanIf the record has fields others than the primary keys.voidinit()Initialize the object.booleanCheck if this record is expired.booleanlike(BaseRecord other) Check if this record matches a partial record.abstract voidsetDateCreated(long time) Set the creation time for the record.abstract voidsetDateModified(long time) Set the modification time for the record.booleanshouldBeDeleted(long currentTime) Called when this record is expired and expired deletion is enabled, checks for the deletion.toString()voidvalidate()Validates the record.
-
Field Details
-
ERROR_MSG_CREATION_TIME_NEGATIVE
- See Also:
-
ERROR_MSG_MODIFICATION_TIME_NEGATIVE
- See Also:
-
-
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
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
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
Generates a cache key from a map of values.- Parameters:
keys- Map of values.- Returns:
- String mashup of key values.
-
like
Check if this record matches a partial record.- Parameters:
other- Partial record.- Returns:
- If this record matches.
-
equals
Override equals check to use primary key(s) for comparison. -
hashCode
public int hashCode()Override hash code to use primary key(s) for comparison. -
compareTo
- Specified by:
compareToin interfaceComparable<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
-