forked from ydb-platform/nbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfsync_queue.h
119 lines (89 loc) · 2.86 KB
/
fsync_queue.h
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#pragma once
#include "public.h"
#include <cloud/filestore/libs/service/filestore.h>
#include <cloud/storage/core/libs/common/error.h>
#include <cloud/storage/core/libs/common/public.h>
#include <cloud/storage/core/libs/diagnostics/logging.h>
#include <cloud/storage/core/protos/error.pb.h>
#include <library/cpp/threading/future/future.h>
#include <util/generic/hash.h>
#include <util/generic/map.h>
#include <util/system/mutex.h>
namespace NCloud::NFileStore::NVFS {
////////////////////////////////////////////////////////////////////////////////
using TNodeId = TScopedHandle<ui64, InvalidNodeId, struct TNodeIdTag>;
using THandle = TScopedHandle<ui64, InvalidHandle, struct THandleTag>;
////////////////////////////////////////////////////////////////////////////////
class TFSyncCache
{
public:
using TRequestId = ui64;
struct TRequest
{
TRequestId ReqId = 0;
TNodeId NodeId;
THandle Handle;
};
private:
struct TItem
{
TRequest Request;
NThreading::TPromise<NProto::TError> Promise = {};
};
using TRequestMap = TMap<TRequestId, TItem>;
using TMetaMap = THashMap<TNodeId, TRequestMap>;
using TDataMap = THashMap<TNodeId, THashMap<THandle, TRequestMap>>;
private:
const TString LogTag;
const ILoggingServicePtr Logging;
TLog Log;
TMetaMap Meta;
TRequestMap GlobalMeta;
TDataMap Data;
TRequestMap GlobalData;
public:
TFSyncCache(TString logTag, ILoggingServicePtr logging);
void AddRequest(const TRequest& request);
NThreading::TFuture<NProto::TError> AddFSyncRequest(const TRequest& request);
void RemoveRequest(const TRequest& request);
private:
void CheckFSyncNotifications();
bool NotifyAndEraseLatest(TRequestMap& map);
void Notify(
const TRequest& request,
NThreading::TPromise<NProto::TError>&& promise);
bool IsFSync(const TItem& item) const;
};
class TFSyncQueue
{
using TRequestId = TFSyncCache::TRequestId;
using TRequest = TFSyncCache::TRequest;
private:
const TString LogTag;
const ILoggingServicePtr Logging;
TLog Log;
TFSyncCache CurrentState;
TMutex StateMutex;
public:
TFSyncQueue(const TString& fileSystemId, ILoggingServicePtr logging);
void Enqueue(
TRequestId reqId,
TNodeId nodeId,
THandle handle = {});
void Dequeue(
TRequestId reqId,
const NProto::TError& error,
TNodeId nodeId,
THandle handle = {});
// Meta requests.
NThreading::TFuture<NProto::TError> WaitForRequests(
TRequestId reqId,
TNodeId nodeId = {});
// Data requests.
NThreading::TFuture<NProto::TError> WaitForDataRequests(TRequestId reqId);
NThreading::TFuture<NProto::TError> WaitForDataRequests(
TRequestId reqId,
TNodeId nodeId,
THandle handle);
};
} // namespace NCloud::NFileStore::NVFS