-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bundles repair): add bundle repair worker PE-4041
Adds a bundle repair worker that queries `bundles` and `bundle_data_item` tables to determine which bundles have been fully imported. It does this by setting bundle `last_fully_indexed_at` based on a comparison of `bundle_data_items` for each bundle to `matched_data_item_count` on the bundles (taking filters into account) and then using those `last_fully_indexed_at` timestamps to determine if the bundle should be reprocessed.
- Loading branch information
Showing
18 changed files
with
322 additions
and
41 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
2 changes: 2 additions & 0 deletions
2
migrations/2023.06.28T21.52.29.bundles.add-bundles-root-tx-id.sql
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,2 @@ | ||
ALTER TABLE bundles ADD COLUMN root_transaction_id BLOB; | ||
UPDATE bundles SET root_transaction_id = id; |
15 changes: 15 additions & 0 deletions
15
migrations/2023.06.28T22.02.57.bundles.add-bundles-indexes.sql
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,15 @@ | ||
CREATE INDEX IF NOT EXISTS bundles_last_queued_at_idx | ||
ON bundles (last_queued_at); | ||
CREATE INDEX IF NOT EXISTS bundles_last_skipped_at_idx | ||
ON bundles (last_skipped_at); | ||
CREATE INDEX IF NOT EXISTS bundles_last_fully_indexed_at_idx | ||
ON bundles (last_fully_indexed_at); | ||
CREATE INDEX IF NOT EXISTS bundles_matched_data_item_count_idx | ||
ON bundles (matched_data_item_count); | ||
CREATE INDEX IF NOT EXISTS bundles_unbundle_filter_id_idx | ||
ON bundles (unbundle_filter_id); | ||
CREATE INDEX IF NOT EXISTS bundles_index_filter_id_idx | ||
ON bundles (index_filter_id); | ||
|
||
CREATE INDEX IF NOT EXISTS bundle_data_items_parent_id_filter_id_idx | ||
ON bundle_data_items (parent_id, filter_id); |
1 change: 1 addition & 0 deletions
1
migrations/down/2023.06.28T21.52.29.bundles.add-bundles-root-tx-id.sql
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 @@ | ||
ALTER TABLE bundles DROP COLUMN root_transaction_id; |
8 changes: 8 additions & 0 deletions
8
migrations/down/2023.06.28T22.02.57.bundles.add-bundles-indexes.sql
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,8 @@ | ||
DROP INDEX IF EXISTS bundle_data_items_parent_id_filter_id_idx; | ||
|
||
DROP INDEX IF EXISTS bundles_unbundle_filter_id_idx; | ||
DROP INDEX IF EXISTS bundles_index_filter_id_idx; | ||
DROP INDEX IF EXISTS bundles_matched_data_item_count_idx; | ||
DROP INDEX IF EXISTS bundles_last_fully_indexed_at_idx; | ||
DROP INDEX IF EXISTS bundles_last_skipped_at_idx; | ||
DROP INDEX IF EXISTS bundles_last_queued_at_idx; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
-- selectFailedBundleIds | ||
SELECT DISTINCT id | ||
FROM ( | ||
SELECT b.root_transaction_id AS id | ||
FROM bundles b | ||
WHERE ( | ||
(b.last_queued_at IS NULL AND b.last_skipped_at IS NULL) | ||
OR ( | ||
b.last_queued_at IS NOT NULL | ||
AND ( | ||
b.last_skipped_at IS NULL | ||
OR b.last_skipped_at <= b.last_queued_at | ||
) | ||
AND b.last_queued_at < @reprocess_cutoff | ||
) | ||
) | ||
AND b.last_fully_indexed_at IS NULL | ||
AND ( | ||
b.matched_data_item_count IS NULL | ||
OR b.matched_data_item_count > 0 | ||
) | ||
ORDER BY b.last_queued_at ASC | ||
LIMIT @limit | ||
) | ||
ORDER BY RANDOM() | ||
|
||
-- updateFullyIndexedAt | ||
UPDATE bundles | ||
SET | ||
first_fully_indexed_at = IFNULL(first_fully_indexed_at, @fully_indexed_at), | ||
last_fully_indexed_at = @fully_indexed_at | ||
WHERE matched_data_item_count IS NOT NULL | ||
AND matched_data_item_count > 0 | ||
AND EXISTS ( | ||
SELECT 1 | ||
FROM bundle_data_items bdi | ||
WHERE bdi.parent_id = bundles.id | ||
AND bdi.filter_id = bundles.unbundle_filter_id | ||
GROUP BY bdi.parent_id | ||
HAVING COUNT(*) = bundles.matched_data_item_count | ||
) AND last_fully_indexed_at IS NULL | ||
|
||
--insertMissingBundles | ||
INSERT INTO bundles ( | ||
id, | ||
root_transaction_id, | ||
format_id | ||
) | ||
SELECT | ||
sttf.transaction_id, | ||
sttf.transaction_id, | ||
(SELECT id FROM bundle_formats WHERE format = 'ans-104') | ||
FROM stable_transaction_tags sttf | ||
JOIN stable_transaction_tags sttv ON sttv.transaction_id = sttf.transaction_id | ||
WHERE sttf.tag_name_hash = x'BF796ECA81CCE3FF36CEA53FA1EBB0F274A0FF29' | ||
AND sttf.tag_value_hash = x'7E57CFE843145135AEE1F4D0D63CEB7842093712' | ||
AND sttv.tag_name_hash = x'858B76CB055E360A2E4C3C38F4A3049F80175216' | ||
AND sttv.tag_value_hash = x'F7CA6A21D278EB5CE64611AADBDB77EF1511D3DD' | ||
UNION ALL | ||
SELECT | ||
nttf.transaction_id, | ||
nttf.transaction_id, | ||
(SELECT id FROM bundle_formats WHERE format = 'ans-104') | ||
FROM new_transaction_tags nttf | ||
JOIN new_transaction_tags nttv ON nttv.transaction_id = nttf.transaction_id | ||
WHERE nttf.tag_name_hash = x'BF796ECA81CCE3FF36CEA53FA1EBB0F274A0FF29' | ||
AND nttf.tag_value_hash = x'7E57CFE843145135AEE1F4D0D63CEB7842093712' | ||
AND nttv.tag_name_hash = x'858B76CB055E360A2E4C3C38F4A3049F80175216' | ||
AND nttv.tag_value_hash = x'F7CA6A21D278EB5CE64611AADBDB77EF1511D3DD' | ||
LIMIT 10000 | ||
ON CONFLICT DO NOTHING |
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.