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

Add management command to precreate partitioned tables #14076

Merged
merged 6 commits into from
Jun 5, 2023

Conversation

gamuniz
Copy link
Contributor

@gamuniz gamuniz commented Jun 1, 2023

SUMMARY

Useful for automating a pg_dump as it holds exclusive locks on main_jobevent etc during a pg_dump

example of automation:

- name: precreate partitioned tables
  shell: awx-manage precreate_partitions
  become_user: awx
  become: true
  register: partitions
ISSUE TYPE
  • New or Enhanced Feature
COMPONENT NAME
  • API
AWX VERSION
make VERSION
awx: 22.3.1.dev22+gfdce6c9b35.d20230601

ADDITIONAL INFORMATION

@gamuniz gamuniz marked this pull request as ready for review June 1, 2023 21:31
def _create_partitioned_tables(self, count):
start = now()
while count > 0:
for table in ("main_inventoryupdateevent", "main_jobevent", "main_projectupdateevent", "main_systemjobevent"):
Copy link
Member

Choose a reason for hiding this comment

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

I would like to make 1 request that we don't hard-code these table names. Import this method instead, you may find it necessary to move into utils:

def unified_job_class_to_event_table_name(job_class):
return f'main_{job_class().event_class.__name__.lower()}'

With that method, you don't need to provide a table name for the loop, but you do need to provide the models. Those would be Job, AdHocCommand, ProjectUpdate, InventoryUpdate, SystemJob.

I listed 5 and you listed 4, I think you're missing the ad hoc commands as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I refactored based on your feedback @AlanCoding. Let me know if you had something different in mind here.

@gamuniz gamuniz requested a review from AlanCoding June 2, 2023 17:04
while count > 0:
for table in tables:
create_partition(table, start)
print(f'Creating partitions for {table} {start}')
Copy link
Member

Choose a reason for hiding this comment

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

I'm just slightly confused about this message coming after the create_partition call. Maybe it should say "Created" instead of "creating"

Copy link
Contributor Author

@gamuniz gamuniz Jun 3, 2023

Choose a reason for hiding this comment

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

Yeah I agree, that message was mostly for me during writing/debug to make sure I had the correct tables/timestamps

Gabe Muniz added 6 commits June 5, 2023 14:03
Useful for automating a pg_dump as it holds exclusive locks on main_jobevent etc during a pg_dump

example of automation:

- name: precreate partitioned tables
  shell: awx-manage precreate_partitions
  become_user: awx
  become: true
  register: partitions
Imported the function to cleanup_jobs.py and precreate_partitions.py
Removed hardcoded table names in favor of looping through the models
@TheRealHaoLiu TheRealHaoLiu enabled auto-merge (squash) June 5, 2023 18:03
@TheRealHaoLiu TheRealHaoLiu merged commit 6976ac9 into ansible:devel Jun 5, 2023
13 of 14 checks passed
AlanCoding pushed a commit to AlanCoding/awx that referenced this pull request Jul 13, 2023
AlexSCorey pushed a commit to AlexSCorey/awx that referenced this pull request Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants