midenok / mariadb

MariaDB server is a community developed fork of MySQL server. Started by core members of the original MySQL team, MariaDB actively works with outside developers to deliver the most featureful, stable, and sanely licensed open SQL server in the industry.
GNU General Public License v2.0
0 stars 0 forks source link

mydumper #120

Open midenok opened 1 year ago

midenok commented 1 year ago

https://github.com/mydumper/mydumper/issues

#19 0x00007f4d769eebd9 in mysql_real_query (mysql=0x7f4d751d0000, query=0x7f4d6f20f000 "SHOW INDEX FROM `sys`.`x$host_summary_by_statement_latency`", length=59) at ../src/libmariadb/libmariadb/mariadb_lib.c:2903
#20 0x00007f4d769efed9 in mysql_query (mysql=0x7f4d751d0000, query=0x7f4d6f20f000 "SHOW INDEX FROM `sys`.`x$host_summary_by_statement_latency`") at ../src/libmariadb/libmariadb/mariadb_lib.c:2470
#21 0x00005600fb1a2fe1 in get_field_for_dbt (conn=0x7f4d751d0000, dbt=0x7f4d6f1f95c0, conf=0x7ffc852020d0) at ../src/extra/mydumper/src/mydumper_chunks.c:831
#22 0x00005600fb19d4d3 in new_db_table (conn=0x7f4d751d0000, conf=0x7ffc852020d0, database=0x7f4d75148f00, table=0x7f4d751e25e8 "x$host_summary_by_statement_latency", table_collation=0x0, datalength=0x7f4d751e2611 "", rows_in_sts=0) at ../src/extra/mydumper/src/mydumper_working_thread.c:1436
#23 0x00005600fb199763 in new_table_to_dump (conn=0x7f4d751d0000, conf=0x7ffc852020d0, is_view=1, is_sequence=0, database=0x7f4d75148f00, table=0x7f4d751e25e8 "x$host_summary_by_statement_latency", collation=0x0, datalength=0x7f4d751e2611 "", ecol=0x0, rows_in_sts=0) at ../src/extra/mydumper/src/mydumper_working_thread.c:1506
#24 0x00005600fb199182 in dump_database_thread (conn=0x7f4d751d0000, conf=0x7ffc852020d0, database=0x7f4d75148f00) at ../src/extra/mydumper/src/mydumper_working_thread.c:1786
#25 0x00005600fb1989f9 in thd_JOB_DUMP_DATABASE (td=0x7f4d75088268, job=0x7f4d7511c6b0) at ../src/extra/mydumper/src/mydumper_working_thread.c:312

Create job to dump table schema

#0  0x0000561013997a49 in create_job_to_dump_database (database=0x561014940dc0, conf=0x7ffe77c4e660) at ../src/extra/mydumper/src/mydumper_jobs.c:1190
#1  0x000056101398ff0f in start_dump () at ../src/extra/mydumper/src/mydumper_start_dump.c:1062
#2  0x0000561013986c89 in main (argc=7, argv=0x7ffe77c4e918) at ../src/extra/mydumper/src/mydumper.c:151
#0  create_job_to_dump_table_schema (dbt=0x7ff938de1000, conf=0x7ffc25020f80) at ../src/extra/mydumper/src/mydumper_jobs.c:1028
#1  0x0000560983404824 in new_table_to_dump (conn=0x7ff93ed5a000, conf=0x7ffc25020f80, is_view=0, is_sequence=0, database=0x7ff93ec4e450, table=0x7ff93ed6b068 "t1", collation=0x7ff93ed6b07d "latin1_swedish_ci", datalength=0x7ff93ed6b093 "ema", ecol=0x7ff93ed6b06b "MyISAM", rows_in_sts=0) at ../src/extra/mydumper/src/mydumper_working_thread.c:1519
#2  0x0000560983404182 in dump_database_thread (conn=0x7ff93ed5a000, conf=0x7ffc25020f80, database=0x7ff93ec4e450) at ../src/extra/mydumper/src/mydumper_working_thread.c:1786
#3  0x00005609834039f9 in thd_JOB_DUMP_DATABASE (td=0x7ff93ec881f8, job=0x7ff93ec21840) at ../src/extra/mydumper/src/mydumper_working_thread.c:312
(rr) p sj->filename
$13 = 0x7ff93ed60180 "export-20231013-163043/test.t1-schema.sql"
#0  thd_JOB_DUMP_ALL_DATABASES (td=0x562670c92a48, job=0x562670c62ed0) at /home/midenok/src/mariadb/10.6/src/extra/mydumper/src/mydumper_working_thread.c:279
#1  0x000056267086d669 in process_job_builder_job (td=0x562670c92a48, job=0x562670c62ed0) at /home/midenok/src/mariadb/10.6/src/extra/mydumper/src/mydumper_working_thread.c:722
#2  0x000056267086d9a6 in process_queue (queue=0x562670c8e530, td=0x562670c92a48, p=0x56267086d600 <process_job_builder_job>, f=0x0) at /home/midenok/src/mariadb/10.6/src/extra/mydumper/src/mydumper_working_thread.c:819
#3  0x000056267086e83f in working_thread (td=0x562670c92a48) at /home/midenok/src/mariadb/10.6/src/extra/mydumper/src/mydumper_working_thread.c:1195

