pt-online-schema-change script returns 1 even when there is no error

Bug #1338488 reported by Pedro Ibáñez
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Percona Toolkit moved to https://jira.percona.com/projects/PT
Expired
Undecided
Unassigned

Bug Description

[In:Percona Toolkit Documentation]
Hi,

I'm using pt-online-schema-change percona-toolkit-2.2.8-1 into a script for changing around 100 tables , before I run the command with the --execute flag I like to run it with the --dry-run flag and I found out what looks like a bug, the percona script always returns 1 even when it does not fail:

pt-online-schema-change --alter ADD KEY index_2(TIPO,ID,CALIFICADOR) h=X.X.X.X,u=root,p=XXXXXX,D=MYBBDD,t=DATOSAUX --nocheck-plan --alter-foreign-keys-method auto --statistics --dry-run

Operation, tries, wait:
  copy_rows, 10, 0.25
  create_triggers, 10, 1
  drop_triggers, 10, 1
  swap_tables, 10, 1
  update_foreign_keys, 10, 1
No foreign keys reference `MYBBDD`.`DATOSAUX`; ignoring --alter-foreign-keys-method.
Starting a dry run. `MYBBDD`.`DATOSAUX` will not be altered. Specify --execute instead of --dry-run to alter the table.
Creating new table...
Created new table MYBBDD._DATOSAUX_new OK.
Altering new table...
Altered `MYBBDD`.`_DATOSAUX_new` OK.
Not creating triggers because this is a dry run.
Not copying rows because this is a dry run.
Not swapping tables because this is a dry run.
Not dropping old table because this is a dry run.
Not dropping triggers because this is a dry run.
2014-07-07T10:25:28 Dropping new table...
2014-07-07T10:25:28 Dropped new table OK.
# Event Count
# ====== =====
# INSERT 0
Dry run complete. `MYBBDD`.`DATOSAUX` was not altered.
Ret:1

The script didn't fail and returns 1 ¿¿??

Now I altered the table manually and launch the script again:

pt-online-schema-change --alter ADD KEY index_2(TIPO,ID,CALIFICADOR) h=X.X.X.X,u=root,p=XXXXXX,D=MYBBDD,t=DATOSAUX --nocheck-plan --alter-foreign-keys-method auto --statistics --dry-run
Operation, tries, wait:
  copy_rows, 10, 0.25
  create_triggers, 10, 1
  drop_triggers, 10, 1
  swap_tables, 10, 1
  update_foreign_keys, 10, 1
No foreign keys reference `MYBBDD`.`DATOSAUX`; ignoring --alter-foreign-keys-method.
Starting a dry run. `MYBBDD`.`DATOSAUX` will not be altered. Specify --execute instead of --dry-run to alter the table.
Creating new table...
Created new table MYBBDD._DATOSAUX_new OK.
Altering new table...
2014-07-07T10:25:28 Dropping new table...
2014-07-07T10:25:28 Dropped new table OK.
# Event Count
# ====== =====
# INSERT 0
Dry run complete. `MYBBDD`.`DATOSAUX` was not altered.
     (in cleanup) Error altering new table `MYBBDD`.`_DATOSAUX_new`: BD::mysql:db do failed: Duplicate key name 'index_2' [for statement "ALTER TABLE `MYBBDD`.`_DATOSAUX_new` ADD KEY index_2(TIPO,ID,CALIFICADOR)"] at /usr/bin/pt-online-schema-change line 8588.

# Event Count
# ====== =====
# INSERT 0
Dry run complete. `MYBBDD`.`DATOSAUX` was not altered.
Ret:1

It fails and returns 1, so, how can I check inside a script that the dry-run worked properly? is it the normal behavior of the pt-online-schema-change?

Thank you

Revision history for this message
Nilnandan Joshi (nilnandan-joshi) wrote :

Hi, I have tried to reproduce the same but I'm getting 0 if its successful otherwise error. Can you check or provide that script that how it returns error when pt-osc is successful or not?

