Skip to content

Commit c36ae2b

Browse files
Restore lost code once again
1 parent 2624f93 commit c36ae2b

File tree

2 files changed

+67
-7
lines changed

2 files changed

+67
-7
lines changed

ydb/core/persqueue/key.h

+65-5
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ class TKeyPrefix : public TBuffer
3535
: Partition(partition)
3636
{
3737
Resize(UnmarkedSize());
38-
*PtrType() = type;
39-
memcpy(PtrPartition(), Sprintf("%.10" PRIu32, Partition.InternalPartitionId).data(), 10);
38+
SetType(type);
39+
memcpy(PtrPartition(), Sprintf("%.10" PRIu32, Partition.InternalPartitionId).data(), 10);
4040
}
4141

4242
TKeyPrefix(EType type, const TPartitionId& partition, EMark mark)
@@ -62,25 +62,84 @@ class TKeyPrefix : public TBuffer
6262
static constexpr ui32 MarkPosition() { return UnmarkedSize(); }
6363
static constexpr ui32 MarkedSize() { return UnmarkedSize() + 1; }
6464

65+
6566
void SetType(EType type) {
66-
*PtrType() = type;
67+
if (!IsServicePartition()) {
68+
*PtrType() = type;
69+
return;
70+
}
71+
switch (type) {
72+
case TypeNone:
73+
*PtrType() = TypeNone;
74+
return;
75+
case TypeData:
76+
*PtrType() = ServiceTypeData;
77+
return;
78+
case TypeTmpData:
79+
*PtrType() = ServiceTypeTmpData;
80+
return;
81+
case TypeInfo:
82+
*PtrType() = ServiceTypeInfo;
83+
return;
84+
case TypeMeta:
85+
*PtrType() = ServiceTypeMeta;
86+
return;
87+
case TypeTxMeta:
88+
*PtrType() = ServiceTypeTxMeta;
89+
return;
90+
default:
91+
Y_ABORT();
92+
}
6793
}
6894

95+
6996
EType GetType() const {
70-
return EType(*PtrType());
97+
switch (*PtrType()) {
98+
case TypeNone:
99+
return TypeNone;
100+
case TypeData:
101+
case ServiceTypeData:
102+
return TypeData;
103+
case TypeTmpData:
104+
case ServiceTypeTmpData:
105+
return TypeTmpData;
106+
case TypeInfo:
107+
case ServiceTypeInfo:
108+
return TypeInfo;
109+
case TypeMeta:
110+
case ServiceTypeMeta:
111+
return TypeMeta;
112+
case TypeTxMeta:
113+
case ServiceTypeTxMeta:
114+
return TypeTxMeta;
115+
}
116+
Y_ABORT();
117+
return TypeNone;
71118
}
72119

120+
bool IsServicePartition() const {return Partition.WriteId.Defined();}
121+
73122
const TPartitionId& GetPartition() const { return Partition; }
74123

75124
protected:
76125
static constexpr ui32 UnmarkedSize() { return 1 + 10; }
77126

78127
void ParsePartition()
79128
{
80-
Partition.InternalPartitionId = FromString<ui32>(TStringBuf{PtrPartition(), 10});
129+
Partition.OriginalPartitionId = FromString<ui32>(TStringBuf{PtrPartition(), 10});
130+
Partition.InternalPartitionId = Partition.OriginalPartitionId;
81131
}
82132

133+
83134
private:
135+
enum EServiceType : char {
136+
ServiceTypeInfo = 'M',
137+
ServiceTypeData = 'D',
138+
ServiceTypeTmpData = 'X',
139+
ServiceTypeMeta = 'J',
140+
ServiceTypeTxMeta = 'K'
141+
};
142+
84143
char* PtrType() { return Data(); }
85144
char* PtrMark() { return Data() + UnmarkedSize(); }
86145
char* PtrPartition() { return Data() + 1; }
@@ -90,6 +149,7 @@ class TKeyPrefix : public TBuffer
90149
const char* PtrPartition() const { return Data() + 1; }
91150

92151
TPartitionId Partition;
152+
93153
};
94154

95155
// {char type; ui32 partiton; ui64 offset; ui16 partNo; ui32 count, ui16 internalPartsCount}

ydb/core/persqueue/ut/internals_ut.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,10 @@ Y_UNIT_TEST(StoreKeys) {
233233
UNIT_ASSERT_VALUES_EQUAL(keyOld.ToString(), "d0000000009_00000000000000000008_00007_0000000006_00005");
234234

235235
TKey keyNew(TKeyPrefix::TypeData, TPartitionId{5, 1, 9}, 8, 7, 6, 5, false);
236-
UNIT_ASSERT_VALUES_EQUAL(keyNew.ToString(), "D0000000000_90000000000000000008_00007_0000000006_00005");
236+
UNIT_ASSERT_VALUES_EQUAL(keyNew.ToString(), "D0000000009_00000000000000000008_00007_0000000006_00005");
237237

238238
keyNew.SetType(TKeyPrefix::TypeInfo);
239-
UNIT_ASSERT_VALUES_EQUAL(keyNew.ToString(), "M0000000000_90000000000000000008_00007_0000000006_00005");
239+
UNIT_ASSERT_VALUES_EQUAL(keyNew.ToString(), "M00000000009_00000000000000000008_00007_0000000006_00005");
240240
}
241241

242242
Y_UNIT_TEST(RestoreKeys) {

0 commit comments

Comments
 (0)