Skip to content
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

Merged
merged 8 commits into from
Aug 22, 2023
Merged

support CDC #221

merged 8 commits into from
Aug 22, 2023

Conversation

ondrajodas
Copy link
Contributor

@ondrajodas ondrajodas marked this pull request as ready for review August 22, 2023 07:13
Copy link
Contributor Author

@ondrajodas ondrajodas left a 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;
Copy link
Contributor Author

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
Copy link
Contributor Author

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') &&
Copy link
Contributor Author

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;
Copy link
Contributor Author

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

Comment on lines +120 to +128
$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'];
Copy link
Contributor Author

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

Comment on lines +104 to +109
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);
Copy link
Contributor Author

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'])) {
Copy link
Contributor Author

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

@ondrajodas ondrajodas requested review from AdamVyborny and removed request for AdamVyborny August 22, 2023 07:28
@ondrajodas
Copy link
Contributor Author

tak jsem ještě doplnil 2 testy

AdamVyborny
AdamVyborny previously approved these changes Aug 22, 2023
Copy link
Contributor

@AdamVyborny AdamVyborny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🤞

@ondrajodas
Copy link
Contributor Author

@AdamVyborny ještě jednou pls.... fixoval jsem testy

Copy link
Contributor

@AdamVyborny AdamVyborny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

@ondrajodas ondrajodas merged commit 79c1153 into master Aug 22, 2023
1 check passed
@ondrajodas ondrajodas deleted the CM-692-ondra branch August 22, 2023 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants