Skip to content

Commit c2c899d

Browse files
Merge c186978 into 5594dac
2 parents 5594dac + c186978 commit c2c899d

File tree

1 file changed

+84
-7
lines changed

1 file changed

+84
-7
lines changed

ydb/core/persqueue/key.h

+84-7
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,100 @@ class TKeyPrefix : public TBuffer
6262
static constexpr ui32 MarkPosition() { return UnmarkedSize(); }
6363
static constexpr ui32 MarkedSize() { return UnmarkedSize() + 1; }
6464

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

96+
6997
EType GetType() const {
70-
return EType(*PtrType());
98+
switch (*PtrType()) {
99+
case TypeNone:
100+
case ServiceTypeNone:
101+
return TypeNone;
102+
case TypeData:
103+
case ServiceTypeData:
104+
return TypeData;
105+
case TypeTmpData:
106+
case ServiceTypeTmpData:
107+
return TypeTmpData;
108+
case TypeInfo:
109+
case ServiceTypeInfo:
110+
return TypeInfo;
111+
case TypeMeta:
112+
case ServiceTypeMeta:
113+
return TypeMeta;
114+
case TypeTxMeta:
115+
case ServiceTypeTxMeta:
116+
return TypeTxMeta;
117+
default:
118+
Y_ABORT();
119+
}
71120
}
72121

122+
bool IsServicePartition() const {return ServicePartition.GetOrElse(false) || Partition.WriteId.Defined();}
123+
73124
const TPartitionId& GetPartition() const { return Partition; }
74125

75126
protected:
76127
static constexpr ui32 UnmarkedSize() { return 1 + 10; }
77128

78-
void ParsePartition()
129+
void ParsePartition()
79130
{
80-
Partition.InternalPartitionId = FromString<ui32>(TStringBuf{PtrPartition(), 10});
131+
Partition.OriginalPartitionId = FromString<ui32>(TStringBuf{PtrPartition(), 10});
132+
//ToDo: deside what to do here. We only save one number for partition
133+
Partition.InternalPartitionId = Partition.OriginalPartitionId;
134+
switch (*PtrType()) {
135+
case TypeNone:
136+
case TypeData:
137+
case TypeTmpData:
138+
case TypeInfo:
139+
case TypeMeta:
140+
case TypeTxMeta:
141+
ServicePartition = false;
142+
break;
143+
default:
144+
ServicePartition = true;
145+
}
81146
}
82147

148+
83149
private:
150+
enum EServiceType : char {
151+
ServiceTypeNone = 1,
152+
ServiceTypeInfo = 'M',
153+
ServiceTypeData = 'D',
154+
ServiceTypeTmpData = 'X',
155+
ServiceTypeMeta = 'J',
156+
ServiceTypeTxMeta = 'K'
157+
};
158+
84159
char* PtrType() { return Data(); }
85160
char* PtrMark() { return Data() + UnmarkedSize(); }
86161
char* PtrPartition() { return Data() + 1; }
@@ -90,6 +165,8 @@ class TKeyPrefix : public TBuffer
90165
const char* PtrPartition() const { return Data() + 1; }
91166

92167
TPartitionId Partition;
168+
TMaybe<bool> ServicePartition;
169+
93170
};
94171

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

0 commit comments

Comments
 (0)