File: bidirectional.t

package info (click to toggle)
percona-toolkit 3.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 68,916 kB
  • sloc: perl: 241,287; sql: 22,868; sh: 19,746; javascript: 6,799; makefile: 353; awk: 38; python: 30; sed: 1
file content (540 lines) | stat: -rw-r--r-- 19,224 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
#!/usr/bin/env perl

BEGIN {
   die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
      unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
   unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
};

use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use Test::More;

use PerconaTest;
use Sandbox;
require "$trunk/bin/pt-table-sync";

use Data::Dumper;
$Data::Dumper::Indent    = 0;
$Data::Dumper::Sortkeys  = 1;
$Data::Dumper::Quotekeys = 0;

my $dp = new DSNParser(opts=>$dsn_opts);
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
my $c1_dbh = $sb->get_dbh_for('master');

diag(`$trunk/sandbox/start-sandbox master 2900 >/dev/null`);
my $r1_dbh = $sb->get_dbh_for('master3');

diag(`$trunk/sandbox/start-sandbox master 2901 >/dev/null`);
my $r2_dbh = $sb->get_dbh_for('master4');

if ( !$c1_dbh ) {
   plan skip_all => 'Cannot connect to sandbox master';
}
elsif ( !$r1_dbh ) {
   plan skip_all => 'Cannot connect to second sandbox master';

}
else {
   plan tests => 23;
}

my $output;
my $cnf = '/tmp/12345/my.sandbox.cnf';
my @args = ('-F', $cnf, 'h=127.1,P=12345', 'P=2900', qw(-d bidi --bidirectional));

$sb->wipe_clean($c1_dbh);
$sb->wipe_clean($r1_dbh);

sub load_bidi_data {
   $sb->load_file('master', 't/pt-table-sync/samples/bidirectional/table.sql');
   $sb->load_file('master3', 't/pt-table-sync/samples/bidirectional/table.sql');
   $sb->load_file('master', 't/pt-table-sync/samples/bidirectional/master-data.sql');
   $sb->load_file('master3', 't/pt-table-sync/samples/bidirectional/remote-1.sql');
}

my $r1_data_synced =  [
   [1,   'abc',   1,  '2010-02-01 05:45:30'],
   [2,   'def',   2,  '2010-01-31 06:11:11'],
   [3,   'ghi',   5,  '2010-02-01 09:17:52'],
   [4,   'jkl',   6,  '2010-02-01 10:11:33'],
   [5,   undef,   0,  '2010-02-02 05:10:00'],
   [6,   'p',     4,  '2010-01-31 10:17:00'],
   [7,   'qrs',   5,  '2010-02-01 10:11:11'],
   [8,   'tuv',   6,  '2010-01-31 10:17:20'],
   [9,   'wxy',   7,  '2010-02-01 10:17:00'],
   [10,  'z',     8,  '2010-01-31 10:17:08'],
   [11,  '?',     0,  '2010-01-29 11:17:12'],
   [12,  '',      0,  '2010-02-01 11:17:00'],
   [13,  'hmm',   1,  '2010-02-02 12:17:31'],
   [14,  undef,   0,  '2010-01-31 10:17:00'],
   [15,  'gtg',   7,  '2010-02-02 06:01:08'],
   [17,  'good',  1,  '2010-02-02 21:38:03'],
   [20,  'new', 100,  '2010-02-01 04:15:36'],
];


load_bidi_data();
$c1_dbh->do('use bidi');
$r1_dbh->do('use bidi');

my $res = $c1_dbh->selectall_arrayref('select * from bidi.t order by id');
is_deeply(
   $res,
   [
      [1,   'abc',   1,  '2010-02-01 05:45:30'],
      [2,   'def',   2,  '2010-01-31 06:11:11'],
      [3,   'ghi',   5,  '2010-02-01 09:17:52'],
      [4,   'jkl',   6,  '2010-02-01 10:11:33'],
      [5,   'mno',   3,  '2010-02-01 10:17:40'],
      [6,   'p',     4,  '2010-01-31 10:17:00'],
      [7,   'qrs',   5,  '2010-02-01 10:11:11'],
      [8,   'tuv',   6,  '2010-01-31 10:17:20'],
      [9,   'wxy',   7,  '2010-02-01 10:17:00'],
      [10,  'z',     8,  '2010-01-31 10:17:08'],
      [12,  '',      0,  '2010-02-01 11:17:00'],
      [13,  undef,   0,  '2010-02-01 12:17:31'],
      [14,  undef,   0,  '2010-01-31 10:17:00'],
      [15,  'NA',    0,  '2010-01-31 07:00:01'],
      [20,  'new', 100,  '2010-02-01 04:15:36'],
   ],
   'c1 data before sync'
);

