Package com.apple.foundationdb.record
Class RecordStoreState
- java.lang.Object
-
- com.apple.foundationdb.record.RecordStoreState
-
- Direct Known Subclasses:
MutableRecordStoreState
@API(MAINTAINED) public class RecordStoreState extends Object
TheRecordStoreState
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 Summary
Fields Modifier and Type Field Description static RecordStoreState
EMPTY
Deprecated.as this object usually has the wrong store headerprotected AtomicReference<Map<String,IndexState>>
indexStateMap
protected AtomicReference<RecordMetaDataProto.DataStoreInfo>
storeHeader
-
Constructor Summary
Constructors Constructor Description RecordStoreState()
Deprecated.as the default store header is incorrect for most record storesRecordStoreState(RecordMetaDataProto.DataStoreInfo storeHeader, Map<String,IndexState> indexStateMap)
Creates aRecordStoreState
with the given index states.RecordStoreState(Map<String,IndexState> indexStateMap)
Deprecated.as the default store header is incorrect for most record stores
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
allIndexesReadable()
Determines whether all of the indexes in the store are currently readable.void
beginRead()
Begin using this record store state.boolean
compatibleWith(RecordStoreState other)
Determines if it is safe to use queries and other operations planned with the passedRecordStoreState
with a record store that has the current state.void
endRead()
End using this record store state.boolean
equals(Object o)
Checks if thisRecordStoreState
specifies identical state as the given object.Set<String>
getDisabledIndexNames()
Get the names of any disabled indexes.Map<String,IndexState>
getIndexStates()
Retrieve the mapping from index names toIndexState
that is underlying thisRecordStoreState
.IndexState
getState(Index index)
Determine the state of an index.IndexState
getState(String indexName)
Determine the state of the index with the given name.RecordMetaDataProto.DataStoreInfo
getStoreHeader()
Get the store header associated with this record store state.Set<String>
getWriteOnlyIndexNames()
Get the names of any write-only indexes.int
hashCode()
Creates a valid hash code of this state based on the hashes of its members.boolean
isDisabled(Index index)
Determines whether the index is disabled.boolean
isDisabled(String indexName)
Determines whether the index of the given is disabled.boolean
isReadable(Index index)
Determines whether the index is readable.boolean
isReadable(String indexName)
Determines whether the index of the given name is readable.boolean
isWriteOnly(Index index)
Determines whether the index provided is a write-only index.boolean
isWriteOnly(String indexName)
Determines whether the index of the given name is a write-only index.RecordStoreState
toImmutable()
Create an immutable version of thisRecordStoreState
.MutableRecordStoreState
toMutable()
Create a mutable copy of thisRecordStoreState
.String
toString()
A human-readable representation of the state.RecordStoreState
withIndexesInState(List<String> indexNames, IndexState state)
Create a new version of this RecordStoreState, but with the specified indexes in the specified state, ignoring their present state.RecordStoreState
withWriteOnlyIndexes(List<String> writeOnlyIndexNames)
Create a new version of thisRecordStoreState
, but with additionalIndexState.WRITE_ONLY
indexes.protected Map<String,IndexState>
writeOnlyMap(List<String> writeOnlyIndexNames)
-
-
-
Field Detail
-
EMPTY
@Deprecated @Nonnull public static final RecordStoreState EMPTY
Deprecated.as this object usually has the wrong store headerEmptyRecordStoreState
. 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.
-
storeHeader
@Nonnull protected final AtomicReference<RecordMetaDataProto.DataStoreInfo> storeHeader
-
indexStateMap
@Nonnull protected final AtomicReference<Map<String,IndexState>> indexStateMap
-
-
Constructor Detail
-
RecordStoreState
@API(INTERNAL) public RecordStoreState(@Nullable RecordMetaDataProto.DataStoreInfo storeHeader, @Nullable Map<String,IndexState> indexStateMap)
Creates aRecordStoreState
with the given index states. Only indexes that are not in the default state (IndexState.READABLE
) need to be included in the map.- Parameters:
storeHeader
- header information for the given storeindexStateMap
- mapping from index name to index state
-
RecordStoreState
@Deprecated public RecordStoreState(@Nullable Map<String,IndexState> indexStateMap)
Deprecated.as the default store header is incorrect for most record storesCreates aRecordStoreState
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 storesCreates an emptyRecordStoreState
instance. This is the state that an emptyFDBRecordStoreBase
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. UntilendRead()
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 toIndexState
that is underlying thisRecordStoreState
. 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 andfalse
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 andfalse
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 andfalse
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 andfalse
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 andfalse
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 andfalse
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 returnIndexState.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 returnIndexState.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 andfalse
otherwise
-
compatibleWith
public boolean compatibleWith(@Nonnull RecordStoreState other)
Determines if it is safe to use queries and other operations planned with the passedRecordStoreState
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
- theRecordStoreState
to check compatibility with- Returns:
- whether operations planned with
other
will be correct if the state is actually described by thisRecordStoreState
-
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 modifystate
- 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 thisRecordStoreState
, but with additionalIndexState.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.
-
writeOnlyMap
@Nonnull protected Map<String,IndexState> writeOnlyMap(@Nonnull List<String> writeOnlyIndexNames)
-
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 thisRecordStoreState
specifies identical state as the given object.
-
hashCode
public int hashCode()
Creates a valid hash code of this state based on the hashes of its members.
-
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.
-
toImmutable
@Nonnull public RecordStoreState toImmutable()
Create an immutable version of thisRecordStoreState
. If the state object is already immutable, this will returnthis
. 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 thisRecordStoreState
. 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
-
-