-
Notifications
You must be signed in to change notification settings - Fork 2
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
support CDC #221
support CDC #221
Conversation
a87515d
to
1e62341
Compare
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.
nějak se mi nepodařilo rozběhat na to testy tak abych nemusí čekat 24h na nové časové okno, takže zatím takto
{ | ||
$this->cdcMode = $cdcMode; | ||
if ($cdcMode === true) { | ||
$this->disableBcp = true; |
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.
při CDC se spouští export jen přes PDO
SET @from_lsn = sys.fn_cdc_map_time_to_lsn('smallest greater than or equal', @begin_time); | ||
SET @from_lsn = ISNULL(sys.fn_cdc_map_time_to_lsn('smallest greater than or equal', @begin_time), [sys].[fn_cdc_get_min_lsn]('$cdcName')); | ||
SET @to_lsn = sys.fn_cdc_map_time_to_lsn('largest less than or equal', @end_time); | ||
IF @to_lsn < @from_lsn |
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.
když když konec časového okna bude před začátkem (to znamená že jsme nějaké okno přeskočili) tak to skončí errorem
try { | ||
$result = parent::export($cdcExportConfig); | ||
} catch (Throwable $e) { | ||
if (strpos($e->getMessage(), 'The end LSN is less than the start LSN') && |
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.
při chybě časových oken je volitelný fallback na full load
throw $e; | ||
} | ||
} | ||
$result['state']['lastFetchedTime'] = $lsnTime; |
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.
ukládám konec časového okna
$sqlToLsnTime = <<<SQL | ||
DECLARE @to_lsn binary(10); | ||
SET @to_lsn = [sys].[fn_cdc_get_max_lsn](); | ||
SELECT sys.fn_cdc_map_lsn_to_time(@to_lsn) as last_fetched_time; | ||
SQL; | ||
$sqlToLsnTime = $this->connection->query($sqlToLsnTime); | ||
$lsnTimeResponse = $sqlToLsnTime->fetchAll(); | ||
assert(count($lsnTimeResponse) === 1, 'Expected one row'); | ||
$lsnTime = $lsnTimeResponse[0]['last_fetched_time']; |
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.
zjištění času konce časového okna
DECLARE @begin_time datetime, @end_time datetime, @from_lsn binary(10), @to_lsn binary(10); | ||
SET @begin_time = CONVERT(DATETIME, '{$this->state['lastFetchedTime']}'); | ||
SET @end_time = GETDATE(); | ||
SET @from_lsn = sys.fn_cdc_map_time_to_lsn('smallest greater than or equal', @begin_time); | ||
SET @from_lsn = ISNULL(sys.fn_cdc_map_time_to_lsn('smallest greater than or equal', @begin_time), [sys].[fn_cdc_get_min_lsn]('$cdcName')); | ||
SET @to_lsn = sys.fn_cdc_map_time_to_lsn('largest less than or equal', @end_time); |
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.
$columns = $this->getQueryFactory()->getColumnsForSelect($exportConfig, $this->connection); | ||
|
||
$cdcExportConfig = clone $exportConfig; | ||
if (!empty($this->state['lastFetchedTime'])) { |
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.
CDC mode se může použít až při druhém a dalším běhu konfigurace... při prvním běhu se tohle přeskočí a pustí fullLoad
tak jsem ještě doplnil 2 testy |
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.
LGTM 🤞
@AdamVyborny ještě jednou pls.... fixoval jsem testy |
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.
Ok
Jira - https://keboola.atlassian.net/browse/CM-692