diff --git a/src/applications/almanac/util/AlmanacKeys.php b/src/applications/almanac/util/AlmanacKeys.php index 7ed9098e97..83a4f4021b 100644 --- a/src/applications/almanac/util/AlmanacKeys.php +++ b/src/applications/almanac/util/AlmanacKeys.php @@ -1,77 +1,77 @@ getKey($cache_key); if (!$device) { $viewer = PhabricatorUser::getOmnipotentUser(); $device = id(new AlmanacDeviceQuery()) ->setViewer($viewer) ->withNames(array($device_id)) ->executeOne(); if (!$device) { throw new Exception( pht( 'This host has device ID "%s", but there is no corresponding '. 'device record in Almanac.', $device_id)); } $cache->setKey($cache_key, $device); } return $device; } public static function getClusterSSHUser() { // NOTE: When instancing, we currently use the SSH username to figure out // which instance you are connecting to. We can't use the host name because // we have no way to tell which host you think you're reaching: the SSH // protocol does not have a mechanism like a "Host" header. $username = PhabricatorEnv::getEnvConfig('cluster.instance'); if (strlen($username)) { - return $username; +// return $username; } $username = PhabricatorEnv::getEnvConfig('diffusion.ssh-user'); if (strlen($username)) { return $username; } return null; } } diff --git a/src/applications/diffusion/ssh/DiffusionGitReceivePackSSHWorkflow.php b/src/applications/diffusion/ssh/DiffusionGitReceivePackSSHWorkflow.php index d48abc159e..54220f0776 100644 --- a/src/applications/diffusion/ssh/DiffusionGitReceivePackSSHWorkflow.php +++ b/src/applications/diffusion/ssh/DiffusionGitReceivePackSSHWorkflow.php @@ -1,135 +1,140 @@ setName('git-receive-pack'); $this->setArguments( array( array( 'name' => 'dir', 'wildcard' => true, ), )); } protected function executeRepositoryOperations() { $host_wait_start = microtime(true); $repository = $this->getRepository(); $viewer = $this->getSSHUser(); $device = AlmanacKeys::getLiveDevice(); // This is a write, and must have write access. $this->requireWriteAccess(); $cluster_engine = id(new DiffusionRepositoryClusterEngine()) ->setViewer($viewer) ->setRepository($repository) ->setLog($this); if ($this->shouldProxy()) { $command = $this->getProxyCommand(true); - $did_synchronize = false; + $did_write = false; if ($device) { $this->writeClusterEngineLogMessage( pht( "# Push received by \"%s\", forwarding to cluster host.\n", $device->getName())); } } else { $command = csprintf('git-receive-pack %s', $repository->getLocalPath()); - $did_synchronize = true; + $did_write = true; $cluster_engine->synchronizeWorkingCopyBeforeWrite(); if ($device) { $this->writeClusterEngineLogMessage( pht( "# Ready to receive on cluster host \"%s\".\n", $device->getName())); } } $caught = null; try { $err = $this->executeRepositoryCommand($command); } catch (Exception $ex) { $caught = $ex; } // We've committed the write (or rejected it), so we can release the lock // without waiting for the client to receive the acknowledgement. - if ($did_synchronize) { + if ($did_write) { $cluster_engine->synchronizeWorkingCopyAfterWrite(); } if ($caught) { throw $caught; } if (!$err) { - $repository->writeStatusMessage( - PhabricatorRepositoryStatusMessage::TYPE_NEEDS_UPDATE, - PhabricatorRepositoryStatusMessage::CODE_OKAY); $this->waitForGitClient(); - $host_wait_end = microtime(true); + // When a repository is clustered, we reach this cleanup code on both + // the proxy and the actual final endpoint node. Don't do more cleanup + // or logging than we need to. + if ($did_write) { + $repository->writeStatusMessage( + PhabricatorRepositoryStatusMessage::TYPE_NEEDS_UPDATE, + PhabricatorRepositoryStatusMessage::CODE_OKAY); - $this->updatePushLogWithTimingInformation( - $this->getClusterEngineLogProperty('writeWait'), - $this->getClusterEngineLogProperty('readWait'), - ($host_wait_end - $host_wait_start)); + $host_wait_end = microtime(true); + $this->updatePushLogWithTimingInformation( + $this->getClusterEngineLogProperty('writeWait'), + $this->getClusterEngineLogProperty('readWait'), + ($host_wait_end - $host_wait_start)); + } } return $err; } private function executeRepositoryCommand($command) { $repository = $this->getRepository(); $command = PhabricatorDaemon::sudoCommandAsDaemonUser($command); $future = id(new ExecFuture('%C', $command)) ->setEnv($this->getEnvironment()); return $this->newPassthruCommand() ->setIOChannel($this->getIOChannel()) ->setCommandChannelFromExecFuture($future) ->execute(); } private function updatePushLogWithTimingInformation( $write_wait, $read_wait, $host_wait) { if ($write_wait !== null) { $write_wait = (int)(1000000 * $write_wait); } if ($read_wait !== null) { $read_wait = (int)(1000000 * $read_wait); } if ($host_wait !== null) { $host_wait = (int)(1000000 * $host_wait); } $identifier = $this->getRequestIdentifier(); $event = new PhabricatorRepositoryPushEvent(); $conn = $event->establishConnection('w'); queryfx( $conn, 'UPDATE %T SET writeWait = %nd, readWait = %nd, hostWait = %nd WHERE requestIdentifier = %s', $event->getTableName(), $write_wait, $read_wait, $host_wait, $identifier); } } diff --git a/src/applications/drydock/interface/command/DrydockSSHCommandInterface.php b/src/applications/drydock/interface/command/DrydockSSHCommandInterface.php index 1aab14b57b..7ebd95938b 100644 --- a/src/applications/drydock/interface/command/DrydockSSHCommandInterface.php +++ b/src/applications/drydock/interface/command/DrydockSSHCommandInterface.php @@ -1,59 +1,59 @@ credential === null) { $credential_phid = $this->getConfig('credentialPHID'); $this->credential = PassphraseSSHKey::loadFromPHID( $credential_phid, PhabricatorUser::getOmnipotentUser()); } return $this->credential; } public function setConnectTimeout($timeout) { $this->connectTimeout = $timeout; return $this; } public function getExecFuture($command) { $credential = $this->loadCredential(); $argv = func_get_args(); $argv = $this->applyWorkingDirectoryToArgv($argv); $full_command = call_user_func_array('csprintf', $argv); $flags = array(); - $flags[] = '-o'; - $flags[] = 'LogLevel=quiet'; + // $flags[] = '-o'; + // $flags[] = 'LogLevel=quiet'; $flags[] = '-o'; $flags[] = 'StrictHostKeyChecking=no'; $flags[] = '-o'; $flags[] = 'UserKnownHostsFile=/dev/null'; $flags[] = '-o'; $flags[] = 'BatchMode=yes'; if ($this->connectTimeout) { $flags[] = '-o'; $flags[] = 'ConnectTimeout='.$this->connectTimeout; } return new ExecFuture( 'ssh %Ls -l %P -p %s -i %P %s -- %s', $flags, $credential->getUsernameEnvelope(), $this->getConfig('port'), $credential->getKeyfileEnvelope(), $this->getConfig('host'), $full_command); } }