Skip to content

Commit

Permalink
TKeyPrefix constructor (#6148)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alek5andr-Kotov authored Jul 2, 2024
1 parent e2ed478 commit c7a7fef
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 28 deletions.
31 changes: 31 additions & 0 deletions ydb/core/persqueue/key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,37 @@ TKey MakeKeyFromString(const TString& s, const TPartitionId& partition)
t.IsHead());
}

void TKeyPrefix::SetTypeImpl(EType type, bool isServicePartition)
{
char c = type;

if (isServicePartition) {
switch (type) {
case TypeNone:
break;
case TypeData:
c = ServiceTypeData;
break;
case TypeTmpData:
c = ServiceTypeTmpData;
break;
case TypeInfo:
c = ServiceTypeInfo;
break;
case TypeMeta:
c = ServiceTypeMeta;
break;
case TypeTxMeta:
c = ServiceTypeTxMeta;
break;
default:
Y_ABORT();
}
}

*PtrType() = c;
}

bool TKeyPrefix::HasServiceType() const
{
switch (*PtrType()) {
Expand Down
32 changes: 4 additions & 28 deletions ydb/core/persqueue/key.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class TKeyPrefix : public TBuffer
: Partition(partition)
{
Resize(UnmarkedSize());
SetType(type);
SetTypeImpl(type, IsServicePartition());
memcpy(PtrPartition(), Sprintf("%.10" PRIu32, Partition.InternalPartitionId).data(), 10);
}

Expand Down Expand Up @@ -68,32 +68,7 @@ class TKeyPrefix : public TBuffer


void SetType(EType type) {
if (!IsServicePartition() && !HasServiceType()) {
*PtrType() = type;
return;
}
switch (type) {
case TypeNone:
*PtrType() = TypeNone;
return;
case TypeData:
*PtrType() = ServiceTypeData;
return;
case TypeTmpData:
*PtrType() = ServiceTypeTmpData;
return;
case TypeInfo:
*PtrType() = ServiceTypeInfo;
return;
case TypeMeta:
*PtrType() = ServiceTypeMeta;
return;
case TypeTxMeta:
*PtrType() = ServiceTypeTxMeta;
return;
default:
Y_ABORT();
}
SetTypeImpl(type, IsServicePartition() || HasServiceType());
}

EType GetType() const {
Expand Down Expand Up @@ -144,6 +119,8 @@ class TKeyPrefix : public TBuffer
ServiceTypeTxMeta = 'K'
};

void SetTypeImpl(EType, bool isServicePartition);

char* PtrType() { return Data(); }
char* PtrMark() { return Data() + UnmarkedSize(); }
char* PtrPartition() { return Data() + 1; }
Expand All @@ -153,7 +130,6 @@ class TKeyPrefix : public TBuffer
const char* PtrPartition() const { return Data() + 1; }

TPartitionId Partition;

};

std::pair<TKeyPrefix, TKeyPrefix> MakeKeyPrefixRange(TKeyPrefix::EType type, const TPartitionId& partition);
Expand Down

0 comments on commit c7a7fef

Please sign in to comment.