define ( 'FRIENDICA_CODENAME', 'Asparagus');
define ( 'FRIENDICA_VERSION', '3.5.2-rc' );
define ( 'DFRN_PROTOCOL_VERSION', '2.23' );
-define ( 'DB_UPDATE_VERSION', 1225 );
+define ( 'DB_UPDATE_VERSION', 1226 );
/**
* @brief Constant with a HTML line break.
-- ------------------------------------------
--- Friendica 3.5.2-dev (Asparagus)
--- DB_UPDATE_VERSION 1221
+-- Friendica 3.5.2-rc (Asparagus)
+-- DB_UPDATE_VERSION 1226
-- ------------------------------------------
--
CREATE TABLE IF NOT EXISTS `conv` (
`id` int(10) unsigned NOT NULL auto_increment,
- `guid` varchar(64) NOT NULL DEFAULT '',
+ `guid` varchar(255) NOT NULL DEFAULT '',
`recips` text,
`uid` int(11) NOT NULL DEFAULT 0,
`creator` varchar(255) NOT NULL DEFAULT '',
`updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
PRIMARY KEY(`id`),
INDEX `addr` (`addr`(32)),
- INDEX `url` (`url`)
+ UNIQUE INDEX `url` (`url`(190))
) DEFAULT COLLATE utf8mb4_general_ci;
--
`generation` tinyint(3) NOT NULL DEFAULT 0,
`server_url` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY(`id`),
- INDEX `nurl` (`nurl`(64)),
+ UNIQUE INDEX `nurl` (`nurl`(190)),
INDEX `name` (`name`(64)),
INDEX `nick` (`nick`(32)),
INDEX `addr` (`addr`(64)),
`last_contact` datetime DEFAULT '0001-01-01 00:00:00',
`last_failure` datetime DEFAULT '0001-01-01 00:00:00',
PRIMARY KEY(`id`),
- INDEX `nurl` (`nurl`(32))
+ UNIQUE INDEX `nurl` (`nurl`(190))
) DEFAULT COLLATE utf8mb4_general_ci;
--
INDEX `uid_parenturi` (`uid`,`parent-uri`(190)),
INDEX `uid_contactid_created` (`uid`,`contact-id`,`created`),
INDEX `authorid_created` (`author-id`,`created`),
+ INDEX `ownerid` (`owner-id`),
INDEX `uid_uri` (`uid`,`uri`(190)),
INDEX `resource-id` (`resource-id`),
INDEX `contactid_allowcid_allowpid_denycid_denygid` (`contact-id`,`allow_cid`(10),`allow_gid`(10),`deny_cid`(10),`deny_gid`(10)),
CREATE TABLE IF NOT EXISTS `mail` (
`id` int(10) unsigned NOT NULL auto_increment,
`uid` int(10) unsigned NOT NULL DEFAULT 0,
- `guid` varchar(64) NOT NULL DEFAULT '',
+ `guid` varchar(255) NOT NULL DEFAULT '',
`from-name` varchar(255) NOT NULL DEFAULT '',
`from-photo` varchar(255) NOT NULL DEFAULT '',
`from-url` varchar(255) NOT NULL DEFAULT '',
INDEX `uid_seen` (`uid`,`seen`),
INDEX `convid` (`convid`),
INDEX `uri` (`uri`(64)),
- INDEX `parent-uri` (`parent-uri`(64))
+ INDEX `parent-uri` (`parent-uri`(64)),
+ INDEX `contactid` (`contact-id`)
) DEFAULT COLLATE utf8mb4_general_ci;
--
`deny_cid` mediumtext,
`deny_gid` mediumtext,
PRIMARY KEY(`id`),
+ INDEX `contactid` (`contact-id`),
INDEX `uid_contactid` (`uid`,`contact-id`),
INDEX `uid_profile` (`uid`,`profile`),
INDEX `uid_album_scale_created` (`uid`,`album`(32),`scale`,`created`),
INDEX `uid_network_created` (`uid`,`network`,`created`),
INDEX `uid_contactid_commented` (`uid`,`contact-id`,`commented`),
INDEX `uid_contactid_created` (`uid`,`contact-id`,`created`),
+ INDEX `contactid` (`contact-id`),
+ INDEX `ownerid` (`owner-id`),
+ INDEX `authorid` (`author-id`),
INDEX `uid_created` (`uid`,`created`),
INDEX `uid_commented` (`uid`,`commented`),
INDEX `uid_wall_created` (`uid`,`wall`,`created`)
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`pid` int(11) NOT NULL DEFAULT 0,
`executed` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
- PRIMARY KEY(`id`)
+ PRIMARY KEY(`id`),
+ INDEX `priority_created` (`priority`,`created`)
) DEFAULT COLLATE utf8mb4_general_ci;
),
"indexes" => array(
"PRIMARY" => array("id"),
+ "priority_created" => array("priority", "created"),
)
);
// Check free memory
if ($a->min_memory_reached()) {
+ logger('Memory limit reached, quitting.', LOGGER_DEBUG);
return;
}
// Count active workers and compare them with a maximum value that depends on the load
if (poller_too_much_workers()) {
+ logger('Active worker limit reached, quitting.', LOGGER_DEBUG);
return;
}
if (!poller_execute($r[0])) {
+ logger('Process execution failed, quitting.', LOGGER_DEBUG);
return;
}
// Quit the poller once every hour
- if (time() > ($starttime + 3600))
+ if (time() > ($starttime + 3600)) {
+ logger('Process lifetime reachted, quitting.', LOGGER_DEBUG);
return;
+ }
}
+ logger("Couldn't select a workerqueue entry, quitting.", LOGGER_DEBUG);
}
/**
if (function_exists($funcname)) {
poller_exec_function($queue, $funcname, $argv);
-
dba::delete('workerqueue', array('id' => $queue["id"]));
} else {
logger("Function ".$funcname." does not exist");
$maxqueues = $queues;
+ $active = poller_active_workers();
+
// Decrease the number of workers at higher load
$load = current_load();
if ($load) {
$slope = $maxworkers / pow($maxsysload, $exponent);
$queues = ceil($slope * pow(max(0, $maxsysload - $load), $exponent));
- $active = 0;
-
// Create a list of queue entries grouped by their priority
$listitem = array();
$processes = dba::p("SELECT COUNT(*) AS `running` FROM `process` WHERE NOT EXISTS (SELECT id FROM `workerqueue` WHERE `workerqueue`.`pid` = `process`.`pid`)");
if ($process = dba::fetch($processes)) {
$listitem[0] = "0:".$process["running"];
- $active += $process["running"];
}
dba::close($processes);
// Now adding all processes with workerqueue entries
$entries = dba::p("SELECT COUNT(*) AS `entries`, `priority` FROM `workerqueue` GROUP BY `priority`");
while ($entry = dba::fetch($entries)) {
- $processes = dba::p("SELECT COUNT(*) AS `running` FROM `process` LEFT JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid` WHERE `priority` = ?", $entry["priority"]);
+ $processes = dba::p("SELECT COUNT(*) AS `running` FROM `process` INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid` WHERE `priority` = ?", $entry["priority"]);
if ($process = dba::fetch($processes)) {
$listitem[$entry["priority"]] = $entry["priority"].":".$process["running"]."/".$entry["entries"];
- $active += $process["running"];
}
dba::close($processes);
}
$a = get_app();
$a->proc_run($args);
}
- } else {
- $active = poller_active_workers();
}
return($active >= $queues);
*/
function poller_worker_process() {
- dba::transaction();
-
// Check if we should pass some low priority process
$highest_priority = 0;
if (poller_passing_slow($highest_priority)) {
+ dba::p('LOCK TABLES `workerqueue` WRITE');
+
// Are there waiting processes with a higher priority than the currently highest?
$r = q("SELECT * FROM `workerqueue`
WHERE `executed` <= '%s' AND `priority` < %d
- ORDER BY `priority`, `created` LIMIT 1 FOR UPDATE",
+ ORDER BY `priority`, `created` LIMIT 1",
dbesc(NULL_DATE),
intval($highest_priority));
if (dbm::is_result($r)) {
// Give slower processes some processing time
$r = q("SELECT * FROM `workerqueue`
WHERE `executed` <= '%s' AND `priority` > %d
- ORDER BY `priority`, `created` LIMIT 1 FOR UPDATE",
+ ORDER BY `priority`, `created` LIMIT 1",
dbesc(NULL_DATE),
intval($highest_priority));
if (dbm::is_result($r)) {
return $r;
}
+ } else {
+ dba::p('LOCK TABLES `workerqueue` WRITE');
}
// If there is no result (or we shouldn't pass lower processes) we check without priority limit
if (!dbm::is_result($r)) {
- $r = q("SELECT * FROM `workerqueue` WHERE `executed` <= '%s' ORDER BY `priority`, `created` LIMIT 1 FOR UPDATE", dbesc(NULL_DATE));
+ $r = q("SELECT * FROM `workerqueue` WHERE `executed` <= '%s' ORDER BY `priority`, `created` LIMIT 1", dbesc(NULL_DATE));
+ }
+
+ // We only unlock the tables here, when we got no data
+ if (!dbm::is_result($r)) {
+ dba::p('UNLOCK TABLES');
}
return $r;
/**
* @brief Assigns a workerqueue entry to the current process
*
- * All the checks after the update are only needed with MyISAM.
+ * When we are sure that the table locks are working correctly, we can remove the checks from here
*
* @param array $queue Workerqueue entry
*
function poller_claim_process($queue) {
$mypid = getmypid();
- if (!dba::update('workerqueue', array('executed' => datetime_convert(), 'pid' => $mypid),
- array('id' => $queue["id"], 'pid' => 0))) {
+ $success = dba::update('workerqueue', array('executed' => datetime_convert(), 'pid' => $mypid),
+ array('id' => $queue["id"], 'pid' => 0));
+ dba::p('UNLOCK TABLES');
+
+ if (!$success) {
logger("Couldn't update queue entry ".$queue["id"]." - skip this execution", LOGGER_DEBUG);
- dba::commit();
return false;
}
$id = q("SELECT `pid`, `executed` FROM `workerqueue` WHERE `id` = %d", intval($queue["id"]));
if (!$id) {
logger("Queue item ".$queue["id"]." vanished - skip this execution", LOGGER_DEBUG);
- dba::commit();
return false;
} elseif ((strtotime($id[0]["executed"]) <= 0) OR ($id[0]["pid"] == 0)) {
logger("Entry for queue item ".$queue["id"]." wasn't stored - skip this execution", LOGGER_DEBUG);
- dba::commit();
return false;
} elseif ($id[0]["pid"] != $mypid) {
logger("Queue item ".$queue["id"]." is to be executed by process ".$id[0]["pid"]." and not by me (".$mypid.") - skip this execution", LOGGER_DEBUG);
- dba::commit();
return false;
}
- dba::commit();
return true;
}
require_once('mod/proxy.php');
require_once('include/xml.php');
require_once('include/cache.php');
+require_once('include/enotify.php');
/**
* @brief Outputs the counts and the lists of various notifications
return;
}
- // If the last worker fork was less than 10 seconds before then don't fork another one.
+ // If the last worker fork was less than 2 seconds before then don't fork another one.
// This should prevent the forking of masses of workers.
$cachekey = 'app:proc_run:started';
$result = Cache::get($cachekey);
- if (!is_null($result) AND ( time() - $result) < 10) {
+ if (!is_null($result) AND ( time() - $result) < 2) {
return;
}
<?php
-define('UPDATE_VERSION' , 1225);
+define('UPDATE_VERSION' , 1226);
/**
*