plpgsql and replacing pgmemcache with pgmemcached

Today I ran into a bit of a problem while replacing pgmemcache with pgmemcached (gotta love the naming on these two).
pgmemcache returns True or False depending on success or failure, for example:

society=# select memcache_replace('boguskey', 'nonsense data');
(1 row)

Time: 2.504 ms

With pgmemcached we get the following behavior:

society=# select pgmemcached_replace('boguskey', 'nonsense data');
ERROR:  memcached_result: NOT STORED

Since we're calling memcache from within triggers it is no good when the triggers starts to break on the account of exceptions being raised. So to deal with this we could, in the case of *_replace catch others (to catch all exceptions) or internal_error (to catch the specific exception thrown by pgmemcached) or change the trigger to use *_set function insted since it behaves the same in both cases.

Is it wise to use *_set in this case? Every block using exception handling will create a subtransaction hence it could have an inpact on performance, especially when used inside triggers.

I have yet to run some perfomance testing to see what impact *_set vs *_replace with exception handling will have on our database.

The lessons learned today was: BEGIN ... EXCEPTION and to use \set VERBOSITY 'verbose' to get the exact error code returned by a third party library (in our case XX000 which is internal_error). I also picked up others since I was unaware of it.


Kommentera inlägget här:

Kom ihåg mig?

E-postadress: (publiceras ej)



RSS 2.0