Files
UnrealEngineUWP/Engine/Source/Developer/DerivedDataCache/Private/S3DerivedDataBackend.h
andrew grant 2d7a1db75c Changed the S3 DDC backend so it elects not to write to lower cache levels.
(This value is only checked on backends that have a cache of the data, so data that is not in the S3 DDC will still be written back to lower levels if the S3 cache misses).

Changed the speed class for backends to be elligible to be backfilled to fast.

[at]devin.doucette [at]ben.marsh

#ROBOMERGE-SOURCE: CL 12647496 via CL 12647501 via CL 12649274 via CL 12649832 via CL 12649856 via CL 12649891
#ROBOMERGE-BOT: RELEASE (Release-Engine-Staging -> Main) (v675-12543919)

[CL 12649923 by andrew grant in Main branch]
2020-04-07 00:58:22 -04:00

99 lines
3.3 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "DerivedDataBackendInterface.h"
#include "DerivedDataCacheUsageStats.h"
// Macro for whether to enable the S3 backend. libcurl is not currently available on Mac.
#if PLATFORM_WINDOWS
#define WITH_S3_DDC_BACKEND 1
#else
#define WITH_S3_DDC_BACKEND 0
#endif
#if WITH_S3_DDC_BACKEND
/**
* Backend for a read-only AWS S3 based caching service.
**/
class FS3DerivedDataBackend : public FDerivedDataBackendInterface
{
public:
/**
* Creates the backend, checks health status and attempts to acquire an access token.
*
* @param InRootManifestPath Local path to the JSON manifest in the workspace containing a list of files to download
* @param InBaseUrl Base URL for the bucket, with trailing slash (eg. https://foo.s3.us-east-1.amazonaws.com/)
* @param InRegion Name of the AWS region (eg. us-east-1)
* @param InCanaryObjectKey Key for a canary object used to test whether this backend is usable
* @param InCachePath Path to cache the DDC files
* @param InAccessKey The AWS access key
* @param InSecretKey The AWS secret key
*/
FS3DerivedDataBackend(const TCHAR* InRootManifestPath, const TCHAR* InBaseUrl, const TCHAR* InRegion, const TCHAR* InCanaryObjectKey, const TCHAR* InCachePath, const TCHAR* InAccessKey, const TCHAR* InSecretKey);
~FS3DerivedDataBackend();
/**
* Checks is backend is usable (reachable and accessible).
* @return true if usable
*/
bool IsUsable() const;
/* S3 Cache cannot be written to*/
bool IsWritable() override { return false; }
/* S3 Cache does not try to write back to lower caches (e.g. Shared DDC) */
bool BackfillLowerCacheLevels() override { return false; }
bool CachedDataProbablyExists(const TCHAR* CacheKey) override;
bool GetCachedData(const TCHAR* CacheKey, TArray<uint8>& OutData) override;
void PutCachedData(const TCHAR* CacheKey, TArrayView<const uint8> InData, bool bPutEvenIfExists) override;
void RemoveCachedData(const TCHAR* CacheKey, bool bTransient) override;
void GatherUsageStats(TMap<FString, FDerivedDataCacheUsageStats>& UsageStatsMap, FString&& GraphPath) override;
FString GetName() const override;
ESpeedClass GetSpeedClass() override;
bool TryToPrefetch(const TCHAR* CacheKey) override;
bool WouldCache(const TCHAR* CacheKey, TArrayView<const uint8> InData) override;
bool ApplyDebugOptions(FBackendDebugOptions& InOptions) override;
private:
struct FBundle;
struct FBundleEntry;
struct FBundleDownload;
class FRequest;
class FRequestPool;
FString RootManifestPath;
FString BaseUrl;
FString Region;
FString CanaryObjectKey;
FString CacheDir;
TArray<FBundle> Bundles;
TUniquePtr<FRequestPool> RequestPool;
FDerivedDataCacheUsageStats UsageStats;
bool bEnabled;
bool DownloadManifest(FFeedbackContext* Context);
void RemoveUnusedBundles();
void ReadBundle(FBundle& Bundle);
bool FindBundleEntry(const TCHAR* CacheKey, const FBundle*& OutBundle, const FBundleEntry*& OutBundleEntry) const;
/* Debug helpers */
bool DidSimulateMiss(const TCHAR* InKey);
bool ShouldSimulateMiss(const TCHAR* InKey);
/** Debug Options */
FBackendDebugOptions DebugOptions;
/** Keys we ignored due to miss rate settings */
FCriticalSection MissedKeysCS;
TSet<FName> DebugMissedKeys;
};
#endif