aboutsummaryrefslogtreecommitdiff
path: root/zenstore/compactcas.h
blob: abea83dbde969b644b24376ea14e376f04e0537b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include <zencore/zencore.h>

#include <zencore/iobuffer.h>
#include <zencore/iohash.h>
#include <zencore/string.h>
#include <zencore/thread.h>
#include <zencore/uid.h>
#include <zencore/windows.h>
#include <zenstore/cas.h>
#include <zenstore/caslog.h>
#include <zenstore/basicfile.h>

#include <atlfile.h>
#include <functional>

namespace zen {

//////////////////////////////////////////////////////////////////////////

#pragma pack(push)
#pragma pack(1)

struct CasDiskLocation
{
	uint64_t Offset;
	uint32_t Size;	// TODO: Make this more like the IoStore index so we can store larger chunks (should be five bytes)
};

struct CasDiskIndexEntry
{
	IoHash			Key;
	CasDiskLocation Location;
};

#pragma pack(pop)

static_assert(sizeof(CasDiskIndexEntry) == 32);

struct CasContainerStrategy
{
	CasContainerStrategy(const CasStoreConfiguration& Config, CasStore::Stats& Stats) : m_Config(Config), m_Stats(Stats) {}
	CasStore::InsertResult InsertChunk(const void* chunkData, size_t chunkSize, const IoHash& chunkHash);
	CasStore::InsertResult InsertChunk(IoBuffer Chunk, const IoHash& chunkHash);
	IoBuffer			   FindChunk(const IoHash& chunkHash);
	void				   Initialize(const std::string_view ContainerBaseName, uint64_t Alignment, bool IsNewStore);

private:
	const CasStoreConfiguration&   m_Config;
	CasStore::Stats&			   m_Stats;
	uint64_t					   m_PayloadAlignment = 1 << 4;
	bool						   m_IsInitialized	  = false;
	CasBlobFile					   m_SmallObjectFile;
	CasBlobFile					   m_SmallObjectIndex;
	TCasLogFile<CasDiskIndexEntry> m_CasLog;

	RwLock														m_LocationMapLock;
	std::unordered_map<IoHash, CasDiskLocation, IoHash::Hasher> m_LocationMap;
	RwLock														m_InsertLock;  // used to serialize inserts
	std::atomic<uint64_t>										m_CurrentInsertOffset = 0;
	std::atomic<uint64_t>										m_CurrentIndexOffset  = 0;
};

}  // namespace zen