Fron time to time I use to move entries related to deleted instances to shadow tables, using the command:
This is now failing [*] for the instance_metadata table because of a 'duplicate entry for the primary key' problem:
DBDuplicateEntry: (pymysql.err.IntegrityError) (1062, u"Duplicate entry '6' for key 'PRIMARY'") [SQL: u'INSERT INTO shadow_instance_metadata (created_at, updated_at, deleted_at, deleted, id, `key`, value, instance_uuid) SELECT instance_metadata.created_at, instance_metadata.updated_at, instance_metadata.deleted_at, instance_metadata.deleted,
instance_metadata.id, instance_metadata.`key`, instance_metadata.value, instance_metadata.instance_uuid \nFROM instance_metadata \nWHERE instance_metadata.deleted != %(deleted_1)s ORDER BY
instance_metadata.id \n LIMIT %(param_1)s'] [parameters: {u'param_1': 1, u'deleted_1': 0}]
mysql> SELECT instance_metadata.created_at, instance_metadata.updated_at, instance_metadata.deleted_at, instance_metadata.deleted,
instance_metadata.id, instance_metadata.`key`, instance_metadata.value, instance_metadata.instance_uuid FROM instance_metadata WHERE instance_metadata.deleted != 0 ORDER BY
instance_metadata.id limit 1;
+---------------------+------------+---------------------+---------+----+-------+-------+--------------------------------------+
| created_at | updated_at | deleted_at | deleted | id | key | value | instance_uuid |
+---------------------+------------+---------------------+---------+----+-------+-------+--------------------------------------+
| 2018-09-20 07:40:56 | NULL | 2018-09-20 07:54:26 | 6 | 6 | group | node | a9000ff7-2298-454c-bf71-9e3c62ec0f3c |
+---------------------+------------+---------------------+---------+----+-------+-------+--------------------------------------+
1 row in set (0.00 sec)
But there is a 5-years old entry (if I am not wrong we were running Havana at that time) in the shadow table with that id:
mysql> select * from shadow_instance_metadata where id='6';
+---------------------+------------+---------------------+----+----------+---------------------+--------------------------------------+---------+
| created_at | updated_at | deleted_at | id | key | value | instance_uuid | deleted |
+---------------------+------------+---------------------+----+----------+---------------------+--------------------------------------+---------+
| 2014-11-04 12:57:10 | NULL | 2014-11-04 13:06:45 | 6 | director | microbosh-openstack | 5db5b17b-69f2-4f0a-bdd2-efe710268021 | 6 |
+---------------------+------------+---------------------+----+----------+---------------------+--------------------------------------+---------+
1 row in set (0.00 sec)
mysql>
I wonder how could that happen.
Can I simply remove that entry from the shadow table (I am not really interested to keep it) or are there better (cleaner) way to fix the problem ?