From ae9f2c5348c1ade0ac8f2d313576f69645e50ed7 Mon Sep 17 00:00:00 2001 From: Semih Okur Date: Tue, 4 Jun 2024 19:18:48 +0000 Subject: [PATCH] Merged PR 788202: Pass OrchestratorIpAddress to cache initialization Pass OrchestratorIpAddress to cache initialization --- Public/Src/Engine/Dll/CacheInitializer.cs | 22 ++++++++++--------- .../Engine/Dll/Distribution/WorkerService.cs | 5 +++++ Public/Src/Engine/Dll/Engine.cs | 5 +++++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Public/Src/Engine/Dll/CacheInitializer.cs b/Public/Src/Engine/Dll/CacheInitializer.cs index 70e150962..e61cdbf82 100644 --- a/Public/Src/Engine/Dll/CacheInitializer.cs +++ b/Public/Src/Engine/Dll/CacheInitializer.cs @@ -78,7 +78,7 @@ namespace BuildXL.Engine RootTranslator rootTranslator, bool? recoveryStatus, CancellationToken cancellationToken, - + string orchestratorIpAddress = null, // Only used for testing purposes to inject cache. Func testHookCacheFactory = null) { @@ -110,7 +110,8 @@ namespace BuildXL.Engine cacheDirectory, config, enableFingerprintLookup: config.Cache.Incremental, - rootTranslator); + rootTranslator, + orchestratorIpAddress); if (!maybeCacheCoreEngineCache.Succeeded) { @@ -269,8 +270,8 @@ namespace BuildXL.Engine PathTable pathTable, string cacheDirectory, ICacheConfiguration config, - RootTranslator rootTranslator = null, - IDistributionConfiguration distributionConfiguration = null) + string orchestratorIpAddress, + RootTranslator rootTranslator) { Contract.Requires(pathTable != null); Contract.Requires(pathTable.IsValid); @@ -301,12 +302,12 @@ namespace BuildXL.Engine cacheConfigContent = cacheConfigContent.Replace("[BuildXLCacheUniverse]", EngineEnvironmentSettings.CacheUniverse.Value ?? string.Empty); cacheConfigContent = cacheConfigContent.Replace("[BuildXLCacheNamespace]", EngineEnvironmentSettings.CacheNamespace.Value ?? string.Empty); - var orchestratorLocation = distributionConfiguration?.OrchestratorLocation?.IpAddress; - if (string.IsNullOrEmpty(orchestratorLocation)) + if (string.IsNullOrEmpty(orchestratorIpAddress)) { - orchestratorLocation = Environment.MachineName; + orchestratorIpAddress = Environment.MachineName; } - cacheConfigContent = cacheConfigContent.Replace("[BuildXLSelectedLeader]", orchestratorLocation); + + cacheConfigContent = cacheConfigContent.Replace("[BuildXLSelectedLeader]", orchestratorIpAddress); var vfsCasRoot = config.VfsCasRoot.IsValid ? config.VfsCasRoot.ToString(pathTable) @@ -346,7 +347,8 @@ namespace BuildXL.Engine string cacheDirectory, IConfiguration config, bool enableFingerprintLookup, - RootTranslator rootTranslator) + RootTranslator rootTranslator, + string orchestratorIpAddress) { Contract.Requires(pathTable != null); Contract.Requires(pathTable.IsValid); @@ -360,7 +362,7 @@ namespace BuildXL.Engine ICacheCoreSession session = null; try { - Possible cacheConfigData = TryGetCacheConfigData(pathTable, cacheDirectory, config.Cache, rootTranslator, config.Distribution); + Possible cacheConfigData = TryGetCacheConfigData(pathTable, cacheDirectory, config.Cache, orchestratorIpAddress, rootTranslator); if (!cacheConfigData.Succeeded) { return cacheConfigData.Failure; diff --git a/Public/Src/Engine/Dll/Distribution/WorkerService.cs b/Public/Src/Engine/Dll/Distribution/WorkerService.cs index 20b9f9f7f..986ea382b 100644 --- a/Public/Src/Engine/Dll/Distribution/WorkerService.cs +++ b/Public/Src/Engine/Dll/Distribution/WorkerService.cs @@ -90,6 +90,9 @@ namespace BuildXL.Engine.Distribution private readonly ConcurrentBigSet m_handledBuildRequests = new ConcurrentBigSet(); + /// + public string OrchestratorIpAddress { get; private set; } + /// /// Identifies the worker /// @@ -215,6 +218,7 @@ namespace BuildXL.Engine.Distribution internal bool SayHello(IDistributionServiceLocation orchestratorLocation) { + OrchestratorIpAddress = orchestratorLocation.IpAddress; var timeout = GrpcSettings.WorkerAttachTimeout; Logger.Log.DistributionSayingHelloToOrchestrator(m_appLoggingContext); var helloTask = ((IWorkerService)this).SayHelloAsync(orchestratorLocation); @@ -397,6 +401,7 @@ namespace BuildXL.Engine.Distribution m_orchestratorClient.Initialize(buildStartData.OrchestratorLocation.IpAddress, buildStartData.OrchestratorLocation.Port, OnConnectionFailureAsync); } + OrchestratorIpAddress = buildStartData.OrchestratorLocation.IpAddress; WorkerId = BuildStartData.WorkerId; m_attachCallCompletion.TrySetResult(true); } diff --git a/Public/Src/Engine/Dll/Engine.cs b/Public/Src/Engine/Dll/Engine.cs index 5585e1f93..923a8868d 100644 --- a/Public/Src/Engine/Dll/Engine.cs +++ b/Public/Src/Engine/Dll/Engine.cs @@ -1839,6 +1839,8 @@ namespace BuildXL.Engine try { + string orchestratorIpAddress = null; + if (Configuration.Distribution.BuildRole == DistributedBuildRoles.Worker) { if (Configuration.Distribution.OrchestratorLocation != null) @@ -1862,6 +1864,8 @@ namespace BuildXL.Engine "An error should have been logged during waiting for attaching to the orchestrator."); return BuildXLEngineResult.Failed(engineState); } + + orchestratorIpAddress = m_workerService.OrchestratorIpAddress; } cacheInitializationTask = CacheInitializer.GetCacheInitializationTask( @@ -1870,6 +1874,7 @@ namespace BuildXL.Engine Configuration.Layout.CacheDirectory.ToString(Context.PathTable), Configuration.Logging.LogsDirectory.ToString(Context.PathTable), Configuration, + orchestratorIpAddress: orchestratorIpAddress, rootTranslator: m_rootTranslator, recoveryStatus: recoveryStatus, cancellationToken: Context.CancellationToken,