O escravo não está funcionando devido a um erro de chave primária, conforme mostrado abaixo:
Last_SQL_Errno: 1062
Last_SQL_Error: Error 'Duplicate entry '550696860' for key 'PRIMARY'' on query.
Default database: 'vserv'.
Query:
'INSERT INTO ox_data_intermediate_ad
(date_time, ad_id, zone_id, clicks, impressions,
requests, operation_interval, operation_interval_id,
interval_start, interval_end, creative_id, updated)
SELECT
date_time, ad_id, zone_id, SUM(clicks) AS clicks,
SUM(impressions) AS impressions, SUM(requests) AS requests,
5 AS operation_interval, 1871 AS operation_interval_id,
'2012-05-26 11:55:00' AS interval_start,
'2012-05-26 11:59:59' AS interval_end,
0 AS creative_id, '2012-05-26 12:04:01' AS updated
FROM
(
SELECT
interval_start AS date_time, creative_id AS ad_id, zone_id AS zone_id,
count AS clicks, 0 AS impressions, 0 AS requests
FROM
ox_data_bkt_c
WHERE
interval_start >= '2012-05-26 11:55:00'
AN
A consulta mencionada não tenta inserir a coluna auto-incrementada data_intermediate_ad_id
. Ele espera que o mysql adicione automaticamente o próximo ID. Quando verifiquei o escravo, encontrei um registro para a chave primária 550696860.
Mestre é 5.0 e escravo é 5.5.24
O segundo escravo com versão 5.5.21 está funcionando bem. Este é um bug relacionado à versão 5.5.24?
A query que está com problema é a seguinte:
INSERT INTO
ox_data_intermediate_ad
(date_time, ad_id, zone_id, clicks, impressions, requests, operation_interval, operation_interval_id, interval_start, interval_end, creative_id, updated)
SELECT
date_time, ad_id, zone_id, SUM(clicks) AS clicks, SUM(impressions) AS impressions, SUM(requests) AS requests, 5 AS operation_interval, 1591 AS operation_interval_id, '2012-05-25 12:35:00' AS interval_start, '2012-05-25 12:39:59' AS interval_end, 0 AS creative_id, '2012-05-25 12:43:01' AS updated
FROM
(
SELECT
interval_start AS date_time, creative_id AS ad_id, zone_id AS zone_id, count AS clicks, 0 AS impressions, 0 AS requests
FROM
ox_data_bkt_c
WHERE
interval_start >= '2012-05-25 12:35:00'
AND
interval_start <= '2012-05-25 12:39:59' UNION ALL
SELECT
interval_start AS date_time, creative_id AS ad_id, zone_id AS zone_id, 0 AS clicks, count AS impressions, 0 AS requests
FROM
ox_data_bkt_m
WHERE
interval_start >= '2012-05-25 12:35:00'
AND
interval_start <= '2012-05-25 12:39:59' UNION ALL
SELECT
interval_start AS date_time, creative_id AS ad_id, zone_id AS zone_id, 0 AS clicks, 0 AS impressions, count AS requests
FROM
ox_data_bkt_r
WHERE
interval_start >= '2012-05-25 12:35:00'
AND
interval_start <= '2012-05-25 12:39:59'
) AS virtual_table
GROUP BY
date_time, ad_id, zone_id
Gostaria de saber por que o escravo tem um problema com a insert into ... select
declaração.
Erro de chave duplicada nunca deve acontecer. Quando isso acontecer, provavelmente
Nunca escreva para um Escravo. Recomenda-se configurar readonly=ON no Slave. Isso (principalmente) evitará gravações acidentais. No entanto, o usuário 'root' (ou qualquer usuário SUPER) ignorará a verificação somente leitura.
Como Aaron mencionou, o percona.com possui uma ferramenta para verificar a consistência entre o mestre e o escravo. Eles têm outra ferramenta para sincronizá-los.