Skip to content

Commit 39b3548

Browse files
Gazizonokigithub-actions[bot]
authored andcommitted
[C++ SDK] Added PreferPrimaryPile balancing policy (#24283)
1 parent 25785fa commit 39b3548

File tree

93 files changed

+389
-212
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+389
-212
lines changed

.github/last_commit.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
730ae3fcb84a9a6b29a233c52ee6c519cac1e144
1+
110937321b45fb3be9ca39ff3bb83bcdfcf52c97

include/ydb-cpp-sdk/client/discovery/discovery.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,7 @@ struct TEndpointInfo {
6666
};
6767

6868
struct TPileState {
69-
enum EState {
70-
UNSPECIFIED = 0 /* "unspecified" */,
71-
PRIMARY = 1 /* "primary" */,
72-
PROMOTED = 2 /* "promoted" */,
73-
SYNCHRONIZED = 3 /* "synchronized" */,
74-
NOT_SYNCHRONIZED = 4 /* "not_synchronized" */,
75-
SUSPENDED = 5 /* "suspended" */,
76-
DISCONNECTED = 6 /* "disconnected" */
77-
};
69+
using EState = NYdb::EPileState;
7870

7971
EState State;
8072
std::string PileName;

include/ydb-cpp-sdk/client/driver/driver.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,20 @@ class TDriverConfig {
2626
//! where "<protocol>://" can be "grpc://" or "grpcs://" or be absent, "<hostname:port>" is endpoint,
2727
//! "/?database=<database-path>" is optional
2828
TDriverConfig(const std::string& connectionString = "");
29+
2930
//! Endpoint to initiate connections with Ydb cluster,
3031
//! client will connect to others nodes according to client loadbalancing
3132
TDriverConfig& SetEndpoint(const std::string& endpoint);
33+
3234
//! Set number of network threads, default: 2
3335
TDriverConfig& SetNetworkThreadsNum(size_t sz);
36+
3437
//! Set number of client pool threads, if 0 adaptive thread pool will be used.
3538
//! NOTE: in case of no zero value it is possible to get deadlock if all threads
3639
//! of this pool is blocked somewhere in user code.
3740
//! default: 0
3841
TDriverConfig& SetClientThreadsNum(size_t sz);
42+
3943
//! Warning: not recommended to change
4044
//! Set max number of queued responses. 0 - no limit
4145
//! There is a queue to perform async calls to user code,
@@ -46,29 +50,37 @@ class TDriverConfig {
4650
//! This value doesn't make sense if SetClientThreadsNum is 0
4751
//! default: 0
4852
TDriverConfig& SetMaxClientQueueSize(size_t sz);
53+
4954
//! Enable Ssl.
5055
//! caCerts - The buffer containing the PEM encoded root certificates for SSL/TLS connections.
5156
//! If this parameter is empty, the default roots will be used.
5257
TDriverConfig& UseSecureConnection(const std::string& caCerts = std::string());
5358
TDriverConfig& SetUsePerChannelTcpConnection(bool usePerChannel);
5459
TDriverConfig& UseClientCertificate(const std::string& clientCert, const std::string& clientPrivateKey);
60+
5561
//! Set token, this option can be overridden for client by ClientSettings
5662
TDriverConfig& SetAuthToken(const std::string& token);
63+
5764
//! Set database, this option can be overridden for client by ClientSettings
5865
TDriverConfig& SetDatabase(const std::string& database);
66+
5967
//! Set credentials data, this option can be overridden for client by ClientSettings
6068
TDriverConfig& SetCredentialsProviderFactory(std::shared_ptr<ICredentialsProviderFactory> credentialsProviderFactory);
69+
6170
//! Set behaviour of discovery routine
6271
//! See EDiscoveryMode enum comments
6372
//! default: EDiscoveryMode::Sync
6473
TDriverConfig& SetDiscoveryMode(EDiscoveryMode discoveryMode);
74+
6575
//! Max number of requests in queue waiting for discovery if "Async" mode chosen
6676
//! default: 100
6777
TDriverConfig& SetMaxQueuedRequests(size_t sz);
78+
6879
//! Limit using of memory for grpc buffer pool. 0 means disabled.
6980
//! If enabled the size must be greater than size of recieved message.
7081
//! default: 0
7182
TDriverConfig& SetGrpcMemoryQuota(uint64_t bytes);
83+
7284
//! Specify tcp keep alive settings
7385
//! This option allows to adjust tcp keep alive settings, useful to work
7486
//! with balancers or to detect unexpected connectivity problem.
@@ -83,12 +95,20 @@ class TDriverConfig {
8395
//! NOTE: Please read OS documentation and investigate your network topology before touching this option.
8496
//! default: true, 30, 5, 10 for linux, and true and OS default for others POSIX
8597
TDriverConfig& SetTcpKeepAliveSettings(bool enable, size_t idle, size_t count, size_t interval);
98+
8699
//! Enable or disable drain of client logic (e.g. session pool drain) during dtor call
87100
TDriverConfig& SetDrainOnDtors(bool allowed);
101+
102+
//! Set policy for balancing
103+
//! default: TBalancingPolicy::UsePreferableLocation()
104+
TDriverConfig& SetBalancingPolicy(TBalancingPolicy&& policy);
105+
106+
//! DEPRECATED
88107
//! Set policy for balancing
89108
//! Params is a optionally field to set policy settings
90109
//! default: EBalancingPolicy::UsePreferableLocation
91110
TDriverConfig& SetBalancingPolicy(EBalancingPolicy policy, const std::string& params = std::string());
111+
92112
//! Set grpc level keep alive. If keepalive ping was delayed more than given timeout
93113
//! internal grpc routine fails request with TRANSIENT_FAILURE or TRANSPORT_UNAVAILABLE error
94114
//! Note: this timeout should not be too small to prevent fail due to
@@ -97,6 +117,7 @@ class TDriverConfig {
97117
//! default: enabled, 10 seconds
98118
TDriverConfig& SetGRpcKeepAliveTimeout(TDuration timeout);
99119
TDriverConfig& SetGRpcKeepAlivePermitWithoutCalls(bool permitWithoutCalls);
120+
100121
//! Set inactive socket timeout.
101122
//! Used to close connections, that were inactive for given time.
102123
//! Closes unused connections every 1/10 of timeout, so deletion time is approximate.
@@ -107,11 +128,14 @@ class TDriverConfig {
107128
//! Set maximum incoming message size.
108129
//! Note: this option overrides MaxMessageSize for incoming messages.
109130
//! default: 0
131+
110132
TDriverConfig& SetMaxInboundMessageSize(uint64_t maxInboundMessageSize);
133+
111134
//! Set maximum outgoing message size.
112135
//! Note: this option overrides MaxMessageSize for outgoing messages.
113136
//! default: 0
114137
TDriverConfig& SetMaxOutboundMessageSize(uint64_t maxOutboundMessageSize);
138+
115139
//! Note: if this option is unset, default 64_MB message size will be used.
116140
//! default: 0
117141
TDriverConfig& SetMaxMessageSize(uint64_t maxMessageSize);

include/ydb-cpp-sdk/client/types/ydb.h

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#include "fwd.h"
44
#include "status_codes.h"
55

6+
#include <memory>
7+
#include <string>
8+
9+
610
namespace NYdb::inline V3 {
711

812
enum class EDiscoveryMode {
@@ -22,12 +26,47 @@ enum class EDiscoveryMode {
2226
Off
2327
};
2428

29+
//! @deprecated Use TBalancingPolicy instead
2530
enum class EBalancingPolicy {
2631
//! Use all available cluster nodes regardless datacenter locality
2732
UseAllNodes,
2833
//! Use preferable location,
2934
//! params is a name of location (VLA, MAN), if params is empty local datacenter is used
30-
UsePreferableLocation
35+
UsePreferableLocation,
36+
};
37+
38+
enum EPileState {
39+
UNSPECIFIED = 0 /* "unspecified" */,
40+
PRIMARY = 1 /* "primary" */,
41+
PROMOTED = 2 /* "promoted" */,
42+
SYNCHRONIZED = 3 /* "synchronized" */,
43+
NOT_SYNCHRONIZED = 4 /* "not_synchronized" */,
44+
SUSPENDED = 5 /* "suspended" */,
45+
DISCONNECTED = 6 /* "disconnected" */
46+
};
47+
48+
class TBalancingPolicy {
49+
friend class TDriverConfig;
50+
friend class TDriver;
51+
public:
52+
//! Use preferable location,
53+
//! location is a name of datacenter (VLA, MAN), if location is empty local datacenter is used
54+
static TBalancingPolicy UsePreferableLocation(const std::string& location = {});
55+
56+
//! Use all available cluster nodes regardless datacenter locality
57+
static TBalancingPolicy UseAllNodes();
58+
59+
//! EXPERIMENTAL
60+
//! Use pile with preferable state
61+
static TBalancingPolicy UsePreferablePileState(EPileState pileState = EPileState::PRIMARY);
62+
63+
class TImpl;
64+
private:
65+
TBalancingPolicy(std::unique_ptr<TImpl>&& impl);
66+
67+
TBalancingPolicy(EBalancingPolicy policy, const std::string& params);
68+
69+
std::unique_ptr<TImpl> Impl_;
3170
};
3271

3372
} // namespace NYdb

src/client/common_client/impl/client.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "iface.h"
44

55
#define INCLUDE_YDB_INTERNAL_H
6-
#include <src/client/impl/ydb_internal/grpc_connections/grpc_connections.h>
6+
#include <src/client/impl/internal/grpc_connections/grpc_connections.h>
77
#undef INCLUDE_YDB_INTERNAL_H
88

99
#include <ydb-cpp-sdk/client/types/exceptions/exceptions.h>

src/client/common_client/settings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <ydb-cpp-sdk/client/common_client/settings.h>
22

3-
#include <src/client/impl/ydb_internal/common/parser.h>
3+
#include <src/client/impl/internal/common/parser.h>
44

55
namespace NYdb::inline V3 {
66

src/client/coordination/coordination.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include <ydb-cpp-sdk/client/coordination/coordination.h>
22

33
#define INCLUDE_YDB_INTERNAL_H
4-
#include <src/client/impl/ydb_internal/make_request/make.h>
5-
#include <src/client/impl/ydb_internal/scheme_helpers/helpers.h>
4+
#include <src/client/impl/internal/make_request/make.h>
5+
#include <src/client/impl/internal/scheme_helpers/helpers.h>
66
#undef INCLUDE_YDB_INTERNAL_H
77

88
#include <src/api/grpc/ydb_coordination_v1.grpc.pb.h>

src/client/datastreams/datastreams.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <ydb-cpp-sdk/client/datastreams/datastreams.h>
22

33
#define INCLUDE_YDB_INTERNAL_H
4-
#include <src/client/impl/ydb_internal/make_request/make.h>
4+
#include <src/client/impl/internal/make_request/make.h>
55
#undef INCLUDE_YDB_INTERNAL_H
66

77
#include <ydb-cpp-sdk/library/issue/yql_issue.h>

src/client/driver/driver.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#include <ydb-cpp-sdk/client/driver/driver.h>
22

33
#define INCLUDE_YDB_INTERNAL_H
4-
#include <src/client/impl/ydb_internal/driver/constants.h>
5-
#include <src/client/impl/ydb_internal/grpc_connections/grpc_connections.h>
6-
#include <src/client/impl/ydb_internal/logger/log.h>
4+
#include <src/client/impl/internal/driver/constants.h>
5+
#include <src/client/impl/internal/grpc_connections/grpc_connections.h>
6+
#include <src/client/impl/internal/logger/log.h>
77
#undef INCLUDE_YDB_INTERNAL_H
88

99
#include <library/cpp/logger/log.h>
10-
#include <src/client/impl/ydb_internal/common/parser.h>
11-
#include <src/client/impl/ydb_internal/common/getenv.h>
10+
#include <src/client/impl/internal/common/parser.h>
11+
#include <src/client/impl/internal/common/getenv.h>
1212
#include <ydb-cpp-sdk/client/common_client/ssl_credentials.h>
1313
#include <util/stream/file.h>
1414
#include <ydb-cpp-sdk/client/resources/ydb_ca.h>
@@ -41,7 +41,7 @@ class TDriverConfig::TImpl : public IConnectionsParams {
4141
size_t GetMaxQueuedRequests() const override { return MaxQueuedRequests; }
4242
TTcpKeepAliveSettings GetTcpKeepAliveSettings() const override { return TcpKeepAliveSettings; }
4343
bool GetDrinOnDtors() const override { return DrainOnDtors; }
44-
TBalancingSettings GetBalancingSettings() const override { return BalancingSettings; }
44+
TBalancingPolicy::TImpl GetBalancingSettings() const override { return BalancingSettings; }
4545
TDuration GetGRpcKeepAliveTimeout() const override { return GRpcKeepAliveTimeout; }
4646
bool GetGRpcKeepAlivePermitWithoutCalls() const override { return GRpcKeepAlivePermitWithoutCalls; }
4747
TDuration GetSocketIdleTimeout() const override { return SocketIdleTimeout; }
@@ -69,7 +69,7 @@ class TDriverConfig::TImpl : public IConnectionsParams {
6969
TCP_KEEPALIVE_INTERVAL
7070
};
7171
bool DrainOnDtors = true;
72-
TBalancingSettings BalancingSettings = TBalancingSettings{EBalancingPolicy::UsePreferableLocation, std::string()};
72+
TBalancingPolicy::TImpl BalancingSettings = TBalancingPolicy::TImpl("");
7373
TDuration GRpcKeepAliveTimeout = TDuration::Seconds(10);
7474
bool GRpcKeepAlivePermitWithoutCalls = true;
7575
TDuration SocketIdleTimeout = TDuration::Minutes(6);
@@ -170,11 +170,15 @@ TDriverConfig& TDriverConfig::SetDrainOnDtors(bool allowed) {
170170
return *this;
171171
}
172172

173-
TDriverConfig& TDriverConfig::SetBalancingPolicy(EBalancingPolicy policy, const std::string& params) {
174-
Impl_->BalancingSettings = TBalancingSettings{policy, params};
173+
TDriverConfig& TDriverConfig::SetBalancingPolicy(TBalancingPolicy&& policy) {
174+
Impl_->BalancingSettings = std::move(*policy.Impl_);
175175
return *this;
176176
}
177177

178+
TDriverConfig& TDriverConfig::SetBalancingPolicy(EBalancingPolicy policy, const std::string& params) {
179+
return SetBalancingPolicy(TBalancingPolicy(policy, params));
180+
}
181+
178182
TDriverConfig& TDriverConfig::SetGRpcKeepAliveTimeout(TDuration timeout) {
179183
Impl_->GRpcKeepAliveTimeout = timeout;
180184
return *this;
@@ -253,7 +257,7 @@ TDriverConfig TDriver::GetConfig() const {
253257
Impl_->TcpKeepAliveSettings_.Interval
254258
);
255259
config.SetDrainOnDtors(Impl_->DrainOnDtors_);
256-
config.SetBalancingPolicy(Impl_->BalancingSettings_.Policy, Impl_->BalancingSettings_.PolicyParams);
260+
config.SetBalancingPolicy(std::make_unique<TBalancingPolicy::TImpl>(Impl_->BalancingSettings_));
257261
config.SetGRpcKeepAliveTimeout(Impl_->GRpcKeepAliveTimeout_);
258262
config.SetGRpcKeepAlivePermitWithoutCalls(Impl_->GRpcKeepAlivePermitWithoutCalls_);
259263
config.SetSocketIdleTimeout(Impl_->SocketIdleTimeout_);

src/client/export/export.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <ydb-cpp-sdk/client/export/export.h>
22

33
#define INCLUDE_YDB_INTERNAL_H
4-
#include <src/client/impl/ydb_internal/make_request/make.h>
4+
#include <src/client/impl/internal/make_request/make.h>
55
#undef INCLUDE_YDB_INTERNAL_H
66

77
#include <src/api/grpc/ydb_discovery_v1.grpc.pb.h>

0 commit comments

Comments
 (0)