Skip to content

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

Open
ashishsodhi1 wants to merge 1 commit into
magro:masterfrom
ashishsodhi1:master
Open

#319 Need flag to support AWS Static and Dynamic modes.#324
ashishsodhi1 wants to merge 1 commit into
magro:masterfrom
ashishsodhi1:master

Conversation

@ashishsodhi1

Copy link
Copy Markdown

No description provided.

@magro

magro commented Dec 5, 2016

Copy link
Copy Markdown
Owner

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

@magro

magro commented Dec 5, 2016

Copy link
Copy Markdown
Owner

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

ashishsodhi commented Dec 6, 2016

Copy link
Copy Markdown

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

sbellary commented Jan 4, 2017

Copy link
Copy Markdown

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

Thanks

@magro

magro commented Jan 4, 2017

Copy link
Copy Markdown
Owner

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

import net.spy.memcached.DefaultConnectionFactory;

/**
* Created by asodhi on 11/29/2016.

Copy link
Copy Markdown
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 :-)

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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
Copy Markdown
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?

Copy link
Copy Markdown

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
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Rename to MemcachedElastiCacheConnectionFactory?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yes agree will rename.

long maxReconnectDelay, Statistics statistics );
}

static interface MemcachedNodeURLBasedConnectionFactory {

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ok will do


static interface MemcachedNodeURLBasedConnectionFactory {
ConnectionFactory createBinaryConnectionFactory(long operationTimeout,
long maxReconnectDelay, boolean isClientDynamicMode);

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

@ashishsodhi ashishsodhi Jan 13, 2017

Copy link
Copy Markdown

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?


protected static MemcachedNodeURLBasedConnectionFactory createMemcachedNodeURLBasedConnectionFactory() {
try {
Class.forName("net.spy.memcached.ClientMode");

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

Copy link
Copy Markdown

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

@ashishsodhi ashishsodhi Jan 13, 2017

Copy link
Copy Markdown

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);
}
...

}
}

protected static MemcachedNodeURLBasedConnectionFactory createMemcachedNodeURLBasedConnectionFactory() {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Rename to createMemcachedConnectionFactory?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ok

@eschulma

Copy link
Copy Markdown

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

@magro

magro commented Mar 14, 2018

Copy link
Copy Markdown
Owner

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

@eschulma

Copy link
Copy Markdown

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

@magro

magro commented Mar 15, 2018

Copy link
Copy Markdown
Owner

@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