Skip to content

Commit

Permalink
Cosmetic changes & simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberROFL committed Oct 11, 2024
1 parent 7401315 commit 125a8b4
Show file tree
Hide file tree
Showing 19 changed files with 266 additions and 364 deletions.
3 changes: 1 addition & 2 deletions ydb/core/wrappers/abstract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#include "fake_storage_config.h"
#include "s3_storage_config.h"

#include <util/system/rwlock.h>

namespace NKikimr::NWrappers::NExternalStorage {

IExternalStorageOperator::TPtr IExternalStorageConfig::ConstructStorageOperator(bool verbose) const {
Expand All @@ -17,4 +15,5 @@ IExternalStorageConfig::TPtr IExternalStorageConfig::Construct(const NKikimrSche
return std::make_shared<TS3ExternalStorageConfig>(settings);
}
}

}
8 changes: 5 additions & 3 deletions ydb/core/wrappers/abstract.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#pragma once
#include <ydb/core/base/events.h>

#include <ydb/core/protos/flat_scheme_op.pb.h>
#include <ydb/core/wrappers/events/abstract.h>
#include <ydb/core/wrappers/events/common.h>
#include <ydb/core/wrappers/events/delete_objects.h>
#include <ydb/core/wrappers/events/get_object.h>
#include <ydb/core/wrappers/events/list_objects.h>
#include <ydb/core/wrappers/events/object_exists.h>
#include <ydb/core/wrappers/events/get_object.h>
#include <util/generic/ptr.h>

#include <memory>

