Class RecordStoreState

  • Direct Known Subclasses:
    MutableRecordStoreState

    @API(MAINTAINED)
    public class RecordStoreState
    extends Object
    The RecordStoreState interface handles information that might differ between otherwise identical record stores. In particular, it handles the data that might be different between two different record stores that have the same meta-data.

    At the moment, this class tracks two pieces of store-specific meta-data:

    • The store header. The header is a Protobuf message including information such as the store's format and meta-data version. This is used at store initialization time to validate the meta-data being used and take appropriate action on meta-data changes.
    • Index state information. This includes whether each index is currently readable, disabled, or write-only. This information is used by the planner when selecting indexes and by the store when choosing which indexes to update upon record insertion.
    • Field Detail

      • EMPTY

        @Deprecated
        @Nonnull
        public static final RecordStoreState EMPTY
        Deprecated.
        as this object usually has the wrong store header
        Empty RecordStoreState. This is the state of an empty record store that has not yet been used. Calling the argument-less constructor of this class will produce a logically-equivalent object, but having this code around avoids having to instantiate this class unnecessarily.

        When this object was initially introduced, the only information included in the record store state was index readability information. This was the common case, and therefore sharing the same object for most record stores was desirable. However, the store header information is not likely to be the same for multiple record stores, so using this record store state is usually not recommended.

    • Constructor Detail

      • RecordStoreState

        @Deprecated
        public RecordStoreState​(@Nullable
                                Map<String,​IndexState> indexStateMap)
        Deprecated.
        as the default store header is incorrect for most record stores
        Creates a RecordStoreState with the given index states. Only indexes that are not in the default state (IndexState.READABLE) need to be included in the map. This initializes the record store state with a default store header, which is not the expected state for most record stores. As a result, this constructor has been deprecated in favor of the constructor where a store header must be provided.
        Parameters:
        indexStateMap - mapping from index name to index state
      • RecordStoreState

        @Deprecated
        public RecordStoreState()
        Deprecated.
        as the default store header is incorrect for most record stores
        Creates an empty RecordStoreState instance. This is the state that an empty FDBRecordStoreBase would be expected to be in. All indexes are assumed to be readable with this constructor. This also initializes the record store state with the default store header, which is not the expected state for most record stores. As a result, this constructor has been deprecated in favor of the constructor where a store header must be provided.
    • Method Detail

      • beginRead

        public void beginRead()
        Begin using this record store state. Until endRead() is called, the state will not change.
      • endRead

        public void endRead()
        End using this record store state.
        See Also:
        beginRead()
      • getIndexStates

        @Nonnull
        public Map<String,​IndexState> getIndexStates()
        Retrieve the mapping from index names to IndexState that is underlying this RecordStoreState. This operation is constant time as it does not return a copy, but the map that is returned is immutable.
        Returns:
        the underlying mapping of index names to their state
      • isWriteOnly

        public boolean isWriteOnly​(@Nonnull
                                   Index index)
        Determines whether the index provided is a write-only index. This is determined by looking it up in the set.
        Parameters:
        index - the index to check
        Returns:
        true if the given index is write-only and false otherwise
      • isWriteOnly

        public boolean isWriteOnly​(@Nonnull
                                   String indexName)
        Determines whether the index of the given name is a write-only index. This is determined by looking it up the set.
        Parameters:
        indexName - the name of the index to check
        Returns:
        true if the given name is the name of a write-only index and false otherwise
      • isDisabled

        public boolean isDisabled​(@Nonnull
                                  Index index)
        Determines whether the index is disabled. This is determined by looking it up in the set.
        Parameters:
        index - the index to check
        Returns:
        true if the given index is disabled and false otherwise
      • isDisabled

        public boolean isDisabled​(@Nonnull
                                  String indexName)
        Determines whether the index of the given is disabled. This is determined by looking it up in the set.
        Parameters:
        indexName - the name of the index to check
        Returns:
        true if the given index is disabled and false otherwise
      • isReadable

        public boolean isReadable​(@Nonnull
                                  Index index)
        Determines whether the index is readable. This is done just by process of elimination, i.e., making sure it is not write-only and not disabled.
        Parameters:
        index - the index to check
        Returns:
        true if the given index is readable and false otherwise
      • isReadable

        public boolean isReadable​(@Nonnull
                                  String indexName)
        Determines whether the index of the given name is readable. This is done just by process of elimination, i.e., making sure it is not write-only and not disabled.
        Parameters:
        indexName - the name of the index to check
        Returns:
        true if the given index is readable and false otherwise
      • getState

        @Nonnull
        public IndexState getState​(@Nonnull
                                   Index index)
        Determine the state of an index. Note that all indexes are assumed to be readable unless marked otherwise, i.e., this will return IndexState.READABLE if it is given an index that is not explicitly in its write-only or disabled lists.
        Parameters:
        index - the index to check
        Returns:
        the state of the given index
      • getState

        @Nonnull
        public IndexState getState​(@Nonnull
                                   String indexName)
        Determine the state of the index with the given name. Note that all indexes are assumed to be readable unless marked otherwise, i.e., this will return IndexState.READABLE if it is given an index name that is not explicitly in its write-only or disabled lists.
        Parameters:
        indexName - the name of the index to check
        Returns:
        the state of the given index
      • allIndexesReadable

        public boolean allIndexesReadable()
        Determines whether all of the indexes in the store are currently readable. That is to say, it makes sure there are no disabled indexes and no write-only indexes.
        Returns:
        true if all of the indexes are readable and false otherwise
      • compatibleWith

        public boolean compatibleWith​(@Nonnull
                                      RecordStoreState other)
        Determines if it is safe to use queries and other operations planned with the passed RecordStoreState with a record store that has the current state. It is possible that these operations will be less efficient with the older state information, but they should not cause correctness problems.
        Parameters:
        other - the RecordStoreState to check compatibility with
        Returns:
        whether operations planned with other will be correct if the state is actually described by this RecordStoreState
      • getWriteOnlyIndexNames

        public Set<String> getWriteOnlyIndexNames()
        Get the names of any write-only indexes.
        Returns:
        a set of indexes that are write-only for this store
      • getDisabledIndexNames

        public Set<String> getDisabledIndexNames()
        Get the names of any disabled indexes.
        Returns:
        a set of indexes that are disabled for this store
      • withIndexesInState

        @Nonnull
        public RecordStoreState withIndexesInState​(@Nonnull
                                                   List<String> indexNames,
                                                   @Nonnull
                                                   IndexState state)
        Create a new version of this RecordStoreState, but with the specified indexes in the specified state, ignoring their present state.
        Parameters:
        indexNames - the names of the indexes to modify
        state - the new state for the given indexes
        Returns:
        a new store state with the given indexes in the given state
      • withWriteOnlyIndexes

        @Nonnull
        public RecordStoreState withWriteOnlyIndexes​(@Nonnull
                                                     List<String> writeOnlyIndexNames)
        Create a new version of this RecordStoreState, but with additional IndexState.WRITE_ONLY indexes.
        Parameters:
        writeOnlyIndexNames - the indexes to be marked as WRITE_ONLY. If the index is already DISABLED, it will stay disabled, but will otherwise be set to WRITE_ONLY.
        Returns:
        a new version of this RecordStoreState, but with additional WRITE_ONLY indexes.
      • getStoreHeader

        @Nonnull
        public RecordMetaDataProto.DataStoreInfo getStoreHeader()
        Get the store header associated with this record store state. This contains information like the format version and meta-data version of the record store.
        Returns:
        the store header associated with the record store
      • equals

        public boolean equals​(Object o)
        Checks if this RecordStoreState specifies identical state as the given object.
        Overrides:
        equals in class Object
        Parameters:
        o - the object to check for equality
        Returns:
        true if the passed object is a RecordStoreState instance and if the other state matches this RecordStoreState and false otherwise
      • hashCode

        public int hashCode()
        Creates a valid hash code of this state based on the hashes of its members.
        Overrides:
        hashCode in class Object
        Returns:
        a hash code based off of the state's members hashes
      • toString

        public String toString()
        A human-readable representation of the state. This is essentially just a print out of the member variables of the state.
        Overrides:
        toString in class Object
        Returns:
        the human-readable state representation
      • toImmutable

        @Nonnull
        public RecordStoreState toImmutable()
        Create an immutable version of this RecordStoreState. If the state object is already immutable, this will return this. This version of the record store state is safe to cache as none of its members can be mutated.
        Returns:
        an immutable version of this RecordStoreState
      • toMutable

        @Nonnull
        public MutableRecordStoreState toMutable()
        Create a mutable copy of this RecordStoreState. The returned object will contain the same information as this record store state, but it will be mutable and will not share any mutable objects with this object.
        Returns:
        a mutable copy of this RecordStoreState