nilnandan@nilnandan-Dell-XPS:~$ pt-online-schema-change --alter 'ADD KEY i_c(c)' h=127.0.0.1,u=root,p=root,D=dbtest,t=sbtest --nocheck-plan --alter-foreign-keys-method auto --statistics --dry-run
Operation, tries, wait:
  copy_rows, 10, 0.25
  create_triggers, 10, 1
  drop_triggers, 10, 1
  swap_tables, 10, 1
  update_foreign_keys, 10, 1
No foreign keys reference `dbtest`.`sbtest`; ignoring --alter-foreign-keys-method.
Starting a dry run. `dbtest`.`sbtest` will not be altered. Specify --execute instead of --dry-run to alter the table.
Creating new table...
Created new table dbtest._sbtest_new OK.
Altering new table...
Altered `dbtest`.`_sbtest_new` OK.
Not creating triggers because this is a dry run.
Not copying rows because this is a dry run.
Not swapping tables because this is a dry run.
Not dropping old table because this is a dry run.
Not dropping triggers because this is a dry run.
2014-08-04T15:20:52 Dropping new table...
2014-08-04T15:20:52 Dropped new table OK.
# Event Count
# ====== =====
# INSERT 0
Dry run complete. `dbtest`.`sbtest` was not altered.
nilnandan@nilnandan-Dell-XPS:~$
nilnandan@nilnandan-Dell-XPS:~$ echo $?
0
nilnandan@nilnandan-Dell-XPS:~$
nilnandan@nilnandan-Dell-XPS:~$ pt-online-schema-change --alter 'ADD KEY i_c(c)' h=127.0.0.1,u=root,p=root,D=dbtest,t=sbtest --nocheck-plan --alter-foreign-keys-method auto --statistics --dry-run
Operation, tries, wait:
  copy_rows, 10, 0.25
  create_triggers, 10, 1
  drop_triggers, 10, 1
  swap_tables, 10, 1
  update_foreign_keys, 10, 1
No foreign keys reference `dbtest`.`sbtest`; ignoring --alter-foreign-keys-method.
Starting a dry run. `dbtest`.`sbtest` will not be altered. Specify --execute instead of --dry-run to alter the table.
Creating new table...
Created new table dbtest._sbtest_new OK.
Altering new table...
2014-08-04T15:34:06 Dropping new table...
2014-08-04T15:34:06 Dropped new table OK.
# Event Count
# ====== =====
# INSERT 0
Dry run complete. `dbtest`.`sbtest` was not altered.

Segmentation fault (core dumped)
nilnandan@nilnandan-Dell-XPS:~$
nilnandan@nilnandan-Dell-XPS:~$ echo $?
139
nilnandan@nilnandan-Dell-XPS:~$

Changed in percona-toolkit:
status: New → Incomplete
Revision history for this message
Pedro Ibáñez (pibanez) wrote : Re: [Bug 1338488] Re: pt-online-schema-change script returns 1 even when there is no error
Download full text (3.8 KiB)

Hello Hilnandan,

you got the return code 139 because of the core dump, can you try again
with the core dumps disabled?

Cheers

