Added read-only connection support for manticore

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO 2024-01-02 08:09:53 +01:00
parent 3637d59942
commit 8da731c174
6 changed files with 26 additions and 18 deletions

View File

@ -1,7 +1,15 @@
1.4.5:
------
- Added read-only connection support for manticore
If using sphinx, add the following to config-site.php:
$config['SPHINX_HOSTNAME_READONLY'] = '127.0.0.1:9306';
1.4.4: 1.4.4:
------ ------
Renamed "group" table to "usergroup" - Renamed "group" table to "usergroup"
Be sure to run util/db-upgrade.sql on the mysql piler database Be sure to run util/db-upgrade.sql on the mysql piler database

View File

@ -248,7 +248,8 @@ index note1
searchd searchd
{ {
listen = 127.0.0.1:9312 listen = 127.0.0.1:9312
listen = 127.0.0.1:9306:mysql41 listen = 127.0.0.1:9306
listen = 127.0.0.1:9307:mysql_readonly
log = /var/piler/manticore/manticore.log log = /var/piler/manticore/manticore.log
binlog_max_log_size = 256M binlog_max_log_size = 256M
binlog_path = /var/piler/manticore binlog_path = /var/piler/manticore

View File

@ -49,8 +49,8 @@ class ControllerMessageBulkremove extends Controller {
AUDIT(ACTION_REMOVE_MESSAGE, '', '', $id, ''); AUDIT(ACTION_REMOVE_MESSAGE, '', '', $id, '');
$db->query("UPDATE " . TABLE_META . " SET retained=? WHERE id=?", [NOW, $id]); $db->query("UPDATE " . TABLE_META . " SET retained=? WHERE id=?", [NOW, $id]);
if(RT) { if(RT) {
$sphx = Registry::get('sphx'); $sphxrw = Registry::get('sphxrw');
$sphx->query("DELETE FROM " . SPHINX_MAIN_INDEX . " WHERE id=" . (int)$this->data['id']); $sphxrw->query("DELETE FROM " . SPHINX_MAIN_INDEX . " WHERE id=" . (int)$this->data['id']);
} }
syslog(LOG_INFO, $this->data['username'] . " removed message: $id"); syslog(LOG_INFO, $this->data['username'] . " removed message: $id");

View File

@ -41,8 +41,8 @@ class ControllerMessageRemove extends Controller {
$db->query("UPDATE " . TABLE_META . " SET retained=? WHERE id=?", [NOW, $id]); $db->query("UPDATE " . TABLE_META . " SET retained=? WHERE id=?", [NOW, $id]);
$db->query("UPDATE " . TABLE_DELETED . " SET deleted=1 WHERE id=?", [$id]); $db->query("UPDATE " . TABLE_DELETED . " SET deleted=1 WHERE id=?", [$id]);
if(RT) { if(RT) {
$sphx = Registry::get('sphx'); $sphxrw = Registry::get('sphxrw');
$sphx->query("DELETE FROM " . SPHINX_MAIN_INDEX . " WHERE id=", (int)$this->data['id']); $sphxrw->query("DELETE FROM " . SPHINX_MAIN_INDEX . " WHERE id=", (int)$this->data['id']);
} }
syslog(LOG_INFO, $this->data['username'] . " removed message: $id"); syslog(LOG_INFO, $this->data['username'] . " removed message: $id");

View File

@ -41,8 +41,10 @@ Registry::set('db', $db);
Registry::set('DB_DRIVER', DB_DRIVER); Registry::set('DB_DRIVER', DB_DRIVER);
$sphx = new DB(SPHINX_DRIVER, SPHINX_HOSTNAME, "", "", SPHINX_DATABASE, ""); $sphx = new DB(SPHINX_DRIVER, SPHINX_HOSTNAME_READONLY, "", "", SPHINX_DATABASE, "");
$sphxrw = new DB(SPHINX_DRIVER, SPHINX_HOSTNAME, "", "", SPHINX_DATABASE, "");
Registry::set('sphx', $sphx); Registry::set('sphx', $sphx);
Registry::set('sphxrw', $sphxrw);
if(MEMCACHED_ENABLED) { if(MEMCACHED_ENABLED) {
@ -112,6 +114,3 @@ else {
$controller = new Front(); $controller = new Front();
$controller->dispatch($action, new Router('common/not_found')); $controller->dispatch($action, new Router('common/not_found'));
?>

View File

@ -486,13 +486,13 @@ class ModelSearchMessage extends Model {
if($tag == '') { if($tag == '') {
if(RT) { if(RT) {
$this->sphx->query("DELETE FROM " . SPHINX_TAG_INDEX . " WHERE uid=$uid AND mid=$id"); $this->sphxrw->query("DELETE FROM " . SPHINX_TAG_INDEX . " WHERE uid=$uid AND mid=$id");
} else { } else {
$query = $this->db->query("DELETE FROM " . TABLE_TAG . " WHERE uid=? AND id=?", array($uid, $id)); $query = $this->db->query("DELETE FROM " . TABLE_TAG . " WHERE uid=? AND id=?", array($uid, $id));
} }
} else { } else {
if(RT) { if(RT) {
$this->sphx->query("REPLACE INTO " . SPHINX_TAG_INDEX . " (mid, uid, tag) VALUES (?,?,?)",[$id,$uid,$tag]); $this->sphxrw->query("REPLACE INTO " . SPHINX_TAG_INDEX . " (mid, uid, tag) VALUES (?,?,?)",[$id,$uid,$tag]);
} else { } else {
$query = $this->db->query("UPDATE " . TABLE_TAG . " SET tag=? WHERE uid=? AND id=?", array($tag, $uid, $id)); $query = $this->db->query("UPDATE " . TABLE_TAG . " SET tag=? WHERE uid=? AND id=?", array($tag, $uid, $id));
if($this->db->countAffected() == 0) { if($this->db->countAffected() == 0) {
@ -510,7 +510,7 @@ class ModelSearchMessage extends Model {
if(RT) { if(RT) {
$ids_str = implode(",", $ids); $ids_str = implode(",", $ids);
$this->sphx->query("DELETE FROM " . SPHINX_TAG_INDEX . " WHERE uid=$uid AND mid IN ($ids_str)"); $this->sphxrw->query("DELETE FROM " . SPHINX_TAG_INDEX . " WHERE uid=$uid AND mid IN ($ids_str)");
} else { } else {
$query = $this->db->query("DELETE FROM " . TABLE_TAG . " WHERE uid=? AND id IN ($q)", $arr); $query = $this->db->query("DELETE FROM " . TABLE_TAG . " WHERE uid=? AND id IN ($q)", $arr);
} }
@ -518,7 +518,7 @@ class ModelSearchMessage extends Model {
if($tag) { if($tag) {
foreach ($ids as $id) { foreach ($ids as $id) {
if(RT) { if(RT) {
$this->sphx->query("INSERT INTO " . SPHINX_TAG_INDEX . " (mid, uid, tag) VALUES(?,?,?)", [$id, $uid, $tag]); $this->sphxrw->query("INSERT INTO " . SPHINX_TAG_INDEX . " (mid, uid, tag) VALUES(?,?,?)", [$id, $uid, $tag]);
} else { } else {
$query = $this->db->query("INSERT INTO " . TABLE_TAG . " (id, uid, tag) VALUES(?,?,?)", array($id, $uid, $tag)); $query = $this->db->query("INSERT INTO " . TABLE_TAG . " (id, uid, tag) VALUES(?,?,?)", array($id, $uid, $tag));
} }
@ -561,10 +561,10 @@ class ModelSearchMessage extends Model {
public function add_message_rt_note($id = '', $uid = 0, $note = '') { public function add_message_rt_note($id = '', $uid = 0, $note = '') {
if($id == '' || $uid <= 0) { return 0; } if($id == '' || $uid <= 0) { return 0; }
$this->sphx->query("DELETE FROM " . SPHINX_NOTE_INDEX . " WHERE uid=$uid AND mid=$id"); $this->sphxrw->query("DELETE FROM " . SPHINX_NOTE_INDEX . " WHERE uid=$uid AND mid=$id");
if($note) { if($note) {
$this->sphx->query("INSERT INTO " . SPHINX_NOTE_INDEX . " (mid, uid, note) VALUES (?,?,?)",[$id,$uid,$note]); $this->sphxrw->query("INSERT INTO " . SPHINX_NOTE_INDEX . " (mid, uid, note) VALUES (?,?,?)",[$id,$uid,$note]);
} }
return 1; return 1;