-
Notifications
You must be signed in to change notification settings - Fork 606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kafka connect distributed #12960
Draft
niksaveliev
wants to merge
6
commits into
ydb-platform:main
Choose a base branch
from
niksaveliev:kafka-connect-distributed
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+4,609
−2,010
Draft
Kafka connect distributed #12960
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
155 changes: 155 additions & 0 deletions
155
ydb/core/kafka_proxy/actors/kafka_balance_actor_sql.cpp
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,155 @@ | ||
#include "kafka_balancer_actor.h" | ||
|
||
namespace NKafka { | ||
|
||
// savnik add db | ||
|
||
const TString SELECT_STATE_AND_GENERATION = R"( | ||
--!syntax_v1 | ||
DECLARE $ConsumerGroup AS Utf8; | ||
|
||
SELECT state, generation | ||
FROM kafka_connect_groups | ||
WHERE consumer_group = $ConsumerGroup; | ||
)"; | ||
|
||
const TString INSERT_NEW_GROUP = R"( | ||
--!syntax_v1 | ||
DECLARE $ConsumerGroup AS Utf8; | ||
DECLARE $Generation AS Uint64; | ||
DECLARE $State AS Uint64; | ||
|
||
INSERT INTO kafka_connect_groups | ||
( | ||
consumer_group, | ||
generation, | ||
state, | ||
current_generation_start_time | ||
) | ||
VALUES | ||
( | ||
$ConsumerGroup, | ||
$Generation, | ||
$State, | ||
CurrentUtcDateTime() | ||
); | ||
)"; | ||
|
||
const TString UPDATE_GROUP = R"( | ||
--!syntax_v1 | ||
DECLARE $ConsumerGroup AS Utf8; | ||
DECLARE $NewState AS Uint64; | ||
DECLARE $OldGeneration AS Uint64; | ||
|
||
UPDATE kafka_connect_groups | ||
SET | ||
state = $NewState, | ||
generation = $OldGeneration + 1 | ||
WHERE consumer_group = $ConsumerGroup; | ||
)"; | ||
|
||
const TString SELECT_MASTER = R"( | ||
--!syntax_v1 | ||
DECLARE $ConsumerGroup AS Utf8; | ||
DECLARE $Generation AS Uint64; | ||
|
||
SELECT member_id | ||
FROM kafka_connect_members | ||
WHERE consumer_group = $ConsumerGroup | ||
AND generation = $Generation | ||
ORDER BY join_time | ||
LIMIT 1; | ||
)"; | ||
|
||
const TString INSERT_MEMBER_AND_SELECT_MASTER = R"( | ||
--!syntax_v1 | ||
DECLARE $ConsumerGroup AS Utf8; | ||
DECLARE $Generation AS Uint64; | ||
DECLARE $MemberId AS Utf8; | ||
DECLARE $WorkerState AS String; | ||
|
||
INSERT INTO kafka_connect_members ( | ||
consumer_group, | ||
generation, | ||
member_id, | ||
join_time, | ||
hearbeat_deadline, | ||
worker_state | ||
) | ||
VALUES ( | ||
$ConsumerGroup, | ||
$Generation, | ||
$MemberId, | ||
CurrentUtcDateTime(), | ||
CurrentUtcDateTime() + Interval("PT5S"), | ||
niksaveliev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$WorkerState | ||
); | ||
|
||
SELECT member_id AS master_id | ||
FROM kafka_connect_members | ||
WHERE consumer_group = $ConsumerGroup | ||
AND generation = $Generation | ||
ORDER BY join_time | ||
LIMIT 1; | ||
)"; | ||
|
||
|
||
// savnik Леша говорил про пагинацию | ||
|
||
const TString UPSERT_ASSIGNMENTS_AND_SET_WORKING_STATE = R"( | ||
--!syntax_v1 | ||
DECLARE $Assignments AS List<Struct<MemberId: Utf8, Assignment: Bytes>>; | ||
DECLARE $ConsumerGroup AS Utf8; | ||
|
||
UPSERT INTO kafka_connect_members | ||
SELECT | ||
item.MemberId AS member_id, | ||
item.Assignment AS assignment, | ||
$ConsumerGroup AS consumer_group | ||
FROM AS_TABLE($Assignments) AS item; | ||
|
||
UPDATE kafka_connect_groups | ||
SET state = 2 | ||
WHERE consumer_group = $ConsumerGroup; | ||
|
||
)"; | ||
|
||
const TString UPDATE_GROUPS_AND_SELECT_WORKER_STATES = R"( | ||
--!syntax_v1 | ||
DECLARE $ConsumerGroup AS Utf8; | ||
DECLARE $State AS Uint64; | ||
DECLARE $Generation AS Uint64; | ||
|
||
UPDATE kafka_connect_groups | ||
SET state = $State | ||
WHERE consumer_group = $ConsumerGroup; | ||
|
||
SELECT worker_state | ||
FROM kafka_connect_members | ||
WHERE consumer_group = $ConsumerGroup | ||
AND generation = $Generation; | ||
)"; | ||
|
||
const TString CHECK_GROUP_STATE = R"( | ||
--!syntax_v1 | ||
DECLARE $ConsumerGroup AS Utf8; | ||
|
||
SELECT state, generation | ||
FROM kafka_connect_groups | ||
WHERE consumer_group = $ConsumerGroup; | ||
)"; | ||
|
||
const TString FETCH_ASSIGNMENT = R"( | ||
--!syntax_v1 | ||
DECLARE $ConsumerGroup AS Utf8; | ||
DECLARE $Generation AS Uint64; | ||
DECLARE $MemberId AS Utf8; | ||
|
||
SELECT assignment | ||
FROM kafka_connect_members | ||
WHERE consumer_group = $ConsumerGroup | ||
AND generation = $Generation | ||
AND member_id = $MemberId; | ||
)"; | ||
|
||
} // namespace NKafka |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In code you using INSERT_MEMBER_AND_SELECT_MASTER_QUERY. No _QUERY suffix here.
And you should check that visibility of transaction changes is enabled. What if min join-time in this request?