/Users/deen/code/yugabyte-db/src/yb/yql/pgwrapper/pg_mini_test_base.cc
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) YugaByte, Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
4 | | // in compliance with the License. You may obtain a copy of the License at |
5 | | // |
6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
7 | | // |
8 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
9 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
10 | | // or implied. See the License for the specific language governing permissions and limitations |
11 | | // under the License. |
12 | | // |
13 | | |
14 | | #include "yb/yql/pgwrapper/pg_mini_test_base.h" |
15 | | |
16 | | #include "yb/master/sys_catalog_initialization.h" |
17 | | |
18 | | #include "yb/tserver/mini_tablet_server.h" |
19 | | #include "yb/tserver/tablet_server.h" |
20 | | |
21 | | #include "yb/util/tsan_util.h" |
22 | | |
23 | | DECLARE_bool(enable_ysql); |
24 | | DECLARE_bool(hide_pg_catalog_table_creation_logs); |
25 | | DECLARE_bool(master_auto_run_initdb); |
26 | | DECLARE_bool(ysql_disable_index_backfill); |
27 | | DECLARE_int32(client_read_write_timeout_ms); |
28 | | DECLARE_int32(pggate_rpc_timeout_secs); |
29 | | DECLARE_int32(pgsql_proxy_webserver_port); |
30 | | DECLARE_int32(ysql_num_shards_per_tserver); |
31 | | |
32 | | namespace yb { |
33 | | namespace pgwrapper { |
34 | | |
35 | 0 | void PgMiniTestBase::DoTearDown() { |
36 | 0 | if (pg_supervisor_) { |
37 | 0 | pg_supervisor_->Stop(); |
38 | 0 | } |
39 | 0 | YBMiniClusterTestBase::DoTearDown(); |
40 | 0 | } |
41 | | |
42 | 0 | void PgMiniTestBase::SetUp() { |
43 | 0 | HybridTime::TEST_SetPrettyToString(true); |
44 | |
|
45 | 0 | FLAGS_client_read_write_timeout_ms = 120000 * kTimeMultiplier; |
46 | 0 | FLAGS_enable_ysql = true; |
47 | 0 | FLAGS_hide_pg_catalog_table_creation_logs = true; |
48 | 0 | FLAGS_master_auto_run_initdb = true; |
49 | 0 | FLAGS_pggate_rpc_timeout_secs = 120; |
50 | 0 | FLAGS_ysql_disable_index_backfill = true; |
51 | 0 | FLAGS_ysql_num_shards_per_tserver = 1; |
52 | | |
53 | |
|
54 | 0 | master::SetDefaultInitialSysCatalogSnapshotFlags(); |
55 | 0 | YBMiniClusterTestBase::SetUp(); |
56 | |
|
57 | 0 | MiniClusterOptions mini_cluster_opt = MiniClusterOptions { |
58 | 0 | .num_masters = NumMasters(), |
59 | 0 | .num_tablet_servers = NumTabletServers(), |
60 | 0 | .num_drives = 1, |
61 | 0 | .master_env = env_.get() |
62 | 0 | }; |
63 | 0 | cluster_ = std::make_unique<MiniCluster>(mini_cluster_opt); |
64 | 0 | ASSERT_OK(cluster_->Start()); |
65 | |
|
66 | 0 | ASSERT_OK(WaitForInitDb(cluster_.get())); |
67 | |
|
68 | 0 | auto port = cluster_->AllocateFreePort(); |
69 | 0 | auto pg_process_conf = ASSERT_RESULT(CreatePgProcessConf(port)); |
70 | 0 | FLAGS_pgsql_proxy_webserver_port = cluster_->AllocateFreePort(); |
71 | |
|
72 | 0 | LOG(INFO) << "Starting PostgreSQL server listening on " |
73 | 0 | << pg_process_conf.listen_addresses << ":" << pg_process_conf.pg_port << ", data: " |
74 | 0 | << pg_process_conf.data_dir |
75 | 0 | << ", pgsql webserver port: " << FLAGS_pgsql_proxy_webserver_port; |
76 | |
|
77 | 0 | BeforePgProcessStart(); |
78 | 0 | pg_supervisor_ = std::make_unique<PgSupervisor>(pg_process_conf); |
79 | 0 | ASSERT_OK(pg_supervisor_->Start()); |
80 | |
|
81 | 0 | DontVerifyClusterBeforeNextTearDown(); |
82 | 0 | } |
83 | | |
84 | 0 | Result<PgProcessConf> PgMiniTestBase::CreatePgProcessConf(uint16_t port) { |
85 | 0 | auto pg_ts = RandomElement(cluster_->mini_tablet_servers()); |
86 | 0 | PgProcessConf pg_process_conf = VERIFY_RESULT(PgProcessConf::CreateValidateAndRunInitDb( |
87 | 0 | AsString(Endpoint(pg_ts->bound_rpc_addr().address(), port)), |
88 | 0 | pg_ts->options()->fs_opts.data_paths.front() + "/pg_data", |
89 | 0 | pg_ts->server()->GetSharedMemoryFd())); |
90 | |
|
91 | 0 | pg_process_conf.master_addresses = pg_ts->options()->master_addresses_flag; |
92 | 0 | pg_process_conf.force_disable_log_file = true; |
93 | 0 | pg_host_port_ = HostPort(pg_process_conf.listen_addresses, pg_process_conf.pg_port); |
94 | |
|
95 | 0 | return pg_process_conf; |
96 | 0 | } |
97 | | |
98 | 0 | Status PgMiniTestBase::RestartCluster() { |
99 | 0 | pg_supervisor_->Stop(); |
100 | 0 | RETURN_NOT_OK(cluster_->RestartSync()); |
101 | 0 | pg_supervisor_ = std::make_unique<PgSupervisor>( |
102 | 0 | VERIFY_RESULT(CreatePgProcessConf(pg_host_port_.port()))); |
103 | 0 | return pg_supervisor_->Start(); |
104 | 0 | } |
105 | | |
106 | | const std::shared_ptr<tserver::MiniTabletServer> PgMiniTestBase::PickPgTabletServer( |
107 | 0 | const MiniCluster::MiniTabletServers& servers) { |
108 | 0 | return RandomElement(servers); |
109 | 0 | } |
110 | | |
111 | | } // namespace pgwrapper |
112 | | } // namespace yb |