namespace NKikimr::NWrappers {

Expand Down
48 changes: 26 additions & 22 deletions ydb/core/wrappers/events/abstract.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#include <ydb/core/base/events.h>
#include <util/generic/ptr.h>

#include <memory>

namespace NKikimr::NWrappers::NExternalStorage {

Expand All @@ -11,28 +13,30 @@ class IRequestContext {
};

#define EV_REQUEST_RESPONSE(name) \
Ev##name##Request, \
Ev##name##Response

enum EEv {
EvBegin = EventSpaceBegin(TKikimrEvents::ES_S3_WRAPPER),

EV_REQUEST_RESPONSE(GetObject),
EV_REQUEST_RESPONSE(HeadObject),
EV_REQUEST_RESPONSE(PutObject),
EV_REQUEST_RESPONSE(DeleteObject),
EV_REQUEST_RESPONSE(DeleteObjects),
EV_REQUEST_RESPONSE(CreateMultipartUpload),
EV_REQUEST_RESPONSE(UploadPart),
EV_REQUEST_RESPONSE(CompleteMultipartUpload),
EV_REQUEST_RESPONSE(AbortMultipartUpload),
EV_REQUEST_RESPONSE(ListObjects),
EV_REQUEST_RESPONSE(CheckObjectExists),
EV_REQUEST_RESPONSE(UploadPartCopy),
EvEnd,
};
Ev##name##Request, \
Ev##name##Response

enum EEv {
EvBegin = EventSpaceBegin(TKikimrEvents::ES_S3_WRAPPER),

EV_REQUEST_RESPONSE(GetObject),
EV_REQUEST_RESPONSE(HeadObject),
EV_REQUEST_RESPONSE(PutObject),
EV_REQUEST_RESPONSE(DeleteObject),
EV_REQUEST_RESPONSE(DeleteObjects),
EV_REQUEST_RESPONSE(CreateMultipartUpload),
EV_REQUEST_RESPONSE(UploadPart),
EV_REQUEST_RESPONSE(CompleteMultipartUpload),
EV_REQUEST_RESPONSE(AbortMultipartUpload),
EV_REQUEST_RESPONSE(ListObjects),
EV_REQUEST_RESPONSE(CheckObjectExists),
EV_REQUEST_RESPONSE(UploadPartCopy),

EvEnd,
};

#undef EV_REQUEST_RESPONSE

static_assert(EvEnd < EventSpaceEnd(TKikimrEvents::ES_S3_WRAPPER), "expect EvEnd < EventSpaceEnd(TKikimrEvents::ES_S3_WRAPPER)");
static_assert(EvEnd < EventSpaceEnd(TKikimrEvents::ES_S3_WRAPPER), "expect EvEnd < EventSpaceEnd(TKikimrEvents::ES_S3_WRAPPER)");

}
122 changes: 49 additions & 73 deletions ydb/core/wrappers/events/common.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
#pragma once

#include "abstract.h"
#include "s3_out.h"

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

#include <ydb/core/base/events.h>
#include <ydb/core/protos/flat_scheme_op.pb.h>

#include <util/generic/ptr.h>

namespace NKikimr::NWrappers::NExternalStorage {

template <typename TDerived, ui32 EventType, typename T>
struct TGenericRequest: public NActors::TEventLocal<TDerived, EventType> {
private:
IRequestContext::TPtr RequestContext;

public:
using TRequest = T;
TRequest Request;

IRequestContext::TPtr GetRequestContext() const {
return RequestContext;
}
Expand All @@ -30,11 +28,7 @@ struct TGenericRequest: public NActors::TEventLocal<TDerived, EventType> {
return Request;
}

explicit TGenericRequest(const TRequest& request)
: Request(request) {
}

explicit TGenericRequest(const TRequest& request, IRequestContext::TPtr requestContext)
explicit TGenericRequest(const TRequest& request, IRequestContext::TPtr requestContext = nullptr)
: RequestContext(requestContext)
, Request(request)
{
Expand All @@ -57,7 +51,8 @@ struct TRequestWithBody: public TGenericRequest<TDerived, EventType, T> {

explicit TRequestWithBody(const typename TGeneric::TRequest& request, TString&& body)
: TGeneric(request)
, Body(std::move(body)) {
, Body(std::move(body))
{
}

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

template <typename TDerived, ui32 EventType, typename TAwsResultExt, typename U = TAwsResultExt>
struct TBaseGenericResponse: public NActors::TEventLocal<TDerived, EventType> {
template <typename TDerived, ui32 EventType, typename T, typename U = T>
struct TGenericResponse: public NActors::TEventLocal<TDerived, EventType> {
private:
using TBase = NActors::TEventLocal<TDerived, EventType>;
IRequestContext::TPtr RequestContext;

public:
using TOutcome = Aws::Utils::Outcome<TAwsResultExt, Aws::S3::S3Error>;
using TOutcome = Aws::Utils::Outcome<T, Aws::S3::S3Error>;
using TResult = Aws::Utils::Outcome<U, Aws::S3::S3Error>;
using TAwsResult = U;
using TAwsOutcome = TResult;
using TKey = std::optional<TString>;

TKey Key;
TResult Result;

explicit TBaseGenericResponse(const TOutcome& outcome)
: Result(TDerived::ResultFromOutcome(outcome)) {
explicit TGenericResponse(const TOutcome& outcome, IRequestContext::TPtr requestContext = nullptr)
: RequestContext(requestContext)
, Result(TDerived::ResultFromOutcome(outcome))
{
}

explicit TBaseGenericResponse(const TOutcome& outcome, IRequestContext::TPtr requestContext)
explicit TGenericResponse(const TKey& key, const TOutcome& outcome, IRequestContext::TPtr requestContext = nullptr)
: RequestContext(requestContext)
, Result(TDerived::ResultFromOutcome(outcome)) {
, Key(key)
, Result(TDerived::ResultFromOutcome(outcome))
{
}

bool IsSuccess() const {
return Result.IsSuccess();
}

const Aws::S3::S3Error& GetError() const {
return Result.GetError();
}

const U& GetResult() const {
return Result.GetResult();
}

template <class T>
std::shared_ptr<T> GetRequestContextAs() const {
return dynamic_pointer_cast<T>(RequestContext);
template <typename Type>
std::shared_ptr<Type> GetRequestContextAs() const {
Y_ABORT_UNLESS(RequestContext);
return dynamic_pointer_cast<Type>(RequestContext);
}

static TResult ResultFromOutcome(const TOutcome& outcome) {
return outcome;
}

TString ToString() const override {
return TStringBuilder() << this->ToStringHeader() << " {"
<< " Result: " << Result
<< " }";
}
};

template <typename TDerived, ui32 EventType, typename TAwsResult, typename U = TAwsResult>
struct TGenericResponse: public TBaseGenericResponse<TDerived, EventType, TAwsResult, U> {
private:
using TBase = TBaseGenericResponse<TDerived, EventType, TAwsResult, U>;
public:
using TOutcome = typename TBase::TOutcome;
using TResult = typename TBase::TResult;
using TKey = std::optional<TString>;

TKey Key;

explicit TGenericResponse(const TKey& key, const TOutcome& outcome)
: TBase(outcome)
, Key(key) {
}

explicit TGenericResponse(const TKey& key, const TOutcome& outcome, IRequestContext::TPtr requestContext)
: TBase(outcome, requestContext)
, Key(key)
{
}

TString ToString() const override {
return TStringBuilder() << this->ToStringHeader() << " {"
<< " Key: " << (Key ? "null" : *Key)
<< " Result: " << TBase::Result
<< " Result: " << Result
<< " }";
}
};
Expand All @@ -153,18 +126,21 @@ template <typename TDerived, ui32 EventType, typename T, typename U>
struct TResponseWithBody: public TGenericResponse<TDerived, EventType, T, U> {
private:
using TBase = TGenericResponse<TDerived, EventType, T, U>;

public:
using TKey = typename TBase::TKey;

TString Body;

explicit TResponseWithBody(const TKey& key, const typename TBase::TOutcome& outcome)
: TBase(key, outcome) {
: TBase(key, outcome)
{
}

explicit TResponseWithBody(const TKey& key, const typename TBase::TOutcome& outcome, TString&& body)
: TBase(key, outcome)
, Body(std::move(body)) {
, Body(std::move(body))
{
}

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

#define DEFINE_REQUEST(name, base) \
struct TEv##name##Request: public base<TEv##name##Request, Ev##name##Request, Aws::S3::Model::name##Request> { \
using TBase::TBase; \
}
struct TEv##name##Request: public base<TEv##name##Request, Ev##name##Request, Aws::S3::Model::name##Request> { \
using TBase::TBase; \
}

#define DEFINE_GENERIC_REQUEST(name) \
DEFINE_REQUEST(name, TGenericRequest)
DEFINE_REQUEST(name, TGenericRequest)

#define DECLARE_GENERIC_RESPONSE(name) \
struct TEv##name##Response: public TGenericResponse<TEv##name##Response, Ev##name##Response, Aws::S3::Model::name##Result> {\
private:\
using TBase = TGenericResponse<TEv##name##Response, Ev##name##Response, Aws::S3::Model::name##Result>;\
public:\
using TBase::TBase;
struct TEv##name##Response: public TGenericResponse<TEv##name##Response, Ev##name##Response, Aws::S3::Model::name##Result> { \
private: \
using TBase = TGenericResponse<TEv##name##Response, Ev##name##Response, Aws::S3::Model::name##Result>; \
public: \
using TBase::TBase;

#define DECLARE_RESPONSE_WITH_BODY(name, result_t) \
struct TEv##name##Response: public TResponseWithBody<TEv##name##Response, Ev##name##Response, Aws::S3::Model::name##Result, result_t> {\
private:\
using TBase = TResponseWithBody<TEv##name##Response, Ev##name##Response, Aws::S3::Model::name##Result, result_t>;\
public:\
using TBase::TBase;
struct TEv##name##Response: public TResponseWithBody<TEv##name##Response, Ev##name##Response, Aws::S3::Model::name##Result, result_t> { \
private: \
using TBase = TResponseWithBody<TEv##name##Response, Ev##name##Response, Aws::S3::Model::name##Result, result_t>; \
public: \
using TBase::TBase;

#define DEFINE_GENERIC_RESPONSE(name) \
DECLARE_GENERIC_RESPONSE(name) \
}
DECLARE_GENERIC_RESPONSE(name) \
}

#define DEFINE_GENERIC_REQUEST_RESPONSE(name) \
DEFINE_GENERIC_REQUEST(name); \
DEFINE_GENERIC_RESPONSE(name)
DEFINE_GENERIC_REQUEST(name); \
DEFINE_GENERIC_RESPONSE(name)

DEFINE_REQUEST(PutObject, TRequestWithBody);
DEFINE_GENERIC_RESPONSE(PutObject);
Expand Down
32 changes: 13 additions & 19 deletions ydb/core/wrappers/events/delete_objects.h
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
#pragma once
#include "abstract.h"
#include "common.h"

#include <ydb/core/base/events.h>
#include <ydb/core/protos/flat_scheme_op.pb.h>
#include "common.h"

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

namespace NKikimr::NWrappers::NExternalStorage {

class TEvDeleteObjectsRequest: public TGenericRequest<TEvDeleteObjectsRequest, EvDeleteObjectsRequest, Aws::S3::Model::DeleteObjectsRequest> {
private:
using TBase = TGenericRequest<TEvDeleteObjectsRequest, EvDeleteObjectsRequest, Aws::S3::Model::DeleteObjectsRequest>;
public:
using TBase::TBase;
};
class TEvDeleteObjectsRequest: public TGenericRequest<TEvDeleteObjectsRequest, EvDeleteObjectsRequest, Aws::S3::Model::DeleteObjectsRequest> {
private:
using TBase = TGenericRequest<TEvDeleteObjectsRequest, EvDeleteObjectsRequest, Aws::S3::Model::DeleteObjectsRequest>;
public:
using TBase::TBase;
};

class TEvDeleteObjectsResponse: public TBaseGenericResponse<TEvDeleteObjectsResponse, EvDeleteObjectsResponse, Aws::S3::Model::DeleteObjectsResult> {
private:
using TBase = TBaseGenericResponse<TEvDeleteObjectsResponse, EvDeleteObjectsResponse, Aws::S3::Model::DeleteObjectsResult>;
public:
using TBase::TBase;
};
class TEvDeleteObjectsResponse: public TGenericResponse<TEvDeleteObjectsResponse, EvDeleteObjectsResponse, Aws::S3::Model::DeleteObjectsResult> {
private:
using TBase = TGenericResponse<TEvDeleteObjectsResponse, EvDeleteObjectsResponse, Aws::S3::Model::DeleteObjectsResult>;
public:
using TBase::TBase;
};

}
Loading

0 comments on commit 125a8b4

Please sign in to comment.