Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#41 Replace TMaybe to std::optional after update #81

Merged
merged 7 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions client/draft/ydb_scripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace NScripting {
using namespace NThreading;

TExecuteYqlResult::TExecuteYqlResult(TStatus&& status, std::vector<TResultSet>&& resultSets,
const TMaybe<NTable::TQueryStats>& queryStats)
const std::optional<NTable::TQueryStats>& queryStats)
: TStatus(std::move(status))
, ResultSets_(std::move(resultSets))
, QueryStats_(queryStats) {}
Expand All @@ -36,7 +36,7 @@ TResultSetParser TExecuteYqlResult::GetResultSetParser(size_t resultIndex) const
return TResultSetParser(GetResultSet(resultIndex));
}

const TMaybe<NTable::TQueryStats>& TExecuteYqlResult::GetStats() const {
const std::optional<NTable::TQueryStats>& TExecuteYqlResult::GetStats() const {
return QueryStats_;
}

Expand Down Expand Up @@ -77,7 +77,7 @@ class TYqlResultPartIterator::TReaderImpl {
EStatus clientStatus = static_cast<EStatus>(self->Response_.status());
TPlainStatus plainStatus{ clientStatus, std::move(issues), self->Endpoint_, {} };
TStatus status{ std::move(plainStatus) };
TMaybe<NTable::TQueryStats> queryStats;
std::optional<NTable::TQueryStats> queryStats;

if (self->Response_.result().has_query_stats()) {
queryStats = NTable::TQueryStats(self->Response_.result().query_stats());
Expand Down Expand Up @@ -164,12 +164,12 @@ class TScriptingClient::TImpl : public TClientImplCommon<TScriptingClient::TImpl
auto extractor = [promise]
(google::protobuf::Any* any, TPlainStatus status) mutable {
std::vector<TResultSet> res;
TMaybe<NTable::TQueryStats> queryStats;
std::optional<NTable::TQueryStats> queryStats;
if (any) {
Ydb::Scripting::ExecuteYqlResult result;
any->UnpackTo(&result);

for (size_t i = 0; i < result.result_sets_size(); i++) {
for (size_t i = 0; i < static_cast<size_t>(result.result_sets_size()); i++) {
res.push_back(TResultSet(*result.mutable_result_sets(i)));
}

Expand Down
18 changes: 9 additions & 9 deletions client/draft/ydb_scripting.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ namespace NScripting {
class TExecuteYqlResult : public TStatus {
public:
TExecuteYqlResult(TStatus&& status, std::vector<TResultSet>&& resultSets,
const TMaybe<NTable::TQueryStats>& queryStats);
const std::optional<NTable::TQueryStats>& queryStats);

const std::vector<TResultSet>& GetResultSets() const;
TResultSet GetResultSet(size_t resultIndex) const;

TResultSetParser GetResultSetParser(size_t resultIndex) const;

const TMaybe<NTable::TQueryStats>& GetStats() const;
const std::optional<NTable::TQueryStats>& GetStats() const;

private:
std::vector<TResultSet> ResultSets_;
TMaybe<NTable::TQueryStats> QueryStats_;
std::optional<NTable::TQueryStats> QueryStats_;
};

class TYqlPartialResult {
Expand All @@ -41,31 +41,31 @@ class TYqlPartialResult {

class TYqlResultPart : public TStreamPartStatus {
public:
bool HasPartialResult() const { return PartialResult_.Defined(); }
bool HasPartialResult() const { return PartialResult_.has_value(); }
const TYqlPartialResult& GetPartialResult() const { return *PartialResult_; }

bool HasQueryStats() const { return QueryStats_.Defined(); }
bool HasQueryStats() const { return QueryStats_.has_value(); }
const NTable::TQueryStats& GetQueryStats() const { return *QueryStats_; }
NTable::TQueryStats ExtractQueryStats() { return std::move(*QueryStats_); }

TYqlResultPart(TStatus&& status)
: TStreamPartStatus(std::move(status))
{}

TYqlResultPart(TStatus&& status, const TMaybe<NTable::TQueryStats> &queryStats)
TYqlResultPart(TStatus&& status, const std::optional<NTable::TQueryStats> &queryStats)
: TStreamPartStatus(std::move(status))
, QueryStats_(queryStats)
{}

TYqlResultPart(TStatus&& status, TYqlPartialResult&& partialResult, const TMaybe<NTable::TQueryStats> &queryStats)
TYqlResultPart(TStatus&& status, TYqlPartialResult&& partialResult, const std::optional<NTable::TQueryStats> &queryStats)
: TStreamPartStatus(std::move(status))
, PartialResult_(std::move(partialResult))
, QueryStats_(queryStats)
{}

private:
TMaybe<TYqlPartialResult> PartialResult_;
TMaybe<NTable::TQueryStats> QueryStats_;
std::optional<TYqlPartialResult> PartialResult_;
std::optional<NTable::TQueryStats> QueryStats_;
};

using TAsyncYqlResultPart = NThreading::TFuture<TYqlResultPart>;
Expand Down
20 changes: 10 additions & 10 deletions client/impl/ydb_internal/grpc_connections/grpc_connections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,18 +265,18 @@ void TGRpcConnectionsImpl::ScheduleCallback(
}

TDbDriverStatePtr TGRpcConnectionsImpl::GetDriverState(
const TMaybe<std::string>& database,
const TMaybe<std::string>& discoveryEndpoint,
const TMaybe<EDiscoveryMode>& discoveryMode,
const TMaybe<TSslCredentials>& sslCredentials,
const TMaybe<std::shared_ptr<ICredentialsProviderFactory>>& credentialsProviderFactory
const std::optional<std::string>& database,
const std::optional<std::string>& discoveryEndpoint,
const std::optional<EDiscoveryMode>& discoveryMode,
const std::optional<TSslCredentials>& sslCredentials,
const std::optional<std::shared_ptr<ICredentialsProviderFactory>>& credentialsProviderFactory
) {
return StateTracker_.GetDriverState(
database ? database.GetRef() : DefaultDatabase_,
discoveryEndpoint ? discoveryEndpoint.GetRef() : DefaultDiscoveryEndpoint_,
discoveryMode ? discoveryMode.GetRef() : DefaultDiscoveryMode_,
sslCredentials ? sslCredentials.GetRef() : SslCredentials_,
credentialsProviderFactory ? credentialsProviderFactory.GetRef() : DefaultCredentialsProviderFactory_);
database.value_or(DefaultDatabase_),
discoveryEndpoint.value_or(DefaultDiscoveryEndpoint_),
discoveryMode.value_or(DefaultDiscoveryMode_),
sslCredentials.value_or(SslCredentials_),
credentialsProviderFactory.value_or(DefaultCredentialsProviderFactory_));
}

IQueueClientContextPtr TGRpcConnectionsImpl::CreateContext() {
Expand Down
10 changes: 5 additions & 5 deletions client/impl/ydb_internal/grpc_connections/grpc_connections.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ class TGRpcConnectionsImpl
// This method returns DbDriverState (or just db state) for given database credentials pair
// this state is used to keep data related to particular database.
TDbDriverStatePtr GetDriverState(
const TMaybe<std::string>& database,
const TMaybe<std::string>& discoveryEndpoint,
const TMaybe<EDiscoveryMode>& discoveryMode,
const TMaybe<TSslCredentials>& sslCredentials,
const TMaybe<std::shared_ptr<ICredentialsProviderFactory>>& credentialsProviderFactory
const std::optional<std::string>& database,
const std::optional<std::string>& discoveryEndpoint,
const std::optional<EDiscoveryMode>& discoveryMode,
const std::optional<TSslCredentials>& sslCredentials,
const std::optional<std::shared_ptr<ICredentialsProviderFactory>>& credentialsProviderFactory
);
IQueueClientContextPtr CreateContext() override;
bool TryCreateContext(IQueueClientContextPtr& context);
Expand Down
1 change: 0 additions & 1 deletion client/impl/ydb_internal/retry/retry.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <library/cpp/threading/future/core/fwd.h>
#include <util/datetime/base.h>
#include <util/datetime/cputimer.h>
#include <util/generic/maybe.h>
#include <util/generic/ptr.h>
#include <util/system/types.h>

Expand Down
8 changes: 4 additions & 4 deletions client/impl/ydb_internal/retry/retry_async.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class TRetryWithSession : public TRetryContext<TClient, TAsyncStatusType> {

private:
TOperation Operation_;
TMaybe<TSession> Session_;
std::optional<TSession> Session_;

public:
explicit TRetryWithSession(
Expand Down Expand Up @@ -158,14 +158,14 @@ class TRetryWithSession : public TRetryContext<TClient, TAsyncStatusType> {

private:
void Reset() override {
Session_.Clear();
Session_.reset();
}

TAsyncStatusType RunOperation() override {
if constexpr (TFunctionArgs<TOperation>::Length == 1) {
return Operation_(this->Session_.GetRef());
return Operation_(this->Session_.value());
} else {
return Operation_(this->Session_.GetRef(), this->GetRemainingTimeout());
return Operation_(this->Session_.value(), this->GetRemainingTimeout());
}
}
};
Expand Down
12 changes: 5 additions & 7 deletions client/impl/ydb_internal/retry/retry_sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include <client/ydb_retry/retry.h>
#include <client/ydb_types/status/status.h>

#include <util/generic/maybe.h>

namespace NYdb::NRetry::Sync {

template <typename TClient, typename TStatusType>
Expand Down Expand Up @@ -89,7 +87,7 @@ class TRetryWithSession : public TRetryContext<TClient, TStatusType> {

private:
const TOperation& Operation_;
TMaybe<TSession> Session_;
std::optional<TSession> Session_;

public:
TRetryWithSession(TClient& client, const TOperation& operation, const TRetryOperationSettings& settings)
Expand All @@ -99,7 +97,7 @@ class TRetryWithSession : public TRetryContext<TClient, TStatusType> {

protected:
TStatusType Retry() override {
TMaybe<TStatusType> status;
std::optional<TStatusType> status;

if (!Session_) {
auto settings = TCreateSessionSettings().ClientTimeout(this->Settings_.GetSessionClientTimeout_);
Expand All @@ -119,14 +117,14 @@ class TRetryWithSession : public TRetryContext<TClient, TStatusType> {

TStatusType RunOperation() override {
if constexpr (TFunctionArgs<TOperation>::Length == 1) {
return Operation_(this->Session_.GetRef());
return Operation_(this->Session_.value());
} else {
return Operation_(this->Session_.GetRef(), this->GetRemainingTimeout());
return Operation_(this->Session_.value(), this->GetRemainingTimeout());
}
}

void Reset() override {
Session_.Clear();
Session_.reset();
}
};

Expand Down
4 changes: 2 additions & 2 deletions client/impl/ydb_internal/table_helpers/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace NYdb {

inline Ydb::Table::QueryStatsCollection::Mode GetStatsCollectionMode(TMaybe<NTable::ECollectQueryStatsMode> mode) {
if (mode) {
inline Ydb::Table::QueryStatsCollection::Mode GetStatsCollectionMode(std::optional<NTable::ECollectQueryStatsMode> mode) {
if (mode.has_value()) {
switch (*mode) {
case NTable::ECollectQueryStatsMode::None:
return Ydb::Table::QueryStatsCollection::STATS_COLLECTION_NONE;
Expand Down
10 changes: 5 additions & 5 deletions client/ydb_common_client/impl/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class TClientImplCommon
public:
TClientImplCommon(
std::shared_ptr<TGRpcConnectionsImpl>&& connections,
const TMaybe<std::string>& database,
const TMaybe<std::string>& discoveryEndpoint,
const TMaybe<EDiscoveryMode>& discoveryMode,
const TMaybe<TSslCredentials>& sslCredentials,
const TMaybe<std::shared_ptr<ICredentialsProviderFactory>>& credentialsProviderFactory)
const std::optional<std::string>& database,
const std::optional<std::string>& discoveryEndpoint,
const std::optional<EDiscoveryMode>& discoveryMode,
const std::optional<TSslCredentials>& sslCredentials,
const std::optional<std::shared_ptr<ICredentialsProviderFactory>>& credentialsProviderFactory)
: Connections_(std::move(connections))
, DbDriverState_(Connections_->GetDriverState(
database, discoveryEndpoint, discoveryMode, sslCredentials, credentialsProviderFactory))
Expand Down
4 changes: 2 additions & 2 deletions client/ydb_common_client/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace NYdb {

TCommonClientSettings& TCommonClientSettings::AuthToken(const TMaybe<std::string>& token) {
return CredentialsProviderFactory(CreateOAuthCredentialsProviderFactory(token.GetRef()));
TCommonClientSettings& TCommonClientSettings::AuthToken(const std::optional<std::string>& token) {
return CredentialsProviderFactory(CreateOAuthCredentialsProviderFactory(token.value()));
}

TCommonClientSettings GetClientSettingsFromConnectionString(const std::string& connectionString) {
Expand Down
4 changes: 2 additions & 2 deletions client/ydb_common_client/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct TCommonClientSettings {
//! Allows to override current discovery endpoint
FLUENT_SETTING_OPTIONAL(std::string, DiscoveryEndpoint);
//! Allows to override current token for client
TSelf& AuthToken(const TMaybe<std::string>& token);
TSelf& AuthToken(const std::optional<std::string>& token);
//! Allows to override current credentials provider
FLUENT_SETTING_OPTIONAL(std::shared_ptr<ICredentialsProviderFactory>, CredentialsProviderFactory);
//! Allows to override discovery mode
Expand All @@ -46,7 +46,7 @@ struct TCommonClientSettingsBase : public TCommonClientSettings {

COMMON_CLIENT_SETTINGS_TO_DERIVED(std::string, Database);
COMMON_CLIENT_SETTINGS_TO_DERIVED(std::string, DiscoveryEndpoint);
COMMON_CLIENT_SETTINGS_TO_DERIVED(TMaybe<std::string>, AuthToken);
COMMON_CLIENT_SETTINGS_TO_DERIVED(std::optional<std::string>, AuthToken);
COMMON_CLIENT_SETTINGS_TO_DERIVED(std::shared_ptr<ICredentialsProviderFactory>, CredentialsProviderFactory);
COMMON_CLIENT_SETTINGS_TO_DERIVED(EDiscoveryMode, DiscoveryMode);
COMMON_CLIENT_SETTINGS_TO_DERIVED(TSslCredentials, SslCredentials);
Expand Down
12 changes: 6 additions & 6 deletions client/ydb_coordination/coordination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ struct TNodeDescription::TImpl {
Proto_ = desc;
}

TMaybe<TDuration> SelfCheckPeriod_;
TMaybe<TDuration> SessionGracePeriod_;
std::optional<TDuration> SelfCheckPeriod_;
std::optional<TDuration> SessionGracePeriod_;
EConsistencyMode ReadConsistencyMode_;
EConsistencyMode AttachConsistencyMode_;
ERateLimiterCountersMode RateLimiterCountersMode_;
Expand All @@ -102,11 +102,11 @@ TNodeDescription::TNodeDescription(
: Impl_(new TImpl(desc))
{ }

const TMaybe<TDuration>& TNodeDescription::GetSelfCheckPeriod() const {
const std::optional<TDuration>& TNodeDescription::GetSelfCheckPeriod() const {
return Impl_->SelfCheckPeriod_;
}

const TMaybe<TDuration>& TNodeDescription::GetSessionGracePeriod() const {
const std::optional<TDuration>& TNodeDescription::GetSessionGracePeriod() const {
return Impl_->SessionGracePeriod_;
}

Expand Down Expand Up @@ -733,7 +733,7 @@ class TSessionContext : public TThrRefBase {
Y_ABORT_UNLESS(ConnectionState == EConnectionState::ATTACHING);
SessionState = ESessionState::ATTACHED;
ConnectionState = EConnectionState::CONNECTED;
SessionExpireDeadline.Clear();
SessionExpireDeadline.reset();
SessionReconnectDelay = TDuration::Zero();
if (ClosedPromise.Initialized()) {
// Send the delayed close request, will fail if cancelled
Expand Down Expand Up @@ -1777,7 +1777,7 @@ class TSessionContext : public TThrRefBase {

// Reconnection uses sleep between attempts
IQueueClientContextPtr SleepContext;
TMaybe<TInstant> SessionExpireDeadline;
std::optional<TInstant> SessionExpireDeadline;
TDuration SessionReconnectDelay = TDuration::Zero();

IProcessor::TPtr Processor;
Expand Down
6 changes: 2 additions & 4 deletions client/ydb_coordination/coordination.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#include <client/ydb_driver/driver.h>

#include <util/generic/maybe.h>

namespace Ydb {
namespace Coordination {
class DescribeNodeResult;
Expand Down Expand Up @@ -99,8 +97,8 @@ class TNodeDescription {
public:
TNodeDescription(const Ydb::Coordination::DescribeNodeResult& desc);

const TMaybe<TDuration>& GetSelfCheckPeriod() const;
const TMaybe<TDuration>& GetSessionGracePeriod() const;
const std::optional<TDuration>& GetSelfCheckPeriod() const;
const std::optional<TDuration>& GetSessionGracePeriod() const;
EConsistencyMode GetReadConsistencyMode() const;
EConsistencyMode GetAttachConsistencyMode() const;
ERateLimiterCountersMode GetRateLimiterCountersMode() const;
Expand Down
Loading
Loading