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

ENG-11253: create partial unique index on template #378

Merged
merged 1 commit into from
Dec 11, 2020

Conversation

ryli17
Copy link
Contributor

@ryli17 ryli17 commented Dec 10, 2020

Description

  • Create partial unique index on template.name so that the unique constraint on name is enforced for not deleted templates.
  • Remove unnecessary query check when insert into template table to avoid potential concurrent issue.

Why is this needed

https://packet.atlassian.net/browse/ENG-11253
https://packet.atlassian.net/browse/ENG-10638

How Has This Been Tested?

manually

How are existing users impacted? What migration steps/scripts do we need?

New database migration "202012091055-add-partial-unique-constraint-on-template" need to be applied.

Checklist:

I have:

  • updated the documentation and/or roadmap (if required)
  • added unit or e2e tests
  • provided instructions on how to upgrade

@codecov
Copy link

codecov bot commented Dec 10, 2020

Codecov Report

Merging #378 (fd6cd3a) into master (6d9159b) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #378   +/-   ##
=======================================
  Coverage   28.73%   28.73%           
=======================================
  Files          19       19           
  Lines        1385     1385           
=======================================
  Hits          398      398           
  Misses        960      960           
  Partials       27       27           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6d9159b...fd6cd3a. Read the comment docs.

Signed-off-by: Ryan Li <ryli@equinix.com>
@kqdeng
Copy link
Contributor

kqdeng commented Dec 10, 2020

verified manually on sandbox setup:

  • creating a template with the same name as a non-deleted template => returns (expected) error
  • creating a template with the same name as a deleted template => template creates successfully
  • can create templates concurrently
root@tink-provisioner:~/tink/deploy# docker exec -it deploy_tink-cli_1 ash
/ # tink template list
+--------------------------------------+---------------+-------------------------------+-------------------------------+
| TEMPLATE ID                          | TEMPLATE NAME | CREATED AT                    | UPDATED AT                    |
+--------------------------------------+---------------+-------------------------------+-------------------------------+
| bf93ae98-b83a-440b-9fb7-6af98f3b2968 | ubuntu        | 2020-11-11 03:08:43 +0000 UTC | 2020-11-11 03:08:43 +0000 UTC |
| 31f1e261-4699-44b9-8458-bbe0fac65f44 | linux         | 2020-11-11 07:08:32 +0000 UTC | 2020-11-11 07:08:32 +0000 UTC |
+--------------------------------------+---------------+-------------------------------+-------------------------------+
/ # ls
bin    dev    etc    hello  home   lib    media  mnt    opt    proc   root   run    sbin   srv    sys    tmp    usr    var
/ # vi hello
/ # tink template create -n hello -p hello
Created Template:  54c1509d-3b2d-11eb-ac02-0242ac120004
/ #
/ #
/ # tink template create -n hello -p hello
2020/12/10 21:19:07 rpc error: code = Unknown desc = INSERT: pq: duplicate key value violates unique constraint "uidx_template_name"
/ #
/ #
/ # tink template list
+--------------------------------------+---------------+-------------------------------+-------------------------------+
| TEMPLATE ID                          | TEMPLATE NAME | CREATED AT                    | UPDATED AT                    |
+--------------------------------------+---------------+-------------------------------+-------------------------------+
| bf93ae98-b83a-440b-9fb7-6af98f3b2968 | ubuntu        | 2020-11-11 03:08:43 +0000 UTC | 2020-11-11 03:08:43 +0000 UTC |
| 31f1e261-4699-44b9-8458-bbe0fac65f44 | linux         | 2020-11-11 07:08:32 +0000 UTC | 2020-11-11 07:08:32 +0000 UTC |
| 54c1509d-3b2d-11eb-ac02-0242ac120004 | hello         | 2020-12-10 21:19:04 +0000 UTC | 2020-12-10 21:19:04 +0000 UTC |
+--------------------------------------+---------------+-------------------------------+-------------------------------+
/ # tink template delete 54c1509d-3b2d-11eb-ac02-0242ac120004
/ #
/ # tink template list
+--------------------------------------+---------------+-------------------------------+-------------------------------+
| TEMPLATE ID                          | TEMPLATE NAME | CREATED AT                    | UPDATED AT                    |
+--------------------------------------+---------------+-------------------------------+-------------------------------+
| bf93ae98-b83a-440b-9fb7-6af98f3b2968 | ubuntu        | 2020-11-11 03:08:43 +0000 UTC | 2020-11-11 03:08:43 +0000 UTC |
| 31f1e261-4699-44b9-8458-bbe0fac65f44 | linux         | 2020-11-11 07:08:32 +0000 UTC | 2020-11-11 07:08:32 +0000 UTC |
+--------------------------------------+---------------+-------------------------------+-------------------------------+
/ # tink template create -n hello -p hello
Created Template:  723b8546-3b2d-11eb-ac02-0242ac120004
/ #
/ # tink template get 723b8546-3b2d-11eb-ac02-0242ac120004
version: "0.1"
name: hello_world_workflow
global_timeout: 600
tasks:
  - name: "hello world"
    worker: "{{.device_1}}"
    actions:
      - name: "hello_world"
        image: hello-world
        timeout: 60

/ # cat create-temp.sh
cat hello | tink template create -n test01
cat hello | tink template create -n test02
cat hello | tink template create -n test03
cat hello | tink template create -n test04
cat hello | tink template create -n test05
cat hello | tink template create -n test06
cat hello | tink template create -n test07
cat hello | tink template create -n test08
cat hello | tink template create -n test09
cat hello | tink template create -n test010
/ #
/ # cat create-temp.sh | parallel
Created Template:  eff34bd1-3bc8-11eb-ac02-0242ac120004
Created Template:  eff3a7fc-3bc8-11eb-ac02-0242ac120004
Created Template:  eff40ba5-3bc8-11eb-ac02-0242ac120004
Created Template:  eff3b5a5-3bc8-11eb-ac02-0242ac120004
Created Template:  eff4635c-3bc8-11eb-ac02-0242ac120004
Created Template:  eff44488-3bc8-11eb-ac02-0242ac120004
Created Template:  eff4dac4-3bc8-11eb-ac02-0242ac120004
Created Template:  eff4f298-3bc8-11eb-ac02-0242ac120004
Created Template:  eff53c45-3bc8-11eb-ac02-0242ac120004
Created Template:  eff53d77-3bc8-11eb-ac02-0242ac120004
/ #

@gianarb gianarb requested a review from mmlb December 11, 2020 08:42
Copy link
Contributor

@gianarb gianarb left a comment

Choose a reason for hiding this comment

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

Well done! Thank you for taking the time!

@gianarb gianarb added the ready-to-merge Signal to Mergify to merge the PR. label Dec 11, 2020
@gianarb gianarb removed the request for review from mmlb December 11, 2020 08:54
@mergify mergify bot merged commit 1fdd722 into tinkerbell:master Dec 11, 2020
@mmlb mmlb removed the ready-to-merge Signal to Mergify to merge the PR. label Jan 25, 2021
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.

4 participants