$res = $r1_dbh->selectall_arrayref('select * from bidi.t order by id');
is_deeply(
   $res,
   [
      [1,   'abc',   1,  '2010-02-01 05:45:30'],
      [2,   'def',   2,  '2010-01-31 06:11:11'],
      [3,   'ghi',   5,  '2010-02-01 09:17:51'],
      [4,   'jkl',   6,  '2010-02-01 10:11:33'],
      [5,   undef,   0,  '2010-02-02 05:10:00'],
      [6,   'p',     4,  '2010-01-31 10:17:00'],
      [7,   'qrs',   5,  '2010-02-01 10:11:11'],
      [8,   'tuv',   6,  '2010-01-31 10:17:20'],
      [9,   'wxy',   7,  '2010-02-01 10:17:00'],
      [10,  'z',     8,  '2010-01-31 10:17:08'],
      [11,  '?',     0,  '2010-01-29 11:17:12'],
      [12,  '',      0,  '2010-02-01 11:17:00'],
      [13,  'hmm',   1,  '2010-02-02 12:17:31'],
      [14,  undef,   0,  '2010-01-31 10:17:00'],
      [15,  'gtg',   7,  '2010-02-02 06:01:08'],
      [17,  'good',  1,  '2010-02-02 21:38:03'],
   ],
   'r1 data before sync'
);

$output = output(
   sub { pt_table_sync::main(@args, qw(--print --execute),
      qw(--conflict-column ts --conflict-comparison newest)) }
);

is(
   $output,
"/*127.1:2900*/ UPDATE `bidi`.`t` SET `c`='ghi', `d`='5', `ts`='2010-02-01 09:17:52' WHERE `id`='3' LIMIT 1;
/*127.1:12345*/ UPDATE `bidi`.`t` SET `c`=NULL, `d`='0', `ts`='2010-02-02 05:10:00' WHERE `id`='5' LIMIT 1;
/*127.1:12345*/ INSERT INTO `bidi`.`t`(`id`, `c`, `d`, `ts`) VALUES ('11', '?', '0', '2010-01-29 11:17:12');
/*127.1:12345*/ UPDATE `bidi`.`t` SET `c`='hmm', `d`='1', `ts`='2010-02-02 12:17:31' WHERE `id`='13' LIMIT 1;
/*127.1:12345*/ UPDATE `bidi`.`t` SET `c`='gtg', `d`='7', `ts`='2010-02-02 06:01:08' WHERE `id`='15' LIMIT 1;
/*127.1:12345*/ INSERT INTO `bidi`.`t`(`id`, `c`, `d`, `ts`) VALUES ('17', 'good', '1', '2010-02-02 21:38:03');
/*127.1:2900*/ INSERT INTO `bidi`.`t`(`id`, `c`, `d`, `ts`) VALUES ('20', 'new', '100', '2010-02-01 04:15:36');
",
   '--print correct SQL for c1<->r1 bidirectional sync'
);

$res = $c1_dbh->selectall_arrayref('select * from bidi.t order by id');
is_deeply(
   $res,
   $r1_data_synced,
   'Synced c1'
);

$res = $r1_dbh->selectall_arrayref('select * from bidi.t order by id');
is_deeply(
   $res,
   $r1_data_synced,
   'Synced r1'
);

# Set a threshold which will cause some unresolvable conflicts.
load_bidi_data();

my $err = '';
{
   local *STDERR;
   open STDERR, '>', \$err;
   $output = output(
      sub { pt_table_sync::main(@args, qw(--print --execute),
         qw(--conflict-column ts --conflict-comparison newest),
         qw(--conflict-threshold 30m)) }
   );
}