Dumping data

#0  message_dumping_data (td=0x7ff93ec881c0, tj=0x7ff93ed03000) at ../src/extra/mydumper/src/mydumper_write.c:355
#1  0x000056098341a4d3 in write_row_into_file_in_sql_mode (conn=0x7ff93ed1d000, result=0x7ff93ec54580, tj=0x7ff93ed03000) at ../src/extra/mydumper/src/mydumper_write.c:540
#2  0x000056098341d5b1 in write_table_job_into_file (conn=0x7ff93ed1d000, tj=0x7ff93ed03000) at ../src/extra/mydumper/src/mydumper_write.c:678
#3  0x0000560983404d49 in thd_JOB_DUMP (td=0x7ff93ec881c0, job=0x7ff93ec2c950) at ../src/extra/mydumper/src/mydumper_working_thread.c:474
#4  0x000056098340627a in process_job (td=0x7ff93ec881c0, job=0x7ff93ec2c950) at ../src/extra/mydumper/src/mydumper_working_thread.c:751
#5  0x00005609834064c6 in process_queue (queue=0x7ff93ec4c500, td=0x7ff93ec881c0, p=0x560983406200 <process_job>, f=0x56098340e3c0 <give_me_another_non_innodb_chunk_step>) at ../src/extra/mydumper/src/mydumper_working_thread.c:818
#6  0x0000560983407518 in working_thread (td=0x7ff93ec881c0) at ../src/extra/mydumper/src/mydumper_working_thread.c:1219
#7  0x00007ff940144331 in  () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0

Dumping sequence

#0  do_JOB_SEQUENCE (td=0x7fbf484881c0, job=0x7fbf4851c650) at ../src/extra/mydumper/src/mydumper_jobs.c:899
#1  0x0000560fe83122e6 in process_job (td=0x7fbf484881c0, job=0x7fbf4851c650) at ../src/extra/mydumper/src/mydumper_working_thread.c:769
#2  0x0000560fe83124c6 in process_queue (queue=0x7fbf4844c440, td=0x7fbf484881c0, p=0x560fe8312200 <process_job>, f=0x0) at ../src/extra/mydumper/src/mydumper_working_thread.c:818
#3  0x0000560fe8313609 in working_thread (td=0x7fbf484881c0) at ../src/extra/mydumper/src/mydumper_working_thread.c:1235
#4  0x00007fbf49744331 in  () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#5  0x00007fbf48e97ada in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:444
#6  0x00007fbf48f282e4 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:100
midenok commented 1 year ago

Database schema filename built

#0  build_schema_filename (database=0x7fed44004360 "mydumper_0", suffix=0x56267084c1bf "schema-create") at ../src/extra/mydumper/src/mydumper_common.c:232
#1  0x0000562670865d6e in create_database_related_job (database=0x7fed44004250, conf=0x7ffd2726ee90, type=JOB_CREATE_DATABASE, suffix=0x56267084c1bf "schema-create") at ../src/extra/mydumper/src/mydumper_jobs.c:968
#2  0x0000562670865dc9 in create_job_to_dump_schema (database=0x7fed44004250, conf=0x7ffd2726ee90) at ../src/extra/mydumper/src/mydumper_jobs.c:975
#3  0x000056267086ad61 in thd_JOB_DUMP_ALL_DATABASES (td=0x562670c92a48, job=0x562670c62ed0) at /home/midenok/src/mariadb/10.6/src/extra/mydumper/src/mydumper_working_thread.c:294

