Skip to content

Commit 0659951

Browse files
al13n321Enmk
authored andcommitted
Partially cherry-picked 9a3adc7 for Context::getDefaultOrAuxiliaryZooKeeper
1 parent 0984d0f commit 0659951

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

src/Common/ZooKeeper/ZooKeeper.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,11 +1686,10 @@ std::string normalizeZooKeeperPath(std::string zookeeper_path, bool check_starts
16861686

16871687
String extractZooKeeperName(const String & path)
16881688
{
1689-
static constexpr auto default_zookeeper_name = "default";
16901689
if (path.empty())
16911690
throw DB::Exception(DB::ErrorCodes::BAD_ARGUMENTS, "ZooKeeper path should not be empty");
16921691
if (path[0] == '/')
1693-
return default_zookeeper_name;
1692+
return String(DEFAULT_ZOOKEEPER_NAME);
16941693
auto pos = path.find(":/");
16951694
if (pos != String::npos && pos < path.find('/'))
16961695
{
@@ -1699,7 +1698,7 @@ String extractZooKeeperName(const String & path)
16991698
throw DB::Exception(DB::ErrorCodes::BAD_ARGUMENTS, "Zookeeper path should start with '/' or '<auxiliary_zookeeper_name>:/'");
17001699
return zookeeper_name;
17011700
}
1702-
return default_zookeeper_name;
1701+
return String(DEFAULT_ZOOKEEPER_NAME);
17031702
}
17041703

17051704
String extractZooKeeperPath(const String & path, bool check_starts_with_slash, LoggerPtr log)

src/Common/ZooKeeper/ZooKeeper.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ namespace zkutil
4747
/// Preferred size of multi() command (in number of ops)
4848
constexpr size_t MULTI_BATCH_SIZE = 100;
4949

50+
/// Path "default:/foo" refers to znode "/foo" in the default zookeeper,
51+
/// path "other:/foo" refers to znode "/foo" in auxiliary zookeeper named "other".
52+
constexpr std::string_view DEFAULT_ZOOKEEPER_NAME = "default";
53+
5054
struct ShuffleHost
5155
{
5256
enum AvailabilityZoneInfo

src/Interpreters/Context.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3746,6 +3746,11 @@ zkutil::ZooKeeperPtr Context::getAuxiliaryZooKeeper(const String & name) const
37463746
return zookeeper->second;
37473747
}
37483748

3749+
std::shared_ptr<zkutil::ZooKeeper> Context::getDefaultOrAuxiliaryZooKeeper(const String & name) const
3750+
{
3751+
return name == zkutil::DEFAULT_ZOOKEEPER_NAME ? getZooKeeper() : getAuxiliaryZooKeeper(name);
3752+
}
3753+
37493754

37503755
std::map<String, zkutil::ZooKeeperPtr> Context::getAuxiliaryZooKeepers() const
37513756
{

src/Interpreters/Context.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,8 @@ class Context: public ContextData, public std::enable_shared_from_this<Context>
997997
std::shared_ptr<zkutil::ZooKeeper> getZooKeeper() const;
998998
/// Same as above but return a zookeeper connection from auxiliary_zookeepers configuration entry.
999999
std::shared_ptr<zkutil::ZooKeeper> getAuxiliaryZooKeeper(const String & name) const;
1000+
/// If name == "default", same as getZooKeeper(), otherwise same as getAuxiliaryZooKeeper().
1001+
std::shared_ptr<zkutil::ZooKeeper> getDefaultOrAuxiliaryZooKeeper(const String & name) const;
10001002
/// return Auxiliary Zookeeper map
10011003
std::map<String, zkutil::ZooKeeperPtr> getAuxiliaryZooKeepers() const;
10021004

0 commit comments

Comments
 (0)