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

#319 Need flag to support AWS Static and Dynamic modes. #324

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ashishsodhi1
Copy link

No description provided.

@magro
Copy link
Owner

magro commented Dec 5, 2016

Thanks for the PR! Can you tell what's the motivation, which problem is solved and how to use it?

@magro
Copy link
Owner

magro commented Dec 5, 2016

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.

@ashishsodhi
Copy link

ashishsodhi commented Dec 6, 2016

Hi
https://github.com/awslabs/aws-elasticache-cluster-client-memcached-for-java
-Dclient.mode=memcached_client_mode
This argument is used to specify the mode of the client that you want to run. Supported options are Static and Dynamic. Dynamic mode enables Auto Discovery feature. Static mode runs without Auto Discovery and has the same functionality as a classic spymemcached client. By default it is set to Dynamic.

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..

@sbellary
Copy link

sbellary commented Jan 4, 2017

Hi Margo,
Did you get a chance to look into this? Is this going to be incorporated? PLease let us know

Thanks

@magro
Copy link
Owner

magro commented Jan 4, 2017

@sbellary Not yet, sorry, I'm having a look now.

import net.spy.memcached.DefaultConnectionFactory;

/**
* Created by asodhi on 11/29/2016.
Copy link
Owner

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 :-)

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) {
Copy link
Owner

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.

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) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no try/catch needed.

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.
Copy link
Owner

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?

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 {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to MemcachedElastiCacheConnectionFactory?

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 {
Copy link
Owner

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.

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);
Copy link
Owner

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.

Copy link

@ashishsodhi ashishsodhi Jan 13, 2017

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");
Copy link
Owner

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.

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;
Copy link
Owner

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.

Copy link

@ashishsodhi ashishsodhi Jan 13, 2017

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

https://github.com/awslabs/aws-elasticache-cluster-client-memcached-for-java/blob/master/src/main/java/net/spy/memcached/MemcachedClient.java

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() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to createMemcachedConnectionFactory?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@eschulma
Copy link

Is this being worked on? I have the exact same need.

@magro
Copy link
Owner

magro commented Mar 14, 2018

@eschulma I think it's stalled. Maybe you want to pick up what's already there and continue with this?

@eschulma
Copy link

My environment is working, and I don't remember much about this now. But it looked like @ashishsodhi was close to being done.

@magro
Copy link
Owner

magro commented Mar 15, 2018

@eschulma ok :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants