Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Cache] Add DSN, createClient & better error reporting to MemcachedAdapter#21108

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@nicolas-grekas
Copy link
Member

@nicolas-grekasnicolas-grekas commentedDec 30, 2016
edited
Loading

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets-
LicenseMIT
Doc PRsymfony/symfony-docs#7265

Replaces#20863
ping@robfrawley: would you mind opening a doc PR for this?

@nicolas-grekasnicolas-grekasforce-pushed thefeature-advanced-memcached-cache-pool branch 9 times, most recently from70e509a to6d35624CompareDecember 30, 2016 15:43
@nicolas-grekasnicolas-grekas added this to the3.3 milestoneDec 30, 2016
@nicolas-grekasnicolas-grekasforce-pushed thefeature-advanced-memcached-cache-pool branch 2 times, most recently from95ad534 to6e68d2cCompareDecember 30, 2016 16:26
}
if ($client->getOption(\Memcached::OPT_NO_BLOCK)) {
thrownewCacheException('MemcachedAdapter: OPT_NO_BLOCK must be disabled.');
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand the serializer requirement, but why are weforcing binary protocol and no_block=false?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Binary because we must support all chars in keys especially spaces, per psr-6.
No block because we need guarantees when reading/writing to the cache. Dealing with async would make the code complex for no benefit.

Copy link
Contributor

@robfrawleyrobfrawleyDec 30, 2016
edited
Loading

Choose a reason for hiding this comment

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

Regardingbinary_protocol requirement: I'm on board with this.

But, regardingno_block requirement: I disagree. The intended use of this option doesn't require any additional code, and, in fact, writing such code would invalidate the entire intended usage and benefits ofno_block. The expectation when it is enabled is that the userdoesn't need guarantees when writing. It is acommonly used option and generally doesn't change expectations; due to the design of memcached, one can never assume a value exists as it may have been purged at any time by the LRU algorithm, and will definitely not exist after a restart of the daemon.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

fixed for no_block

unset($options['persistent_id'],$options['username'],$options['password']);

// set client's options
foreach ($optionsas$name =>$value) {
Copy link
Contributor

@robfrawleyrobfrawleyDec 30, 2016
edited
Loading

Choose a reason for hiding this comment

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

This needs to beforeach (array_reverse($options) as $name => $value) as seen in my PR, otherwise defaul values that affect multiple options (such aslibketama_compatible) will overwrite use-provided values.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I think reverse or not, it's the responsibility of the user to order correctly. I'd better behave the same as the native setOptions so that expectations don't have to be reversed when using our lib...

Copy link
Contributor

@robfrawleyrobfrawleyDec 30, 2016
edited
Loading

Choose a reason for hiding this comment

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

It's due to our code, though. The default option oflibketama_compatible in combination with$options += static::$defaultClientOptions; means a user cannot change, for example, the hash algorithm, ever...as our default oflibketama_compatible will be appliedafter the user-provided option (for example['hash' => 'something-else']), resetting the hash tomd5. The options need to be applied in reverse order to allow the user to overwrite our defaults.

Copy link
Contributor

@robfrawleyrobfrawleyDec 30, 2016
edited
Loading

Choose a reason for hiding this comment

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

To clarify: the user should, rightfully, assume that any options they provide will overwrite our defaults. The issue is,some options actually affect multiple options. Without reversing the array, the user options will not always result in a proper assignment; while reversing the options ensures user options always overwrite defaults.

It's not theorder of options that is important, it's the order ofdefault options touser options that is important.Default options must be applied first, so either the assignment needs to change:

# from this:$options +=static::$defaultClientOptions;# to this (or something similar):foreach (static::$defaultClientOptionsas$name =>$option) {if (!array_key_exists($name,$options) {array_unshift($options, [$name =>$option]);    }}

OR the order of options needs to be reversed:

# from this:foreach ($optionsas$name =>$value) {}# to this (or something similar):foreach (array_reverse($options)as$name =>$value) {}

Otherwise options will behave unexpectedly for the user.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

understood, fixed also

}

// set client's servers, taking care of persistent connections
if (!$client->isPristine()) {
Copy link
Contributor

@robfrawleyrobfrawleyDec 30, 2016
edited
Loading

Choose a reason for hiding this comment

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

We shouldn't add servers after a connection is open (even when the user has added an additional server to their configuration)?

Copy link
MemberAuthor

@nicolas-grekasnicolas-grekasDec 30, 2016
edited
Loading

Choose a reason for hiding this comment

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

Not sure to get what you mean. Do you see anything wrong with this logic?
Here it is: if the connection is not pristine (meaning it's a 2nd use persistent connection), then we check if there is any change in the list of server. If there is, we reset the list and set the new one.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. Had trouble following the code, but makes sense now.

@robfrawley
Copy link
Contributor

robfrawley commentedDec 30, 2016
edited
Loading

A documentation PR for#20863 is already open (see issuesymfony/symfony-docs#7256 and PRsymfony/symfony-docs#7265) and it doesn't require much at all to update it for this PR. I will ensure it is accurate after the implementation details I've asked about are handled/clarified. Thanks!

nicolas-grekas reacted with thumbs up emoji

@nicolas-grekasnicolas-grekasforce-pushed thefeature-advanced-memcached-cache-pool branch 3 times, most recently fromd2565af to9e899a4CompareDecember 30, 2016 21:37
@robfrawley
Copy link
Contributor

I'd add a test to cover the serialize requirement:

/**     * @expectedException \Symfony\Component\Cache\Exception\CacheException     * @expectedExceptionMessage MemcachedAdapter: PHP or IGBINARY must be used.     */publicfunctiontestOptionSerializer()    {newMemcachedAdapter(MemcachedAdapter::createConnection(array(),array('serializer' =>'json')));    }

@nicolas-grekasnicolas-grekasforce-pushed thefeature-advanced-memcached-cache-pool branch from9e899a4 to4e31feaCompareDecember 31, 2016 09:15
@nicolas-grekas
Copy link
MemberAuthor

@robfrawley test case added, thanks. Note also that considering your comment about no block, and the use case here (a cache layer), I enabled no-block by default. Tests are green which means it's good for PSR-6!

robfrawley reacted with thumbs up emoji

@nicolas-grekasnicolas-grekasforce-pushed thefeature-advanced-memcached-cache-pool branch from4e31fea to95c9777CompareDecember 31, 2016 09:29
@robfrawley
Copy link
Contributor

robfrawley commentedDec 31, 2016
edited
Loading

Platform.sh is not properly building the documentation for a bunch of PRs ATM, but I think the docs are accurate with regard to this PR (updated to show correct defaults per your latest updates):give it a look here.


if (!$container->hasDefinition($name =md5($dsn))) {
$definition =newDefinition(\Redis::class);
$definition =newDefinition('_');
Copy link
Member

Choose a reason for hiding this comment

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

What about usingAdapterInterface::class to not make it harder for bundles that do static analyses of the container?

return MemcachedAdapter::createConnection($dsn,$options);
}

thrownewInvalidArgumentException(sprintf('Unsupported DSN: %s.',$dsn));
Copy link
Member

Choose a reason for hiding this comment

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

Should theAbstractAdapter really be aware of all adapters that require a connection?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

This is a stateless static method, no need for yet another class. This has to be somewhere :)
Other comments addressed.

}
$opt =$client->getOption(\Memcached::OPT_SERIALIZER);
if (\Memcached::SERIALIZER_PHP !==$opt && \Memcached::SERIALIZER_IGBINARY !==$opt) {
thrownewCacheException('MemcachedAdapter: serializer must be PHP or IGBINARY.');
Copy link
Member

Choose a reason for hiding this comment

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

Should we useOPT_SERIALIZER instead ofserializer here to be consistent with the exception message below?

Copy link
Contributor

@robfrawleyrobfrawleyDec 31, 2016
edited
Loading

Choose a reason for hiding this comment

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

The way this code is setup and documented, you passserializer, notopt_serializer, so I would argue the inverse: theother exception message should be amend to:

binary_protocol must be used

if (is_string($servers)) {
$servers =array($servers);
}elseif (!is_array($servers)) {
thrownewInvalidArgumentException(sprintf('MemcachedAdapter::createClient() expects array or string as first argument, %s given.',get_type($servers)));
Copy link
Member

Choose a reason for hiding this comment

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

gettype()

@nicolas-grekasnicolas-grekasforce-pushed thefeature-advanced-memcached-cache-pool branch 3 times, most recently from36fd01e to3eae606CompareJanuary 2, 2017 17:04
@nicolas-grekasnicolas-grekasforce-pushed thefeature-advanced-memcached-cache-pool branch from3eae606 to87030b4CompareJanuary 3, 2017 16:10
@xabbuh
Copy link
Member

👍

@robfrawley
Copy link
Contributor

robfrawley commentedJan 3, 2017
edited
Loading

@nicolas-grekas Do we want the RedisAdapter to accept an array of DSNs like the MemcacheAdapter; I'm looking into bringing the RedisAdapter documentation in-line with the new MemcacheAdapter documentation, re:symfony/symfony-docs/#7265@269875795. It appears it does not at this time.

@nicolas-grekas
Copy link
MemberAuthor

@robfrawley it would be great yes

@nicolas-grekas
Copy link
MemberAuthor

Thank you@robfrawley.

@nicolas-grekasnicolas-grekas merged commit87030b4 intosymfony:masterJan 4, 2017
nicolas-grekas added a commit that referenced this pull requestJan 4, 2017
… to MemcachedAdapter (nicolas-grekas, robfrawley)This PR was merged into the 3.3-dev branch.Discussion----------[Cache] Add DSN, createClient & better error reporting to MemcachedAdapter| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | -| License       | MIT| Doc PR        |symfony/symfony-docs#7265Replaces#20863ping@robfrawley: would you mind opening a doc PR for this?Commits-------87030b4 [cache] Add tests for MemcachedAdapter::createClient()e109438 [Cache] Add DSN, createClient & better error reporting to MemcachedAdapter
@nicolas-grekasnicolas-grekas deleted the feature-advanced-memcached-cache-pool branchJanuary 4, 2017 06:52
@fabpotfabpot mentioned this pull requestMay 1, 2017
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@xabbuhxabbuhxabbuh left review comments

+1 more reviewer

@robfrawleyrobfrawleyrobfrawley left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

3.3

Development

Successfully merging this pull request may close these issues.

4 participants

@nicolas-grekas@robfrawley@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp