diff --git a/resources/sql/autopatches/20180223.log.01.bytelength.sql b/resources/sql/autopatches/20180223.log.01.bytelength.sql new file mode 100644 --- /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 --- a/src/applications/harbormaster/storage/build/HarbormasterBuildLog.php +++ b/src/applications/harbormaster/storage/build/HarbormasterBuildLog.php @@ -12,6 +12,7 @@ protected $duration; protected $live; protected $filePHID; + protected $byteLength; private $buildTarget = self::ATTACHABLE; private $rope; @@ -42,7 +43,8 @@ return id(new HarbormasterBuildLog()) ->setBuildTargetPHID($build_target->getPHID()) ->setDuration(null) - ->setLive(1); + ->setLive(1) + ->setByteLength(0); } public function scheduleRebuild($force) { @@ -70,6 +72,7 @@ 'live' => 'bool', 'filePHID' => 'phid?', + 'byteLength' => 'uint64', ), self::CONFIG_KEY_SCHEMA => array( 'key_buildtarget' => array( @@ -341,24 +344,28 @@ $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 --- a/src/applications/harbormaster/worker/HarbormasterLogWorker.php +++ b/src/applications/harbormaster/worker/HarbormasterLogWorker.php @@ -57,6 +57,19 @@ $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(); }