View schema written

#0  m_fopen (filename=0x7fc3cf2fd9e8, type=0x55619246636c "w") at ../src/extra/mydumper/src/mydumper_working_thread.c:157
#1  0x000055619247af9b in write_view_definition_into_file (conn=0x7fc3c0000b90, dbt=0x7fc3b4003e90, filename=0x7fc3b400e860 "/home/midenok/src/mariadb/10.6/build/mysql-test/var/tmp/mydumper/test.v1-schema.sql", filename2=0x7fc3b400e8f0 "/home/midenok/src/mariadb/10.6/build/mysql-test/var/tmp/mydumper/test.v1-schema-view.sql", checksum_filename=0) at ../src/extra/mydumper/src/mydumper_jobs.c:393
#2  0x000055619247e91e in do_JOB_VIEW (td=0x5561940ca130, job=0x7fc3b4004560) at ../src/extra/mydumper/src/mydumper_jobs.c:892
#3  0x00005561924867b4 in process_job (td=0x5561940ca130, job=0x7fc3b4004560) at ../src/extra/mydumper/src/mydumper_working_thread.c:767
#4  0x00005561924869a6 in process_queue (queue=0x5561940bdfa0, td=0x5561940ca130, p=0x5561924866e0 <process_job>, f=0x0) at ../src/extra/mydumper/src/mydumper_working_thread.c:819
#5  0x0000556192487ae9 in working_thread (td=0x5561940ca130) at ../src/extra/mydumper/src/mydumper_working_thread.c:1236
#6  0x00007fc3d7106331 in  () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0

Data loaded with INSERT

#9  0x00007ffff78422af in mysql_real_query () from /usr/lib/x86_64-linux-gnu/libmysqlclient.so.21
#10 0x00005555555746f3 in restore_data_in_gstring_by_statement (td=0x5555555c8e80, data=0x7fffc40173c0, is_schema=0, query_counter=0x7fffd1ffaaf4) at ../src/extra/mydumper/src/myloader_restore.c:36
#11 0x00005555555755e1 in split_and_restore_data_in_gstring_by_statement (td=0x5555555c8e80, data=0x7fffe400c000, is_schema=0, query_counter=0x7fffd1ffaaf4, offset_line=33940) at ../src/extra/mydumper/src/myloader_restore.c:129
#12 0x0000555555575c90 in restore_data_from_file (td=0x5555555c8e80, database=0x5555555e3100 "vtrack", table=0x5555555f51c0 "vg_activation", filename=0x7fffc402bef0 "vtrack.vg_activation.00000.sql", is_schema=0) at ../src/extra/mydumper/src/myloader_restore.c:213
#13 0x0000555555577fa8 in process_restore_job (td=0x5555555c8e80, rj=0x7fffc402c820) at ../src/extra/mydumper/src/myloader_restore_job.c:258
#14 0x0000555555578d19 in process_job (td=0x5555555c8e80, job=0x7fffb4009080) at ../src/extra/mydumper/src/myloader_control_job.c:78
#15 0x000055555557c3c1 in process_loader_thread (td=0x5555555c8e80) at ../src/extra/mydumper/src/myloader_worker_loader.c:126
#16 0x000055555557bf2a in loader_thread (td=0x5555555c8e80) at ../src/extra/mydumper/src/myloader_worker_loader.c:172
#17 0x00007ffff7144331 in ?? () from /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#18 0x00007ffff6897ada in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:444
#19 0x00007ffff692847c in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:78

Mydumper splitting data into multiple files

Myloader multi-threading works on file-level. Multiple data-files must exist and they may be scheduled to different threads.

sub_part determines file number.