On 04/08/14 12:07, Nilnandan Joshi wrote:
> Hi, I have tried to reproduce the same but I'm getting 0 if its
> successful otherwise error. Can you check or provide that script that
> how it returns error when pt-osc is successful or not?
>
> nilnandan@nilnandan-Dell-XPS:~$ pt-online-schema-change --alter 'ADD KEY i_c(c)' h=127.0.0.1,u=root,p=root,D=dbtest,t=sbtest --nocheck-plan --alter-foreign-keys-method auto --statistics --dry-run
> Operation, tries, wait:
> copy_rows, 10, 0.25
> create_triggers, 10, 1
> drop_triggers, 10, 1
> swap_tables, 10, 1
> update_foreign_keys, 10, 1
> No foreign keys reference `dbtest`.`sbtest`; ignoring --alter-foreign-keys-method.
> Starting a dry run. `dbtest`.`sbtest` will not be altered. Specify --execute instead of --dry-run to alter the table.
> Creating new table...
> Created new table dbtest._sbtest_new OK.
> Altering new table...
> Altered `dbtest`.`_sbtest_new` OK.
> Not creating triggers because this is a dry run.
> Not copying rows because this is a dry run.
> Not swapping tables because this is a dry run.
> Not dropping old table because this is a dry run.
> Not dropping triggers because this is a dry run.
> 2014-08-04T15:20:52 Dropping new table...
> 2014-08-04T15:20:52 Dropped new table OK.
> # Event Count
> # ====== =====
> # INSERT 0
> Dry run complete. `dbtest`.`sbtest` was not altered.
> nilnandan@nilnandan-Dell-XPS:~$
> nilnandan@nilnandan-Dell-XPS:~$ echo $?
> 0
> nilnandan@nilnandan-Dell-XPS:~$
> nilnandan@nilnandan-Dell-XPS:~$ pt-online-schema-change --alter 'ADD KEY i_c(c)' h=127.0.0.1,u=root,p=root,D=dbtest,t=sbtest --nocheck-plan --alter-foreign-keys-method auto --statistics --dry-run
> Operation, tries, wait:
> copy_rows, 10, 0.25
> create_triggers, 10, 1
> drop_triggers, 10, 1
> swap_tables, 10, 1
> update_foreign_keys, 10, 1
> No foreign keys reference `dbtest`.`sbtest`; ignoring --alter-foreign-keys-method.
> Starting a dry run. `dbtest`.`sbtest` will not be altered. Specify --execute instead of --dry-run to alter the table.
> Creating new table...
> Created new table dbtest._sbtest_new OK.
> Altering new table...
> 2014-08-04T15:34:06 Dropping new table...
> 2014-08-04T15:34:06 Dropped new table OK.
> # Event Count
> # ====== =====
> # INSERT 0
> Dry run complete. `dbtest`.`sbtest` was not altered.
>
> Segmentation fault (core dumped)
> nilnandan@nilnandan-Dell-XPS:~$
> nilnandan@nilnandan-Dell-XPS:~$ echo $?
> 139
> nilnandan@nilnandan-Dell-XPS:~$
>
>
> ** Changed in: percona-toolkit
> Status: New => Incomplete
>

--
EDICOM

*PEDRO IBAÑEZ REQUENA*
Systems Engineer
EDICOM
*Tel.* +34 902 119 229 / 961 366 564 ext. 5232
*Email:* <email address hidden> <mailto:<email address hidden>>

 *EDICOM HIGHLIGHTS*

 Edicom Qualified Challenger
<http://www.edicomgroup.com/es_ES/magic-quadrant-gartner/edicom>

www.edicomgroup.com <http://www.edicomgroup.com> |
newsroom.edicomgroup.com <http://newsroom.edicomgroup.com> | Privacy
Policy <http://www.edicomgroup.com/es_ES/info/privacy> |

Para quejas o reclamac...

Read more...

Revision history for this message
Frank Cizmich (frank-cizmich) wrote :

I'm also unable to replicate this using PT 2.2.8

--dry-run exits with 0 when successful, 255 otherwise.

same with --execute

Pedro, can you provide the script you are using? How are you checking the exit value?

Regards!

Revision history for this message
Pedro Ibáñez (pibanez) wrote :

Ok, I have found the problem, it is the fault of my script, your awesome tool is working properly, look:

 [[ "${DEBUG}" -eq "0" ]] && pt-online-schema-change --alter "${ALTER}" h=${HOST},u=${USUARIO},p=${PASS},D=${BBDD},t=${tabla} --nocheck-plan --alter-foreign-keys-method auto --statistics --dry-run 2> ${DRYRUNLOG}

 [[ "${DEBUG}" -eq "1" ]] && echo pt-online-schema-change --alter "${ALTER}" h=${HOST},u=${USUARIO},p=${PASS},D=${BBDD},t=${tabla} --nocheck-plan --alter-foreign-keys-method auto --statistics --dry-run

RETORNO=$?

I was saving the return value of the echo command instead of the right pt-online-schema-change return code, I just changed the order of the checks and now everything is working properly.
I have to apology for the inconvenience and your time checking it out, thank you very much for your help guys.

Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for Percona Toolkit because there has been no activity for 60 days.]

Changed in percona-toolkit:
status: Incomplete → Expired
Revision history for this message
Shahriyar Rzayev (rzayev-sehriyar) wrote :

Percona now uses JIRA for bug reports so this bug report is migrated to: https://jira.percona.com/browse/PT-1232

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.