Skip to content

Commit b1f1273

Browse files
authored
Cosmetic changes & simplification (#10362)
1 parent 56e8de9 commit b1f1273

19 files changed

+266
-364
lines changed

ydb/core/wrappers/abstract.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
#include "fake_storage_config.h"
33
#include "s3_storage_config.h"
44

5-
#include <util/system/rwlock.h>
6-
75
namespace NKikimr::NWrappers::NExternalStorage {
86

97
IExternalStorageOperator::TPtr IExternalStorageConfig::ConstructStorageOperator(bool verbose) const {
@@ -17,4 +15,5 @@ IExternalStorageConfig::TPtr IExternalStorageConfig::Construct(const NKikimrSche
1715
return std::make_shared<TS3ExternalStorageConfig>(settings);
1816
}
1917
}
18+
2019
}

ydb/core/wrappers/abstract.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#pragma once
2-
#include <ydb/core/base/events.h>
2+
3+
#include <ydb/core/protos/flat_scheme_op.pb.h>
34
#include <ydb/core/wrappers/events/abstract.h>
45
#include <ydb/core/wrappers/events/common.h>
56
#include <ydb/core/wrappers/events/delete_objects.h>
7+
#include <ydb/core/wrappers/events/get_object.h>
68
#include <ydb/core/wrappers/events/list_objects.h>
79
#include <ydb/core/wrappers/events/object_exists.h>
8-
#include <ydb/core/wrappers/events/get_object.h>
9-
#include <util/generic/ptr.h>
10+
11+
#include <memory>
1012

1113
namespace NKikimr::NWrappers {
1214

ydb/core/wrappers/events/abstract.h

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#pragma once
2+
23
#include <ydb/core/base/events.h>
3-
#include <util/generic/ptr.h>
4+
5+
#include <memory>
46

57
namespace NKikimr::NWrappers::NExternalStorage {
68

@@ -11,28 +13,30 @@ class IRequestContext {
1113
};
1214

1315
#define EV_REQUEST_RESPONSE(name) \
14-
Ev##name##Request, \
15-
Ev##name##Response
16-
17-
enum EEv {
18-
EvBegin = EventSpaceBegin(TKikimrEvents::ES_S3_WRAPPER),
19-
20-
EV_REQUEST_RESPONSE(GetObject),
21-
EV_REQUEST_RESPONSE(HeadObject),
22-
EV_REQUEST_RESPONSE(PutObject),
23-
EV_REQUEST_RESPONSE(DeleteObject),
24-
EV_REQUEST_RESPONSE(DeleteObjects),
25-
EV_REQUEST_RESPONSE(CreateMultipartUpload),
26-
EV_REQUEST_RESPONSE(UploadPart),
27-
EV_REQUEST_RESPONSE(CompleteMultipartUpload),
28-
EV_REQUEST_RESPONSE(AbortMultipartUpload),
29-
EV_REQUEST_RESPONSE(ListObjects),
30-
EV_REQUEST_RESPONSE(CheckObjectExists),
31-
EV_REQUEST_RESPONSE(UploadPartCopy),
32-
EvEnd,
33-
};
16+
Ev##name##Request, \
17+
Ev##name##Response
18+
19+
enum EEv {
20+
EvBegin = EventSpaceBegin(TKikimrEvents::ES_S3_WRAPPER),
21+
22+
EV_REQUEST_RESPONSE(GetObject),
23+
EV_REQUEST_RESPONSE(HeadObject),
24+
EV_REQUEST_RESPONSE(PutObject),
25+
EV_REQUEST_RESPONSE(DeleteObject),
26+
EV_REQUEST_RESPONSE(DeleteObjects),
27+
EV_REQUEST_RESPONSE(CreateMultipartUpload),
28+
EV_REQUEST_RESPONSE(UploadPart),
29+
EV_REQUEST_RESPONSE(CompleteMultipartUpload),
30+
EV_REQUEST_RESPONSE(AbortMultipartUpload),
31+
EV_REQUEST_RESPONSE(ListObjects),
32+
EV_REQUEST_RESPONSE(CheckObjectExists),
33+
EV_REQUEST_RESPONSE(UploadPartCopy),
34+
35+
EvEnd,
36+
};
3437

3538
#undef EV_REQUEST_RESPONSE
3639

37-
static_assert(EvEnd < EventSpaceEnd(TKikimrEvents::ES_S3_WRAPPER), "expect EvEnd < EventSpaceEnd(TKikimrEvents::ES_S3_WRAPPER)");
40+
static_assert(EvEnd < EventSpaceEnd(TKikimrEvents::ES_S3_WRAPPER), "expect EvEnd < EventSpaceEnd(TKikimrEvents::ES_S3_WRAPPER)");
41+
3842
}

ydb/core/wrappers/events/common.h

Lines changed: 49 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
#pragma once
2+
23
#include "abstract.h"
34
#include "s3_out.h"
45

56
#include <ydb/library/actors/core/event_local.h>
67

7-
#include <ydb/core/base/events.h>
8-
#include <ydb/core/protos/flat_scheme_op.pb.h>
9-
10-
#include <util/generic/ptr.h>
11-
128
namespace NKikimr::NWrappers::NExternalStorage {
139

1410
template <typename TDerived, ui32 EventType, typename T>
1511
struct TGenericRequest: public NActors::TEventLocal<TDerived, EventType> {
1612
private:
1713
IRequestContext::TPtr RequestContext;
14+
1815
public:
1916
using TRequest = T;
2017
TRequest Request;
18+
2119
IRequestContext::TPtr GetRequestContext() const {
2220
return RequestContext;
2321
}
@@ -30,11 +28,7 @@ struct TGenericRequest: public NActors::TEventLocal<TDerived, EventType> {
3028
return Request;
3129
}
3230

33-
explicit TGenericRequest(const TRequest& request)
34-
: Request(request) {
35-
}
36-
37-
explicit TGenericRequest(const TRequest& request, IRequestContext::TPtr requestContext)
31+
explicit TGenericRequest(const TRequest& request, IRequestContext::TPtr requestContext = nullptr)
3832
: RequestContext(requestContext)
3933
, Request(request)
4034
{
@@ -57,7 +51,8 @@ struct TRequestWithBody: public TGenericRequest<TDerived, EventType, T> {
5751

5852
explicit TRequestWithBody(const typename TGeneric::TRequest& request, TString&& body)
5953
: TGeneric(request)
60-
, Body(std::move(body)) {
54+
, Body(std::move(body))
55+
{
6156
}
6257

6358
TString ToString() const override {
@@ -70,81 +65,59 @@ struct TRequestWithBody: public TGenericRequest<TDerived, EventType, T> {
7065
using TBase = TRequestWithBody<TDerived, EventType, T>;
7166
};
7267

73-
template <typename TDerived, ui32 EventType, typename TAwsResultExt, typename U = TAwsResultExt>
74-
struct TBaseGenericResponse: public NActors::TEventLocal<TDerived, EventType> {
68+
template <typename TDerived, ui32 EventType, typename T, typename U = T>
69+
struct TGenericResponse: public NActors::TEventLocal<TDerived, EventType> {
7570
private:
76-
using TBase = NActors::TEventLocal<TDerived, EventType>;
7771
IRequestContext::TPtr RequestContext;
72+
7873
public:
79-
using TOutcome = Aws::Utils::Outcome<TAwsResultExt, Aws::S3::S3Error>;
74+
using TOutcome = Aws::Utils::Outcome<T, Aws::S3::S3Error>;
8075
using TResult = Aws::Utils::Outcome<U, Aws::S3::S3Error>;
8176
using TAwsResult = U;
82-
using TAwsOutcome = TResult;
8377
using TKey = std::optional<TString>;
8478

79+
TKey Key;
8580
TResult Result;
8681

87-
explicit TBaseGenericResponse(const TOutcome& outcome)
88-
: Result(TDerived::ResultFromOutcome(outcome)) {
82+
explicit TGenericResponse(const TOutcome& outcome, IRequestContext::TPtr requestContext = nullptr)
83+
: RequestContext(requestContext)
84+
, Result(TDerived::ResultFromOutcome(outcome))
85+
{
8986
}
9087

91-
explicit TBaseGenericResponse(const TOutcome& outcome, IRequestContext::TPtr requestContext)
88+
explicit TGenericResponse(const TKey& key, const TOutcome& outcome, IRequestContext::TPtr requestContext = nullptr)
9289
: RequestContext(requestContext)
93-
, Result(TDerived::ResultFromOutcome(outcome)) {
90+
, Key(key)
91+
, Result(TDerived::ResultFromOutcome(outcome))
92+
{
9493
}
9594

9695
bool IsSuccess() const {
9796
return Result.IsSuccess();
9897
}
98+
9999
const Aws::S3::S3Error& GetError() const {
100100
return Result.GetError();
101101
}
102+
102103
const U& GetResult() const {
103104
return Result.GetResult();
104105
}
105106

106-
template <class T>
107-
std::shared_ptr<T> GetRequestContextAs() const {
108-
return dynamic_pointer_cast<T>(RequestContext);
107+
template <typename Type>
108+
std::shared_ptr<Type> GetRequestContextAs() const {
109+
Y_ABORT_UNLESS(RequestContext);
110+
return dynamic_pointer_cast<Type>(RequestContext);
109111
}
110112

111113
static TResult ResultFromOutcome(const TOutcome& outcome) {
112114
return outcome;
113115
}
114116

115-
TString ToString() const override {
116-
return TStringBuilder() << this->ToStringHeader() << " {"
117-
<< " Result: " << Result
118-
<< " }";
119-
}
120-
};
121-
122-
template <typename TDerived, ui32 EventType, typename TAwsResult, typename U = TAwsResult>
123-
struct TGenericResponse: public TBaseGenericResponse<TDerived, EventType, TAwsResult, U> {
124-
private:
125-
using TBase = TBaseGenericResponse<TDerived, EventType, TAwsResult, U>;
126-
public:
127-
using TOutcome = typename TBase::TOutcome;
128-
using TResult = typename TBase::TResult;
129-
using TKey = std::optional<TString>;
130-
131-
TKey Key;
132-
133-
explicit TGenericResponse(const TKey& key, const TOutcome& outcome)
134-
: TBase(outcome)
135-
, Key(key) {
136-
}
137-
138-
explicit TGenericResponse(const TKey& key, const TOutcome& outcome, IRequestContext::TPtr requestContext)
139-
: TBase(outcome, requestContext)
140-
, Key(key)
141-
{
142-
}
143-
144117
TString ToString() const override {
145118
return TStringBuilder() << this->ToStringHeader() << " {"
146119
<< " Key: " << (Key ? "null" : *Key)
147-
<< " Result: " << TBase::Result
120+
<< " Result: " << Result
148121
<< " }";
149122
}
150123
};
@@ -153,18 +126,21 @@ template <typename TDerived, ui32 EventType, typename T, typename U>
153126
struct TResponseWithBody: public TGenericResponse<TDerived, EventType, T, U> {
154127
private:
155128
using TBase = TGenericResponse<TDerived, EventType, T, U>;
129+
156130
public:
157131
using TKey = typename TBase::TKey;
158132

159133
TString Body;
160134

161135
explicit TResponseWithBody(const TKey& key, const typename TBase::TOutcome& outcome)
162-
: TBase(key, outcome) {
136+
: TBase(key, outcome)
137+
{
163138
}
164139

165140
explicit TResponseWithBody(const TKey& key, const typename TBase::TOutcome& outcome, TString&& body)
166141
: TBase(key, outcome)
167-
, Body(std::move(body)) {
142+
, Body(std::move(body))
143+
{
168144
}
169145

170146
TString ToString() const override {
@@ -177,34 +153,34 @@ struct TResponseWithBody: public TGenericResponse<TDerived, EventType, T, U> {
177153
};
178154

179155
#define DEFINE_REQUEST(name, base) \
180-
struct TEv##name##Request: public base<TEv##name##Request, Ev##name##Request, Aws::S3::Model::name##Request> { \
181-
using TBase::TBase; \
182-
}
156+
struct TEv##name##Request: public base<TEv##name##Request, Ev##name##Request, Aws::S3::Model::name##Request> { \
157+
using TBase::TBase; \
158+
}
183159

184160
#define DEFINE_GENERIC_REQUEST(name) \
185-
DEFINE_REQUEST(name, TGenericRequest)
161+
DEFINE_REQUEST(name, TGenericRequest)
186162

187163
#define DECLARE_GENERIC_RESPONSE(name) \
188-
struct TEv##name##Response: public TGenericResponse<TEv##name##Response, Ev##name##Response, Aws::S3::Model::name##Result> {\
189-
private:\
190-
using TBase = TGenericResponse<TEv##name##Response, Ev##name##Response, Aws::S3::Model::name##Result>;\
191-
public:\
192-
using TBase::TBase;
164+
struct TEv##name##Response: public TGenericResponse<TEv##name##Response, Ev##name##Response, Aws::S3::Model::name##Result> { \
165+
private: \
166+
using TBase = TGenericResponse<TEv##name##Response, Ev##name##Response, Aws::S3::Model::name##Result>; \
167+
public: \
168+
using TBase::TBase;
193169

194170
#define DECLARE_RESPONSE_WITH_BODY(name, result_t) \
195-
struct TEv##name##Response: public TResponseWithBody<TEv##name##Response, Ev##name##Response, Aws::S3::Model::name##Result, result_t> {\
196-
private:\
197-
using TBase = TResponseWithBody<TEv##name##Response, Ev##name##Response, Aws::S3::Model::name##Result, result_t>;\
198-
public:\
199-
using TBase::TBase;
171+
struct TEv##name##Response: public TResponseWithBody<TEv##name##Response, Ev##name##Response, Aws::S3::Model::name##Result, result_t> { \
172+
private: \
173+
using TBase = TResponseWithBody<TEv##name##Response, Ev##name##Response, Aws::S3::Model::name##Result, result_t>; \
174+
public: \
175+
using TBase::TBase;
200176

201177
#define DEFINE_GENERIC_RESPONSE(name) \
202-
DECLARE_GENERIC_RESPONSE(name) \
203-
}
178+
DECLARE_GENERIC_RESPONSE(name) \
179+
}
204180

205181
#define DEFINE_GENERIC_REQUEST_RESPONSE(name) \
206-
DEFINE_GENERIC_REQUEST(name); \
207-
DEFINE_GENERIC_RESPONSE(name)
182+
DEFINE_GENERIC_REQUEST(name); \
183+
DEFINE_GENERIC_RESPONSE(name)
208184

209185
DEFINE_REQUEST(PutObject, TRequestWithBody);
210186
DEFINE_GENERIC_RESPONSE(PutObject);
Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,24 @@
11
#pragma once
2-
#include "abstract.h"
3-
#include "common.h"
42

5-
#include <ydb/core/base/events.h>
6-
#include <ydb/core/protos/flat_scheme_op.pb.h>
3+
#include "common.h"
74

8-
#include <contrib/libs/aws-sdk-cpp/aws-cpp-sdk-s3/include/aws/s3/S3Errors.h>
95
#include <contrib/libs/aws-sdk-cpp/aws-cpp-sdk-s3/include/aws/s3/model/DeleteObjectsRequest.h>
106
#include <contrib/libs/aws-sdk-cpp/aws-cpp-sdk-s3/include/aws/s3/model/DeleteObjectsResult.h>
11-
#include <ydb/library/actors/core/event_local.h>
12-
#include <util/generic/ptr.h>
137

148
namespace NKikimr::NWrappers::NExternalStorage {
159

16-
class TEvDeleteObjectsRequest: public TGenericRequest<TEvDeleteObjectsRequest, EvDeleteObjectsRequest, Aws::S3::Model::DeleteObjectsRequest> {
17-
private:
18-
using TBase = TGenericRequest<TEvDeleteObjectsRequest, EvDeleteObjectsRequest, Aws::S3::Model::DeleteObjectsRequest>;
19-
public:
20-
using TBase::TBase;
21-
};
10+
class TEvDeleteObjectsRequest: public TGenericRequest<TEvDeleteObjectsRequest, EvDeleteObjectsRequest, Aws::S3::Model::DeleteObjectsRequest> {
11+
private:
12+
using TBase = TGenericRequest<TEvDeleteObjectsRequest, EvDeleteObjectsRequest, Aws::S3::Model::DeleteObjectsRequest>;
13+
public:
14+
using TBase::TBase;
15+
};
2216

23-
class TEvDeleteObjectsResponse: public TBaseGenericResponse<TEvDeleteObjectsResponse, EvDeleteObjectsResponse, Aws::S3::Model::DeleteObjectsResult> {
24-
private:
25-
using TBase = TBaseGenericResponse<TEvDeleteObjectsResponse, EvDeleteObjectsResponse, Aws::S3::Model::DeleteObjectsResult>;
26-
public:
27-
using TBase::TBase;
28-
};
17+
class TEvDeleteObjectsResponse: public TGenericResponse<TEvDeleteObjectsResponse, EvDeleteObjectsResponse, Aws::S3::Model::DeleteObjectsResult> {
18+
private:
19+
using TBase = TGenericResponse<TEvDeleteObjectsResponse, EvDeleteObjectsResponse, Aws::S3::Model::DeleteObjectsResult>;
20+
public:
21+
using TBase::TBase;
22+
};
2923

3024
}

0 commit comments

Comments
 (0)