gboolean update_files_on_table_job(struct table_job *tj){
  if (tj->sql_file == 0){
    if (tj->chunk_step_item->chunk_type == INTEGER && tj->chunk_step_item->chunk_step->integer_step.is_step_fixed_length ){
      if (tj->chunk_step_item->chunk_step->integer_step.is_unsigned)
        tj->sub_part = tj->chunk_step_item->chunk_step->integer_step.type.unsign.min / tj->chunk_step_item->chunk_step->integer_step.step + 1; 
      else
        tj->sub_part = tj->chunk_step_item->chunk_step->integer_step.type.sign.min   / tj->chunk_step_item->chunk_step->integer_step.step + 1;
    }

    if (load_data){
      initialize_load_data_fn(tj);
      tj->sql_filename = build_data_filename(tj->dbt->database->filename, tj->dbt->table_filename, tj->nchunk, tj->sub_part);
      tj->sql_file = m_open(&(tj->sql_filename),"w");
      return TRUE;
    }else{
      initialize_sql_fn(tj);
    }
  }
  return FALSE;
}

initialize_chunk_step_item() must be called to set chunk_type to non-zero.

void set_chunk_strategy_for_dbt(MYSQL *conn, struct db_table *dbt){
  g_mutex_lock(dbt->chunks_mutex);
  struct chunk_step_item * csi = NULL;

  guint64 rows = get_rows_from_explain(conn, dbt, NULL ,NULL);
  if (rows > dbt->min_chunk_step_size){
    GList *partitions=NULL;
    if (split_partitions || dbt->partition_regex){
      csi = g_new0(struct chunk_step_item, 1);
      csi->chunk_step=NULL;
      csi->chunk_functions.process=&process_none_chunk;
      partitions = get_partitions_for_table(conn, dbt);
      csi->chunk_type=PARTITION;
      csi->chunk_functions.process = &process_partition_chunk;
      csi->chunk_functions.get_next = &get_next_partition_chunk;
      csi->chunk_step=new_real_partition_step(partitions,0,0);
    }else{
      if (dbt->starting_chunk_step_size > 0) {
        csi = initialize_chunk_step_item(conn, dbt, 0, NULL, rows);
      }else{
        csi = new_none_chunk_step();
      }
    }
  }else{
    csi = new_none_chunk_step();
  }
//  dbt->initial_chunk_step=csi;
  dbt->chunks=g_list_prepend(dbt->chunks,csi);
  g_async_queue_push(dbt->chunks_queue, csi);
  dbt->status=READY;
  g_mutex_unlock(dbt->chunks_mutex);
}
Num     Type           Disp Enb Address            What
1       breakpoint     keep n   0x0000558670d478c9 in write_row_into_file_in_sql_mode at ../src/extra/mydumper/src/mydumper_write.c:548
        btc
2       breakpoint     keep n   0x0000558670d2ec0c in update_files_on_table_job at ../src/extra/mydumper/src/mydumper_jobs.c:1058
        btc
3       hw watchpoint  keep n                      -location tj->sub_part
4       breakpoint     keep y   0x0000558670d4dadf in new_integer_step_item at ../src/extra/mydumper/src/mydumper_integer_chunks.c:96
        btc
5       breakpoint     keep y   0x0000558670d39c73 in initialize_chunk_step_item at ../src/extra/mydumper/src/mydumper_chunks.c:100
        btc
6       breakpoint     keep n   0x0000558670d3a760 in set_chunk_strategy_for_dbt at ../src/extra/mydumper/src/mydumper_chunks.c:276
        breakpoint already hit 3 times
        btc
7       breakpoint     keep y   0x0000558670d3a7a5 in set_chunk_strategy_for_dbt at ../src/extra/mydumper/src/mydumper_chunks.c:281
        breakpoint already hit 1 time
        btc
midenok commented 10 months ago

Create job to dump chunk

#0  create_job_to_dump_chunk (dbt=0x55c01cb2a630, partition=0x0, nchunk=0, order_by=0x0, chunk_step_item=0x7f859000cff0, f=0x7f85aadf4a50 <g_async_queue_push>, queue=0x55c01caefb80) at /home/midenok/src/mariadb/10.6/src/extra/mydumper/src/mydumper_jobs.c:1171
#1  0x000055c01ae3128e in table_job_enqueue (pop_queue=0x55c01cacc570, push_queue=0x55c01caefb80, table_list=0x55c01cad67c0) at ../src/extra/mydumper/src/mydumper_chunks.c:480
#2  0x000055c01ae3142a in chunk_builder_thread (conf=0x7ffc5f080350) at ../src/extra/mydumper/src/mydumper_chunks.c:520
#3  0x00007f85aae59331 in  () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#4  0x00007f85aa497ada in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:444
#5  0x00007f85aa5282e4 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:100
midenok commented 10 months ago

