Package org.apache.solr.common.cloud
Class DocCollection
- java.lang.Object
-
- org.apache.solr.common.cloud.ZkNodeProps
-
- org.apache.solr.common.cloud.DocCollection
-
- All Implemented Interfaces:
Iterable<Slice>
,MapSerializable
,MapWriter
,NavigableObject
,org.noggit.JSONWriter.Writable
public class DocCollection extends ZkNodeProps implements Iterable<Slice>
Models a Collection in zookeeper (but that Java name is obviously taken, hence "DocCollection")
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
DocCollection.CollectionStateProps
JSON properties related to a collection's state.static interface
DocCollection.PrsSupplier
-
Nested classes/interfaces inherited from interface org.apache.solr.common.MapWriter
MapWriter.EntryWriter
-
-
Field Summary
Fields Modifier and Type Field Description static String
COLLECTIONS_ZKNODE
-
Fields inherited from class org.apache.solr.common.cloud.ZkNodeProps
propMap
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description DocCollection
copyWithSlices(Map<String,Slice> slices)
Use this to make an exact copy of DocCollection with a new set of Slices and every other property as isstatic DocCollection
create(String name, Map<String,Slice> slices, Map<String,Object> props, DocRouter router, int zkVersion, Instant creationTime, DocCollection.PrsSupplier prsSupplier)
Builds a DocCollection with an optional PrsSupplierboolean
equals(Object that)
void
forEachReplica(BiConsumer<String,Replica> consumer)
Collection<Slice>
getActiveSlices()
Return the list of active slices for this collection.Slice[]
getActiveSlicesArr()
Return array of active slices for this collection (performance optimization).Map<String,Slice>
getActiveSlicesMap()
Get the map of active slices (sliceName->Slice) for this collection.int
getChildNodesVersion()
static String
getCollectionPath(String coll)
static String
getCollectionPathRoot(String coll)
String
getConfigName()
Return non-null config nameInstant
getCreationTime()
The creation time of the Collection.int
getExpectedReplicaCount(Replica.Type type, int def)
Replica
getLeader(String sliceName)
List<Replica>
getLeaderReplicas(String nodeName)
Get the list of all leaders hosted on the given node ornull
if none.String
getName()
Return collection name.Integer
getNumNrtReplicas()
Integer
getNumPullReplicas()
Integer
getNumTlogReplicas()
PerReplicaStates
getPerReplicaStates()
Replica
getReplica(String coreNodeName)
Replica
getReplica(BiPredicate<String,Replica> predicate)
List<Replica>
getReplicas()
List<Replica>
getReplicas(String nodeName)
Get the list of replicas hosted on the given node ornull
if none.List<Replica>
getReplicas(EnumSet<Replica.Type> s)
Integer
getReplicationFactor()
DocRouter
getRouter()
String
getShardId(String nodeName, String coreName)
Get the shardId of a core on a specific nodeSlice
getSlice(String sliceName)
Collection<Slice>
getSlices()
Gets the list of all slices for this collection.Map<String,Slice>
getSlicesMap()
Get the map of all slices (sliceName->Slice) for this collection.String
getZNode()
int
getZNodeVersion()
int
hashCode()
static boolean
isFullyActive(Set<String> liveNodes, DocCollection collectionState, int expectedShards, int expectedReplicas)
Check that all replicas in a collection are liveboolean
isModified(int dataVersion, int childVersion)
boolean
isPerReplicaState()
boolean
isReadOnly()
Iterator<Slice>
iterator()
DocCollection
setPerReplicaStates(PerReplicaStates newPerReplicaStates)
Update our state with a state of aPerReplicaStates
which could override states ofReplica
.String
toString()
static Object
verifyProp(Map<String,Object> props, String propName)
static Object
verifyProp(Map<String,Object> props, String propName, Object def)
void
writeMap(MapWriter.EntryWriter ew)
-
Methods inherited from class org.apache.solr.common.cloud.ZkNodeProps
containsKey, fromKeyVals, get, getBool, getInt, getProperties, getStr, getStr, keySet, load, plus, plus, shallowCopy
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface org.apache.solr.common.NavigableObject
_forEachEntry, _forEachEntry, _forEachEntry, _get, _get, _getStr, _getStr, _size
-
-
-
-
Field Detail
-
COLLECTIONS_ZKNODE
public static final String COLLECTIONS_ZKNODE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DocCollection
@Deprecated public DocCollection(String name, Map<String,Slice> slices, Map<String,Object> props, DocRouter router)
Deprecated.
-
-
Method Detail
-
create
public static DocCollection create(String name, Map<String,Slice> slices, Map<String,Object> props, DocRouter router, int zkVersion, Instant creationTime, DocCollection.PrsSupplier prsSupplier)
Builds a DocCollection with an optional PrsSupplier- Parameters:
name
- The name of the collectionslices
- The logical shards of the collection. This is used directly and a copy is not made.props
- The properties of the slice. This is used directly and a copy is not made.router
- router to partition int range into n rangeszkVersion
- The version of the Collection node in Zookeeper (used for conditional updates).creationTime
- The creation time of the collectionprsSupplier
- optional supplier for PerReplicaStates (PRS) for PRS enabled collections- Returns:
- a newly constructed DocCollection
-
setPerReplicaStates
public final DocCollection setPerReplicaStates(PerReplicaStates newPerReplicaStates)
Update our state with a state of aPerReplicaStates
which could override states ofReplica
.Take note that it updates the underlying AtomicReference such that all Slice and Replica that holds the same AtomicReference will see the same update
This does not create a new DocCollection.
-
copyWithSlices
public DocCollection copyWithSlices(Map<String,Slice> slices)
Use this to make an exact copy of DocCollection with a new set of Slices and every other property as is- Parameters:
slices
- the new set of Slices- Returns:
- the resulting DocCollection
-
getName
public String getName()
Return collection name.
-
getConfigName
public String getConfigName()
Return non-null config name
-
forEachReplica
public void forEachReplica(BiConsumer<String,Replica> consumer)
- Parameters:
consumer
- consume shardName vs. replica
-
getSlices
public Collection<Slice> getSlices()
Gets the list of all slices for this collection.
-
getActiveSlices
public Collection<Slice> getActiveSlices()
Return the list of active slices for this collection.
-
getActiveSlicesArr
public Slice[] getActiveSlicesArr()
Return array of active slices for this collection (performance optimization).
-
getSlicesMap
public Map<String,Slice> getSlicesMap()
Get the map of all slices (sliceName->Slice) for this collection.
-
getActiveSlicesMap
public Map<String,Slice> getActiveSlicesMap()
Get the map of active slices (sliceName->Slice) for this collection.
-
getReplicas
public List<Replica> getReplicas(String nodeName)
Get the list of replicas hosted on the given node ornull
if none.
-
getLeaderReplicas
public List<Replica> getLeaderReplicas(String nodeName)
Get the list of all leaders hosted on the given node ornull
if none.
-
getZNodeVersion
public int getZNodeVersion()
-
getChildNodesVersion
public int getChildNodesVersion()
-
isModified
public boolean isModified(int dataVersion, int childVersion)
-
getReplicationFactor
public Integer getReplicationFactor()
- Returns:
- replication factor for this collection or null if no replication factor exists.
-
getZNode
public String getZNode()
-
getRouter
public DocRouter getRouter()
-
isReadOnly
public boolean isReadOnly()
-
getCreationTime
public Instant getCreationTime()
The creation time of the Collection. When this collection is read from ZooKeeper, this is the creation time of the collection node.
-
toString
public String toString()
- Overrides:
toString
in classZkNodeProps
-
writeMap
public void writeMap(MapWriter.EntryWriter ew) throws IOException
- Specified by:
writeMap
in interfaceMapWriter
- Overrides:
writeMap
in classZkNodeProps
- Throws:
IOException
-
isFullyActive
public static boolean isFullyActive(Set<String> liveNodes, DocCollection collectionState, int expectedShards, int expectedReplicas)
Check that all replicas in a collection are live- See Also:
CollectionStatePredicate
-
getReplica
public Replica getReplica(BiPredicate<String,Replica> predicate)
- Parameters:
predicate
- test against shardName vs. replica- Returns:
- the first replica that matches the predicate
-
getReplicas
public List<Replica> getReplicas(EnumSet<Replica.Type> s)
-
getShardId
public String getShardId(String nodeName, String coreName)
Get the shardId of a core on a specific node
-
equals
public boolean equals(Object that)
- Overrides:
equals
in classZkNodeProps
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classZkNodeProps
-
getNumNrtReplicas
public Integer getNumNrtReplicas()
- Returns:
- the number of replicas of type
Replica.Type.NRT
this collection was created with
-
getNumTlogReplicas
public Integer getNumTlogReplicas()
- Returns:
- the number of replicas of type
Replica.Type.TLOG
this collection was created with
-
getNumPullReplicas
public Integer getNumPullReplicas()
- Returns:
- the number of replicas of type
Replica.Type.PULL
this collection was created with
-
isPerReplicaState
public boolean isPerReplicaState()
-
getPerReplicaStates
public PerReplicaStates getPerReplicaStates()
-
getExpectedReplicaCount
public int getExpectedReplicaCount(Replica.Type type, int def)
-
-