is(
   $output,
"/*127.1:12345*/ UPDATE `bidi`.`t` SET `c`=NULL, `d`='0', `ts`='2010-02-02 05:10:00' WHERE `id`='5' LIMIT 1;
/*127.1:12345*/ INSERT INTO `bidi`.`t`(`id`, `c`, `d`, `ts`) VALUES ('11', '?', '0', '2010-01-29 11:17:12');
/*127.1:12345*/ UPDATE `bidi`.`t` SET `c`='hmm', `d`='1', `ts`='2010-02-02 12:17:31' WHERE `id`='13' LIMIT 1;
/*127.1:12345*/ UPDATE `bidi`.`t` SET `c`='gtg', `d`='7', `ts`='2010-02-02 06:01:08' WHERE `id`='15' LIMIT 1;
/*127.1:12345*/ INSERT INTO `bidi`.`t`(`id`, `c`, `d`, `ts`) VALUES ('17', 'good', '1', '2010-02-02 21:38:03');
/*127.1:2900*/ INSERT INTO `bidi`.`t`(`id`, `c`, `d`, `ts`) VALUES ('20', 'new', '100', '2010-02-01 04:15:36');
",
  'SQL for c1<->r1 with conflict'
);

is(
   $err,
"# Cannot resolve conflict WHERE `id`='3': `ts` values do not differ by the threhold, 30m.
",
   'Warns about conflict'
);

$res = $c1_dbh->selectall_arrayref('select * from bidi.t order by id');
is_deeply(
   $res,
   [
      [1,   'abc',   1,  '2010-02-01 05:45:30'],
      [2,   'def',   2,  '2010-01-31 06:11:11'],
      [3,   'ghi',   5,  '2010-02-01 09:17:52'], # not synced
      [4,   'jkl',   6,  '2010-02-01 10:11:33'],
      [5,   undef,   0,  '2010-02-02 05:10:00'],
      [6,   'p',     4,  '2010-01-31 10:17:00'],
      [7,   'qrs',   5,  '2010-02-01 10:11:11'],
      [8,   'tuv',   6,  '2010-01-31 10:17:20'],
      [9,   'wxy',   7,  '2010-02-01 10:17:00'],
      [10,  'z',     8,  '2010-01-31 10:17:08'],
      [11,  '?',     0,  '2010-01-29 11:17:12'],
      [12,  '',      0,  '2010-02-01 11:17:00'],
      [13,  'hmm',   1,  '2010-02-02 12:17:31'],
      [14,  undef,   0,  '2010-01-31 10:17:00'],
      [15,  'gtg',   7,  '2010-02-02 06:01:08'],
      [17,  'good',  1,  '2010-02-02 21:38:03'],
      [20,  'new', 100,  '2010-02-01 04:15:36'],
   ],
   'Synced c1 except conflict'
);

$res = $r1_dbh->selectall_arrayref('select * from bidi.t order by id');
is_deeply(
   $res,
   [
      [1,   'abc',   1,  '2010-02-01 05:45:30'],
      [2,   'def',   2,  '2010-01-31 06:11:11'],
      [3,   'ghi',   5,  '2010-02-01 09:17:51'], # not synced
      [4,   'jkl',   6,  '2010-02-01 10:11:33'],
      [5,   undef,   0,  '2010-02-02 05:10:00'],
      [6,   'p',     4,  '2010-01-31 10:17:00'],
      [7,   'qrs',   5,  '2010-02-01 10:11:11'],
      [8,   'tuv',   6,  '2010-01-31 10:17:20'],
      [9,   'wxy',   7,  '2010-02-01 10:17:00'],
      [10,  'z',     8,  '2010-01-31 10:17:08'],
      [11,  '?',     0,  '2010-01-29 11:17:12'],
      [12,  '',      0,  '2010-02-01 11:17:00'],
      [13,  'hmm',   1,  '2010-02-02 12:17:31'],
      [14,  undef,   0,  '2010-01-31 10:17:00'],
      [15,  'gtg',   7,  '2010-02-02 06:01:08'],
      [17,  'good',  1,  '2010-02-02 21:38:03'],
      [20,  'new', 100,  '2010-02-01 04:15:36'],
   ],
   'Synced r1 except conflict'
);

# Now die on conflict error.
load_bidi_data();

{
   $err = '';
   local *STDERR;
   open STDERR, '>', \$err;
   $output = output(
      sub { pt_table_sync::main(@args, qw(--print --execute),
         qw(--conflict-column ts --conflict-comparison newest),
         qw(--conflict-threshold 30m --conflict-error die)) }
   );
};

