Files
UnrealEngineUWP/Engine/Source/Developer/Virtualization/Private/VirtualizationFileBackend.h
paul chipchase 8d77e84166 Refactor the VA pushing API so that we only need to implement a single path
#rb Per.Larsson
#jira UE-163103
#rnx
#preflight 6318989c2b7fe03eb664e9f0

### VirtualizationSystem/VirtualizationManager
- Added an overload of ::Push taking just one FPUshRequest so that people don't have to keep adding MakeArrayView boiler plate when pushing a single request
- Change the order of the last two parameters for the raw ::Push call as this will group all of the payload specific parameters together and leave the target storage type at the end. It is unlikely that anyone is calling the older version but it has been deprecated for safety.

### IVirtualizationBackend
- The none FPushRequest overload of ::PushData is no longer virtual, it just converts the parameters to FPushRequest and calls that overload instead. In this way we now only have one pushing code path in our backends. We could probably look into removing this overload at this point (since the higher level IVirtualizationSystem will now convert all push requests into a FPushRequest form) but it is not considered worth it at the moment when the simple overload covers our needs.
- Removed EPushResult in favour of just returning true/false for the overall operation.If the caller needs a more detailed breakdown then they will have to use an overload that takes an FPushRequest over raw parameters.
-- At the moment FPushRequest does not contain a full breakdown of what happened, so with this submit we are effectively losing the ability to find out if the payload was already in the backends or not, however the batch version of push was already not returning this info so it is not a big loss. Fixing FPushRequest to return a better break down of what happened will be done in UE-160942
- Removed the none batch Push paths from the source control and ddc backends as they already supported batch pushing.
- File backend needed to be converted to supporting batch pushing, which is pretty much the same code as before except we need to iterate over the container of FPushRequests.
-- The backend does not early out on error as it tends to be quite fast. We might want to consider an official policy for the VA system, if we should early out of errors or not.

[CL 21907558 by paul chipchase in ue5-main branch]
2022-09-08 19:35:36 -04:00

65 lines
2.3 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "IVirtualizationBackend.h"
namespace UE::Virtualization
{
/**
* A basic backend based on the file system. This can be used to access/store virtualization
* data either on a local disk or a network share. It is intended to be used as a caching system
* to speed up operations (running a local cache or a shared cache for a site) rather than as the
* proper backend solution.
*
* Ini file setup:
* 'Name'=(Type=FileSystem, Path="XXX", RetryCount=X, RetryWaitTime=X)
*
* Required Values:
* 'Name': The backend name in the hierarchy.
* 'Type': The backend will be of type 'FFileSystemBackend'.
* 'Path': The root directory where the files are stored.
*
* Optional Values:
* RetryCount: How many times we should try to open a payload file for read before giving up with
* an error. Useful when many threads/processes can be pushing/pulling from the same
* path/ [Default=10]
* RetryWaitTime: The length of time the process should wait between each read attempt in milliseconds.
* Remember that the max length of time that the process can stall attempting to read
* a payload file is RetryCount * RetryWaitTime; [Default=100ms]
*/
class FFileSystemBackend final : public IVirtualizationBackend
{
public:
explicit FFileSystemBackend(FStringView ProjectName, FStringView ConfigName, FStringView DebugName);
virtual ~FFileSystemBackend() = default;
private:
/* IVirtualizationBackend implementation */
virtual bool Initialize(const FString& ConfigEntry) override;
virtual EConnectionStatus OnConnect() override;
virtual bool PushData(TArrayView<FPushRequest> Requests) override;
virtual FCompressedBuffer PullData(const FIoHash& Id) override;
virtual bool DoesPayloadExist(const FIoHash& Id) override;
private:
void CreateFilePath(const FIoHash& PayloadId, FStringBuilderBase& OutPath);
TUniquePtr<FArchive> OpenFileForReading(const TCHAR* FilePath);
/** The root directory where the payload files should be located. */
FString RootDirectory;
/** The number of times to retry opening a payload file for read */
int32 RetryCount = 10;
/** The length of time (in milliseconds) to wait after each attempt before retrying. */
int32 RetryWaitTimeMS = 100;
};
} // namespace UE::Virtualization