Skip to content

Commit

Permalink
Changelog:
Browse files Browse the repository at this point in the history
- Handles compressed pages (based on twindb#21)
- Additional logging
  • Loading branch information
voltageek committed Jul 27, 2024
1 parent 63b8aea commit a8e8092
Show file tree
Hide file tree
Showing 4 changed files with 2,121 additions and 29 deletions.
17 changes: 11 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ OBJECTS = stream_parser.o c_parser.o
TARGETS = stream_parser c_parser innochecksum_changer
SRCS = stream_parser.c include/mysql_def.h c_parser.c
INC_PATH = -I./include
LIBS = -pthread -lm
LIBS = -pthread
SUFFIX_LIBS = -lm -lz
BINDIR ?= ./bin

CC ?= gcc
INSTALL ?=install
YACC = bison
LEX = flex

OS_VERSION ?= jammy
PLATFORM ?= ubuntu
OS_VERSION ?= 7

CFLAGS += -D_FILE_OFFSET_BITS=64 -Wall -g -O3 -pipe -fgnu89-inline
INSTALLFLAGS ?=-s
Expand All @@ -30,7 +32,7 @@ stream_parser.o: stream_parser.c include/mysql_def.h
$(CC) $(CFLAGS) $(INC_PATH) -c $<

stream_parser: stream_parser.o
$(CC) $(CFLAGS) $(INC_PATH) $(LIB_PATH) $(LIBS) $(LDFLAGS) $< -o $@
$(CC) $(CFLAGS) $(INC_PATH) $(LIB_PATH) $(LIBS) $(LDFLAGS) $< -o $@ $(SUFFIX_LIBS)

sql_parser.o: sql_parser.c
$(CC) $(CFLAGS) $(INC_PATH) -c $<
Expand Down Expand Up @@ -71,13 +73,16 @@ clean:
rm -f *.o *.core
rm -rf omnibus-undrop-for-innodb/pkg/

package: ## Build package - OS_VERSION can be: focal, jammy.
package: ## Build package - PLATFORM must be one of "centos", "debian", "ubuntu". OS_VERSION must be: 6, 7, jessie, stretch, xenial, bionic, cosmic.
@docker run \
-v $(shell pwd):/undrop-for-innodb \
--name builder_undrop \
--rm \
--dns 8.8.8.8 \
--dns 208.67.222.222 \
--env PLATFORM=${PLATFORM} \
--env OS_VERSION=${OS_VERSION} \
"twindb/omnibus-ubuntu:${OS_VERSION}" \
"twindb/omnibus-${PLATFORM}:backup-${OS_VERSION}" \
bash -l /undrop-for-innodb/omnibus-undrop-for-innodb/omnibus_build.sh


Expand All @@ -91,5 +96,5 @@ docker-start:
--dns 208.67.222.222 \
--env PLATFORM=${PLATFORM} \
--env OS_VERSION=${OS_VERSION} \
"twindb/omnibus-ubuntu:${OS_VERSION}" \
"twindb/omnibus-${PLATFORM}:backup-${OS_VERSION}" \
bash -l
41 changes: 27 additions & 14 deletions c_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ bool debug = 0;
//bool process_redundant = 0;
//bool process_compact = 0;
bool process_56 = 0;
bool output_sql_inserts = 0;
char blob_dir[256] = ".";
char dump_prefix[256] = "default";
char path_ibdata[256];
Expand Down Expand Up @@ -138,27 +139,30 @@ ut_print_buf(
ulint process_ibrec(page_t *page, rec_t *rec, table_def_t *table, ulint *offsets, bool hex) {
ulint data_size;
int i;
// Print trx_id and rollback pointer
for(i = 0; i < table->fields_count; i++) {
ulint len;
byte *field = rec_get_nth_field(rec, offsets, i, &len);

if (table->fields[i].type == FT_INTERNAL){
if (debug) printf("Field #%i @ %p: length %lu, value: ", i, field, len);
print_field_value(field, len, &(table->fields[i]), hex);
if (i < table->fields_count - 1) fprintf(f_result, "\t");
if (debug) printf("\n");
if (!output_sql_inserts) {
// Print trx_id and rollback pointer
for(i = 0; i < table->fields_count; i++) {
ulint len;
byte *field = rec_get_nth_field(rec, offsets, i, &len);

if (table->fields[i].type == FT_INTERNAL){
if (debug) printf("Field #%i @ %p: length %lu, value: ", i, field, len);
print_field_value(field, len, &(table->fields[i]), hex);
if (i < table->fields_count - 1) fprintf(f_result, "\t");
if (debug) printf("\n");
}
}
}
}

// Print table name
if (debug) {
printf("Processing record %p from table '%s'\n", rec, table->name);
rec_print_new(stdout, rec, offsets);
} else if (output_sql_inserts) {
fprintf(f_result, "INSERT INTO `%s` VALUES(", table->name);
} else {
fprintf(f_result, "%s\t", table->name);
}

data_size = rec_offs_data_size(offsets);

for(i = 0; i < table->fields_count; i++) {
Expand All @@ -179,9 +183,14 @@ ulint process_ibrec(page_t *page, rec_t *rec, table_def_t *table, ulint *offsets
}
}

if (i < table->fields_count - 1) fprintf(f_result, "\t");
if (i < table->fields_count - 1) {
if (output_sql_inserts) fprintf(f_result, ",");
else fprintf(f_result, "\t");
}
if (debug) printf("\n");
}
if (output_sql_inserts)
fprintf(f_result, ");");
fprintf(f_result, "\n");
return data_size; // point to the next possible record's start
}
Expand Down Expand Up @@ -767,6 +776,7 @@ void usage() {
" -i <file> -- Read external pages at their offsets from <file>.\n"
" -p prefix -- Use prefix for a directory name in LOAD DATA INFILE command\n"
" -x -- Print text values in hexadecimal format.\n"
" -s -- Output format as Insert statements.\n"
"\n"
);
}
Expand All @@ -788,7 +798,7 @@ int main(int argc, char **argv) {
char sql_file[1024];
bool hex = 0;

while ((ch = getopt(argc, argv, "t:456hdDUVf:T:b:p:o:i:l:x")) != -1) {
while ((ch = getopt(argc, argv, "t:456hdDUVf:T:b:p:o:i:l:x:s")) != -1) {
switch (ch) {
case 'd':
deleted_pages_only = 1;
Expand Down Expand Up @@ -843,6 +853,9 @@ int main(int argc, char **argv) {
case '6':
process_56 = 1;
break;
case 's':
output_sql_inserts = 1;
break;
case 'T':
set_filter_id(optarg);
break;
Expand Down
Loading

0 comments on commit a8e8092

Please sign in to comment.