From b25deaacea75f2e565a58ea14aca19627f5cfa93 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 13 Jan 2010 21:24:02 -0800 Subject: [PATCH 01/11] queue daemon fixes: path fix for xmpp, suppress warning in memcached init --- lib/xmppmanager.php | 2 +- plugins/MemcachePlugin.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/xmppmanager.php b/lib/xmppmanager.php index 9662e97d15..0839cda57a 100644 --- a/lib/xmppmanager.php +++ b/lib/xmppmanager.php @@ -81,7 +81,7 @@ class XmppManager extends IoManager parent::start($master); $this->switchSite(); - require_once "lib/jabber.php"; + require_once INSTALLDIR . "/lib/jabber.php"; # Low priority; we don't want to receive messages diff --git a/plugins/MemcachePlugin.php b/plugins/MemcachePlugin.php index fbc2802f78..bc7fd90765 100644 --- a/plugins/MemcachePlugin.php +++ b/plugins/MemcachePlugin.php @@ -166,7 +166,7 @@ class MemcachePlugin extends Plugin if (is_array($this->servers)) { foreach ($this->servers as $server) { - list($host, $port) = explode(';', $server); + list($host, $port) = @explode(';', $server); if (empty($port)) { $port = 11211; } From 4b839cfc53d1aa5aa64adb940e122efe1475c9e9 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 13 Jan 2010 21:35:47 -0800 Subject: [PATCH 02/11] fix for non-% memory soft limit --- lib/iomaster.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/iomaster.php b/lib/iomaster.php index aff5b145c2..5d1071a392 100644 --- a/lib/iomaster.php +++ b/lib/iomaster.php @@ -231,7 +231,7 @@ class IoMaster return -1; } } else { - return $this->parseMemoryLimit($limit); + return $this->parseMemoryLimit($softLimit); } return $softLimit; } From abd67452dad9c0e53427731d96de15428a99b086 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 13 Jan 2010 22:12:19 -0800 Subject: [PATCH 03/11] go straight to the DB for inbox before insert --- classes/Inbox.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/Inbox.php b/classes/Inbox.php index 83cfe8ef82..f3d4afca39 100644 --- a/classes/Inbox.php +++ b/classes/Inbox.php @@ -103,9 +103,9 @@ class Inbox extends Memcached_DataObject static function insertNotice($user_id, $notice_id) { - $inbox = Inbox::staticGet('user_id', $user_id); + $inbox = DB_DataObject::staticGet('inbox', 'user_id', $user_id); - if (empty($inbox) || $inbox->fake) { + if (empty($inbox)) { $inbox = Inbox::initialize($user_id); } From 16742d0fde811256c386d1bae9768fcd939b9af8 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 13 Jan 2010 22:32:17 -0800 Subject: [PATCH 04/11] do since_id and max_id in inbox --- classes/Inbox.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/classes/Inbox.php b/classes/Inbox.php index f3d4afca39..312b4586b4 100644 --- a/classes/Inbox.php +++ b/classes/Inbox.php @@ -153,8 +153,19 @@ class Inbox extends Memcached_DataObject $ids = unpack('N*', $inbox->notice_ids); - // XXX: handle since_id - // XXX: handle max_id + if (!empty($since_id)) { + $i = array_search($since_id, $ids); + if ($i !== false) { + $ids = array_slice($ids, 0, $i - 1); + } + } + + if (!empty($max_id)) { + $i = array_search($max_id, $ids); + if ($i !== false) { + $ids = array_slice($ids, $i - 1); + } + } $ids = array_slice($ids, $offset, $limit); From 30e50439a32eaf7b68897c5b141c955f6906ad79 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 13 Jan 2010 23:17:37 -0800 Subject: [PATCH 05/11] change double quotes to single quotes in numbered format string --- actions/all.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/all.php b/actions/all.php index efa4521e21..3eb1852147 100644 --- a/actions/all.php +++ b/actions/all.php @@ -81,7 +81,7 @@ class AllAction extends ProfileAction function title() { if ($this->page > 1) { - return sprintf(_("%1$s and friends, page %2$d"), $this->user->nickname, $this->page); + return sprintf(_('%1$s and friends, page %2$d'), $this->user->nickname, $this->page); } else { return sprintf(_("%s and friends"), $this->user->nickname); } From 28fafe803a82a0f5885655dfcad5e835163d3139 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 13 Jan 2010 23:28:51 -0800 Subject: [PATCH 06/11] remove debugging statement for friends_timeline --- actions/apitimelinefriends.php | 1 - 1 file changed, 1 deletion(-) diff --git a/actions/apitimelinefriends.php b/actions/apitimelinefriends.php index ef58b103c5..4e3827baea 100644 --- a/actions/apitimelinefriends.php +++ b/actions/apitimelinefriends.php @@ -72,7 +72,6 @@ class ApiTimelineFriendsAction extends ApiBareAuthAction function prepare($args) { parent::prepare($args); - common_debug("api friends_timeline"); $this->user = $this->getTargetUser($this->arg('id')); if (empty($this->user)) { From 8a7171fde610246e5820ee04441955bd8dd463bf Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 13 Jan 2010 23:38:51 -0800 Subject: [PATCH 07/11] Don't barf on io loop if xmpp connection failed --- lib/xmppmanager.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/xmppmanager.php b/lib/xmppmanager.php index 0839cda57a..dfff63a30c 100644 --- a/lib/xmppmanager.php +++ b/lib/xmppmanager.php @@ -118,7 +118,11 @@ class XmppManager extends IoManager */ public function getSockets() { - return array($this->conn->getSocket()); + if ($this->conn) { + return array($this->conn->getSocket()); + } else { + return array(); + } } /** From 2f32181c930afbbfad7986f84df908cac4ef182d Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 14 Jan 2010 00:19:25 -0800 Subject: [PATCH 08/11] Keep handler registration per-site to fix queue registration in mixed config environment --- lib/stompqueuemanager.php | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/lib/stompqueuemanager.php b/lib/stompqueuemanager.php index 3090e0bfb6..a7d735d1cf 100644 --- a/lib/stompqueuemanager.php +++ b/lib/stompqueuemanager.php @@ -66,10 +66,57 @@ class StompQueueManager extends QueueManager * * @fixme possibly actually do subscription here to save another * loop over all sites later? + * @fixme possibly don't assume it's the current site */ public function addSite($server) { $this->sites[] = $server; + $this->initialize(); + } + + + /** + * Instantiate the appropriate QueueHandler class for the given queue. + * + * @param string $queue + * @return mixed QueueHandler or null + */ + function getHandler($queue) + { + $handlers = $this->handlers[common_config('site', 'server')]; + if (isset($handlers[$queue])) { + $class = $handlers[$queue]; + if (class_exists($class)) { + return new $class(); + } else { + common_log(LOG_ERR, "Nonexistent handler class '$class' for queue '$queue'"); + } + } else { + common_log(LOG_ERR, "Requested handler for unkown queue '$queue'"); + } + return null; + } + + /** + * Get a list of all registered queue transport names. + * + * @return array of strings + */ + function getQueues() + { + return array_keys($this->handlers[common_config('site', 'server')]); + } + + /** + * Register a queue transport name and handler class for your plugin. + * Only registered transports will be reliably picked up! + * + * @param string $transport + * @param string $class + */ + public function connect($transport, $class) + { + $this->handlers[common_config('site', 'server')][$transport] = $class; } /** From 5783874cc20ab0f856ea6b3f41510a303a8bd3a2 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 14 Jan 2010 14:07:24 -0800 Subject: [PATCH 09/11] Clean up host/port separation in memcached plugin -- use : not ; as separator and clean up some warnings --- plugins/MemcachePlugin.php | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/plugins/MemcachePlugin.php b/plugins/MemcachePlugin.php index bc7fd90765..5214ab9c89 100644 --- a/plugins/MemcachePlugin.php +++ b/plugins/MemcachePlugin.php @@ -165,20 +165,18 @@ class MemcachePlugin extends Plugin $this->_conn = new Memcache(); if (is_array($this->servers)) { - foreach ($this->servers as $server) { - list($host, $port) = @explode(';', $server); - if (empty($port)) { - $port = 11211; - } - - $this->_conn->addServer($host, $port, $this->persistent); - } + $servers = $this->servers; } else { - $this->_conn->addServer($this->servers, $this->persistent); - list($host, $port) = explode(';', $this->servers); - if (empty($port)) { + $servers = array($this->servers); + } + foreach ($servers as $server) { + if (strpos($server, ':') !== false) { + list($host, $port) = explode(':', $server); + } else { + $host = $server; $port = 11211; } + $this->_conn->addServer($host, $port, $this->persistent); } From 58bc33850ab615f21b4364aac8b8b7f74a95111d Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 14 Jan 2010 15:32:37 -0800 Subject: [PATCH 10/11] temporary --skip-xmpp flag on queuedaemon.php, allows to run queue daemons but skip subscription to xmpp-based queues (still working on making these behave gracefully when server is down) --- lib/queuemanager.php | 2 +- scripts/queuedaemon.php | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/queuemanager.php b/lib/queuemanager.php index a98c0efffb..b98e57a1ff 100644 --- a/lib/queuemanager.php +++ b/lib/queuemanager.php @@ -157,7 +157,7 @@ abstract class QueueManager extends IoManager } // XMPP output handlers... - if (common_config('xmpp', 'enabled')) { + if (common_config('xmpp', 'enabled') && !defined('XMPP_EMERGENCY_FLAG')) { $this->connect('jabber', 'JabberQueueHandler'); $this->connect('public', 'PublicQueueHandler'); diff --git a/scripts/queuedaemon.php b/scripts/queuedaemon.php index 8ef364fe7b..f8bade39db 100755 --- a/scripts/queuedaemon.php +++ b/scripts/queuedaemon.php @@ -21,7 +21,7 @@ define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); $shortoptions = 'fi:at:'; -$longoptions = array('id=', 'foreground', 'all', 'threads='); +$longoptions = array('id=', 'foreground', 'all', 'threads=', 'skip-xmpp'); /** * Attempts to get a count of the processors available on the current system @@ -260,6 +260,10 @@ if (!$threads) { $daemonize = !(have_option('f') || have_option('--foreground')); $all = have_option('a') || have_option('--all'); +if (have_option('--skip-xmpp')) { + define('XMPP_EMERGENCY_FLAG', true); +} + $daemon = new QueueDaemon($id, $daemonize, $threads, $all); $daemon->runOnce(); From 038287c1ffb71207f8028014f20005483364956d Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 14 Jan 2010 17:14:41 -0800 Subject: [PATCH 11/11] fix for --skip-xmpp hack -- forgot to do it on the ping & confirm handlers --- lib/iomaster.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/iomaster.php b/lib/iomaster.php index 5d1071a392..ce77b53b2e 100644 --- a/lib/iomaster.php +++ b/lib/iomaster.php @@ -70,7 +70,7 @@ class IoMaster $classes = array(); if (Event::handle('StartIoManagerClasses', array(&$classes))) { $classes[] = 'QueueManager'; - if (common_config('xmpp', 'enabled')) { + if (common_config('xmpp', 'enabled') && !defined('XMPP_EMERGENCY_FLAG')) { $classes[] = 'XmppManager'; // handles pings/reconnects $classes[] = 'XmppConfirmManager'; // polls for outgoing confirmations }