Mydumper chunking

1. dbt list built

#0  0x00007f9f5510ed0d in g_list_prepend () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#1  0x000055ebf9612487 in new_table_to_dump (conn=0x7f9f40008cb0, conf=0x7fff98fa8f30, is_view=0, is_sequence=0, database=0x7f9f34014c10, table=0x7f9f40013f08 "staff_list", collation=0x7f9f40013f4b "latin1_swedish_ci", ecol=0x7f9f40013f13 "MEMORY", rows_in_sts=0) at /home/midenok/src/mariadb/10.6/src/extra/mydumper/src/mydumper_working_thread.c:1323
#2  0x000055ebf9611d12 in dump_database_thread (conn=0x7f9f40008cb0, conf=0x7fff98fa8f30, database=0x7f9f34014c10) at /home/midenok/src/mariadb/10.6/src/extra/mydumper/src/mydumper_working_thread.c:1525
#3  0x000055ebf9611689 in thd_JOB_DUMP_DATABASE (td=0x55ebfa565a90, job=0x7f9f340150c0) at /home/midenok/src/mariadb/10.6/src/extra/mydumper/src/mydumper_working_thread.c:312
#4  0x000055ebf96134e7 in process_job_builder_job (td=0x55ebfa565a90, job=0x7f9f340150c0) at /home/midenok/src/mariadb/10.6/src/extra/mydumper/src/mydumper_working_thread.c:685
#5  0x000055ebf9613845 in process_queue (queue=0x55ebfa5628a0, td=0x55ebfa565a90, do_builder=1, chunk_step_queue=0x0) at /home/midenok/src/mariadb/10.6/src/extra/mydumper/src/mydumper_working_thread.c:787
#6  0x000055ebf9613ba1 in working_thread (td=0x55ebfa565a90) at /home/midenok/src/mariadb/10.6/src/extra/mydumper/src/mydumper_working_thread.c:866
#7  0x00007f9f55144331 in  () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#8  0x00007f9f54697ada in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:444
#9  0x00007f9f547282e4 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:100

2. chunk_builder_thread() does table_job_enqueue(), which in loop

pop from give_me_another_innodb_chunk_step_queue

get_next_dbt_and_chunk_step_item() iterates dbt list (innodb_table)

a. if there some dbt with status == DEFINING sets return status true; b. for any dbt->status == UNDEFINED returns immediately true and this dbt;

create_job_to_determine_chunk_type()

Push JOB_DETERMINE_CHUNK_TYPE to conf->innodb_queue

3. working_thread()

  1. pushes to give_me_another_innodb_chunk_step_queue
  2. pops conf->innodb_queue
  3. does process_job(): for JOB_DETERMINE_CHUNK_TYPE runs set_chunk_strategy_for_dbt() which does initialize_chunk_step_item() and that may set integer chunking set_chunk_strategy_for_dbt() pushes to dbt->chunks_queue and sets dbt->status = READY
#0  set_chunk_strategy_for_dbt (conn=0x7f9f34000bb0, dbt=0x7f9f4001af00) at /home/midenok/src/mariadb/10.6/src/extra/mydumper/src/mydumper_chunks.c:276
#1  0x000055ebf96135bd in process_job (td=0x55ebfa565908, job=0x7f9f3c00bab0) at /home/midenok/src/mariadb/10.6/src/extra/mydumper/src/mydumper_working_thread.c:711
#2  0x000055ebf9613865 in process_queue (queue=0x55ebfa52db40, td=0x55ebfa565908, do_builder=0, chunk_step_queue=0x55ebfa52e180) at /home/midenok/src/mariadb/10.6/src/extra/mydumper/src/mydumper_working_thread.c:791
#3  0x000055ebf9613d51 in working_thread (td=0x55ebfa565908) at /home/midenok/src/mariadb/10.6/src/extra/mydumper/src/mydumper_working_thread.c:891
#4  0x00007f9f55144331 in  () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#5  0x00007f9f54697ada in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:444
#6  0x00007f9f547282e4 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:100