is(
   $output,
   "",
  'No SQL for c1<->r1 with die on conflict'
);

# mk-table-sync catches death and warns instead so it can continue
# syncing other tables.
is(
   $err,
"# Cannot resolve conflict WHERE `id`='3': `ts` values do not differ by the threhold, 30m.  while doing bidi.t on 127.1
",
   'Die/warn about conflict'
);

$res = $c1_dbh->selectall_arrayref('select * from bidi.t order by id');
is_deeply(
   $res,
   [
      [1,   'abc',   1,  '2010-02-01 05:45:30'],
      [2,   'def',   2,  '2010-01-31 06:11:11'],
      [3,   'ghi',   5,  '2010-02-01 09:17:52'],
      [4,   'jkl',   6,  '2010-02-01 10:11:33'],
      [5,   'mno',   3,  '2010-02-01 10:17:40'],
      [6,   'p',     4,  '2010-01-31 10:17:00'],
      [7,   'qrs',   5,  '2010-02-01 10:11:11'],
      [8,   'tuv',   6,  '2010-01-31 10:17:20'],
      [9,   'wxy',   7,  '2010-02-01 10:17:00'],
      [10,  'z',     8,  '2010-01-31 10:17:08'],
      [12,  '',      0,  '2010-02-01 11:17:00'],
      [13,  undef,   0,  '2010-02-01 12:17:31'],
      [14,  undef,   0,  '2010-01-31 10:17:00'],
      [15,  'NA',    0,  '2010-01-31 07:00:01'],
      [20,  'new', 100,  '2010-02-01 04:15:36'],
   ],
   'c1 not synced due to die on conflict'
);

$res = $r1_dbh->selectall_arrayref('select * from bidi.t order by id');
is_deeply(
   $res,
   [
      [1,   'abc',   1,  '2010-02-01 05:45:30'],
      [2,   'def',   2,  '2010-01-31 06:11:11'],
      [3,   'ghi',   5,  '2010-02-01 09:17:51'],
      [4,   'jkl',   6,  '2010-02-01 10:11:33'],
      [5,   undef,   0,  '2010-02-02 05:10:00'],
      [6,   'p',     4,  '2010-01-31 10:17:00'],
      [7,   'qrs',   5,  '2010-02-01 10:11:11'],
      [8,   'tuv',   6,  '2010-01-31 10:17:20'],
      [9,   'wxy',   7,  '2010-02-01 10:17:00'],
      [10,  'z',     8,  '2010-01-31 10:17:08'],
      [11,  '?',     0,  '2010-01-29 11:17:12'],
      [12,  '',      0,  '2010-02-01 11:17:00'],
      [13,  'hmm',   1,  '2010-02-02 12:17:31'],
      [14,  undef,   0,  '2010-01-31 10:17:00'],
      [15,  'gtg',   7,  '2010-02-02 06:01:08'],
      [17,  'good',  1,  '2010-02-02 21:38:03'],
   ],
   'r1 not synced due to die on conflict'
);


# #############################################################################
# Test bidirectional sync with 3 servers.
# #############################################################################

# It's confusing but master4 = 2901, aka our 3rd master server.

