Skip to content

Different consistent distribution between v2.2.0 and v3.0.3 (MEMCACHED_BEHAVIOR_KETAMA vs MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED) #344

Closed
@Vincent--

Description

@Vincent--

To be sure we are speaking about the same things, see https://github.com/trondn/libmemcached/blob/master/docs/memcached_behavior.pod

MEMCACHED_BEHAVIOR_KETAMA
Sets the default distribution to MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA and the hash to MEMCACHED_HASH_MD5.

MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
Sets the default distribution to MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA with the weighted support. and the hash to MEMCACHED_HASH_MD5.

So basically, I have 4 webservers using a pool of 2 memcache servers to store session.
I'm trying to upgrade to php7, so my current setup is like that:

  • web1: php7 + memcached3.0.3
  • web2,3,4: php5.6 + memcache2.2.0

Everytimes I try to enable web1, I'm loosing all my sessions. I've checked all the configuration options and everything seems to be ok. With a basic php script I can store and load the session from any webservers, but randomly the session created with one php version is not available from the other php version. Based on these tests, I'm pretty sure the culprit is the consistent distribution which seems different between 2.2.0 and 3.0.3.

From what I can see in the code, a change has been introduced in dc5b22a#diff-25c5e7d3aa23f27466a7f0bbc2c251ec

Previously the session engine was enabling MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED when sess_consistent_hash_enabled was in use:

                if (MEMC_G(sess_consistent_hash_enabled)) {
                    if (memcached_behavior_set(memc_sess->memc_sess, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, (uint64_t) 1) == MEMCACHED_FAILURE) {
                        PS_SET_MOD_DATA(NULL);
                        if (plist_key) {
                            efree(plist_key);
                        }
                        memcached_free(memc_sess->memc_sess);
                        php_error_docref(NULL, E_WARNING, "failed to enable memcached consistent hashing");
                        return FAILURE;
                    }
                }

After that, the default behaviour has been switched to MEMCACHED_BEHAVIOR_KETAMA:

    if (MEMC_SESS_INI(consistent_hash_enabled)) {
        check_set_behavior(MEMCACHED_BEHAVIOR_KETAMA, 1);
    }

I just wanted to know if this change has been done on purpose or if it's a mistake as I cannot see anything related to that in the changelog.
Is it possible to restore the initial behaviour so php5.6 and php7 can coexists in the same infra and use the same memcache pool?
Thanking you in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions