From 57e3d607f566ba1cddbca5b149738632359ae80e Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 23 Feb 2018 05:48:07 -0800 Subject: [PATCH] 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 --- .../20180223.log.01.bytelength.sql | 2 ++ .../storage/build/HarbormasterBuildLog.php | 33 +++++++++++-------- .../worker/HarbormasterLogWorker.php | 13 ++++++++ 3 files changed, 35 insertions(+), 13 deletions(-) create mode 100644 resources/sql/autopatches/20180223.log.01.bytelength.sql diff --git a/resources/sql/autopatches/20180223.log.01.bytelength.sql b/resources/sql/autopatches/20180223.log.01.bytelength.sql new file mode 100644 index 0000000000..a4c3505628 --- /dev/null +++ b/resources/sql/autopatches/20180223.log.01.bytelength.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_harbormaster.harbormaster_buildlog + ADD byteLength BIGINT UNSIGNED NOT NULL; diff --git a/src/applications/harbormaster/storage/build/HarbormasterBuildLog.php b/src/applications/harbormaster/storage/build/HarbormasterBuildLog.php index 0ae4446837..f43f028d5d 100644 --- a/src/applications/harbormaster/storage/build/HarbormasterBuildLog.php +++ b/src/applications/harbormaster/storage/build/HarbormasterBuildLog.php @@ -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 )----------------------------------------- */ diff --git a/src/applications/harbormaster/worker/HarbormasterLogWorker.php b/src/applications/harbormaster/worker/HarbormasterLogWorker.php index b0c84b52f3..d90c2391c0 100644 --- a/src/applications/harbormaster/worker/HarbormasterLogWorker.php +++ b/src/applications/harbormaster/worker/HarbormasterLogWorker.php @@ -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(); } -- 2.51.2