UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
BuildPatchFileConstructor.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "Async/Mutex.h"
7#include "Misc/Guid.h"
8#include "HAL/Runnable.h"
10#include "BuildPatchManifest.h"
14#include "BuildPatchInstall.h"
15
16
17// Forward declarations
18struct FBatchState;
19struct FResumeData;
22enum class EConstructionError : uint8;
23
26
28{
39
40 struct FChunkPart;
41 class IFileSystem;
42 class IChunkSource;
43 class IChunkReferenceTracker;
44 class IInstallerError;
45 class IInstallerAnalytics;
46 class IFileConstructorStat;
47 class IMessagePump;
48 class IBuildManifestSet;
49 class IBuildInstallerThread;
50 class IConstructorChunkDbChunkSource;
51 class IConstructorInstallChunkSource;
52 class IConstructorCloudChunkSource;
53
54
59 {
60 // The manifest set class for details on the installation files.
62
63 // The location for the installation.
65
66 // The location where new installation files will be constructed.
68
69 // The location where temporary files for tracking can be stored.
71
72 // The list of files to be constructed, filename paths should match those contained in manifest.
74
75 // The install mode used for this installation.
76 EInstallMode InstallMode;
77
78 // The location where memory overflow will get written to.
80
82
83 // See comments in installer config
84 bool bInstallToMemory = false;
85 bool bConstructInMemory = false;
87
89
90 static const bool bDefaultSpawnAdditionalIOThreads = true;
91 static const int32 DefaultIOBatchSizeMB = 10;
92 static const int32 DefaultIOBufferSizeMB = 64;
93
99 };
100
106 {
107 friend FChunkBackingStore;
108 public:
109
121 FFileConstructorConfig Configuration, IFileSystem* FileSystem,
123 IChunkReferenceTracker* ChunkReferenceTracker, IInstallerError* InstallerError, IInstallerAnalytics* InstallerAnalytics, IMessagePump* MessagePump,
124 IFileConstructorStat* FileConstructorStat, TMap<FGuid, EConstructorChunkLocation>&& ChunkLocations);
125
130
131 void Run();
132
133 // IControllable interface begin.
134 virtual void SetPaused(bool bInIsPaused) override;
135 virtual void Abort() override;
136 // IControllable interface end.
137
138 void WakeUpDispatch();
139
149
156
163
168
169 private:
170
171 void SetChunkLocation(const FGuid& InGuid, EConstructorChunkLocation InNewLocation);
172
177 void CountBytesProcessed(const int64& ByteCount);
178
182 int64 GetRemainingBytes();
183
190 uint64 CalculateInProgressDiskSpaceRequired(const FFileManifest& InProgressFileManifest, uint64 InProgressFileSize);
191
192 // Calculates the amount of disk space we need to finish the install, needs to be called on file boundaries on the construct thread.
193 uint64 CalculateDiskSpaceRequirementsWithDeleteDuringInstall();
194
199 void ConstructFiles(const FResumeData& ResumeData);
200
201 private:
202 // The configuration for the constructor.
203 const FFileConstructorConfig Configuration;
204
205 // A flag marking that we told the chunk cache to queue required downloads.
206 bool bIsDownloadStarted;
207
208 // A flag marking that we have made the initial disk space check following resume logic complete.
209 bool bInitialDiskSizeCheck;
210
211 // If true, the chunkdb source has chunks to provide
212 bool bHasChunkDbSource = false;
213
214 // Our local resolved copy of the cvar with overrides applied.
215 bool bStallWhenFileSystemThrottled = false;
216
217 // A flag marking whether we should be paused.
218 FThreadSafeBool bIsPaused;
219
220 // A flag marking whether we should abort operations and exit. Always call Abort() to set this.
221 FThreadSafeBool bShouldAbort;
222
223 // Indexes in to ConstructionList and associated parallel arrays. This is the next file that will
224 // start construction when dependencies are met.
225 std::atomic_int32_t NextIndexToConstruct = 0;
226
227 struct FFileToConstruct
228 {
229 const FFileManifest* FileManifest = nullptr;
230
231 // When using an install source with multiple files in flight, we can't start this
232 // file until all of the install sources it needs have been harvested. Since files are
233 // constructed in order, we only track the file that will be harvested last. If this
234 // file has no dependencies this is -1
235 int32 LatestDependentInstallSource = -1;
236 };
237
238 // The in-oder list of files to construct. The array is parallel with Configuration.ConstructList.
239 TArray<FFileToConstruct> ConstructionList;
240
241 // Pointer to the file system.
242 IFileSystem* FileSystem;
243
244 IConstructorChunkDbChunkSource* ChunkDbSource; // can be null if not using.
245 IConstructorInstallChunkSource* InstallSource;
246 IConstructorCloudChunkSource* CloudSource;
247
248 // Keyed off of the filename relative to the install directory.
249 TMap<FString, TArray64<uint8>> MemoryOutputFiles;
250
251 // We always want to know exactly where we think a chunk should be. If it's not there,
252 // we update this list to where it can be found (i.e. cloud)
253 // This is almost always read only after initialization, but in rare situations can be updated
254 // (chunk failures, file resume) and is multi threaded access.
255 FRWLock ChunkLocationsLock;
257 // Track how much data we expect to have to download. This is protected by the ChunkLocationsLock since they are in sync.
258 uint64 DownloadRequirement = 0;
259
260 // Pointer to the chunk reference tracker.
261 IChunkReferenceTracker* ChunkReferenceTracker;
262
263 // Pointer to the installer error class.
264 IInstallerError* InstallerError;
265
266 // Pointer to the installer analytics handler.
267 IInstallerAnalytics* InstallerAnalytics;
268
269 IMessagePump* MessagePump = nullptr;
270
271 // Pointer to the stat class.
272 IFileConstructorStat* FileConstructorStat;
273
274 bool bAllowMultipleFilesInFlight = true;
275
276 bool bShouldLogNextDependencyWait = true;
277
278 // The size we expect for chunks. This should be used for estimation purposes, not anything requiring hard limits.
279 uint32 ExpectedChunkSize = 0;
280
281 // Total job size for tracking progress.
282 int64 TotalJobSize;
283
284 // Byte processed so far for tracking progress.
285 int64 ByteProcessed;
286
287 uint32 MaxWriteBatchSize = 0;
288 uint32 IOBufferSize = 0;
289
290 int32 WriteCount = 0;
291
292 // The amount of disk space requirement that was calculated when beginning the process. 0 if the install process was not started, or no additional space was needed.
293 std::atomic_uint64_t RequiredDiskSpace;
294
295 // The amount of disk space available when beginning the process. 0 if the install process was not started.
296 std::atomic_uint64_t AvailableDiskSpace;
297
298 // Event executed before deleting an old installation file.
299 FOnBeforeDeleteFile BeforeDeleteFileEvent;
300
301
302 TArray<FEvent*> ThreadWakeups;
304 TArray<UE::FMutex> ThreadJobPostingLocks;
305 TArray<FEvent*> ThreadCompleteEvents;
307
308 void QueueGenericThreadTask(int32 ThreadIndex, TUniqueFunction<void(bool)>&& Task);
309 void GenericThreadFn(int32 ThreadIndex);
310 int8 ThreadAssignments[EConstructorChunkLocation::COUNT];
311 int8 WriteThreadIndex = -1;
312
314
315 // Fire this to wake up the main thread to process completed tasks.
316 FEvent* WakeUpDispatchThreadEvent = nullptr;
317
319
320 // Where we are in the chunk consumption list after each file.
321 TArray<int32> FileCompletionPositions;
322
323 void StartReadBatch(FFileConstructionState& CurrentFile, FBatchState& Buffer);
324 void CompleteReadBatch(const FFileManifest& FileManifest, FBatchState& Buffer);
325 void RequestCompletedFn(const FGuid& Guid, bool bAborted, bool bFailedToRead, void* UserPtr);
326
327 std::atomic_int32_t PendingHarvestRequests = 0;
328 void ChunkHarvestCompletedFn(const FGuid& Guid, bool bAborted, bool bFailedToRead, void* UserPtr);
329
330 void StartFile(FFileConstructionState& CurrentFile, const FResumeData& ResumeData);
331 void ResumeFile(FFileConstructionState& FileToResume);
332 void OpenFileToConstruct(FFileConstructionState& CurrentFile);
333 bool HandleInitialDiskSizeCheck(const FFileManifest& CurrentFileManifest, int64 BytesInToCurrentFile);
334 bool HarvestChunksForCompletedFile(const FString& CompletedBuildFileName);
335 void CompleteConstructedFile(FFileConstructionState& CurrentFile);
336 void InitFile(FFileConstructionState& CurrentFile, const FResumeData& ResumeData);
337
338
339
340 public:
350
351 // This isn't safe to call during operations as values are changing on other threads.
353 {
354 return BackingStoreStats;
355 }
356 private:
357
358 FBackingStoreStats BackingStoreStats;
359 };
360
366 {
367 public:
369
373 virtual void OnResumeStarted() = 0;
374
378 virtual void OnResumeCompleted() = 0;
379
384 virtual void OnChunkGet(const FGuid& ChunkId) = 0;
385
391 virtual void OnFileStarted(const FString& Filename, int64 FileSize) = 0;
392
398 virtual void OnFileProgress(const FString& Filename, int64 TotalBytes) = 0;
399
405 virtual void OnFileCompleted(const FString& Filename, bool bSuccess) = 0;
406
410 virtual void OnConstructionCompleted() = 0;
411
416 virtual void OnProcessedDataUpdated(int64 TotalBytes) = 0;
417
422 virtual void OnTotalRequiredUpdated(int64 TotalBytes) = 0;
423
427 virtual void OnBeforeAdminister() = 0;
428
433 virtual void OnAfterAdminister(const ISpeedRecorder::FRecord& Record) = 0;
434
438 virtual void OnBeforeRead() = 0;
439
444 virtual void OnAfterRead(const ISpeedRecorder::FRecord& Record) = 0;
445
449 virtual void OnBeforeWrite() = 0;
450
455 virtual void OnAfterWrite(const ISpeedRecorder::FRecord& Record) = 0;
456 };
457}
458
463{
464 uint64 CalculateRequiredDiskSpace(const FBuildPatchAppManifestPtr& CurrentManifest, const FBuildPatchAppManifestRef& BuildManifest, const BuildPatchServices::EInstallMode& InstallMode, const TSet<FString>& InstallTags);
465}
EConstructionError
Definition BuildPatchFileConstructor.cpp:161
bool bSuccess
Definition ConvexDecomposition3.cpp:819
FPlatformTypes::int8 int8
An 8-bit signed integer.
Definition Platform.h:1121
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition BuildPatchFileConstructor.h:106
virtual void SetPaused(bool bInIsPaused) override
Definition BuildPatchFileConstructor.cpp:1628
virtual void Abort() override
Definition BuildPatchFileConstructor.cpp:1639
void WakeUpDispatch()
Definition BuildPatchFileConstructor.cpp:2691
FBackingStoreStats GetBackingStoreStats()
Definition BuildPatchFileConstructor.h:352
void GrabFilesInstalledToMemory(TMap< FString, TArray64< uint8 > > &OutFilesInstalledToMemory)
Definition BuildPatchFileConstructor.h:164
DECLARE_EVENT_OneParam(FBuildPatchFileConstructor, FOnBeforeDeleteFile, const FString &)
FOnBeforeDeleteFile & OnBeforeDeleteFile()
Definition BuildPatchFileConstructor.cpp:2047
uint64 GetAvailableDiskSpace()
Definition BuildPatchFileConstructor.cpp:2042
uint64 GetRequiredDiskSpace()
Definition BuildPatchFileConstructor.cpp:2037
void Run()
Definition BuildPatchFileConstructor.cpp:1909
~FBuildPatchFileConstructor()
Definition BuildPatchFileConstructor.cpp:1606
Definition IBuildManifestSet.h:85
Definition ChunkReferenceTracker.h:15
Definition ChunkDbChunkSource.h:44
TUniqueFunction< void(bool bIsAborted)> FRequestProcessFn
Definition ChunkSource.h:22
Definition CloudChunkSource.h:56
Definition InstallChunkSource.h:25
Definition Controllable.h:10
Definition BuildPatchFileConstructor.h:366
virtual void OnChunkGet(const FGuid &ChunkId)=0
virtual void OnFileProgress(const FString &Filename, int64 TotalBytes)=0
virtual void OnAfterRead(const ISpeedRecorder::FRecord &Record)=0
virtual void OnFileStarted(const FString &Filename, int64 FileSize)=0
virtual void OnTotalRequiredUpdated(int64 TotalBytes)=0
virtual void OnFileCompleted(const FString &Filename, bool bSuccess)=0
virtual void OnAfterAdminister(const ISpeedRecorder::FRecord &Record)=0
virtual ~IFileConstructorStat()
Definition BuildPatchFileConstructor.h:368
virtual void OnAfterWrite(const ISpeedRecorder::FRecord &Record)=0
virtual void OnProcessedDataUpdated(int64 TotalBytes)=0
Definition FileSystem.h:51
Definition InstallerAnalytics.h:17
Definition InstallerError.h:142
Definition MessagePump.h:13
EConstructorChunkLocation
Definition BuildPatchFileConstructor.h:30
@ DiskOverflow
Definition BuildPatchFileConstructor.h:34
@ Cloud
Definition BuildPatchFileConstructor.h:35
@ ChunkDb
Definition BuildPatchFileConstructor.h:32
@ Install
Definition BuildPatchFileConstructor.h:31
@ Retired
Definition BuildPatchFileConstructor.h:36
@ Memory
Definition BuildPatchFileConstructor.h:33
Definition Archive.h:1208
Definition BuildPatchManifest.h:64
Definition BuildPatchFileConstructor.cpp:403
Definition Event.h:21
Definition ThreadSafeBool.h:17
Definition IBuildInstallerSharedContext.h:33
Definition Array.h:670
Definition UnrealString.h.inl:34
Definition FunctionFwd.h:19
Definition UniquePtr.h:107
Definition CriticalSection.h:14
Definition BuildPatchFileConstructor.h:28
Definition BuildPatchFileConstructor.cpp:67
uint64 CalculateRequiredDiskSpace(const FBuildPatchAppManifestPtr &CurrentManifest, const FBuildPatchAppManifestRef &BuildManifest, const EInstallMode &InstallMode, const TSet< FString > &InInstallTags)
Definition BuildPatchFileConstructor.cpp:77
uint32 DiskLoadFailureCount
Definition BuildPatchFileConstructor.h:346
uint64 DiskPeakUsageBytes
Definition BuildPatchFileConstructor.h:343
uint32 DiskChunkLoadCount
Definition BuildPatchFileConstructor.h:348
uint64 MemoryPeakUsageBytes
Definition BuildPatchFileConstructor.h:344
uint64 MemoryLimitBytes
Definition BuildPatchFileConstructor.h:345
uint32 DiskLostChunkCount
Definition BuildPatchFileConstructor.h:347
Definition BuildPatchFileConstructor.h:59
FString InstallDirectory
Definition BuildPatchFileConstructor.h:64
TOptional< bool > StallWhenFileSystemThrottled
Definition BuildPatchFileConstructor.h:97
FString StagingDirectory
Definition BuildPatchFileConstructor.h:67
TOptional< int32 > DisableResumeBelowMB
Definition BuildPatchFileConstructor.h:98
IBuildInstallerSharedContext * SharedContext
Definition BuildPatchFileConstructor.h:81
bool bInstallToMemory
Definition BuildPatchFileConstructor.h:84
TOptional< int32 > IOBufferSizeMB
Definition BuildPatchFileConstructor.h:96
FString MetaDirectory
Definition BuildPatchFileConstructor.h:70
bool bDeleteChunkDBFilesAfterUse
Definition BuildPatchFileConstructor.h:88
IBuildManifestSet * ManifestSet
Definition BuildPatchFileConstructor.h:61
TOptional< int32 > IOBatchSizeMB
Definition BuildPatchFileConstructor.h:95
TOptional< bool > SpawnAdditionalIOThreads
Definition BuildPatchFileConstructor.h:94
FString BackingStoreDirectory
Definition BuildPatchFileConstructor.h:79
static const int32 DefaultIOBufferSizeMB
Definition BuildPatchFileConstructor.h:92
bool bSkipInitialDiskSizeCheck
Definition BuildPatchFileConstructor.h:86
static const int32 DefaultIOBatchSizeMB
Definition BuildPatchFileConstructor.h:91
EInstallMode InstallMode
Definition BuildPatchFileConstructor.h:76
static const bool bDefaultSpawnAdditionalIOThreads
Definition BuildPatchFileConstructor.h:90
bool bConstructInMemory
Definition BuildPatchFileConstructor.h:85
TArray< FString > ConstructList
Definition BuildPatchFileConstructor.h:73
Definition ManifestData.h:140
Definition SpeedRecorder.h:18
Definition BuildPatchFileConstructor.cpp:2223
Definition BuildPatchFileConstructor.cpp:179
Definition Guid.h:109
Definition BuildPatchFileConstructor.cpp:262
Definition Optional.h:131