aboutsummaryrefslogtreecommitdiffstats
path: root/ydb/core/base/blobstorage.cpp
blob: 60bef7f4dffcc67d8d871eeb52fd9bd8563c9a57 (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
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
120
121
122
123
124
125
126
127
128
129
#include "blobstorage.h"

namespace NKikimr {

NKikimrBlobStorage::EPDiskType PDiskTypeToPDiskType(const TPDiskCategory::EDeviceType type) {
    switch (type) {
        case TPDiskCategory::DEVICE_TYPE_ROT:
            return NKikimrBlobStorage::EPDiskType::ROT;
        case TPDiskCategory::DEVICE_TYPE_SSD:
            return NKikimrBlobStorage::EPDiskType::SSD;
        case TPDiskCategory::DEVICE_TYPE_NVME:
            return NKikimrBlobStorage::EPDiskType::NVME;
        case TPDiskCategory::DEVICE_TYPE_UNKNOWN:
            return NKikimrBlobStorage::EPDiskType::UNKNOWN_TYPE;
        default:
            Y_FAIL("Device type is unknown; type# %" PRIu64, (ui64)type);
    }
}

TPDiskCategory::EDeviceType PDiskTypeToPDiskType(const NKikimrBlobStorage::EPDiskType type) {
    switch (type) {
        case NKikimrBlobStorage::EPDiskType::ROT:
            return TPDiskCategory::DEVICE_TYPE_ROT;
        case NKikimrBlobStorage::EPDiskType::SSD:
            return TPDiskCategory::DEVICE_TYPE_SSD;
        case NKikimrBlobStorage::EPDiskType::NVME:
            return TPDiskCategory::DEVICE_TYPE_NVME;
        case NKikimrBlobStorage::EPDiskType::UNKNOWN_TYPE:
            return TPDiskCategory::DEVICE_TYPE_UNKNOWN;
        default:
            Y_FAIL("Device type is unknown; type# %" PRIu64, (ui64)type);
    }
}

bool operator==(const TPDiskCategory x, const TPDiskCategory y) {
    return x.Kind() == y.Kind() && x.Type() == y.Type();
}

bool operator!=(const TPDiskCategory x, const TPDiskCategory y) {
    return !(x == y);
}

bool operator<(const TPDiskCategory x, const TPDiskCategory y) {
    return std::make_tuple(x.Type(), x.Kind()) < std::make_tuple(y.Type(), y.Kind());
}

std::unique_ptr<TEvBlobStorage::TEvPutResult> TEvBlobStorage::TEvPut::MakeErrorResponse(
        NKikimrProto::EReplyStatus status, const TString& errorReason, ui32 groupId) {
    auto res = std::make_unique<TEvPutResult>(status, Id, TStorageStatusFlags(), groupId, 0.0f);
    res->ErrorReason = errorReason;
    return res;
}

std::unique_ptr<TEvBlobStorage::TEvGetResult> TEvBlobStorage::TEvGet::MakeErrorResponse(
        NKikimrProto::EReplyStatus status, const TString& errorReason, ui32 groupId) {
    auto res = std::make_unique<TEvGetResult>(status, QuerySize, groupId);
    for (ui32 i = 0; i < QuerySize; ++i) {
        const auto& from = Queries[i];
        auto& to = res->Responses[i];
        to.Status = status;
        to.Id = from.Id;
        to.Shift = from.Shift;
        to.RequestedSize = from.Size;
    }
    res->ErrorReason = errorReason;
    return res;
}

std::unique_ptr<TEvBlobStorage::TEvBlockResult> TEvBlobStorage::TEvBlock::MakeErrorResponse(
        NKikimrProto::EReplyStatus status, const TString& errorReason, ui32 /*groupId*/) {
    auto res = std::make_unique<TEvBlockResult>(status);
    res->ErrorReason = errorReason;
    return res;
}

std::unique_ptr<TEvBlobStorage::TEvPatchResult> TEvBlobStorage::TEvPatch::MakeErrorResponse(
        NKikimrProto::EReplyStatus status, const TString& errorReason, ui32 groupId) {
    auto res = std::make_unique<TEvPatchResult>(status, PatchedId, TStorageStatusFlags(), groupId, 0.0f);
    res->ErrorReason = errorReason;
    return res;
}

std::unique_ptr<TEvBlobStorage::TEvInplacePatchResult> TEvBlobStorage::TEvInplacePatch::MakeErrorResponse(
        NKikimrProto::EReplyStatus status, const TString& errorReason) {
    auto res = std::make_unique<TEvInplacePatchResult>(status, PatchedId, TStorageStatusFlags(), 0.0f);
    res->ErrorReason = errorReason;
    return res;
}

std::unique_ptr<TEvBlobStorage::TEvDiscoverResult> TEvBlobStorage::TEvDiscover::MakeErrorResponse(
        NKikimrProto::EReplyStatus status, const TString& errorReason, ui32 /*groupId*/) {
    auto res = std::make_unique<TEvDiscoverResult>(status, MinGeneration, 0);
    res->ErrorReason = errorReason;
    return res;
}

std::unique_ptr<TEvBlobStorage::TEvRangeResult> TEvBlobStorage::TEvRange::MakeErrorResponse(
        NKikimrProto::EReplyStatus status, const TString& errorReason, ui32 groupId) {
    auto res = std::make_unique<TEvRangeResult>(status, From, To, groupId);
    res->ErrorReason = errorReason;
    return res;
}

std::unique_ptr<TEvBlobStorage::TEvCollectGarbageResult> TEvBlobStorage::TEvCollectGarbage::MakeErrorResponse(
        NKikimrProto::EReplyStatus status, const TString& errorReason, ui32 /*groupId*/) {
    auto res = std::make_unique<TEvCollectGarbageResult>(status, TabletId, RecordGeneration, PerGenerationCounter, Channel);
    res->ErrorReason = errorReason;
    return res;
}

std::unique_ptr<TEvBlobStorage::TEvStatusResult> TEvBlobStorage::TEvStatus::MakeErrorResponse(
        NKikimrProto::EReplyStatus status, const TString& errorReason, ui32 /*groupId*/) {
    auto res = std::make_unique<TEvStatusResult>(status, TStorageStatusFlags());
    res->ErrorReason = errorReason;
    return res;
}

};

template<>
void Out<NKikimr::TStorageStatusFlags>(IOutputStream& o,
        typename TTypeTraits<NKikimr::TStorageStatusFlags>::TFuncParam x) {
    return x.Output(o);
}

template<>
void Out<NKikimr::TPDiskCategory>(IOutputStream &str, const NKikimr::TPDiskCategory &value) {
    str << value.ToString();
}