Package org.apache.solr.common.cloud
Class Aliases
java.lang.Object
org.apache.solr.common.cloud.Aliases
Holds collection aliases -- virtual collections that point to one or more other collections. We
might add other types of aliases here some day. Immutable.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptioncloneWithCollectionAlias(String alias, String collections) Creates a new Aliases instance with the same data as the current one but with a modification based on the parameters.cloneWithCollectionAliasProperties(String alias, String propertiesKey, String propertiesValue) Set the value for some properties on a collection alias.cloneWithCollectionAliasProperties(String alias, Map<String, String> properties) Set the values for some properties keys on a collection alias.cloneWithRename(String before, String after) Rename an alias.convertMapOfCommaDelimitedToMapOfList(Map<String, String> collectionAliasMap) convertMapOfListToMapOfCommaDelimited(Map<String, List<String>> collectionAliasMap) voidforEachAlias(BiConsumer<String, List<String>> consumer) static AliasesfromJSON(byte[] bytes, int zNodeVersion) Create an instance from the JSON bytes read from zookeeper.Get a fully parsed map of collection aliases.Get a map similar to the JSON data as stored in zookeeper.Returns an unmodifiable Map of properties for a given alias.intbooleanReturns true if an alias is defined, false otherwise.booleanisRoutedAlias(String aliasName) Returns true if an alias exists and is a routed alias, false otherwise.resolveAliases(String aliasName) List the collections associated with a particular alias.resolveSimpleAlias(String aliasName) Resolve an alias that points to a single collection.static Stringintsize()byte[]toJSON()Serialize our state.toString()
-
Field Details
-
EMPTY
An empty, minimal Aliases primarily used to support the non-cloud solr use cases. Not normally useful in cloud situations where the version of the node needs to be tracked even if all aliases are removed. The -1 version makes it subordinate to any real version, and furthermore we never "set" this EMPTY instance into ZK.
-
-
Method Details
-
forEachAlias
-
size
public int size() -
fromJSON
Create an instance from the JSON bytes read from zookeeper. Generally this should only be done by a ZkStateReader.- Parameters:
bytes- The bytes read via a getData request to zookeeper (possibly null)zNodeVersion- the version of the data in zookeeper that this instance corresponds to- Returns:
- A new immutable Aliases object
-
toJSON
public byte[] toJSON()Serialize our state. -
convertMapOfCommaDelimitedToMapOfList
-
convertMapOfListToMapOfCommaDelimited
-
getZNodeVersion
public int getZNodeVersion() -
getCollectionAliasMap
Get a map similar to the JSON data as stored in zookeeper. Callers may prefer use ofgetCollectionAliasListMap()instead, if collection names will be iterated.- Returns:
- an unmodifiable Map of collection aliases mapped to a comma delimited string of the collection(s) the alias maps to. Does not return null.
-
getCollectionAliasListMap
Get a fully parsed map of collection aliases.- Returns:
- an unmodifiable Map of collection aliases mapped to a list of the collection(s) the alias maps to. Does not return null.
-
getCollectionAliasProperties
Returns an unmodifiable Map of properties for a given alias. This method will never return null.- Parameters:
alias- the name of an alias also found as a key ingetCollectionAliasListMap()- Returns:
- The properties for the alias (possibly empty).
-
resolveAliases
List the collections associated with a particular alias. One level of alias indirection is supported (alias to alias to collection). Such indirection may be deprecated in the future, use with caution.- Returns:
- An unmodifiable list of collections names that the input alias name maps to. If there are none, the input is returned.
-
hasAlias
Returns true if an alias is defined, false otherwise. -
isRoutedAlias
Returns true if an alias exists and is a routed alias, false otherwise. -
resolveSimpleAlias
Resolve an alias that points to a single collection. One level of alias indirection is supported.- Parameters:
aliasName- alias name- Returns:
- original name if there's no such alias, or a resolved name. If an alias points to more than 1 collection (directly or indirectly) an exception is thrown
- Throws:
SolrException- if either direct or indirect alias points to more than 1 name.
-
resolveSimpleAliasGivenAliasMap
public static String resolveSimpleAliasGivenAliasMap(Map<String, List<String>> collectionAliasListMap, String aliasName) throws SolrException- Throws:
SolrException- NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
-
resolveAliasesGivenAliasMap
public static List<String> resolveAliasesGivenAliasMap(Map<String, List<String>> collectionAliasListMap, String aliasName) - NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
-
cloneWithCollectionAlias
Creates a new Aliases instance with the same data as the current one but with a modification based on the parameters.Note that the state in zookeeper is unaffected by this method and the change must still be persisted via
ZkStateReader.AliasesManager#applyModificationAndExportToZk(UnaryOperator)- Parameters:
alias- the alias to update, must not be nullcollections- the comma separated list of collections for the alias, null to remove the alias
-
cloneWithRename
Rename an alias. This performs a "deep rename", which changes also the second-level alias lists. Renaming routed aliases is not supported.Note that the state in zookeeper is unaffected by this method and the change must still be persisted via
ZkStateReader.AliasesManager#applyModificationAndExportToZk(UnaryOperator)- Parameters:
before- previous alias name, must not be nullafter- new alias name. If this is null then it's equivalent to callingcloneWithCollectionAlias(String, String)with the second argument set to null, ie. removing an alias.- Returns:
- new instance with the renamed alias
- Throws:
SolrException- when eitherbeforeorafteris empty, or thebeforename is a routed alias
-
cloneWithCollectionAliasProperties
public Aliases cloneWithCollectionAliasProperties(String alias, String propertiesKey, String propertiesValue) Set the value for some properties on a collection alias. This is done by creating a new Aliases instance with the same data as the current one but with a modification based on the parameters.Note that the state in zookeeper is unaffected by this method and the change must still be persisted via
ZkStateReader.AliasesManager#applyModificationAndExportToZk(UnaryOperator)- Parameters:
alias- the alias to updatepropertiesKey- the key for the propertiespropertiesValue- the properties to add/replace, null to remove the key.- Returns:
- An immutable copy of the aliases with the new properties.
-
cloneWithCollectionAliasProperties
public Aliases cloneWithCollectionAliasProperties(String alias, Map<String, String> properties) throws SolrExceptionSet the values for some properties keys on a collection alias. This is done by creating a new Aliases instance with the same data as the current one but with a modification based on the parameters.Note that the state in zookeeper is unaffected by this method and the change must still be persisted via
ZkStateReader.AliasesManager#applyModificationAndExportToZk(UnaryOperator)- Parameters:
alias- the alias to updateproperties- the properties to add/replace, null values in the map will remove the key.- Returns:
- An immutable copy of the aliases with the new properties.
- Throws:
SolrException
-
toString
-