Skip to content

Commit 8a59d7e

Browse files
author
Shlomi Noach
committed
failing on PK value change
1 parent e740d4b commit 8a59d7e

3 files changed

Lines changed: 27 additions & 44 deletions

File tree

go/logic/applier.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,25 @@ func (this *Applier) ShowStatusVariable(variableName string) (result int64, err
899899
return result, nil
900900
}
901901

902+
func (this *Applier) validateUpdateDoesNotModifyMigrationUniqueKeyColumns(dmlEvent *binlog.BinlogDMLEvent) error {
903+
// log.Debugf("............ UPDATE")
904+
// log.Debugf("............ UPDATE: %+v", this.migrationContext.UniqueKey.Columns.String())
905+
// log.Debugf("............ UPDATE: %+v", dmlEvent.WhereColumnValues.String())
906+
// log.Debugf("............ UPDATE: %+v", dmlEvent.NewColumnValues.String())
907+
for _, column := range this.migrationContext.UniqueKey.Columns.Columns() {
908+
tableOrdinal := this.migrationContext.OriginalTableColumns.Ordinals[column.Name]
909+
whereColumnValue := dmlEvent.WhereColumnValues.AbstractValues()[tableOrdinal]
910+
newColumnValue := dmlEvent.NewColumnValues.AbstractValues()[tableOrdinal]
911+
// log.Debugf("............ UPDATE: old value= %+v", whereColumnValue)
912+
// log.Debugf("............ UPDATE: new value= %+v", newColumnValue)
913+
// log.Debugf("............ UPDATE: equals? %+v", newColumnValue == whereColumnValue)
914+
if newColumnValue != whereColumnValue {
915+
return log.Errorf("gh-ost detected an UPDATE to a unique key column this migration is iterating on. Such update is not supported. Column is %s", column.Name)
916+
}
917+
}
918+
return nil
919+
}
920+
902921
// buildDMLEventQuery creates a query to operate on the ghost table, based on an intercepted binlog
903922
// event entry on the original table.
904923
func (this *Applier) buildDMLEventQuery(dmlEvent *binlog.BinlogDMLEvent) (query string, args []interface{}, rowsDelta int64, err error) {
@@ -915,6 +934,9 @@ func (this *Applier) buildDMLEventQuery(dmlEvent *binlog.BinlogDMLEvent) (query
915934
}
916935
case binlog.UpdateDML:
917936
{
937+
if err := this.validateUpdateDoesNotModifyMigrationUniqueKeyColumns(dmlEvent); err != nil {
938+
return query, args, rowsDelta, err
939+
}
918940
query, sharedArgs, uniqueKeyArgs, err := sql.BuildDMLUpdateQuery(dmlEvent.DatabaseName, this.migrationContext.GetGhostTableName(), this.migrationContext.OriginalTableColumns, this.migrationContext.SharedColumns, this.migrationContext.MappedSharedColumns, &this.migrationContext.UniqueKey.Columns, dmlEvent.NewColumnValues.AbstractValues(), dmlEvent.WhereColumnValues.AbstractValues())
919941
args = append(args, sharedArgs...)
920942
args = append(args, uniqueKeyArgs...)

localtests/test.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,12 @@ test_single() {
170170

171171
build_binary() {
172172
echo "Building"
173+
rm -f $ghost_binary
173174
go build -o $ghost_binary go/cmd/gh-ost/main.go
175+
if [ $? -ne 0 ] ; then
176+
echo "Build failure"
177+
exit 1
178+
fi
174179
}
175180

176181
test_all() {

localtests/update-pk-column/create.sql

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)