Commit 2cccfcd8 authored by unknown's avatar unknown

Applying Sanja's patch which makes the log handler not issue

errors when reading a log record which has a 0-length header
(like LOGREC_REDO_DROP_TABLE).


storage/maria/ma_loghandler.c:
  Functions reading record's header now don't use 0 to indicate error,
  as some valid records have a 0-length header (like REDO_DROP_TABLE).
  Instead, negative values are used for EOF and error.
storage/maria/ma_loghandler.h:
  functions to read record's header now return an int
  (either the length of this header (>=0) or some negative values
  for EOF or error).
storage/maria/ma_recovery.c:
  update to the new log handler's behaviour. Note the @todo.
storage/maria/maria_read_log.c:
  inform when program failed
storage/maria/unittest/ma_test_loghandler-t.c:
  update to new log handler's API
storage/maria/unittest/ma_test_loghandler_multigroup-t.c:
  update to new log handler's API
storage/maria/unittest/ma_test_loghandler_multithread-t.c:
  update to new log handler's API
parent 9554b40d
This diff is collapsed.
......@@ -30,6 +30,9 @@
#define TRANSLOG_FLAGS_NUM ((TRANSLOG_PAGE_CRC | TRANSLOG_SECTOR_PROTECTION | \
TRANSLOG_RECORD_CRC) + 1)
#define RECHEADER_READ_ERROR -1
#define RECHEADER_READ_EOF -2
/*
Page size in transaction log
It should be Power of 2 and multiple of DISK_DRIVE_SECTOR_SIZE
......@@ -228,9 +231,7 @@ translog_write_record(LSN *lsn, enum translog_record_type type,
extern void translog_destroy();
extern translog_size_t translog_read_record_header(LSN lsn,
TRANSLOG_HEADER_BUFFER
*buff);
extern int translog_read_record_header(LSN lsn, TRANSLOG_HEADER_BUFFER *buff);
extern void translog_free_record_header(TRANSLOG_HEADER_BUFFER *buff);
......@@ -247,10 +248,8 @@ extern my_bool translog_init_scanner(LSN lsn,
my_bool fixed_horizon,
struct st_translog_scanner_data *scanner);
extern translog_size_t translog_read_next_record_header(TRANSLOG_SCANNER_DATA
*scanner,
TRANSLOG_HEADER_BUFFER
*buff);
extern int translog_read_next_record_header(TRANSLOG_SCANNER_DATA *scanner,
TRANSLOG_HEADER_BUFFER *buff);
extern my_bool translog_lock();
extern my_bool translog_unlock();
extern void translog_lock_assert_owner();
......
......@@ -194,13 +194,13 @@ int maria_apply_log(LSN lsn, my_bool apply, FILE *trace_file)
struct st_translog_scanner_data scanner;
uint i= 1;
translog_size_t len= translog_read_record_header(lsn, &rec);
int len= translog_read_record_header(lsn, &rec);
/** @todo translog_read_record_header() should be fixed for 0-byte headers */
if (len == 0) /* means error, but apparently EOF too */
/** @todo EOF should be detected */
if (len == RECHEADER_READ_ERROR)
{
fprintf(tracef, "empty log\n");
goto end;
fprintf(tracef, "Cannot find a first record\n");
goto err;
}
if (translog_init_scanner(lsn, 1, &scanner))
......@@ -246,7 +246,7 @@ int maria_apply_log(LSN lsn, my_bool apply, FILE *trace_file)
TRANSLOG_HEADER_BUFFER rec2;
len=
translog_read_record_header(all_active_trans[sid].group_start_lsn, &rec2);
if (len == (TRANSLOG_RECORD_HEADER_MAX_SIZE + 1))
if (len < 0) /* EOF or error */
{
fprintf(tracef, "Cannot find record where it should be\n");
goto err;
......@@ -267,7 +267,7 @@ int maria_apply_log(LSN lsn, my_bool apply, FILE *trace_file)
goto err;
}
len= translog_read_next_record_header(&scanner2, &rec2);
if (len == (TRANSLOG_RECORD_HEADER_MAX_SIZE + 1))
if (len < 0) /* EOF or error */
{
fprintf(tracef, "Cannot find record where it should be\n");
goto err;
......@@ -294,9 +294,17 @@ int maria_apply_log(LSN lsn, my_bool apply, FILE *trace_file)
}
}
len= translog_read_next_record_header(&scanner, &rec);
if (len == (TRANSLOG_RECORD_HEADER_MAX_SIZE + 1))
if (len < 0)
{
fprintf(tracef, "EOF on the log\n");
switch (len)
{
case RECHEADER_READ_EOF:
fprintf(tracef, "EOF on the log\n");
break;
case RECHEADER_READ_ERROR:
fprintf(stderr, "Error reading log\n");
goto err;
}
break;
}
}
......
......@@ -90,11 +90,12 @@ int main(int argc, char **argv)
fprintf(stdout, "TRACE of the last maria_read_log\n");
if (maria_apply_log(lsn, opt_display_and_apply, stdout))
goto err;
fprintf(stdout, "SUCCESS\n");
fprintf(stdout, "%s: SUCCESS\n", my_progname);
goto end;
err:
/* don't touch anything more, in case we hit a bug */
fprintf(stderr, "%s: FAILED\n", my_progname);
exit(1);
end:
maria_end();
......
......@@ -360,8 +360,8 @@ int main(int argc __attribute__((unused)), char *argv[])
rc= 1;
{
translog_size_t len= translog_read_record_header(first_lsn, &rec);
if (len == 0)
int len= translog_read_record_header(first_lsn, &rec);
if (len == RECHEADER_READ_ERROR)
{
fprintf(stderr, "translog_read_record_header failed (%d)\n", errno);
goto err;
......@@ -392,13 +392,13 @@ int main(int argc __attribute__((unused)), char *argv[])
for (i= 1;; i++)
{
len= translog_read_next_record_header(&scanner, &rec);
if (len == 0)
if (len == RECHEADER_READ_ERROR)
{
fprintf(stderr, "1-%d translog_read_next_record_header failed (%d)\n",
i, errno);
goto err;
}
if (rec.lsn == LSN_IMPOSSIBLE)
if (len == RECHEADER_READ_EOF)
{
if (i != ITERATIONS)
{
......@@ -471,13 +471,13 @@ int main(int argc __attribute__((unused)), char *argv[])
translog_free_record_header(&rec);
len= translog_read_next_record_header(&scanner, &rec);
if (len == 0)
if (len == RECHEADER_READ_ERROR)
{
fprintf(stderr, "1-%d translog_read_next_record_header (var) "
"failed (%d)\n", i, errno);
goto err;
}
if (rec.lsn == LSN_IMPOSSIBLE)
if (len == RECHEADER_READ_EOF)
{
fprintf(stderr, "EOL met at the middle of iteration (first var) %u "
"instead of beginning of %u\n", i, ITERATIONS);
......@@ -542,12 +542,12 @@ int main(int argc __attribute__((unused)), char *argv[])
{
fprintf(stderr, "Incorrect LOGREC_VARIABLE_RECORD_2LSN_EXAMPLE "
"data read(%d) "
"type %u, strid %u, len %lu != %lu + 14, hdr len: %u, "
"type %u, strid %u, len %lu != %lu + 14, hdr len: %d, "
"ref1(%lu,0x%lx), ref2(%lu,0x%lx), "
"lsn(%lu,0x%lx)\n",
i, (uint) rec.type, (uint) rec.short_trid,
(ulong) rec.record_length, (ulong) rec_len,
(uint) len,
len,
(ulong) LSN_FILE_NO(ref1), (ulong) LSN_OFFSET(ref1),
(ulong) LSN_FILE_NO(ref2), (ulong) LSN_OFFSET(ref2),
(ulong) LSN_FILE_NO(rec.lsn), (ulong) LSN_OFFSET(rec.lsn));
......@@ -566,13 +566,13 @@ int main(int argc __attribute__((unused)), char *argv[])
translog_free_record_header(&rec);
len= translog_read_next_record_header(&scanner, &rec);
if (len == 0)
if (len == RECHEADER_READ_ERROR)
{
fprintf(stderr, "1-%d translog_read_next_record_header failed (%d)\n",
i, errno);
goto err;
}
if (rec.lsn == LSN_IMPOSSIBLE)
if (len == RECHEADER_READ_EOF)
{
fprintf(stderr, "EOL met at the middle of iteration %u "
"instead of beginning of %u\n", i, ITERATIONS);
......@@ -604,15 +604,15 @@ int main(int argc __attribute__((unused)), char *argv[])
if (rec.type != LOGREC_VARIABLE_RECORD_0LSN_EXAMPLE ||
rec.short_trid != (i % 0xFFFF) ||
rec.record_length != rec_len ||
len != 9 || check_content(rec.header, len))
len != 9 || check_content(rec.header, (uint)len))
{
fprintf(stderr, "Incorrect LOGREC_VARIABLE_RECORD_0LSN_EXAMPLE "
"data read(%d) "
"type %u, strid %u, len %lu != %lu, hdr len: %u, "
"type %u, strid %u, len %lu != %lu, hdr len: %d, "
"lsn(%lu,0x%lx)\n",
i, (uint) rec.type, (uint) rec.short_trid,
(ulong) rec.record_length, (ulong) rec_len,
(uint) len,
len,
(ulong) LSN_FILE_NO(rec.lsn), (ulong) LSN_OFFSET(rec.lsn));
goto err;
}
......
......@@ -349,8 +349,8 @@ int main(int argc __attribute__((unused)), char *argv[])
rc= 1;
{
translog_size_t len= translog_read_record_header(first_lsn, &rec);
if (len == 0)
int len= translog_read_record_header(first_lsn, &rec);
if (len == RECHEADER_READ_ERROR)
{
fprintf(stderr, "translog_read_record_header failed (%d)\n", errno);
translog_free_record_header(&rec);
......@@ -383,14 +383,14 @@ int main(int argc __attribute__((unused)), char *argv[])
for (i= 1;; i++)
{
len= translog_read_next_record_header(&scanner, &rec);
if (len == 0)
if (len == RECHEADER_READ_ERROR)
{
fprintf(stderr, "1-%d translog_read_next_record_header failed (%d)\n",
i, errno);
translog_free_record_header(&rec);
goto err;
}
if (rec.lsn == LSN_IMPOSSIBLE)
if (len == RECHEADER_READ_EOF)
{
if (i != ITERATIONS)
{
......@@ -464,13 +464,13 @@ int main(int argc __attribute__((unused)), char *argv[])
translog_free_record_header(&rec);
len= translog_read_next_record_header(&scanner, &rec);
if (len == 0)
if (len == RECHEADER_READ_ERROR)
{
fprintf(stderr, "1-%d translog_read_next_record_header (var) "
"failed (%d)\n", i, errno);
goto err;
}
if (rec.lsn == LSN_IMPOSSIBLE)
if (len == RECHEADER_READ_EOF)
{
fprintf(stderr, "EOL met at the middle of iteration (first var) %u "
"instead of beginning of %u\n", i, ITERATIONS);
......@@ -490,7 +490,7 @@ int main(int argc __attribute__((unused)), char *argv[])
fprintf(stderr, "Incorrect LOGREC_VARIABLE_RECORD_1LSN_EXAMPLE "
"data read(%d)"
"type %u (%d), strid %u (%d), len %lu, %lu + 7 (%d), "
"hdr len: %u (%d), "
"hdr len: %d (%d), "
"ref(%lu,0x%lx), lsn(%lu,0x%lx) (%d), content: %d\n",
i, (uint) rec.type,
rec.type !=LOGREC_VARIABLE_RECORD_1LSN_EXAMPLE,
......@@ -498,7 +498,7 @@ int main(int argc __attribute__((unused)), char *argv[])
rec.short_trid != (i % 0xFFFF),
(ulong) rec.record_length, (ulong) rec_len,
rec.record_length != rec_len + LSN_STORE_SIZE,
(uint) len,
len,
len != 12,
(ulong) LSN_FILE_NO(ref), (ulong) LSN_OFFSET(ref),
(ulong) LSN_FILE_NO(rec.lsn), (ulong) LSN_OFFSET(rec.lsn),
......@@ -535,12 +535,12 @@ int main(int argc __attribute__((unused)), char *argv[])
{
fprintf(stderr, "Incorrect LOGREC_VARIABLE_RECORD_2LSN_EXAMPLE "
" data read(%d) "
"type %u, strid %u, len %lu != %lu + 14, hdr len: %u, "
"type %u, strid %u, len %lu != %lu + 14, hdr len: %d, "
"ref1(%lu,0x%lx), ref2(%lu,0x%lx), "
"lsn(%lu,0x%lx)\n",
i, (uint) rec.type, (uint) rec.short_trid,
(ulong) rec.record_length, (ulong) rec_len,
(uint) len,
len,
(ulong) LSN_FILE_NO(ref1), (ulong) LSN_OFFSET(ref1),
(ulong) LSN_FILE_NO(ref2), (ulong) LSN_OFFSET(ref2),
(ulong) LSN_FILE_NO(rec.lsn), (ulong) LSN_OFFSET(rec.lsn));
......@@ -561,14 +561,14 @@ int main(int argc __attribute__((unused)), char *argv[])
translog_free_record_header(&rec);
len= translog_read_next_record_header(&scanner, &rec);
if (len == 0)
if (len == RECHEADER_READ_ERROR)
{
fprintf(stderr, "1-%d translog_read_next_record_header failed (%d)\n",
i, errno);
translog_free_record_header(&rec);
goto err;
}
if (rec.lsn == LSN_IMPOSSIBLE)
if (len == RECHEADER_READ_EOF)
{
fprintf(stderr, "EOL met at the middle of iteration %u "
"instead of beginning of %u\n", i, ITERATIONS);
......@@ -606,11 +606,11 @@ int main(int argc __attribute__((unused)), char *argv[])
{
fprintf(stderr, "Incorrect LOGREC_VARIABLE_RECORD_0LSN_EXAMPLE "
"data read(%d) "
"type %u, strid %u, len %lu != %lu, hdr len: %u, "
"type %u, strid %u, len %lu != %lu, hdr len: %d, "
"lsn(%lu,0x%lx)\n",
i, (uint) rec.type, (uint) rec.short_trid,
(ulong) rec.record_length, (ulong) rec_len,
(uint) len,
len,
(ulong) LSN_FILE_NO(rec.lsn), (ulong) LSN_OFFSET(rec.lsn));
translog_free_record_header(&rec);
goto err;
......
......@@ -363,7 +363,8 @@ int main(int argc __attribute__((unused)),
{
uint indeces[WRITERS];
uint index, len, stage;
uint index, stage;
int len;
bzero(indeces, sizeof(uint) * WRITERS);
bzero(indeces, sizeof(indeces));
......@@ -377,14 +378,14 @@ int main(int argc __attribute__((unused)),
{
len= translog_read_next_record_header(&scanner, &rec);
if (len == 0)
if (len == RECHEADER_READ_ERROR)
{
fprintf(stderr, "1-%d translog_read_next_record_header failed (%d)\n",
i, errno);
translog_free_record_header(&rec);
goto err;
}
if (rec.lsn == LSN_IMPOSSIBLE)
if (len == RECHEADER_READ_EOF)
{
if (i != WRITERS * ITERATIONS * 2)
{
......@@ -427,18 +428,18 @@ int main(int argc __attribute__((unused)),
len != 9 ||
rec.record_length != lens[rec.short_trid][index] ||
cmp_translog_addr(lsns2[rec.short_trid][index], rec.lsn) != 0 ||
check_content(rec.header, len))
check_content(rec.header, (uint)len))
{
fprintf(stderr,
"Incorrect LOGREC_VARIABLE_RECORD_0LSN_EXAMPLE "
"data read(%d) "
"thread: %d, iteration %d, stage %d\n"
"type %u (%d), len %u, length %lu %lu (%d) "
"type %u (%d), len %d, length %lu %lu (%d) "
"lsn(%lu,0x%lx) (%lu,0x%lx)\n",
i, (uint) rec.short_trid, index, stage,
(uint) rec.type, (rec.type !=
LOGREC_VARIABLE_RECORD_0LSN_EXAMPLE),
(uint) len,
len,
(ulong) rec.record_length, lens[rec.short_trid][index],
(rec.record_length != lens[rec.short_trid][index]),
(ulong) LSN_FILE_NO(rec.lsn),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment