-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #310 from MikhailBurdukov/multiple_endpoints
Multiple endpoints for connection.
- Loading branch information
Showing
10 changed files
with
366 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include "endpoints_iterator.h" | ||
#include <clickhouse/client.h> | ||
|
||
namespace clickhouse { | ||
|
||
RoundRobinEndpointsIterator::RoundRobinEndpointsIterator(const std::vector<Endpoint>& _endpoints) | ||
: endpoints (_endpoints) | ||
, current_index (endpoints.size() - 1ull) | ||
{ | ||
} | ||
|
||
Endpoint RoundRobinEndpointsIterator::Next() | ||
{ | ||
current_index = (current_index + 1ull) % endpoints.size(); | ||
return endpoints[current_index]; | ||
} | ||
|
||
RoundRobinEndpointsIterator::~RoundRobinEndpointsIterator() = default; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#pragma once | ||
|
||
#include "clickhouse/client.h" | ||
#include <vector> | ||
|
||
namespace clickhouse { | ||
|
||
struct ClientOptions; | ||
|
||
/** | ||
* Base class for iterating through endpoints. | ||
*/ | ||
class EndpointsIteratorBase | ||
{ | ||
public: | ||
virtual ~EndpointsIteratorBase() = default; | ||
|
||
virtual Endpoint Next() = 0; | ||
}; | ||
|
||
class RoundRobinEndpointsIterator : public EndpointsIteratorBase | ||
{ | ||
public: | ||
explicit RoundRobinEndpointsIterator(const std::vector<Endpoint>& opts); | ||
Endpoint Next() override; | ||
|
||
~RoundRobinEndpointsIterator() override; | ||
|
||
private: | ||
const std::vector<Endpoint>& endpoints; | ||
size_t current_index; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.