Class PeerAwareInstanceRegistryImpl
- java.lang.Object
-
- com.netflix.eureka.registry.AbstractInstanceRegistry
-
- com.netflix.eureka.registry.PeerAwareInstanceRegistryImpl
-
- All Implemented Interfaces:
com.netflix.discovery.shared.LookupService<java.lang.String>,LeaseManager<com.netflix.appinfo.InstanceInfo>,InstanceRegistry,PeerAwareInstanceRegistry
- Direct Known Subclasses:
AwsInstanceRegistry
@Singleton public class PeerAwareInstanceRegistryImpl extends AbstractInstanceRegistry implements PeerAwareInstanceRegistry
Handles replication of all operations toAbstractInstanceRegistryto peer Eureka nodes to keep them all in sync.Primary operations that are replicated are the Registers,Renewals,Cancels,Expirations and Status Changes
When the eureka server starts up it tries to fetch all the registry information from the peer eureka nodes.If for some reason this operation fails, the server does not allow the user to get the registry information for a period specified in
EurekaServerConfig.getWaitTimeInMsWhenSyncEmpty().One important thing to note about renewals.If the renewal drops more than the specified threshold as specified in
EurekaServerConfig.getRenewalPercentThreshold()within a period ofEurekaServerConfig.getRenewalThresholdUpdateIntervalMs(), eureka perceives this as a danger and stops expiring instances.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPeerAwareInstanceRegistryImpl.Action
-
Field Summary
Fields Modifier and Type Field Description protected com.netflix.discovery.EurekaClienteurekaClientprotected PeerEurekaNodespeerEurekaNodes-
Fields inherited from class com.netflix.eureka.registry.AbstractInstanceRegistry
allKnownRemoteRegions, clientConfig, expectedNumberOfClientsSendingRenews, lock, numberOfRenewsPerMinThreshold, overriddenInstanceStatusMap, regionNameVSRemoteRegistry, responseCache, serverCodecs, serverConfig
-
-
Constructor Summary
Constructors Constructor Description PeerAwareInstanceRegistryImpl(EurekaServerConfig serverConfig, com.netflix.discovery.EurekaClientConfig clientConfig, ServerCodecs serverCodecs, com.netflix.discovery.EurekaClient eurekaClient, EurekaServerHttpClientFactory eurekaServerHttpClientFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleancancel(java.lang.String appName, java.lang.String id, boolean isReplication)Cancels the registration of an instance.booleandeleteStatusOverride(java.lang.String appName, java.lang.String id, com.netflix.appinfo.InstanceInfo.InstanceStatus newStatus, java.lang.String lastDirtyTimestamp, boolean isReplication)Removes status override for a give instance.protected InstanceStatusOverrideRulegetInstanceInfoOverrideRule()longgetLocalRegistrySize()com.netflix.appinfo.InstanceInfogetNextServerFromEureka(java.lang.String virtualHostname, boolean secure)longgetNumOfReplicationsInLastMin()Gets the number of renewals in the last minute.java.util.List<PeerEurekaNode>getReplicaNodes()Deprecated.usePeerEurekaNodes.getPeerEurekaNodes()directly.java.util.List<com.netflix.discovery.shared.Application>getSortedApplications()Gets the list of allApplicationsfrom the registry in sorted lexical order ofApplication.getName().voidinit(PeerEurekaNodes peerEurekaNodes)intisBelowRenewThresold()Checks if the number of renewals is lesser than threshold.booleanisLeaseExpirationEnabled()Checks whether lease expiration is enabled.intisLeaseExpirationEnabledMetric()booleanisRegisterable(com.netflix.appinfo.InstanceInfo instanceInfo)Checks if an instance is registerable in this region.booleanisSelfPreservationModeEnabled()Checks to see if the self-preservation mode is enabled.intisSelfPreservationModeEnabledMetric()voidopenForTraffic(com.netflix.appinfo.ApplicationInfoManager applicationInfoManager, int count)voidregister(com.netflix.appinfo.InstanceInfo info, boolean isReplication)Registers the information about theInstanceInfoand replicates this information to all peer eureka nodes.booleanrenew(java.lang.String appName, java.lang.String id, boolean isReplication)Marks the given instance of the given app name as renewed, and also marks whether it originated from replication.booleanshouldAllowAccess()booleanshouldAllowAccess(boolean remoteRegionRequired)Checks to see if the registry access is allowed or the server is in a situation where it does not all getting registry information.intshouldAllowAccessMetric()voidshutdown()Perform all cleanup and shutdown operations.voidstatusUpdate(java.lang.String asgName, ASGResource.ASGStatus newStatus, boolean isReplication)Replicate the ASG status updates to peer eureka nodes.booleanstatusUpdate(java.lang.String appName, java.lang.String id, com.netflix.appinfo.InstanceInfo.InstanceStatus newStatus, java.lang.String lastDirtyTimestamp, boolean isReplication)Updates the status of an instance.intsyncUp()Populates the registry information from a peer eureka node.-
Methods inherited from class com.netflix.eureka.registry.AbstractInstanceRegistry
clearRegistry, evict, evict, getApplication, getApplication, getApplicationDeltas, getApplicationDeltasFromMultipleRegions, getApplications, getApplications, getApplicationsFromAllRemoteRegions, getApplicationsFromLocalRegionOnly, getApplicationsFromMultipleRegions, getInstanceByAppAndId, getInstanceByAppAndId, getInstancesById, getInstancesById, getLastNCanceledInstances, getLastNRegisteredInstances, getNumberofElementsininstanceCache, getNumOfRenewsInLastMin, getNumOfRenewsPerMinThreshold, getOverriddenInstanceStatus, getResponseCache, initializedResponseCache, initRemoteRegionRegistry, internalCancel, overriddenInstanceStatusesSnapshot, postInit, register, storeOverriddenStatusIfRequired, storeOverriddenStatusIfRequired, updateRenewsPerMinThreshold
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.netflix.eureka.registry.InstanceRegistry
clearRegistry, getApplication, getApplicationsFromLocalRegionOnly, getInstanceByAppAndId, getInstanceByAppAndId, getLastNCanceledInstances, getLastNRegisteredInstances, getNumOfRenewsInLastMin, getNumOfRenewsPerMinThreshold, getResponseCache, initializedResponseCache, overriddenInstanceStatusesSnapshot, storeOverriddenStatusIfRequired, storeOverriddenStatusIfRequired
-
Methods inherited from interface com.netflix.eureka.lease.LeaseManager
evict, register
-
-
-
-
Field Detail
-
eurekaClient
protected final com.netflix.discovery.EurekaClient eurekaClient
-
peerEurekaNodes
protected volatile PeerEurekaNodes peerEurekaNodes
-
-
Constructor Detail
-
PeerAwareInstanceRegistryImpl
@Inject public PeerAwareInstanceRegistryImpl(EurekaServerConfig serverConfig, com.netflix.discovery.EurekaClientConfig clientConfig, ServerCodecs serverCodecs, com.netflix.discovery.EurekaClient eurekaClient, EurekaServerHttpClientFactory eurekaServerHttpClientFactory)
-
-
Method Detail
-
getInstanceInfoOverrideRule
protected InstanceStatusOverrideRule getInstanceInfoOverrideRule()
- Specified by:
getInstanceInfoOverrideRulein classAbstractInstanceRegistry- Returns:
- The rule that will process the instance status override.
-
init
public void init(PeerEurekaNodes peerEurekaNodes) throws java.lang.Exception
- Specified by:
initin interfacePeerAwareInstanceRegistry- Throws:
java.lang.Exception
-
shutdown
public void shutdown()
Perform all cleanup and shutdown operations.- Specified by:
shutdownin interfaceInstanceRegistry- Overrides:
shutdownin classAbstractInstanceRegistry
-
syncUp
public int syncUp()
Populates the registry information from a peer eureka node. This operation fails over to other nodes until the list is exhausted if the communication fails.- Specified by:
syncUpin interfacePeerAwareInstanceRegistry
-
openForTraffic
public void openForTraffic(com.netflix.appinfo.ApplicationInfoManager applicationInfoManager, int count)- Specified by:
openForTrafficin interfaceInstanceRegistry
-
shouldAllowAccess
public boolean shouldAllowAccess(boolean remoteRegionRequired)
Checks to see if the registry access is allowed or the server is in a situation where it does not all getting registry information. The server does not return registry information for a period specified inEurekaServerConfig.getWaitTimeInMsWhenSyncEmpty(), if it cannot get the registry information from the peer eureka nodes at start up.- Specified by:
shouldAllowAccessin interfacePeerAwareInstanceRegistry- Returns:
- false - if the instances count from a replica transfer returned zero and if the wait time has not elapsed, otherwise returns true
-
shouldAllowAccess
public boolean shouldAllowAccess()
-
shouldAllowAccessMetric
@Monitor(name="eurekaServer.registry.shouldAllowAccess", type=GAUGE) public int shouldAllowAccessMetric()
-
getReplicaNodes
@Deprecated public java.util.List<PeerEurekaNode> getReplicaNodes()
Deprecated.usePeerEurekaNodes.getPeerEurekaNodes()directly. Gets the list of peer eureka nodes which is the list to replicate information to.- Returns:
- the list of replica nodes.
-
cancel
public boolean cancel(java.lang.String appName, java.lang.String id, boolean isReplication)Description copied from class:AbstractInstanceRegistryCancels the registration of an instance.This is normally invoked by a client when it shuts down informing the server to remove the instance from traffic.
- Specified by:
cancelin interfaceLeaseManager<com.netflix.appinfo.InstanceInfo>- Overrides:
cancelin classAbstractInstanceRegistry- Parameters:
appName- the application name of the application.id- the unique identifier of the instance.isReplication- true if this is a replication event from other nodes, false otherwise.- Returns:
- true if the instance was removed from the
AbstractInstanceRegistrysuccessfully, false otherwise.
-
register
public void register(com.netflix.appinfo.InstanceInfo info, boolean isReplication)Registers the information about theInstanceInfoand replicates this information to all peer eureka nodes. If this is replication event from other replica nodes then it is not replicated.- Specified by:
registerin interfacePeerAwareInstanceRegistry- Parameters:
info- theInstanceInfoto be registered and replicated.isReplication- true if this is a replication event from other replica nodes, false otherwise.
-
renew
public boolean renew(java.lang.String appName, java.lang.String id, boolean isReplication)Description copied from class:AbstractInstanceRegistryMarks the given instance of the given app name as renewed, and also marks whether it originated from replication.- Specified by:
renewin interfaceLeaseManager<com.netflix.appinfo.InstanceInfo>- Overrides:
renewin classAbstractInstanceRegistryid- - unique id within appNameisReplication- - whether this is a replicated entry from another ds node- Returns:
- whether the operation of successful
- See Also:
LeaseManager.renew(java.lang.String, java.lang.String, boolean)
-
statusUpdate
public boolean statusUpdate(java.lang.String appName, java.lang.String id, com.netflix.appinfo.InstanceInfo.InstanceStatus newStatus, java.lang.String lastDirtyTimestamp, boolean isReplication)Description copied from class:AbstractInstanceRegistryUpdates the status of an instance. Normally happens to put an instance betweenInstanceInfo.InstanceStatus.OUT_OF_SERVICEandInstanceInfo.InstanceStatus.UPto put the instance in and out of traffic.- Specified by:
statusUpdatein interfaceInstanceRegistry- Overrides:
statusUpdatein classAbstractInstanceRegistry- Parameters:
appName- the application name of the instance.id- the unique identifier of the instance.newStatus- the newInstanceInfo.InstanceStatus.lastDirtyTimestamp- last timestamp when this instance information was updated.isReplication- true if this is a replication event from other nodes, false otherwise.- Returns:
- true if the status was successfully updated, false otherwise.
-
deleteStatusOverride
public boolean deleteStatusOverride(java.lang.String appName, java.lang.String id, com.netflix.appinfo.InstanceInfo.InstanceStatus newStatus, java.lang.String lastDirtyTimestamp, boolean isReplication)Description copied from class:AbstractInstanceRegistryRemoves status override for a give instance.- Specified by:
deleteStatusOverridein interfaceInstanceRegistry- Overrides:
deleteStatusOverridein classAbstractInstanceRegistry- Parameters:
appName- the application name of the instance.id- the unique identifier of the instance.newStatus- the newInstanceInfo.InstanceStatus.lastDirtyTimestamp- last timestamp when this instance information was updated.isReplication- true if this is a replication event from other nodes, false otherwise.- Returns:
- true if the status was successfully updated, false otherwise.
-
statusUpdate
public void statusUpdate(java.lang.String asgName, ASGResource.ASGStatus newStatus, boolean isReplication)Replicate the ASG status updates to peer eureka nodes. If this event is a replication from other nodes, then it is not replicated to other nodes.- Specified by:
statusUpdatein interfacePeerAwareInstanceRegistry- Parameters:
asgName- the asg name for which the status needs to be replicated.newStatus- theASGResource.ASGStatusinformation that needs to be replicated.isReplication- true if this is a replication event from other nodes, false otherwise.
-
isLeaseExpirationEnabled
public boolean isLeaseExpirationEnabled()
Description copied from interface:InstanceRegistryChecks whether lease expiration is enabled.- Specified by:
isLeaseExpirationEnabledin interfaceInstanceRegistry- Returns:
- true if enabled
-
isLeaseExpirationEnabledMetric
@Monitor(name="eurekaServer.registry.isLeaseExpirationEnabled", type=GAUGE) public int isLeaseExpirationEnabledMetric()
-
isSelfPreservationModeEnabled
public boolean isSelfPreservationModeEnabled()
Checks to see if the self-preservation mode is enabled.The self-preservation mode is enabled if the expected number of renewals per minute
AbstractInstanceRegistry.getNumOfRenewsInLastMin()is lesser than the expected threshold which is determined byAbstractInstanceRegistry.getNumOfRenewsPerMinThreshold(). Eureka perceives this as a danger and stops expiring instances as this is most likely because of a network event. The mode is disabled only when the renewals get back to above the threshold or if the flagEurekaServerConfig.shouldEnableSelfPreservation()is set to false.- Specified by:
isSelfPreservationModeEnabledin interfaceInstanceRegistry- Returns:
- true if the self-preservation mode is enabled, false otherwise.
-
isSelfPreservationModeEnabledMetric
@Monitor(name="eurekaServer.registry.isSelfPreservationModeEnabled", type=GAUGE) public int isSelfPreservationModeEnabledMetric()
-
getNextServerFromEureka
public com.netflix.appinfo.InstanceInfo getNextServerFromEureka(java.lang.String virtualHostname, boolean secure)- Specified by:
getNextServerFromEurekain interfacecom.netflix.discovery.shared.LookupService<java.lang.String>
-
getSortedApplications
public java.util.List<com.netflix.discovery.shared.Application> getSortedApplications()
Gets the list of allApplicationsfrom the registry in sorted lexical order ofApplication.getName().- Specified by:
getSortedApplicationsin interfaceInstanceRegistry- Returns:
- the list of
Applicationsin lexical order.
-
getNumOfReplicationsInLastMin
@Monitor(name="numOfReplicationsInLastMin", description="Number of total replications received in the last minute", type=GAUGE) public long getNumOfReplicationsInLastMin()Gets the number of renewals in the last minute.- Returns:
- a long value representing the number of renewals in the last minute.
-
isBelowRenewThresold
@Monitor(name="isBelowRenewThreshold", description="0 = false, 1 = true", type=GAUGE) public int isBelowRenewThresold()Checks if the number of renewals is lesser than threshold.- Specified by:
isBelowRenewThresoldin interfaceInstanceRegistry- Returns:
- 0 if the renewals are greater than threshold, 1 otherwise.
-
isRegisterable
public boolean isRegisterable(com.netflix.appinfo.InstanceInfo instanceInfo)
Checks if an instance is registerable in this region. Instances from other regions are rejected.- Parameters:
instanceInfo- th instance info information of the instance- Returns:
- true, if it can be registered in this server, false otherwise.
-
getLocalRegistrySize
@Monitor(name="localRegistrySize", description="Current registry size", type=GAUGE) public long getLocalRegistrySize()- Overrides:
getLocalRegistrySizein classAbstractInstanceRegistry
-
-