Skip to content

Commit

Permalink
Removed TString, TStringBuf, TVector, TMap, TList, TMutex, TCondVar f…
Browse files Browse the repository at this point in the history
…rom util, refactor string utils (#82)
  • Loading branch information
Gazizonoki authored Mar 7, 2024
1 parent 72c6b28 commit 178e11a
Show file tree
Hide file tree
Showing 626 changed files with 4,652 additions and 14,663 deletions.
39 changes: 21 additions & 18 deletions client/iam/common/iam.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ class TGrpcIamCredentialsProvider : public ICredentialsProvider {
}

void UpdateTicket(bool sync = false) {
with_lock(Lock_) {
{
std::lock_guard guard(Lock_);
if (NeedStop_ || RequestInflight_) {
return;
}
Expand Down Expand Up @@ -129,7 +130,8 @@ class TGrpcIamCredentialsProvider : public ICredentialsProvider {
std::string GetTicket() {
TInstant nextTicketUpdate;
std::string ticket;
with_lock(Lock_) {
{
std::lock_guard guard(Lock_);
ticket = Ticket_;
nextTicketUpdate = NextTicketUpdate_;
if (ticket.empty())
Expand All @@ -142,7 +144,8 @@ class TGrpcIamCredentialsProvider : public ICredentialsProvider {
}

void Stop() {
with_lock(Lock_) {
{
std::lock_guard guard(Lock_);
if (NeedStop_) {
return;
}
Expand All @@ -156,8 +159,9 @@ class TGrpcIamCredentialsProvider : public ICredentialsProvider {
void ProcessIamResponse(NYdbGrpc::TGrpcStatus&& status, TResponse&& result, bool sync) {
if (!status.Ok()) {
TDuration sleepDuration;
with_lock(Lock_) {
LastRequestError_ = NUtils::TYdbStringBuilder()
{
std::lock_guard guard(Lock_);
LastRequestError_ = TStringBuilder()
<< "Last request error was at " << TInstant::Now()
<< ". GrpcStatusCode: " << status.GRpcStatusCode
<< " Message: \"" << status.Msg
Expand All @@ -173,19 +177,18 @@ class TGrpcIamCredentialsProvider : public ICredentialsProvider {

UpdateTicket(sync);
} else {
with_lock(Lock_) {
LastRequestError_ = "";
Ticket_ = result.iam_token();
RequestInflight_ = false;
BackoffTimeout_ = BACKOFF_START;

const auto now = Now();
NextTicketUpdate_ = std::min(
now + IamEndpoint_.RefreshPeriod,
TInstant::Seconds(result.expires_at().seconds())
) - IamEndpoint_.RequestTimeout;
NextTicketUpdate_ = std::max(NextTicketUpdate_, now + TDuration::MilliSeconds(100));
}
std::lock_guard guard(Lock_);
LastRequestError_ = "";
Ticket_ = result.iam_token();
RequestInflight_ = false;
BackoffTimeout_ = BACKOFF_START;

const auto now = Now();
NextTicketUpdate_ = std::min(
now + IamEndpoint_.RefreshPeriod,
TInstant::Seconds(result.expires_at().seconds())
) - IamEndpoint_.RequestTimeout;
NextTicketUpdate_ = std::max(NextTicketUpdate_, now + TDuration::MilliSeconds(100));
}
}

Expand Down
6 changes: 3 additions & 3 deletions client/impl/ydb_internal/db_driver_state/endpoint_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ std::pair<NThreading::TFuture<TEndpointUpdateResult>, bool> TEndpointPool::Updat
if (addr.empty()) {
continue;
}
NUtils::TYdbStringBuilder endpointBuilder;
TStringBuilder endpointBuilder;
endpointBuilder << "ipv6:";
if (addr[0] != '[') {
endpointBuilder << "[";
Expand All @@ -94,7 +94,7 @@ std::pair<NThreading::TFuture<TEndpointUpdateResult>, bool> TEndpointPool::Updat
continue;
}
std::string endpointString =
NUtils::TYdbStringBuilder()
TStringBuilder()
<< "ipv4:"
<< addr
<< ":"
Expand All @@ -104,7 +104,7 @@ std::pair<NThreading::TFuture<TEndpointUpdateResult>, bool> TEndpointPool::Updat
}
if (addDefault) {
std::string endpointString =
NUtils::TYdbStringBuilder()
TStringBuilder()
<< endpoint.address()
<< ":"
<< endpoint.port();
Expand Down
6 changes: 3 additions & 3 deletions client/impl/ydb_internal/grpc_connections/grpc_connections.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class TGRpcConnectionsImpl
nullptr,
TPlainStatus(
EStatus::CLIENT_UNAUTHENTICATED,
NUtils::TYdbStringBuilder() << "Can't get Authentication info from CredentialsProvider. " << e.what()
TStringBuilder() << "Can't get Authentication info from CredentialsProvider. " << e.what()
)
);
return;
Expand Down Expand Up @@ -421,7 +421,7 @@ class TGRpcConnectionsImpl
responseCb(
TPlainStatus(
EStatus::CLIENT_UNAUTHENTICATED,
NUtils::TYdbStringBuilder() << "Can't get Authentication info from CredentialsProvider. " << e.what()
TStringBuilder() << "Can't get Authentication info from CredentialsProvider. " << e.what()
),
nullptr
);
Expand Down Expand Up @@ -517,7 +517,7 @@ class TGRpcConnectionsImpl
connectedCallback(
TPlainStatus(
EStatus::CLIENT_UNAUTHENTICATED,
NUtils::TYdbStringBuilder() << "Can't get Authentication info from CredentialsProvider. " << e.what()
TStringBuilder() << "Can't get Authentication info from CredentialsProvider. " << e.what()
),
nullptr
);
Expand Down
34 changes: 15 additions & 19 deletions client/impl/ydb_internal/kqp_session_common/kqp_session_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,20 @@ const TEndpointKey& TKqpSessionCommon::GetEndpointKey() const {

// Can be called from interceptor, need lock
void TKqpSessionCommon::MarkBroken() {
with_lock(Lock_) {
if (State_ == EState::S_ACTIVE) {
NeedUpdateActiveCounter_ = true;
}
State_ = EState::S_BROKEN;
std::lock_guard guard(Lock_);
if (State_ == EState::S_ACTIVE) {
NeedUpdateActiveCounter_ = true;
}
State_ = EState::S_BROKEN;
}

void TKqpSessionCommon::MarkAsClosing() {
with_lock(Lock_) {
if (State_ == EState::S_ACTIVE) {
NeedUpdateActiveCounter_ = true;
}

State_ = EState::S_CLOSING;
std::lock_guard guard(Lock_);
if (State_ == EState::S_ACTIVE) {
NeedUpdateActiveCounter_ = true;
}

State_ = EState::S_CLOSING;
}

void TKqpSessionCommon::MarkActive() {
Expand All @@ -91,9 +89,8 @@ bool TKqpSessionCommon::IsOwnedBySessionPool() const {

TKqpSessionCommon::EState TKqpSessionCommon::GetState() const {
// See comments in InjectSessionStatusInterception about lock
with_lock(Lock_) {
return State_;
}
std::lock_guard guard(const_cast<TAdaptiveLock&>(Lock_));
return State_;
}

void TKqpSessionCommon::SetNeedUpdateActiveCounter(bool flag) {
Expand All @@ -111,12 +108,11 @@ void TKqpSessionCommon::ScheduleTimeToTouch(TDuration interval,
bool updateTimeInPast)
{
auto now = TInstant::Now();
with_lock(Lock_) {
if (updateTimeInPast) {
TimeInPast_ = now;
}
TimeToTouch_ = now + interval;
std::lock_guard guard(Lock_);
if (updateTimeInPast) {
TimeInPast_ = now;
}
TimeToTouch_ = now + interval;
}

void TKqpSessionCommon::ScheduleTimeToTouchFast(TDuration interval,
Expand Down
1 change: 0 additions & 1 deletion client/impl/ydb_internal/logger/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ target_link_libraries(impl-ydb_internal-logger PUBLIC
contrib-libs-cxxsupp
yutil
library-cpp-logger
cpp-string_builder
)

target_sources(impl-ydb_internal-logger PRIVATE
Expand Down
4 changes: 2 additions & 2 deletions client/impl/ydb_internal/logger/log.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#define INCLUDE_YDB_INTERNAL_H
#include "log.h"

#include <library/cpp/string_builder/string_builder.h>
#include <util/string/builder.h>

#include <util/datetime/base.h>
#include <util/string/builder.h>
Expand Down Expand Up @@ -32,7 +32,7 @@ TLogFormatter GetPrefixLogFormatter(const std::string& prefix) {
constexpr size_t endlLen = 1;

const std::string_view priorityString = LogPriorityToString(priority);
NUtils::TYdbStringBuilder result;
TStringBuilder result;
const size_t toReserve = prefix.size() + message.size() + timeLen + endlLen + priorityString.size();
result.reserve(toReserve);

Expand Down
1 change: 0 additions & 1 deletion client/impl/ydb_internal/plain_status/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ target_link_libraries(impl-ydb_internal-plain_status PUBLIC
protobuf::libprotobuf
library-grpc-client
yql-public-issue
cpp-string_builder
)

target_sources(impl-ydb_internal-plain_status PRIVATE
Expand Down
4 changes: 2 additions & 2 deletions client/impl/ydb_internal/plain_status/status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TPlainStatus::TPlainStatus(
if (grpcStatus.InternalError) {
Status = EStatus::CLIENT_INTERNAL_ERROR;
if (!grpcStatus.Msg.empty()) {
msg = NUtils::TYdbStringBuilder() << "Internal client error: " << grpcStatus.Msg;
msg = TStringBuilder() << "Internal client error: " << grpcStatus.Msg;
} else {
msg = "Unknown internal client error";
}
Expand Down Expand Up @@ -49,7 +49,7 @@ TPlainStatus::TPlainStatus(
Status = EStatus::CLIENT_INTERNAL_ERROR;
break;
}
msg = NUtils::TYdbStringBuilder() << "GRpc error: (" << grpcStatus.GRpcStatusCode << "): " << grpcStatus.Msg;
msg = TStringBuilder() << "GRpc error: (" << grpcStatus.GRpcStatusCode << "): " << grpcStatus.Msg;
} else {
Status = EStatus::SUCCESS;
}
Expand Down
4 changes: 2 additions & 2 deletions client/impl/ydb_internal/plain_status/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ struct TPlainStatus {
return TRANSPORT_STATUSES_FIRST <= status && status <= TRANSPORT_STATUSES_LAST;
}

NUtils::TYdbStringBuilder ToDebugString() const {
NUtils::TYdbStringBuilder ret;
TStringBuilder ToDebugString() const {
TStringBuilder ret;
ret << "Status: " << Status;
if(!Ok())
ret << ", Description: " << SubstGlobalCopy(Issues.ToString(), '\n', ' ');
Expand Down
1 change: 0 additions & 1 deletion client/impl/ydb_internal/value_helpers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ target_link_libraries(impl-ydb_internal-value_helpers PUBLIC
yutil
api-protos
client-ydb_types-fatal_error_handlers
cpp-string_builder
)

target_sources(impl-ydb_internal-value_helpers PRIVATE
Expand Down
6 changes: 3 additions & 3 deletions client/impl/ydb_internal/value_helpers/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "helpers.h"
#include <client/ydb_types/fatal_error_handlers/handlers.h>

#include <library/cpp/string_builder/string_builder.h>
#include <util/string/builder.h>

#include <util/string/builder.h>

Expand Down Expand Up @@ -92,7 +92,7 @@ bool TypesEqual(const Ydb::Type& t1, const Ydb::Type& t2) {
}
return true;
default:
ThrowFatalError(NUtils::TYdbStringBuilder() << "Unexpected Variant type case " << static_cast<int>(t1.type_case()));
ThrowFatalError(TStringBuilder() << "Unexpected Variant type case " << static_cast<int>(t1.type_case()));
return false;
}
return false;
Expand All @@ -106,7 +106,7 @@ bool TypesEqual(const Ydb::Type& t1, const Ydb::Type& t2) {
case Ydb::Type::kEmptyDictType:
return true;
default:
ThrowFatalError(NUtils::TYdbStringBuilder() << "Unexpected type case " << static_cast<int>(t1.type_case()));
ThrowFatalError(TStringBuilder() << "Unexpected type case " << static_cast<int>(t1.type_case()));
return false;
}
}
Expand Down
1 change: 0 additions & 1 deletion client/impl/ydb_stats/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ target_link_libraries(client-impl-ydb_stats PUBLIC
yutil
library-grpc-client
cpp-monlib-metrics
cpp-string_builder
)

target_sources(client-impl-ydb_stats PRIVATE
Expand Down
8 changes: 4 additions & 4 deletions client/impl/ydb_stats/stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,16 @@ struct TStatCollector {

void IncSyncRetryOperation(const EStatus& status) {
if (auto registry = MetricRegistry_.Get()) {
std::string statusName = NUtils::TYdbStringBuilder() << status;
std::string sensor = NUtils::TYdbStringBuilder() << "RetryOperation/" << UnderscoreToUpperCamel(statusName);
std::string statusName = TStringBuilder() << status;
std::string sensor = TStringBuilder() << "RetryOperation/" << UnderscoreToUpperCamel(statusName);
registry->Rate({ {"database", Database_}, {"sensor", sensor} })->Inc();
}
}

void IncAsyncRetryOperation(const EStatus& status) {
if (auto registry = MetricRegistry_.Get()) {
std::string statusName = NUtils::TYdbStringBuilder() << status;
std::string sensor = NUtils::TYdbStringBuilder() << "RetryOperation/" << UnderscoreToUpperCamel(statusName);
std::string statusName = TStringBuilder() << status;
std::string sensor = TStringBuilder() << "RetryOperation/" << UnderscoreToUpperCamel(statusName);
registry->Rate({ {"database", Database_}, {"sensor", sensor} })->Inc();
}
}
Expand Down
2 changes: 1 addition & 1 deletion client/resources/ydb_ca.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <util/generic/string.h>
#include <string>

namespace NYdb {

Expand Down
2 changes: 1 addition & 1 deletion client/resources/ydb_resources.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <util/generic/string.h>
#include <string>

namespace NYdb {

Expand Down
Loading

0 comments on commit 178e11a

Please sign in to comment.