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

#963 MemcachedStorage Notice if deamon is not running, incl. test #980

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

Conversation

patriksima
Copy link
Contributor

No description provided.

@milo
Copy link
Member

milo commented Mar 2, 2013

Is it necessary to fix it in this way? This is an advantage of Memcache to add server which may be offline. Other servers may be online and this one just loose priority.

I hope, better solution is to somehow provide access to 8th addServer() parameter where user can handle these errors.


try {
$cache = new Cache(new MemcachedStorage('localhost', 11666)); // assume that on this port by default is not running
Assert::fail('Expected exception');
Copy link
Member

Choose a reason for hiding this comment

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

There is an Assert::exception() for this purpose.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool. That's exactly what I was looking for. This code I copied from other tests. Btw. Is there any help for Nette/Tester?

@patriksima
Copy link
Contributor Author

I cant imagine that someone uses memcache offline. What's the point? But, if so, can wrap each call addServer in try/catch block and then work with it.

@milo
Copy link
Member

milo commented Mar 2, 2013

$mc->addServer('1st.domain.tld');
$mc->addServer('2nd.domain.tld'); // Offline now? Who cares...
$mc->addServer('3nd.domain.tld');

@patriksima
Copy link
Contributor Author

The point is that the exception is better than hidden notice. Exception can be handled explicitly, notice no.

@patriksima
Copy link
Contributor Author

I can't be sure that pull out failure_callback is the solution. you got it checked?

@milo
Copy link
Member

milo commented Mar 2, 2013

My point is that offline state is a normal cache state, not a fault. Cache is not permanent data storage.

With your patch... what happend when server is online when addServer() and offline when read(), write()? Notice is emmited.

@milo
Copy link
Member

milo commented Mar 2, 2013

I checked that "offline message" notice is catched by callback.

@patriksima
Copy link
Contributor Author

Both method return NULL or FALSE if server failed.

@patriksima
Copy link
Contributor Author

I noticed that method write($key, $data, array $dp) don`t return value. But it should IMHO.

@milo
Copy link
Member

milo commented Mar 2, 2013

Yes, NULL or FALSE is returned without notice, but only when server is offline during addServer(). If gets offline between addServer() and read()/write(), Notice is still thrown.

@patriksima
Copy link
Contributor Author

Okey. I got it. Options:

  • supress notice by Debugger::$strictMode
  • supress notice by @ inside both method read() and write()
  • pull out failure_callback to addServer() method params
  • combination of the above

@patriksima
Copy link
Contributor Author

And I fix write() to return a value. Plus fix assertion in my test.

@dg
Copy link
Member

dg commented Apr 16, 2013

@patriksima I am not using memcached and I don't know if this pull is good to merge. This #980 (comment) makes sense to me.

@patriksima
Copy link
Contributor Author

@dg I wrote options. Which way should I go?

@milo
Copy link
Member

milo commented Apr 24, 2013

I have done small investigation...

One big advantage of Memcache class is, that can be used with offline servers. Actually it works without added servers. Yes, it emits notices/warnings but works.

Adding server even if is offline is important. Memcache do statistics and prioritize servers. Exception cannot be throws due to BC (application stops working with offline server, moreover, addServer is in constructor).

Shut-up operator in read(), write() and others is not IMO good idea due to suppressing warnings too.

Pass failure callback for Memcache::addServer() is a half-good way. It catch all notices, but only host and port is passed and you never get the error message. This can be now achived by $mc->getConnection()->setServerParams(). But there is easy to make a loop when accessing Memcache from callback.

Better solution is install error handler before every memcache method calling and catch notices (see d59555a). I was afraid about performace, but on my laptop:

for ($i = 0; $i < 100000; $i++) { # 20ms
}

for ($i = 0; $i < 100000; $i++) { # 380ms
    set_error_handler(function() { restore_error_handler(); });
    restore_error_handler();
}

Question is, if handle only notices or all errors (http://svn.php.net/viewvc/pecl/memcache/trunk/memcache.c?view=markup).

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

Successfully merging this pull request may close these issues.

None yet

3 participants