Skip to content

Commit 833d136

Browse files
authored
add pgport to command line args and to port allocator (#7528)
1 parent 5a68445 commit 833d136

File tree

5 files changed

+35
-17
lines changed

5 files changed

+35
-17
lines changed

ydb/core/config/init/init_impl.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ struct TCommonAppOptions {
315315
TString GRpcPublicHost = "";
316316
ui32 GRpcPublicPort = 0;
317317
ui32 GRpcsPublicPort = 0;
318+
TString PGWireAddress = "";
319+
ui32 PGWirePort = 0;
318320
TVector<TString> GRpcPublicAddressesV4;
319321
TVector<TString> GRpcPublicAddressesV6;
320322
TString GRpcPublicTargetNameOverride = "";
@@ -326,7 +328,7 @@ struct TCommonAppOptions {
326328
bool SysLogEnabled = false;
327329
bool TcpEnabled = false;
328330
bool SuppressVersionCheck = false;
329-
EWorkload Workload = EWorkload::Hybrid;
331+
EWorkload Workload = EWorkload::Hybrid;
330332

331333
void RegisterCliOptions(NLastGetopt::TOpts& opts) {
332334
opts.AddLongOption("cluster-name", "which cluster this node belongs to")
@@ -383,6 +385,8 @@ struct TCommonAppOptions {
383385
opts.AddLongOption("grpc-public-host", "set public gRPC host for discovery").RequiredArgument("HOST").StoreResult(&GRpcPublicHost);
384386
opts.AddLongOption("grpc-public-port", "set public gRPC port for discovery").RequiredArgument("PORT").StoreResult(&GRpcPublicPort);
385387
opts.AddLongOption("grpcs-public-port", "set public gRPC SSL port for discovery").RequiredArgument("PORT").StoreResult(&GRpcsPublicPort);
388+
opts.AddLongOption("pgwire-address", "set host for listen postgres protocol").RequiredArgument("ADDR").StoreResult(&PGWireAddress);
389+
opts.AddLongOption("pgwire-port", "set port for listen postgres protocol").OptionalArgument("PORT").StoreResult(&PGWirePort);
386390
opts.AddLongOption("grpc-public-address-v4", "set public ipv4 address for discovery").RequiredArgument("ADDR").EmplaceTo(&GRpcPublicAddressesV4);
387391
opts.AddLongOption("grpc-public-address-v6", "set public ipv6 address for discovery").RequiredArgument("ADDR").EmplaceTo(&GRpcPublicAddressesV6);
388392
opts.AddLongOption("grpc-public-target-name-override", "set public hostname override for TLS in discovery").RequiredArgument("HOST").StoreResult(&GRpcPublicTargetNameOverride);
@@ -496,7 +500,7 @@ struct TCommonAppOptions {
496500
if (offset) {
497501
connectorConfig.MutableEndpoint()->Setport(InterconnectPort + offset) ;
498502

499-
// Assign default hostname 'localhost', because
503+
// Assign default hostname 'localhost', because
500504
// connector is usually deployed to the same host as the dynamic node.
501505
if (connectorConfig.GetEndpoint().host().Empty()) {
502506
connectorConfig.MutableEndpoint()->Sethost("localhost");
@@ -597,6 +601,12 @@ struct TCommonAppOptions {
597601
}
598602
ConfigUpdateTracer.AddUpdate(NKikimrConsole::TConfigItem::GRpcConfigItem, TConfigItemInfo::EUpdateKind::UpdateExplicitly);
599603
}
604+
if (PGWireAddress) {
605+
appConfig.MutableLocalPgWireConfig()->SetAddress(PGWireAddress);
606+
}
607+
if (PGWirePort) {
608+
appConfig.MutableLocalPgWireConfig()->SetListeningPort(PGWirePort);
609+
}
600610
for (const auto& addr : GRpcPublicAddressesV4) {
601611
appConfig.MutableGRpcConfig()->AddPublicAddressesV4(addr);
602612
}
@@ -658,7 +668,7 @@ struct TCommonAppOptions {
658668
ApplyDontStartGrpcProxy(*appConfig.MutableGRpcConfig(), ConfigUpdateTracer);
659669
break;
660670
case EWorkload::Hybrid:
661-
// default, do nothing
671+
// default, do nothing
662672
break;
663673
}
664674
}

ydb/tests/functional/postgresql/test_postgres.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ def execute_binary(binary_name, cmd, stdin_string=None):
5959
class BasePostgresTest(object):
6060
@classmethod
6161
def setup_class(cls):
62-
cls.pm = yatest.common.network.PortManager()
63-
cls.pgport = cls.pm.get_port()
6462
cls.cluster = kikimr_cluster_factory(KikimrConfigGenerator(
6563
additional_log_configs={
6664
'LOCAL_PGWIRE': LogLevels.DEBUG,
@@ -70,14 +68,14 @@ def setup_class(cls):
7068
'KQP_PROXY': LogLevels.DEBUG
7169
},
7270
extra_feature_flags=['enable_table_pg_types', 'enable_temp_tables'],
73-
pgwire_port=cls.pgport
7471
))
7572
cls.cluster.start()
7673

74+
cls.pgport = cls.cluster.nodes[1].pgwire_port
75+
7776
@classmethod
7877
def teardown_class(cls):
7978
cls.cluster.stop()
80-
cls.pm.release()
8179

8280

8381
class TestPostgresSuite(BasePostgresTest):

ydb/tests/library/harness/kikimr_config.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ def __init__(
165165
default_user_sid=None,
166166
pg_compatible_expirement=False,
167167
generic_connector_config=None, # typing.Optional[TGenericConnectorConfig]
168-
pgwire_port=None,
169168
):
170169
if extra_feature_flags is None:
171170
extra_feature_flags = []
@@ -262,10 +261,6 @@ def __init__(
262261
self.yaml_config["local_pg_wire_config"] = {}
263262
self.yaml_config["local_pg_wire_config"]["listening_port"] = os.getenv('PGWIRE_LISTENING_PORT')
264263

265-
if pgwire_port:
266-
self.yaml_config["local_pg_wire_config"] = {}
267-
self.yaml_config["local_pg_wire_config"]["listening_port"] = pgwire_port
268-
269264
if disable_iterator_reads:
270265
self.yaml_config["table_service_config"]["enable_kqp_scan_query_source_read"] = False
271266

@@ -400,10 +395,8 @@ def __init__(
400395
if not "local_pg_wire_config" in self.yaml_config:
401396
self.yaml_config["local_pg_wire_config"] = {}
402397

403-
ydb_pg_port=5432
404-
if 'YDB_PG_PORT' in os.environ:
405-
ydb_pg_port = os.environ['YDB_PG_PORT']
406-
self.yaml_config['local_pg_wire_config']['listening_port'] = ydb_pg_port
398+
ydb_pgwire_port=self.port_allocator.get_node_port_allocator(node_id).pgwire_port
399+
self.yaml_config['local_pg_wire_config']['listening_port'] = ydb_pgwire_port
407400

408401
# https://github.com/ydb-platform/ydb/issues/5152
409402
# self.yaml_config["table_service_config"]["enable_pg_consts_to_params"] = True

ydb/tests/library/harness/kikimr_port_allocator.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def __init__(self, port_manager):
8484
self.__grpc_ssl_port = None
8585
self.__ext_port = None
8686
self.__public_http_port = None
87+
self.__pgwire_port = None
8788

8889
@property
8990
def mon_port(self):
@@ -127,6 +128,12 @@ def ext_port(self):
127128
self.__ext_port = self.__port_manager.get_port()
128129
return self.__ext_port
129130

131+
@property
132+
def pgwire_port(self):
133+
if self.__pgwire_port is None:
134+
self.__pgwire_port = self.__port_manager.get_port()
135+
return self.__pgwire_port
136+
130137
@property
131138
def public_http_port(self):
132139
if self.__public_http_port is None:
@@ -162,7 +169,7 @@ def release_ports(self):
162169
class KikimrFixedNodePortAllocator(KikimrNodePortAllocatorInterface):
163170

164171
def __init__(self, base_port_offset, mon_port=8765, grpc_port=2135, mbus_port=2134, ic_port=19001, sqs_port=8771, grpc_ssl_port=2137,
165-
ext_port=2237, public_http_port=8766):
172+
ext_port=2237, public_http_port=8766, pgwire_port=5432):
166173
super(KikimrFixedNodePortAllocator, self).__init__()
167174

168175
self.base_port_offset = base_port_offset
@@ -192,6 +199,10 @@ def __init__(self, base_port_offset, mon_port=8765, grpc_port=2135, mbus_port=21
192199
self.__public_http_port = int(os.getenv('PUBLIC_HTTP_PORT'))
193200
else:
194201
self.__public_http_port = public_http_port
202+
if os.getenv('YDB_PGWIRE_PORT') is not None:
203+
self.__pgwire_port = int(os.getenv('YDB_PGWIRE_PORT'))
204+
else:
205+
self.__pgwire_port = pgwire_port
195206

196207
@property
197208
def mon_port(self):
@@ -224,6 +235,10 @@ def ext_port(self):
224235
def public_http_port(self):
225236
return self.__public_http_port + self.base_port_offset
226237

238+
@property
239+
def pgwire_port(self):
240+
return self.__pgwire_port + self.base_port_offset
241+
227242

228243
class KikimrFixedPortAllocator(KikimrPortAllocatorInterface):
229244
def __init__(self,

ydb/tests/library/harness/kikimr_runner.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def __init__(self, node_id, config_path, port_allocator, cluster_name, configura
6868
self.mon_port = port_allocator.mon_port
6969
self.ic_port = port_allocator.ic_port
7070
self.grpc_ssl_port = port_allocator.grpc_ssl_port
71+
self.pgwire_port = port_allocator.pgwire_port
7172
self.sqs_port = None
7273
if configurator.sqs_service_enabled:
7374
self.sqs_port = port_allocator.sqs_port
@@ -177,6 +178,7 @@ def __make_run_command(self):
177178
"--grpc-port=%s" % self.grpc_port,
178179
"--mon-port=%d" % self.mon_port,
179180
"--ic-port=%d" % self.ic_port,
181+
"--pgwire-port=%d" % self.pgwire_port,
180182
]
181183
)
182184

0 commit comments

Comments
 (0)