1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-09 16:32:39 +01:00

In Harbormaster, record byte length on the build logs

Summary: Depends on D19135. Ref T13088. Denormalize the total log size onto the log itself. This makes reasoning about the log at display time easier, and we don't need to fish around in the database as much to figure out what we're dealing with.

Test Plan: Ran `bin/harbormaster rebuild-log`, saw an existing log populate. Ran `bin/harbormaster write-log`, saw new log write with proper length information.

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13088

Differential Revision: https://secure.phabricator.com/D19136
This commit is contained in:
epriestley 2018-02-23 05:48:07 -08:00
parent d152bd5836
commit 57e3d607f5
3 changed files with 35 additions and 13 deletions

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_harbormaster.harbormaster_buildlog
ADD byteLength BIGINT UNSIGNED NOT NULL;

View file

@ -12,6 +12,7 @@ final class HarbormasterBuildLog
protected $duration;
protected $live;
protected $filePHID;
protected $byteLength;
private $buildTarget = self::ATTACHABLE;
private $rope;
@ -42,7 +43,8 @@ final class HarbormasterBuildLog
return id(new HarbormasterBuildLog())
->setBuildTargetPHID($build_target->getPHID())
->setDuration(null)
->setLive(1);
->setLive(1)
->setByteLength(0);
}
public function scheduleRebuild($force) {
@ -70,6 +72,7 @@ final class HarbormasterBuildLog
'live' => 'bool',
'filePHID' => 'phid?',
'byteLength' => 'uint64',
),
self::CONFIG_KEY_SCHEMA => array(
'key_buildtarget' => array(
@ -341,24 +344,28 @@ final class HarbormasterBuildLog
$append_data = $rope->getPrefixBytes($data_limit);
$data_size = strlen($append_data);
if ($append_id) {
queryfx(
$conn_w,
'UPDATE %T SET chunk = CONCAT(chunk, %B), size = %d WHERE id = %d',
$chunk_table,
$append_data,
$prefix_size + $data_size,
$append_id);
} else {
$this->writeChunk($encoding_text, $data_size, $append_data);
}
$this->openTransaction();
if ($append_id) {
queryfx(
$conn_w,
'UPDATE %T SET chunk = CONCAT(chunk, %B), size = %d WHERE id = %d',
$chunk_table,
$append_data,
$prefix_size + $data_size,
$append_id);
} else {
$this->writeChunk($encoding_text, $data_size, $append_data);
}
$this->byteLength += $data_size;
$this->save();
$this->saveTransaction();
$rope->removeBytesFromHead($data_size);
}
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */

View file

@ -57,6 +57,19 @@ final class HarbormasterLogWorker extends HarbormasterWorker {
$data = $this->getTaskData();
$is_force = idx($data, 'force');
if (!$log->getByteLength() || $is_force) {
$iterator = $log->newChunkIterator()
->setAsString(true);
$byte_length = 0;
foreach ($iterator as $block) {
$byte_length += strlen($block);
}
$log
->setByteLength($byte_length)
->save();
}
if ($log->canCompressLog()) {
$log->compressLog();
}