-
Notifications
You must be signed in to change notification settings - Fork 348
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
#319 Need flag to support AWS Static and Dynamic modes. #324
base: master
Are you sure you want to change the base?
Conversation
Thanks for the PR! Can you tell what's the motivation, which problem is solved and how to use it? |
For me questions arise with the title already, as I don't know what's static / dynamic mode. Links to documentation would of course be useful as well. |
Hi Dynamic mode -> http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/AutoDiscovery.Using.html Static mode->http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/AutoDiscovery.Manual.html Our specific issue was that we were packaging Amazon ElastiCache Cluster Client with our application for application caching so did not have the option of switching between Elastic Client and spymemcached client but still had the requirement to configure session backup with either manually or with dynamic discovery to support testing in local, uat, stage, and aws production environments differently.. |
Hi Margo, Thanks |
@sbellary Not yet, sorry, I'm having a look now. |
import net.spy.memcached.DefaultConnectionFactory; | ||
|
||
/** | ||
* Created by asodhi on 11/29/2016. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're adding class documentation other content would be more useful :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will drop the class documentation looks like pretty much self explanatory.
return maxReconnectDelay; | ||
} | ||
}; | ||
} catch (final Exception e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try/catch should not be needed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure will drop try/catch.
return maxReconnectDelay; | ||
} | ||
}; | ||
} catch (final Exception e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no try/catch needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do.
import java.lang.reflect.*; | ||
|
||
/** | ||
* Created by asodhi on 11/29/2016. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More useful documentation, or drop it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will drop it.
/** | ||
* Created by asodhi on 11/29/2016. | ||
*/ | ||
public class MemcachedElasticConnectionFactory implements StorageClientFactory.MemcachedNodeURLBasedConnectionFactory { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to MemcachedElastiCacheConnectionFactory
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes agree will rename.
@@ -43,6 +43,15 @@ MemcachedClient createCouchbaseClient(MemcachedNodesManager memcachedNodesManage | |||
long maxReconnectDelay, Statistics statistics ); | |||
} | |||
|
|||
static interface MemcachedNodeURLBasedConnectionFactory { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to MemcachedConnectionFactory
? The implementation class MemcachedConnectionFactory
could then be renamed to e.g. StandardMemcachedConnectionFactory
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok will do
@@ -43,6 +43,15 @@ MemcachedClient createCouchbaseClient(MemcachedNodesManager memcachedNodesManage | |||
long maxReconnectDelay, Statistics statistics ); | |||
} | |||
|
|||
static interface MemcachedNodeURLBasedConnectionFactory { | |||
ConnectionFactory createBinaryConnectionFactory(long operationTimeout, | |||
long maxReconnectDelay, boolean isClientDynamicMode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The isClientDynamicMode
should not be part of this API, because its specific to the ElastiCache specific implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally the client mode is determined by the node name in aws client. If the node name contains ".cfg." it would be a dynamic mode. Either we pass the Boolean or we pass the node name?
How about
ConnectionFactory createBinaryConnectionFactory(long operationTimeout,
long maxReconnectDelay, String node);
or
I could add a parameter to the constructor of MemcachedElastiCacheConnectionFactory?
@@ -78,9 +87,30 @@ static MemcachedClient createCouchbaseClient(final MemcachedNodesManager memcach | |||
} | |||
} | |||
|
|||
protected static MemcachedNodeURLBasedConnectionFactory createMemcachedNodeURLBasedConnectionFactory() { | |||
try { | |||
Class.forName("net.spy.memcached.ClientMode"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be extracted into a method like isElastiCacheClientLib
(which also hides exception handling), so that here would be a simple if/else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure will make the change.
boolean isClientDynamicMode = false; | ||
if (memcachedNodesManager.getMemcachedNodes().contains(".cfg.")) | ||
{ | ||
isClientDynamicMode=true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the clientMode set to "Dynamic" statically? And why is this coupled to if (memcachedNodesManager.getMemcachedNodes().contains(".cfg."))
?
I'd expect that the environment variable / system property client.mode
is evaluated...
And as already said, determining the clientMode should be done inside the MemcachedElastiCacheConnectionFactory
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally the client mode is determined by the node name in aws client. If the node name contains ".cfg." it would be a dynamic mode.
Check the implementation in
aws-elasticache-cluster-client-memcachedfor-java -->
/src/main/java/net/spy/memcached/MemcachedClient.java line
...
if(determineClientMode){
if(addrs.size() == 1){
if(addrs.get(0) == null){
throw new NullPointerException("Socket address is null");
}
String hostName = addrs.get(0).getHostName();
//All config endpoints has ".cfg." subdomain in the DNS name.
if(hostName != null && hostName.contains(".cfg.")){
cf = new DefaultConnectionFactory(ClientMode.Dynamic);
}
}
//Fallback to static mode
if(cf == null){
cf = new DefaultConnectionFactory(ClientMode.Static);
}
...
@@ -78,9 +87,30 @@ static MemcachedClient createCouchbaseClient(final MemcachedNodesManager memcach | |||
} | |||
} | |||
|
|||
protected static MemcachedNodeURLBasedConnectionFactory createMemcachedNodeURLBasedConnectionFactory() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to createMemcachedConnectionFactory
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
Is this being worked on? I have the exact same need. |
@eschulma I think it's stalled. Maybe you want to pick up what's already there and continue with this? |
My environment is working, and I don't remember much about this now. But it looked like @ashishsodhi was close to being done. |
@eschulma ok :-) |
No description provided.