Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to EIPManager to check for eip binding at a different (faster) rate when none is bound. #689

Merged
merged 2 commits into from
Oct 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,17 @@ public int getEIPBindRebindRetries() {

}

/*
* (non-Javadoc)
*
* @see com.netflix.eureka.EurekaServerConfig#getEIPBindingRetryInterval()
*/
@Override
public int getEIPBindingRetryIntervalMsWhenUnbound() {
return configInstance.getIntProperty(
namespace + "eipBindRebindRetryIntervalMsWhenUnbound", (1 * 60 * 1000)).get();
}

/*
* (non-Javadoc)
*
Expand All @@ -172,8 +183,7 @@ public int getEIPBindRebindRetries() {
@Override
public int getEIPBindingRetryIntervalMs() {
return configInstance.getIntProperty(
namespace + "eipBindRebindRetryIntervalMs", (5 * 60 * 1000))
.get();
namespace + "eipBindRebindRetryIntervalMs", (5 * 60 * 1000)).get();
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import com.netflix.discovery.converters.XmlXStream;
import com.netflix.eureka.aws.AwsBinder;
import com.netflix.eureka.aws.AwsBinderDelegate;
import com.netflix.eureka.aws.EIPManager;
import com.netflix.eureka.cluster.PeerEurekaNodes;
import com.netflix.eureka.registry.AwsInstanceRegistry;
import com.netflix.eureka.registry.PeerAwareInstanceRegistry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,22 @@ public interface EurekaServerConfig {
*/
int getEIPBindRebindRetries();

/**
* Get the interval with which the server should check if the EIP is bound
* and should try to bind in the case if it is already not bound, iff the EIP
* is not currently bound.
* <p>
* <em>The changes are effective at runtime.</em>
* </p>
*
* @return the time in milliseconds.
*/
int getEIPBindingRetryIntervalMsWhenUnbound();

/**
* Gets the interval with which the server should check if the EIP is bound
* and should try to bind in the case if it is already not bound.
* and should try to bind in the case if it is already not bound, iff the EIP
* is already bound. (so this refresh is just for steady state checks)
* <p>
* <em>The changes are effective at runtime.</em>
* </p>
Expand Down
69 changes: 36 additions & 33 deletions eureka-core/src/main/java/com/netflix/eureka/aws/EIPManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,39 +141,7 @@ private void handleEIPBinding() throws InterruptedException {
}
}
// Schedule a timer which periodically checks for EIP binding.
scheduleEIPBindTask();
}

/**
* Schedules a EIP binding timer task which constantly polls for EIP in the
* same zone and binds it to itself.If the EIP is taken away for some
* reason, this task tries to get the EIP back. Hence it is advised to take
* one EIP assignment per instance in a zone.
*
*/
private void scheduleEIPBindTask() {
timer.schedule(new TimerTask() {
@Override
public void run() {
try {
// If the EIP is not bound, the registry could be stale
// First sync up the registry from the neighboring node before
// trying to bind the EIP
if (!isEIPBound()) {
registry.clearRegistry();
int count = registry.syncUp();
registry.openForTraffic(applicationInfoManager, count);
} else {
// An EIP is already bound
return;
}
bindEIP();
} catch (Throwable e) {
logger.error("Could not bind to EIP", e);
}
}
}, serverConfig.getEIPBindingRetryIntervalMs(),
serverConfig.getEIPBindingRetryIntervalMs());
timer.schedule(new EIPBindingTask(), serverConfig.getEIPBindingRetryIntervalMsWhenUnbound());
}

/**
Expand Down Expand Up @@ -429,4 +397,39 @@ private AmazonEC2 getEC2Service() {
ec2Service.setEndpoint("ec2." + region + ".amazonaws.com");
return ec2Service;
}

/**
* An EIP binding timer task which constantly polls for EIP in the
* same zone and binds it to itself.If the EIP is taken away for some
* reason, this task tries to get the EIP back. Hence it is advised to take
* one EIP assignment per instance in a zone.
*/
private class EIPBindingTask extends TimerTask {
@Override
public void run() {
boolean isEIPBound = false;
try {
isEIPBound = isEIPBound();
// If the EIP is not bound, the registry could be stale. First sync up the registry from the
// neighboring node before trying to bind the EIP
if (!isEIPBound) {
registry.clearRegistry();
int count = registry.syncUp();
registry.openForTraffic(applicationInfoManager, count);
} else {
// An EIP is already bound
return;
}
bindEIP();
} catch (Throwable e) {
logger.error("Could not bind to EIP", e);
} finally {
if (isEIPBound) {
timer.schedule(new EIPBindingTask(), serverConfig.getEIPBindingRetryIntervalMs());
} else {
timer.schedule(new EIPBindingTask(), serverConfig.getEIPBindingRetryIntervalMsWhenUnbound());
}
}
}
};
}