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

Memcached clusters #33

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Memcached clusters #33

wants to merge 2 commits into from

Conversation

berkeli
Copy link
Owner

@berkeli berkeli commented Nov 8, 2022

Use the set and get commands again to understand the behaviour of this mcrouter configuration. How does the behaviour differ from the replicated cluster?

  1. In the case of replicated cluster we can get it from each memcached instance, all of the commands below return the same value since data is replicated:
  • printf "get mykey\r\n" | nc localhost 11211 - this is the router, returns data
  • printf "get mykey\r\n" | nc localhost 11212 - replica, returns same data
  • printf "get mykey\r\n" | nc localhost 11213 - replica, returns same data
  • printf "get mykey\r\n" | nc localhost 11214 - replica, returns same data
  1. In the case of sharded cluster we can can only get the data from the router or from the instance that stores the data, in my case:
  • printf "get mykey\r\n" | nc localhost 11211 - this is the router, returns data
  • printf "get mykey\r\n" | nc localhost 11212 - returns data, as the router stored it in this instance
  • printf "get mykey\r\n" | nc localhost 11213 - doesn't return data
  • printf "get mykey\r\n" | nc localhost 11214 - doesn't return data

@sre-is-laura
Copy link

yep, the cache topology tester looks right to me. good work

Copy link

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

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

This looks great! Left a couple of very minor thoughts on naming :)

"github.com/bradfitz/gomemcache/memcache"
)

type ICacheService interface {

Choose a reason for hiding this comment

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

A common pattern I've seen naming-wise is to name the interface CacheService, to have the standard/obvious implementation be private and called cacheService, and to have NewCacheService return a CacheService (i.e. the interface). This means that you don't need the ugly I-prefix, and that the caller can only access the publicly declared interface functionality rather than relying on internal implementation details.

log.Println(clusterType)
}

func checkIfSharded(router ICacheService, nodes map[string]ICacheService) (string, error) {

Choose a reason for hiding this comment

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

From the name checkIfSharded, I would expect this to probably return a boolean, and it's not super clear what "not sharded" (i.e. false) would mean.

I'd maybe call this checkMode (to imply "there are multiple modes it may return") or detectShardedOrReplicated (to be clear what the universe of return values is).

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.

3 participants