~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/mysqltest.cc

  • Committer: Brian Aker
  • Date: 2008-07-15 01:48:24 UTC
  • mfrom: (77.1.101 codestyle)
  • Revision ID: brian@tangent.org-20080715014824-3ahhe2znii7ummb7
Monty's merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
#include <hash.h>
43
43
#include <stdarg.h>
44
44
#include <violite.h>
45
 
#ifdef HAVE_SYS_WAIT_H
46
 
#include <sys/wait.h>
47
 
#endif
48
 
 
49
45
 
50
46
 
51
47
#define MAX_VAR_NAME_LENGTH    256
3178
3174
  const char *query;
3179
3175
 
3180
3176
 
3181
 
#ifdef HAVE_NDB_BINLOG
3182
 
  /*
3183
 
    Wait for ndb binlog to be up-to-date with all changes
3184
 
    done on the local mysql server
3185
 
  */
3186
 
  {
3187
 
    ulong have_ndbcluster;
3188
 
    if (mysql_query(mysql, query= "show variables like 'have_ndbcluster'"))
3189
 
      die("'%s' failed: %d %s", query,
3190
 
          mysql_errno(mysql), mysql_error(mysql));
3191
 
    if (!(res= mysql_store_result(mysql)))
3192
 
      die("mysql_store_result() returned NULL for '%s'", query);
3193
 
    if (!(row= mysql_fetch_row(res)))
3194
 
      die("Query '%s' returned empty result", query);
3195
 
 
3196
 
    have_ndbcluster= strcmp("YES", row[1]) == 0;
3197
 
    mysql_free_result(res);
3198
 
 
3199
 
    if (have_ndbcluster)
3200
 
    {
3201
 
      uint64_t start_epoch= 0, handled_epoch= 0,
3202
 
        latest_epoch=0, latest_trans_epoch=0,
3203
 
        latest_handled_binlog_epoch= 0, latest_received_binlog_epoch= 0,
3204
 
        latest_applied_binlog_epoch= 0;
3205
 
      int count= 0;
3206
 
      int do_continue= 1;
3207
 
      while (do_continue)
3208
 
      {
3209
 
        const char binlog[]= "binlog";
3210
 
        const char latest_epoch_str[]=
3211
 
          "latest_epoch=";
3212
 
        const char latest_trans_epoch_str[]=
3213
 
          "latest_trans_epoch=";
3214
 
        const char latest_received_binlog_epoch_str[]=
3215
 
          "latest_received_binlog_epoch";
3216
 
        const char latest_handled_binlog_epoch_str[]=
3217
 
          "latest_handled_binlog_epoch=";
3218
 
        const char latest_applied_binlog_epoch_str[]=
3219
 
          "latest_applied_binlog_epoch=";
3220
 
        if (count)
3221
 
          sleep(1);
3222
 
        if (mysql_query(mysql, query= "show engine ndb status"))
3223
 
          die("failed in '%s': %d %s", query,
3224
 
              mysql_errno(mysql), mysql_error(mysql));
3225
 
        if (!(res= mysql_store_result(mysql)))
3226
 
          die("mysql_store_result() returned NULL for '%s'", query);
3227
 
        while ((row= mysql_fetch_row(res)))
3228
 
        {
3229
 
          if (strcmp(row[1], binlog) == 0)
3230
 
          {
3231
 
            const char *status= row[2];
3232
 
 
3233
 
            /* latest_epoch */
3234
 
            while (*status && strncmp(status, latest_epoch_str,
3235
 
                                      sizeof(latest_epoch_str)-1))
3236
 
              status++;
3237
 
            if (*status)
3238
 
            {
3239
 
              status+= sizeof(latest_epoch_str)-1;
3240
 
              latest_epoch= strtoull(status, (char**) 0, 10);
3241
 
            }
3242
 
            else
3243
 
              die("result does not contain '%s' in '%s'",
3244
 
                  latest_epoch_str, query);
3245
 
            /* latest_trans_epoch */
3246
 
            while (*status && strncmp(status, latest_trans_epoch_str,
3247
 
                                      sizeof(latest_trans_epoch_str)-1))
3248
 
              status++;
3249
 
            if (*status)
3250
 
            {
3251
 
              status+= sizeof(latest_trans_epoch_str)-1;
3252
 
              latest_trans_epoch= strtoull(status, (char**) 0, 10);
3253
 
            }
3254
 
            else
3255
 
              die("result does not contain '%s' in '%s'",
3256
 
                  latest_trans_epoch_str, query);
3257
 
            /* latest_received_binlog_epoch */
3258
 
            while (*status &&
3259
 
                   strncmp(status, latest_received_binlog_epoch_str,
3260
 
                           sizeof(latest_received_binlog_epoch_str)-1))
3261
 
              status++;
3262
 
            if (*status)
3263
 
            {
3264
 
              status+= sizeof(latest_received_binlog_epoch_str)-1;
3265
 
              latest_received_binlog_epoch= strtoull(status, (char**) 0, 10);
3266
 
            }
3267
 
            else
3268
 
              die("result does not contain '%s' in '%s'",
3269
 
                  latest_received_binlog_epoch_str, query);
3270
 
            /* latest_handled_binlog */
3271
 
            while (*status &&
3272
 
                   strncmp(status, latest_handled_binlog_epoch_str,
3273
 
                           sizeof(latest_handled_binlog_epoch_str)-1))
3274
 
              status++;
3275
 
            if (*status)
3276
 
            {
3277
 
              status+= sizeof(latest_handled_binlog_epoch_str)-1;
3278
 
              latest_handled_binlog_epoch= strtoull(status, (char**) 0, 10);
3279
 
            }
3280
 
            else
3281
 
              die("result does not contain '%s' in '%s'",
3282
 
                  latest_handled_binlog_epoch_str, query);
3283
 
            /* latest_applied_binlog_epoch */
3284
 
            while (*status &&
3285
 
                   strncmp(status, latest_applied_binlog_epoch_str,
3286
 
                           sizeof(latest_applied_binlog_epoch_str)-1))
3287
 
              status++;
3288
 
            if (*status)
3289
 
            {
3290
 
              status+= sizeof(latest_applied_binlog_epoch_str)-1;
3291
 
              latest_applied_binlog_epoch= strtoull(status, (char**) 0, 10);
3292
 
            }
3293
 
            else
3294
 
              die("result does not contain '%s' in '%s'",
3295
 
                  latest_applied_binlog_epoch_str, query);
3296
 
            if (count == 0)
3297
 
              start_epoch= latest_trans_epoch;
3298
 
            break;
3299
 
          }
3300
 
        }
3301
 
        if (!row)
3302
 
          die("result does not contain '%s' in '%s'",
3303
 
              binlog, query);
3304
 
        if (latest_handled_binlog_epoch > handled_epoch)
3305
 
          count= 0;
3306
 
        handled_epoch= latest_handled_binlog_epoch;
3307
 
        count++;
3308
 
        if (latest_handled_binlog_epoch >= start_epoch)
3309
 
          do_continue= 0;
3310
 
        else if (count > 30)
3311
 
        {
3312
 
          break;
3313
 
        }
3314
 
        mysql_free_result(res);
3315
 
      }
3316
 
    }
3317
 
  }
3318
 
#endif
3319
3177
  if (mysql_query(mysql, query= "show master status"))
3320
3178
    die("failed in 'show master status': %d %s",
3321
3179
        mysql_errno(mysql), mysql_error(mysql));