-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
importer: add ImportEpoch and ImportTypeInProgress table descriptor f…
…ields This patch introduces the new ImportEpoch table descriptor field which provides a count for the number of IMPORT jobs that have been attempted on the table and the ImportTypeInProgress enum which indicates the kind of Import occurring. This work is apart of a larger project to roll back imports without MVCC timestamps. In a future pr (#85138), this epoch will get written to the imported MVCCValueHeader metadata, which in turn allows import rollbacks to use the epoch to determine which keys to delete in the table. We considered binding the import job id to the table descriptor, and in turn to each imported KV's metadata, however, the expected proto encoded size of a job ID was between 7 - 12 bytes, which seemed uncessary. Meanwhile the 4 byte uint32 epoch will encode to 1 byte for the first 256 IMPORT jobs on the table. 2,147,483,648 IMPORT jobs must occur on the table before we worry about integer overflow -- a problem for a future release :D. Informs #85138 Release note: none
- Loading branch information
Showing
12 changed files
with
194 additions
and
16 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
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,81 @@ | ||
# Test that Import INTO properly increments the importEpoch descriptor field only when the user runs | ||
# an IMPORT INTO on a non-empty table. | ||
|
||
new-server name=s1 | ||
---- | ||
|
||
exec-sql | ||
CREATE DATABASE d; | ||
USE d; | ||
CREATE TABLE foo (i INT PRIMARY KEY, s STRING); | ||
CREATE TABLE baz (i INT PRIMARY KEY, s STRING); | ||
INSERT INTO baz VALUES (1, 'x'),(2,'y'),(3,'z'); | ||
---- | ||
|
||
exec-sql | ||
CREATE VIEW import_epoch (epoch, type) | ||
AS WITH tbls AS ( | ||
SELECT id, crdb_internal.pb_to_json('cockroach.sql.sqlbase.Descriptor', descriptor) AS orig FROM system.descriptor | ||
) | ||
SELECT orig->'table'->'importEpoch', orig->'table'->'importTypeInProgress' FROM tbls WHERE id = '109'; | ||
---- | ||
|
||
exec-sql | ||
EXPORT INTO CSV 'nodelocal://0/export1/' FROM SELECT * FROM baz WHERE i = 1; | ||
---- | ||
|
||
exec-sql | ||
IMPORT INTO foo (i,s) CSV DATA ('nodelocal://0/export1/export*-n*.0.csv') | ||
---- | ||
|
||
query-sql | ||
SELECT name, id FROM system.namespace WHERE name = 'foo'; | ||
---- | ||
foo 109 | ||
|
||
query-sql | ||
SELECT * FROM import_epoch | ||
---- | ||
1 <nil> | ||
|
||
exec-sql | ||
EXPORT INTO CSV 'nodelocal://0/export2/' FROM SELECT * FROM baz WHERE i = 2; | ||
---- | ||
|
||
exec-sql | ||
IMPORT INTO foo (i,s) CSV DATA ('nodelocal://0/export2/export*-n*.0.csv') | ||
---- | ||
|
||
query-sql | ||
SELECT * FROM import_epoch | ||
---- | ||
2 <nil> | ||
|
||
exec-sql | ||
SET CLUSTER SETTING jobs.debug.pausepoints = 'import.after_ingest'; | ||
---- | ||
|
||
exec-sql | ||
EXPORT INTO CSV 'nodelocal://0/export3/' FROM SELECT * FROM baz WHERE i = 3; | ||
---- | ||
|
||
# ensure the ImportEpoch increments before planning and does not rollback after the IMPORT INTO | ||
# job gets cancelled | ||
import expect-pausepoint tag=a | ||
IMPORT INTO foo (i,s) CSV DATA ('nodelocal://0/export3/export*-n*.0.csv') | ||
---- | ||
job paused at pausepoint | ||
|
||
query-sql | ||
SELECT * FROM import_epoch | ||
---- | ||
3 "IMPORT_INTO_NON_EMPTY" | ||
|
||
# Cancel the job so that the cleanup hook runs. | ||
job cancel=a | ||
---- | ||
|
||
query-sql | ||
SELECT * FROM import_epoch | ||
---- | ||
3 <nil> |
Large diffs are not rendered by default.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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