summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-01-28 13:35:09 -0800
committerBrion Vibber <brion@pobox.com>2010-01-28 13:35:09 -0800
commitd00ce3854932820cbdb906404d248800c400cbca (patch)
tree2dafb5ce3d749cebf286d614ad438c466b9252d1
parentd773ed8193ee63db360386507e0511d1742b2dd1 (diff)
parent513f8be07a22d722b86509e570bee46d028066f2 (diff)
Merge commit 'origin/master' into testing
-rw-r--r--classes/Memcached_DataObject.php27
-rw-r--r--classes/Session.php43
-rw-r--r--index.php20
-rw-r--r--lib/default.php1
-rw-r--r--lib/stompqueuemanager.php10
-rw-r--r--lib/util.php1
6 files changed, 81 insertions, 21 deletions
diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php
index 2cc6377f8..f4dfe6314 100644
--- a/classes/Memcached_DataObject.php
+++ b/classes/Memcached_DataObject.php
@@ -147,6 +147,7 @@ class Memcached_DataObject extends DB_DataObject
{
$result = parent::insert();
if ($result) {
+ $this->fixupTimestamps();
$this->encache(); // in case of cached negative lookups
}
return $result;
@@ -159,6 +160,7 @@ class Memcached_DataObject extends DB_DataObject
}
$result = parent::update($orig);
if ($result) {
+ $this->fixupTimestamps();
$this->encache();
}
return $result;
@@ -366,7 +368,7 @@ class Memcached_DataObject extends DB_DataObject
}
/**
- * sends query to database - this is the private one that must work
+ * sends query to database - this is the private one that must work
* - internal functions use this rather than $this->query()
*
* Overridden to do logging.
@@ -428,7 +430,7 @@ class Memcached_DataObject extends DB_DataObject
//
// WARNING WARNING if we end up actually using multiple DBs at a time
// we'll need some fancier logic here.
- if (!$exists && !empty($_DB_DATAOBJECT['CONNECTIONS'])) {
+ if (!$exists && !empty($_DB_DATAOBJECT['CONNECTIONS']) && php_sapi_name() == 'cli') {
foreach ($_DB_DATAOBJECT['CONNECTIONS'] as $index => $conn) {
if (!empty($conn)) {
$conn->disconnect();
@@ -529,4 +531,25 @@ class Memcached_DataObject extends DB_DataObject
return $c->delete($cacheKey);
}
+
+ function fixupTimestamps()
+ {
+ // Fake up timestamp columns
+ $columns = $this->table();
+ foreach ($columns as $name => $type) {
+ if ($type & DB_DATAOBJECT_MYSQLTIMESTAMP) {
+ $this->$name = common_sql_now();
+ }
+ }
+ }
+
+ function debugDump()
+ {
+ common_debug("debugDump: " . common_log_objstring($this));
+ }
+
+ function raiseError($message, $type = null, $behaviour = null)
+ {
+ throw new ServerException("DB_DataObject error [$type]: $message");
+ }
}
diff --git a/classes/Session.php b/classes/Session.php
index 79a69a96e..2422f8b68 100644
--- a/classes/Session.php
+++ b/classes/Session.php
@@ -64,8 +64,12 @@ class Session extends Memcached_DataObject
$session = Session::staticGet('id', $id);
if (empty($session)) {
+ self::logdeb("Couldn't find '$id'");
return '';
} else {
+ self::logdeb("Found '$id', returning " .
+ strlen($session->session_data) .
+ " chars of data");
return (string)$session->session_data;
}
}
@@ -77,14 +81,24 @@ class Session extends Memcached_DataObject
$session = Session::staticGet('id', $id);
if (empty($session)) {
+ self::logdeb("'$id' doesn't yet exist; inserting.");
$session = new Session();
$session->id = $id;
$session->session_data = $session_data;
$session->created = common_sql_now();
- return $session->insert();
+ $result = $session->insert();
+
+ if (!$result) {
+ common_log_db_error($session, 'INSERT', __FILE__);
+ self::logdeb("Failed to insert '$id'.");
+ } else {
+ self::logdeb("Successfully inserted '$id' (result = $result).");
+ }
+ return $result;
} else {
+ self::logdeb("'$id' already exists; updating.");
if (strcmp($session->session_data, $session_data) == 0) {
self::logdeb("Not writing session '$id'; unchanged");
return true;
@@ -95,7 +109,16 @@ class Session extends Memcached_DataObject
$session->session_data = $session_data;
- return $session->update($orig);
+ $result = $session->update($orig);
+
+ if (!$result) {
+ common_log_db_error($session, 'UPDATE', __FILE__);
+ self::logdeb("Failed to update '$id'.");
+ } else {
+ self::logdeb("Successfully updated '$id' (result = $result).");
+ }
+
+ return $result;
}
}
}
@@ -106,8 +129,17 @@ class Session extends Memcached_DataObject
$session = Session::staticGet('id', $id);
- if (!empty($session)) {
- return $session->delete();
+ if (empty($session)) {
+ self::logdeb("Can't find '$id' to delete.");
+ } else {
+ $result = $session->delete();
+ if (!$result) {
+ common_log_db_error($session, 'DELETE', __FILE__);
+ self::logdeb("Failed to delete '$id'.");
+ } else {
+ self::logdeb("Successfully deleted '$id' (result = $result).");
+ }
+ return $result;
}
}
@@ -132,7 +164,10 @@ class Session extends Memcached_DataObject
$session->free();
+ self::logdeb("Found " . count($ids) . " ids to delete.");
+
foreach ($ids as $id) {
+ self::logdeb("Destroying session '$id'.");
self::destroy($id);
}
}
diff --git a/index.php b/index.php
index b5edc0f94..5520d690b 100644
--- a/index.php
+++ b/index.php
@@ -152,6 +152,16 @@ function checkMirror($action_obj, $args)
static $alwaysRW = array('session', 'remember_me');
+ // We ensure that these tables always are used
+ // on the master DB
+
+ $config['db']['database_rw'] = $config['db']['database'];
+ $config['db']['ini_rw'] = INSTALLDIR.'/classes/statusnet.ini';
+
+ foreach ($alwaysRW as $table) {
+ $config['db']['table_'.$table] = 'rw';
+ }
+
if (common_config('db', 'mirror') && $action_obj->isReadOnly($args)) {
if (is_array(common_config('db', 'mirror'))) {
// "load balancing", ha ha
@@ -162,16 +172,6 @@ function checkMirror($action_obj, $args)
$mirror = common_config('db', 'mirror');
}
- // We ensure that these tables always are used
- // on the master DB
-
- $config['db']['database_rw'] = $config['db']['database'];
- $config['db']['ini_rw'] = INSTALLDIR.'/classes/statusnet.ini';
-
- foreach ($alwaysRW as $table) {
- $config['db']['table_'.$table] = 'rw';
- }
-
// everyone else uses the mirror
$config['db']['database'] = $mirror;
diff --git a/lib/default.php b/lib/default.php
index c729193b5..8de8b1097 100644
--- a/lib/default.php
+++ b/lib/default.php
@@ -84,6 +84,7 @@ $default =
'control_channel' => '/topic/statusnet-control', // broadcasts to all queue daemons
'stomp_username' => null,
'stomp_password' => null,
+ 'stomp_persistent' => true, // keep items across queue server restart, if persistence is enabled
'monitor' => null, // URL to monitor ping endpoint (work in progress)
'softlimit' => '90%', // total size or % of memory_limit at which to restart queue threads gracefully
'debug_memory' => false, // true to spit memory usage to log
diff --git a/lib/stompqueuemanager.php b/lib/stompqueuemanager.php
index 19e8c49b5..4e2b58602 100644
--- a/lib/stompqueuemanager.php
+++ b/lib/stompqueuemanager.php
@@ -174,12 +174,13 @@ class StompQueueManager extends QueueManager
$this->_connect();
- // XXX: serialize and send entire notice
-
+ $props = array('created' => common_sql_now());
+ if (common_config('queue', 'stomp_persistent')) {
+ $props['persistent'] = 'true';
+ }
$result = $this->con->send($this->queueName($queue),
$msg, // BODY of the message
- array ('created' => common_sql_now(),
- 'persistent' => 'true'));
+ $props);
if (!$result) {
common_log(LOG_ERR, "Error sending $rep to $queue queue");
@@ -242,6 +243,7 @@ class StompQueueManager extends QueueManager
parent::start($master);
$this->_connect();
+ common_log(LOG_INFO, "Subscribing to $this->control");
$this->con->subscribe($this->control);
if ($this->sites) {
foreach ($this->sites as $server) {
diff --git a/lib/util.php b/lib/util.php
index 4312f9876..dd8189a58 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -178,7 +178,6 @@ function common_ensure_session()
}
if (isset($id)) {
session_id($id);
- setcookie(session_name(), $id);
}
@session_start();
if (!isset($_SESSION['started'])) {