@Singleton public class PeerAwareInstanceRegistryImpl extends AbstractInstanceRegistry implements PeerAwareInstanceRegistry
AbstractInstanceRegistry to 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 of
EurekaServerConfig.getRenewalThresholdUpdateIntervalMs(), eureka
perceives this as a danger and stops expiring instances.
| Modifier and Type | Class and Description |
|---|---|
static class |
PeerAwareInstanceRegistryImpl.Action |
| Modifier and Type | Field and Description |
|---|---|
protected com.netflix.discovery.EurekaClientConfig |
clientConfig |
protected com.netflix.discovery.EurekaClient |
eurekaClient |
protected PeerEurekaNodes |
peerEurekaNodes |
protected ServerCodecs |
serverCodecs |
allKnownRemoteRegions, expectedNumberOfRenewsPerMin, lock, numberOfRenewsPerMinThreshold, overriddenInstanceStatusMap, regionNameVSRemoteRegistry, responseCache, serverConfig| Constructor and Description |
|---|
PeerAwareInstanceRegistryImpl(EurekaServerConfig serverConfig,
com.netflix.discovery.EurekaClientConfig clientConfig,
ServerCodecs serverCodecs,
com.netflix.discovery.EurekaClient eurekaClient) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
cancel(java.lang.String appName,
java.lang.String id,
boolean isReplication)
Cancels the registration of an instance.
|
boolean |
deleteStatusOverride(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.
|
long |
getLocalRegistrySize() |
com.netflix.appinfo.InstanceInfo |
getNextServerFromEureka(java.lang.String virtualHostname,
boolean secure) |
long |
getNumOfReplicationsInLastMin()
Gets the number of renewals in the last minute.
|
protected com.netflix.appinfo.InstanceInfo.InstanceStatus |
getOverriddenInstanceStatus(com.netflix.appinfo.InstanceInfo r,
Lease<com.netflix.appinfo.InstanceInfo> existingLease,
boolean isReplication) |
java.util.List<PeerEurekaNode> |
getReplicaNodes()
Deprecated.
use
PeerEurekaNodes.getPeerEurekaNodes() directly.
Gets the list of peer eureka nodes which is the list to replicate
information to. |
java.util.List<com.netflix.discovery.shared.Application> |
getSortedApplications()
Gets the list of all
Applications from the registry in sorted
lexical order of Application.getName(). |
void |
init(PeerEurekaNodes peerEurekaNodes) |
int |
isBelowRenewThresold()
Checks if the number of renewals is lesser than threshold.
|
boolean |
isLeaseExpirationEnabled()
Checks whether lease expiration is enabled.
|
boolean |
isRegisterable(com.netflix.appinfo.InstanceInfo instanceInfo)
Checks if an instance is registerable in this region.
|
boolean |
isSelfPreservationModeEnabled()
Checks to see if the self-preservation mode is enabled.
|
void |
openForTraffic(com.netflix.appinfo.ApplicationInfoManager applicationInfoManager,
int count) |
void |
register(com.netflix.appinfo.InstanceInfo info,
boolean isReplication)
Registers the information about the
InstanceInfo and replicates
this information to all peer eureka nodes. |
boolean |
renew(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.
|
boolean |
shouldAllowAccess() |
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.
|
void |
shutdown()
Perform all cleanup and shutdown operations.
|
void |
statusUpdate(java.lang.String asgName,
ASGResource.ASGStatus newStatus,
boolean isReplication)
Replicate the ASG status updates to peer eureka nodes.
|
boolean |
statusUpdate(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.
|
int |
syncUp()
Populates the registry information from a peer eureka node.
|
clearRegistry, evict, evict, getApplication, getApplication, getApplicationDeltas, getApplicationDeltasFromMultipleRegions, getApplications, getApplications, getApplicationsFromAllRemoteRegions, getApplicationsFromLocalRegionOnly, getApplicationsFromMultipleRegions, getInstanceByAppAndId, getInstanceByAppAndId, getInstancesById, getInstancesById, getLastNCanceledInstances, getLastNRegisteredInstances, getNumberofElementsininstanceCache, getNumOfRenewsInLastMin, getNumOfRenewsPerMinThreshold, getResponseCache, initializedResponseCache, initRemoteRegionRegistry, internalCancel, overriddenInstanceStatusesSnapshot, postInit, register, storeOverriddenStatusIfRequired, storeOverriddenStatusIfRequiredclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitclearRegistry, getApplication, getApplicationsFromLocalRegionOnly, getInstanceByAppAndId, getInstanceByAppAndId, getLastNCanceledInstances, getLastNRegisteredInstances, getNumOfRenewsInLastMin, getNumOfRenewsPerMinThreshold, getResponseCache, initializedResponseCache, overriddenInstanceStatusesSnapshot, storeOverriddenStatusIfRequired, storeOverriddenStatusIfRequiredevict, registerprotected final com.netflix.discovery.EurekaClientConfig clientConfig
protected final ServerCodecs serverCodecs
protected final com.netflix.discovery.EurekaClient eurekaClient
protected volatile PeerEurekaNodes peerEurekaNodes
@Inject public PeerAwareInstanceRegistryImpl(EurekaServerConfig serverConfig, com.netflix.discovery.EurekaClientConfig clientConfig, ServerCodecs serverCodecs, com.netflix.discovery.EurekaClient eurekaClient)
public void init(PeerEurekaNodes peerEurekaNodes) throws java.lang.Exception
init in interface PeerAwareInstanceRegistryjava.lang.Exceptionpublic void shutdown()
shutdown in interface InstanceRegistryshutdown in class AbstractInstanceRegistrypublic int syncUp()
syncUp in interface PeerAwareInstanceRegistrypublic void openForTraffic(com.netflix.appinfo.ApplicationInfoManager applicationInfoManager,
int count)
openForTraffic in interface InstanceRegistrypublic boolean shouldAllowAccess(boolean remoteRegionRequired)
EurekaServerConfig.getWaitTimeInMsWhenSyncEmpty(), if it cannot
get the registry information from the peer eureka nodes at start up.shouldAllowAccess in interface PeerAwareInstanceRegistrypublic boolean shouldAllowAccess()
@Deprecated public java.util.List<PeerEurekaNode> getReplicaNodes()
PeerEurekaNodes.getPeerEurekaNodes() directly.
Gets the list of peer eureka nodes which is the list to replicate
information to.public boolean cancel(java.lang.String appName,
java.lang.String id,
boolean isReplication)
AbstractInstanceRegistryThis is normally invoked by a client when it shuts down informing the server to remove the instance from traffic.
cancel in interface LeaseManager<com.netflix.appinfo.InstanceInfo>cancel in class AbstractInstanceRegistryappName - 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.AbstractInstanceRegistry successfully, false otherwise.public void register(com.netflix.appinfo.InstanceInfo info,
boolean isReplication)
InstanceInfo and replicates
this information to all peer eureka nodes. If this is replication event
from other replica nodes then it is not replicated.register in interface PeerAwareInstanceRegistryinfo - the InstanceInfo to be registered and replicated.isReplication - true if this is a replication event from other replica nodes,
false otherwise.public boolean renew(java.lang.String appName,
java.lang.String id,
boolean isReplication)
AbstractInstanceRegistryrenew in interface LeaseManager<com.netflix.appinfo.InstanceInfo>renew in class AbstractInstanceRegistryid - - unique id within appNameisReplication - - whether this is a replicated entry from another ds nodeLeaseManager.renew(java.lang.String, java.lang.String, boolean)public boolean statusUpdate(java.lang.String appName,
java.lang.String id,
com.netflix.appinfo.InstanceInfo.InstanceStatus newStatus,
java.lang.String lastDirtyTimestamp,
boolean isReplication)
AbstractInstanceRegistryInstanceInfo.InstanceStatus.OUT_OF_SERVICE and
InstanceInfo.InstanceStatus.UP to put the instance in and out of traffic.statusUpdate in interface InstanceRegistrystatusUpdate in class AbstractInstanceRegistryappName - the application name of the instance.id - the unique identifier of the instance.newStatus - the new InstanceInfo.InstanceStatus.lastDirtyTimestamp - last timestamp when this instance information was updated.isReplication - true if this is a replication event from other nodes, false
otherwise.public boolean deleteStatusOverride(java.lang.String appName,
java.lang.String id,
com.netflix.appinfo.InstanceInfo.InstanceStatus newStatus,
java.lang.String lastDirtyTimestamp,
boolean isReplication)
AbstractInstanceRegistrydeleteStatusOverride in interface InstanceRegistrydeleteStatusOverride in class AbstractInstanceRegistryappName - the application name of the instance.id - the unique identifier of the instance.newStatus - the new InstanceInfo.InstanceStatus.lastDirtyTimestamp - last timestamp when this instance information was updated.isReplication - true if this is a replication event from other nodes, false
otherwise.public void statusUpdate(java.lang.String asgName,
ASGResource.ASGStatus newStatus,
boolean isReplication)
statusUpdate in interface PeerAwareInstanceRegistryasgName - the asg name for which the status needs to be replicated.newStatus - the ASGResource.ASGStatus information that needs to be replicated.isReplication - true if this is a replication event from other nodes, false otherwise.public boolean isLeaseExpirationEnabled()
InstanceRegistryisLeaseExpirationEnabled in interface InstanceRegistrypublic boolean isSelfPreservationModeEnabled()
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 by AbstractInstanceRegistry.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 flag
EurekaServerConfig.shouldEnableSelfPreservation() is set to
false.
isSelfPreservationModeEnabled in interface InstanceRegistrypublic com.netflix.appinfo.InstanceInfo getNextServerFromEureka(java.lang.String virtualHostname,
boolean secure)
getNextServerFromEureka in interface com.netflix.discovery.shared.LookupService<java.lang.String>public java.util.List<com.netflix.discovery.shared.Application> getSortedApplications()
Applications from the registry in sorted
lexical order of Application.getName().getSortedApplications in interface InstanceRegistryApplications in lexical order.@Monitor(name="numOfReplicationsInLastMin",
description="Number of total replications received in the last minute",
type=GAUGE)
public long getNumOfReplicationsInLastMin()
@Monitor(name="isBelowRenewThreshold",
description="0 = false, 1 = true",
type=GAUGE)
public int isBelowRenewThresold()
isBelowRenewThresold in interface InstanceRegistrypublic boolean isRegisterable(com.netflix.appinfo.InstanceInfo instanceInfo)
instanceInfo - th instance info information of the instance@Monitor(name="localRegistrySize",
description="Current registry size",
type=GAUGE)
public long getLocalRegistrySize()
getLocalRegistrySize in class AbstractInstanceRegistryprotected com.netflix.appinfo.InstanceInfo.InstanceStatus getOverriddenInstanceStatus(com.netflix.appinfo.InstanceInfo r,
Lease<com.netflix.appinfo.InstanceInfo> existingLease,
boolean isReplication)
getOverriddenInstanceStatus in class AbstractInstanceRegistry