SKIP: {
   skip 'Cannot connect to third sandbox master', 9 unless $r2_dbh;

   load_bidi_data();
   $sb->load_file('master4', 't/pt-table-sync/samples/bidirectional/table.sql');
   $sb->load_file('master4', 't/pt-table-sync/samples/bidirectional/remote-2.sql');

   $res = $r2_dbh->selectall_arrayref('select * from bidi.t order by id');
   is_deeply(
      $res,
      [
         [1,   'abc',   1,  '2010-02-01 05:45:30'],
         [3,   'ghi',   5,  '2010-02-01 09:17:52'], 
         [4,   'jkl',   6,  '2010-02-01 10:11:33'],
         [5,   'mno',   3,  '2010-02-01 10:17:40'],
         [6,   'p',     4,  '2010-01-31 10:17:00'],
         [7,   'qrs',   5,  '2010-02-01 10:11:11'],
         [8,   'TUV',   6,  '2010-01-31 10:17:20'],
         [9,   'wxy',   7,  '2010-02-01 10:17:00'],
         [10,  'rdy',   5,  '2010-02-02 09:09:10'],
         [11,  '?',     0,  '2010-01-29 12:19:48'],
         [12,  '',      0,  '2010-02-01 13:17:19'],
         [13,  undef,   0,  '2010-02-01 12:17:31'],
         [14,  undef,   0,  '2010-02-02 13:00:00'],
         [15,  'NA',    0,  '2010-01-31 07:00:01'],
         [16,  undef,   0,  '2010-02-02 13:20:00'],
      ],
      'r2 data before sync'
   );

   {
      $err = '';
      local *STDERR;
      open STDERR, '>', \$err;
      $output = output(
         sub { pt_table_sync::main(@args, 'h=127.1,P=2901',
            qw(--print --execute --chunk-size 2),
            qw(--conflict-column ts --conflict-comparison newest)) }
      );
   }

   like(
      $err,
      qr/Cannot resolve conflict WHERE `id`='8': `ts` values are the same/,
      'Warned that id=8 differs but has same ts'
   );

   $res = $c1_dbh->selectall_arrayref('select * from bidi.t order by id');
   is_deeply(
      $res,
      [
         ['1','abc','1','2010-02-01 05:45:30'],
         ['2','def','2','2010-01-31 06:11:11'],
         ['3','ghi','5','2010-02-01 09:17:52'],
         ['4','jkl','6','2010-02-01 10:11:33'],
         ['5',undef,'0','2010-02-02 05:10:00'],
         ['6','p','4','2010-01-31 10:17:00'],
         ['7','qrs','5','2010-02-01 10:11:11'],
         ['8','tuv','6','2010-01-31 10:17:20'],
         ['9','wxy','7','2010-02-01 10:17:00'],
         ['10','rdy','5','2010-02-02 09:09:10'],
         ['11','?','0','2010-01-29 12:19:48'],
         ['12','','0','2010-02-01 13:17:19'],
         ['13','hmm','1','2010-02-02 12:17:31'],
         ['14',undef,'0','2010-02-02 13:00:00'],
         ['15','gtg','7','2010-02-02 06:01:08'],
         ['16',undef,'0','2010-02-02 13:20:00'],
         ['17','good','1','2010-02-02 21:38:03'],
         ['20','new','100','2010-02-01 04:15:36']
      ],
      'c1 data synced 1st pass'
   );

   $res = $r1_dbh->selectall_arrayref('select * from bidi.t order by id');
   is_deeply(
      $res,
      [
         ['1','abc','1','2010-02-01 05:45:30'],
         ['2','def','2','2010-01-31 06:11:11'],
         ['3','ghi','5','2010-02-01 09:17:52'],
         ['4','jkl','6','2010-02-01 10:11:33'],
         ['5',undef,'0','2010-02-02 05:10:00'],
         ['6','p','4','2010-01-31 10:17:00'],
         ['7','qrs','5','2010-02-01 10:11:11'],
         ['8','tuv','6','2010-01-31 10:17:20'],
         ['9','wxy','7','2010-02-01 10:17:00'],
         ['10','z','8','2010-01-31 10:17:08'],
         ['11','?','0','2010-01-29 11:17:12'],
         ['12','','0','2010-02-01 11:17:00'],
         ['13','hmm','1','2010-02-02 12:17:31'],
         ['14',undef,'0','2010-01-31 10:17:00'],
         ['15','gtg','7','2010-02-02 06:01:08'],
         ['17','good','1','2010-02-02 21:38:03'],
         ['20','new','100','2010-02-01 04:15:36']
      ],
      'r1 data synced 1st pass'
   );

   $res = $r2_dbh->selectall_arrayref('select * from bidi.t order by id');
   is_deeply(
      $res,
      [
         ['1','abc','1','2010-02-01 05:45:30'],
         ['2','def','2','2010-01-31 06:11:11'],
         ['3','ghi','5','2010-02-01 09:17:52'],
         ['4','jkl','6','2010-02-01 10:11:33'],
         ['5',undef,'0','2010-02-02 05:10:00'],
         ['6','p','4','2010-01-31 10:17:00'],
         ['7','qrs','5','2010-02-01 10:11:11'],
         ['8','TUV','6','2010-01-31 10:17:20'],
         ['9','wxy','7','2010-02-01 10:17:00'],
         ['10','rdy','5','2010-02-02 09:09:10'],
         ['11','?','0','2010-01-29 12:19:48'],
         ['12','','0','2010-02-01 13:17:19'],
         ['13','hmm','1','2010-02-02 12:17:31'],
         ['14',undef,'0','2010-02-02 13:00:00'],
         ['15','gtg','7','2010-02-02 06:01:08'],
         ['16',undef,'0','2010-02-02 13:20:00'],
         ['17','good','1','2010-02-02 21:38:03'],
         ['20','new','100','2010-02-01 04:15:36']
      ],
      'r2 data synced first pass'
   );

   # 2nd pass to sync r2 changes to r1
   {
      $err = '';
      local *STDERR;
      open STDERR, '>', \$err;
      $output = output(
         sub { pt_table_sync::main(@args, 'h=127.1,P=2901',
            qw(--print --execute --chunk-size 2),
            qw(--conflict-column ts --conflict-comparison newest)) }
      );
   }
   
   like(
      $err,
      qr/Cannot resolve conflict WHERE `id`='8': `ts` values are the same/,
      'Warned again that id=8 differs but has same ts'
   );

   my $all_synced = [
      ['1','abc','1','2010-02-01 05:45:30'],
      ['2','def','2','2010-01-31 06:11:11'],
      ['3','ghi','5','2010-02-01 09:17:52'],
      ['4','jkl','6','2010-02-01 10:11:33'],
      ['5',undef,'0','2010-02-02 05:10:00'],
      ['6','p','4','2010-01-31 10:17:00'],
      ['7','qrs','5','2010-02-01 10:11:11'],
      ['8','tuv','6','2010-01-31 10:17:20'],
      ['9','wxy','7','2010-02-01 10:17:00'],
      ['10','rdy','5','2010-02-02 09:09:10'],
      ['11','?','0','2010-01-29 12:19:48'],
      ['12','','0','2010-02-01 13:17:19'],
      ['13','hmm','1','2010-02-02 12:17:31'],
      ['14',undef,'0','2010-02-02 13:00:00'],
      ['15','gtg','7','2010-02-02 06:01:08'],
      ['16',undef,'0','2010-02-02 13:20:00'],
      ['17','good','1','2010-02-02 21:38:03'],
      ['20','new','100','2010-02-01 04:15:36']
   ];

   $res = $c1_dbh->selectall_arrayref('select * from bidi.t order by id');
   is_deeply(
      $res,
      $all_synced,
      'c1 data synced 2nd pass'
   );

   $res = $r1_dbh->selectall_arrayref('select * from bidi.t order by id');
   is_deeply(
      $res,
      $all_synced,
      'r1 data synced 2nd pass'
   );

   $res = $r2_dbh->selectall_arrayref('select * from bidi.t order by id');
   is_deeply(
      $res,
      [
         ['1','abc','1','2010-02-01 05:45:30'],
         ['2','def','2','2010-01-31 06:11:11'],
         ['3','ghi','5','2010-02-01 09:17:52'],
         ['4','jkl','6','2010-02-01 10:11:33'],
         ['5',undef,'0','2010-02-02 05:10:00'],
         ['6','p','4','2010-01-31 10:17:00'],
         ['7','qrs','5','2010-02-01 10:11:11'],
         # Identical to $all_synced except this conflicted row:
            ['8','TUV','6','2010-01-31 10:17:20'],
         ['9','wxy','7','2010-02-01 10:17:00'],
         ['10','rdy','5','2010-02-02 09:09:10'],
         ['11','?','0','2010-01-29 12:19:48'],
         ['12','','0','2010-02-01 13:17:19'],
         ['13','hmm','1','2010-02-02 12:17:31'],
         ['14',undef,'0','2010-02-02 13:00:00'],
         ['15','gtg','7','2010-02-02 06:01:08'],
         ['16',undef,'0','2010-02-02 13:20:00'],
         ['17','good','1','2010-02-02 21:38:03'],
         ['20','new','100','2010-02-01 04:15:36'],
      ],
      'r2 data synced 2nd pass'
   );
}

# #############################################################################
# Done.
# #############################################################################
diag(`$trunk/sandbox/stop-sandbox 2901 >/dev/null`);
diag(`$trunk/sandbox/stop-sandbox 2900 >/dev/null`);
$sb->wipe_clean($c1_dbh);
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
exit;