Refactored session locking logic

* Use a precalculated SHA1 of our lock release script and first
  attempt to EVALSHA the script while falling back to EVAL if that
  fails.  This means that the very first time we attempt to release
  a lock after server restart or script cache will fail but subsequent
  attempts will succeed as Redis will cache the script automatically.

* Reorganized the new locking prototypes by making them static and removing
  them from the header file as they never need to be called from outside
  of redis_session.c anyway.  Did the same for the lock_secret structure
  as we don't need to expose the structure externally.

* Consolidated allocation and deallocation of lock pointers such that our
  redis_pool "constructor" and "desctructor" handle that as well.

* Updating how we release the lock means we no longer need the new REDIS_G
  module globals, so those were removed.

* HOST_NAME_MAX doesn't exist on OSX so added some preprocessor logic around that

Still a WIP as it needs more testing as I'm sure I broke *something* :-)
This commit is contained in:
michael-grunder
2017-11-10 13:46:48 -08:00
parent f2162e5a6a
commit b63d79958e
4 changed files with 184 additions and 169 deletions

View File

@@ -3,20 +3,6 @@
#ifdef PHP_SESSION
#include "ext/session/php_session.h"
typedef struct {
zend_bool is_locked;
char *session_key;
char *lock_key;
char *lock_secret;
} redis_session_lock_status;
int lock_acquire(RedisSock *redis_sock, redis_session_lock_status *lock_status TSRMLS_DC);
void lock_release(RedisSock *redis_sock, redis_session_lock_status *lock_status TSRMLS_DC);
void refresh_lock_status(RedisSock *redis_sock, redis_session_lock_status *lock_status TSRMLS_DC);
int write_allowed(RedisSock *redis_sock, redis_session_lock_status *lock_status TSRMLS_DC);
int upload_lock_release_script(RedisSock *redis_sock TSRMLS_DC);
void calculate_lock_secret(redis_session_lock_status *lock_status);
PS_OPEN_FUNC(redis);
PS_CLOSE_FUNC(redis);
PS_READ_FUNC(redis);