Files
UnrealEngineUWP/Engine/Source/Programs/UnrealBuildAccelerator/Common/Public/UbaStorageClient.h
henrik karlsson 5dc54a8104 [UBA]
* Huge stability push... all (known) paths have been tested heavily on linux with tsan and every single found race condition report has been fixed. Lots of locks have been added/moved/changed and some instances of things have been leaked on purpose to prevent tsan reports during shutdown
* More efficient storage proxy implementation which immediately forward segments to clients once they are available in proxy
* Added UbaAgent -command=x which can be used to send commands to host. Supported commands are "status"which prints out status of all remote sessions. "abort/abortproxy/abortnonproxy" that can be used to abort remote sessions and "disableremote" to have host stop accepting more helpers
* Fixed scheduler::stop bug if remotes were still requesting processes
* Added support for process reuse on linux/macos
* Added support for Coordinator interface and dynamically load coordinator dll in UbaCli
* Restructured code a little bit to be able to queue up all writes in parallel
* Added Show create/write colors to visualizer (defaults to on)
* Fixed so write file times are visualized in visualizer
* Improved socket path for visualizer
* Improved a lot of error messages
* Fixed double close of memory handle in StorageServer
* Changed some ScopedWriteLock to SCOPED_WRITE_LOCK (same for read locks)
* Fixed some missing cleanup of trace view when starting a new trace view in visualizer

[CL 32137083 by henrik karlsson in ue5-main branch]
2024-03-08 18:31:48 -05:00

95 lines
3.5 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "UbaNetworkClient.h"
#include "UbaStorage.h"
namespace uba
{
class NetworkClient;
using StartProxyCallback = bool(void* userData, u16 port, const Guid& storageServerUid);
using GetProxyBackendCallback = NetworkBackend&(void* userData, const tchar* proxyHost);
struct StorageClientCreateInfo : StorageCreateInfo
{
StorageClientCreateInfo(NetworkClient& c, const tchar* rootDir_) : StorageCreateInfo(rootDir_, c.GetLogWriter()), client(c) {}
NetworkClient& client;
const tchar* zone = TC("");
u16 proxyPort = DefaultStorageProxyPort;
bool sendCompressed = true;
GetProxyBackendCallback* getProxyBackendCallback = nullptr;
void* getProxyBackendUserData = nullptr;
StartProxyCallback* startProxyCallback = nullptr;
void* startProxyUserData = nullptr;
};
class StorageClient final : public StorageImpl
{
public:
StorageClient(const StorageClientCreateInfo& info);
~StorageClient();
bool Start();
bool IsUsingProxy();
void StopProxy();
using DirVector = Vector<TString>;
bool PopulateCasFromDirs(const DirVector& directories, u32 workerCount);
#if !UBA_USE_SPARSEFILE
virtual bool GetCasFileName(StringBufferBase& out, const CasKey& casKey) override;
#endif
virtual MappedView MapView(const CasKey& casKey, const tchar* hint) override;
virtual bool GetZone(StringBufferBase& out) override;
virtual bool RetrieveCasFile(RetrieveResult& out, const CasKey& casKey, const tchar* hint, FileMappingBuffer* mappingBuffer = nullptr, u64 memoryMapAlignment = 1, bool allowProxy = true) override;
virtual bool StoreCasFile(CasKey& out, const tchar* fileName, const CasKey& casKeyOverride = CasKeyZero, bool deferCreation = false) override;
virtual bool StoreCasFile(CasKey& out, StringKey fileNameKey, const tchar* fileName, FileMappingHandle mappingFile, u64 mappingOffset, u64 fileSize, const tchar* hint, bool deferCreation = false, bool keepMappingInMemory = false) override;
virtual bool HasCasFile(const CasKey& casKey, CasEntry** out = nullptr) override;
virtual void Ping() override;
virtual void PrintSummary(Logger& logger) override;
static bool SendBatchMessages(Logger& logger, NetworkClient& client, u16 fetchId, u8* slot, u64 capacity, u64 left, u32 messageMaxSize, u32& readIndex, u32& responseSize);
static bool SendAllSegments(NetworkClient& client, u16 fetchId, u8* readBuffer, u64 left, u32 messageMaxSize);
private:
bool SendFile(const CasKey& casKey, const tchar* fileName, u8* sourceMem, u64 sourceSize, const tchar* hint);
bool PopulateCasFromDirsRecursive(const tchar* dir, WorkManager& workManager, UnorderedSet<u64>& seenIds, ReaderWriterLock& seenIdsLock);
NetworkClient& m_client;
bool m_sendCompressed;
Guid m_storageServerUid;
TString m_zone;
ReaderWriterLock m_localStorageFilesLock;
struct LocalFile { CasEntry casEntry; TString fileName; };
UnorderedMap<CasKey, LocalFile> m_localStorageFiles;
ReaderWriterLock m_sendOneAtTheTimeLock;
ReaderWriterLock m_retrieveOneBatchAtTheTimeLock;
static constexpr u8 ServiceId = StorageServiceId;
struct ProxyClient;
TString m_lastTestedProxyIp;
ReaderWriterLock m_proxyClientLock;
ProxyClient* m_proxyClient = nullptr;
u64 m_proxyClientKeepAliveTime = 0;
GetProxyBackendCallback* m_getProxyBackendCallback = nullptr;
void* m_getProxyBackendUserData = nullptr;
StartProxyCallback* m_startProxyCallback = nullptr;
void* m_startProxyUserData = nullptr;
u16 m_proxyPort = 0;
};
}