public class PeerAwareInstanceRegistry extends InstanceRegistry
InstanceRegistry 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 |
PeerAwareInstanceRegistry.Action |
allKnownRemoteRegions, expectedNumberOfRenewsPerMin, lock, numberOfRenewsPerMinThreshold, overriddenInstanceStatusMap, regionNameVSRemoteRegistry| 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.
|
static PeerAwareInstanceRegistry |
getInstance() |
com.netflix.appinfo.InstanceInfo |
getNextServerFromEureka(java.lang.String virtualHostname,
boolean secure) |
int |
getNumOfRenewsPerMinThreshold()
Gets the threshold for the renewals per minute.
|
long |
getNumOfReplicationsInLastMin()
Gets the number of renewals in the last minute.
|
java.util.List<PeerEurekaNode> |
getReplicaNodes()
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(). |
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(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 |
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, getApplication, getApplication, getApplicationDeltas, getApplicationDeltasFromMultipleRegions, getApplications, getApplications, getApplicationsFromAllRemoteRegions, getApplicationsFromLocalRegionOnly, getApplicationsFromMultipleRegions, getInstanceByAppAndId, getInstanceByAppAndId, getInstancesById, getInstancesById, getLastNCanceledInstances, getLastNRegisteredInstances, getNumberofElementsininstanceCache, getNumOfRenewsInLastMin, initRemoteRegionRegistry, postInit, register, storeOverriddenStatusIfRequiredpublic static PeerAwareInstanceRegistry getInstance()
public int syncUp()
public void openForTraffic(int count)
public boolean shouldAllowAccess(boolean remoteRegionRequired)
EurekaServerConfig.getWaitTimeInMsWhenSyncEmpty(), if it cannot
get the registry information from the peer eureka nodes at start up.public boolean shouldAllowAccess()
public java.util.List<PeerEurekaNode> getReplicaNodes()
public boolean cancel(java.lang.String appName,
java.lang.String id,
boolean isReplication)
InstanceRegistryThis 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 InstanceRegistryappName - 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.InstanceRegistry 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.info - 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)
InstanceRegistryrenew in interface LeaseManager<com.netflix.appinfo.InstanceInfo>renew in class InstanceRegistryid - - 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)
InstanceRegistryInstanceInfo.InstanceStatus.OUT_OF_SERVICE and
InstanceInfo.InstanceStatus.UP to put the instance in and out of traffic.statusUpdate in class InstanceRegistryappName - 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)
InstanceRegistrydeleteStatusOverride in class InstanceRegistryappName - 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)
asgName - 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 class InstanceRegistrypublic boolean isSelfPreservationModeEnabled()
The self-preservation mode is enabled if the expected number of renewals
per minute InstanceRegistry.getNumOfRenewsInLastMin() is lesser than the expected
threshold which is determined by 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.
public com.netflix.appinfo.InstanceInfo getNextServerFromEureka(java.lang.String virtualHostname,
boolean secure)
public java.util.List<com.netflix.discovery.shared.Application> getSortedApplications()
Applications from the registry in sorted
lexical order of Application.getName().Applications 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()
@Monitor(name="numOfRenewsPerMinThreshold",
type=GAUGE)
public int getNumOfRenewsPerMinThreshold()
public boolean isRegisterable(com.netflix.appinfo.InstanceInfo instanceInfo)
instanceInfo - - the instance info information of the instance