developers
Threads by month
- ----- 2025 -----
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- 6 participants
- 6824 discussions
MySQL 5.6.9 changed how the number of key parts are measured. They
replaced one simple counter (key_parts) with four counters. Glancing
at the code, i assume that this was done to support extended keys. If
so, the mariadb implementation of extended keys is a lot simpler. We
have to maintain the tokudb storage engine on both mysql and mariadb.
Is the mariadb design going to change to match the 5.6 implementation,
or are the designs now separate?
Thanks
Rich Prohaska
2
1
Re: [Maria-developers] [Commits] Rev 3435: MDEV-532: Async InnoDB commit checkpoint. in http://bazaar.launchpad.net/~maria-captains/maria/10.0
by Kristian Nielsen 14 Dec '12
by Kristian Nielsen 14 Dec '12
14 Dec '12
Hi Serg,
As we discussed under review of MDEV-232, here is a separate patch that makes
InnoDB/XtraDB commit checkpointing be more asynchroneous.
See MDEV-532 for further description of this task.
I hope you will review this, at your convenience.
- Kristian.
knielsen(a)knielsen-hq.org writes:
> At http://bazaar.launchpad.net/~maria-captains/maria/10.0
>
> ------------------------------------------------------------
> revno: 3435
> revision-id: knielsen(a)knielsen-hq.org-20120914124453-zsap6hjclq3vrb6n
> parent: knielsen(a)knielsen-hq.org-20120913123129-kaujy4cw0jc9o08k
> committer: knielsen(a)knielsen-hq.org
> branch nick: work-10.0-mdev225-181-232
> timestamp: Fri 2012-09-14 14:44:53 +0200
> message:
> MDEV-532: Async InnoDB commit checkpoint.
>
> Make the commit checkpoint inside InnoDB be asynchroneous.
> Implement a background thread in binlog to do the writing and flushing of
> binlog checkpoint events to disk.
> === modified file 'mysql-test/suite/binlog/r/binlog_checkpoint.result'
> --- a/mysql-test/suite/binlog/r/binlog_checkpoint.result 2012-09-13 12:31:29 +0000
> +++ b/mysql-test/suite/binlog/r/binlog_checkpoint.result 2012-09-14 12:44:53 +0000
> @@ -70,8 +70,14 @@ show binlog events in 'master-bin.000003
> Log_name Pos Event_type Server_id End_log_pos Info
> master-bin.000003 # Format_desc # # SERVER_VERSION, BINLOG_VERSION
> master-bin.000003 # Binlog_checkpoint # # master-bin.000001
> +SET DEBUG_SYNC= "RESET";
> +SET @old_dbug= @@global.DEBUG_DBUG;
> +SET GLOBAL debug_dbug="+d,binlog_background_checkpoint_processed";
> SET DEBUG_SYNC= "now SIGNAL con2_continue";
> con1 is still pending, no new binlog checkpoint should have been logged.
> +SET DEBUG_SYNC= "now WAIT_FOR binlog_background_checkpoint_processed";
> +SET GLOBAL debug_dbug= @old_dbug;
> +SET DEBUG_SYNC= "RESET";
> show binlog events in 'master-bin.000003' from <binlog_start>;
> Log_name Pos Event_type Server_id End_log_pos Info
> master-bin.000003 # Format_desc # # SERVER_VERSION, BINLOG_VERSION
>
> === modified file 'mysql-test/suite/binlog/r/binlog_xa_recover.result'
> --- a/mysql-test/suite/binlog/r/binlog_xa_recover.result 2012-09-13 12:31:29 +0000
> +++ b/mysql-test/suite/binlog/r/binlog_xa_recover.result 2012-09-14 12:44:53 +0000
> @@ -118,7 +118,11 @@ master-bin.00000<binlog_start> # Table_m
> master-bin.00000<binlog_start> # Write_rows # # table_id: # flags: STMT_END_F
> master-bin.00000<binlog_start> # Xid # # COMMIT /* XID */
> SET DEBUG_SYNC= "now SIGNAL con10_cont";
> +SET @old_dbug= @@global.DEBUG_DBUG;
> +SET GLOBAL debug_dbug="+d,binlog_background_checkpoint_processed";
> SET DEBUG_SYNC= "now SIGNAL con12_cont";
> +SET DEBUG_SYNC= "now WAIT_FOR binlog_background_checkpoint_processed";
> +SET GLOBAL debug_dbug= @old_dbug;
> SET DEBUG_SYNC= "now SIGNAL con11_cont";
> Checking that master-bin.000004 is the last binlog checkpoint
> show binlog events in 'master-bin.00000<binlog_start>' from <binlog_start>;
>
> === modified file 'mysql-test/suite/binlog/t/binlog_checkpoint.test'
> --- a/mysql-test/suite/binlog/t/binlog_checkpoint.test 2012-09-13 12:31:29 +0000
> +++ b/mysql-test/suite/binlog/t/binlog_checkpoint.test 2012-09-14 12:44:53 +0000
> @@ -71,6 +71,12 @@ SET DEBUG_SYNC= "now WAIT_FOR con2_ready
> --let $binlog_file= master-bin.000003
> --source include/show_binlog_events.inc
>
> +# We need to sync the test case with the background processing of the
> +# commit checkpoint, otherwise we get nondeterministic results.
> +SET DEBUG_SYNC= "RESET";
> +SET @old_dbug= @@global.DEBUG_DBUG;
> +SET GLOBAL debug_dbug="+d,binlog_background_checkpoint_processed";
> +
> SET DEBUG_SYNC= "now SIGNAL con2_continue";
>
> connection con2;
> @@ -78,6 +84,12 @@ reap;
>
> connection default;
> --echo con1 is still pending, no new binlog checkpoint should have been logged.
> +# Make sure commit checkpoint is processed before we check that no checkpoint
> +# event has been binlogged.
> +SET DEBUG_SYNC= "now WAIT_FOR binlog_background_checkpoint_processed";
> +SET GLOBAL debug_dbug= @old_dbug;
> +SET DEBUG_SYNC= "RESET";
> +
> --let $binlog_file= master-bin.000003
> --source include/show_binlog_events.inc
>
>
> === modified file 'mysql-test/suite/binlog/t/binlog_xa_recover.test'
> --- a/mysql-test/suite/binlog/t/binlog_xa_recover.test 2012-09-13 12:31:29 +0000
> +++ b/mysql-test/suite/binlog/t/binlog_xa_recover.test 2012-09-14 12:44:53 +0000
> @@ -14,8 +14,24 @@ CREATE TABLE t1 (a INT PRIMARY KEY, b ME
> # Insert some data to force a couple binlog rotations (3), so we get some
> # normal binlog checkpoints before starting the test.
> INSERT INTO t1 VALUES (100, REPEAT("x", 4100));
> +# Wait for the master-bin.000002 binlog checkpoint to appear.
> +--let $wait_for_all= 0
> +--let $show_statement= SHOW BINLOG EVENTS IN "master-bin.000002"
> +--let $field= Info
> +--let $condition= = "master-bin.000002"
> +--source include/wait_show_condition.inc
> INSERT INTO t1 VALUES (101, REPEAT("x", 4100));
> +--let $wait_for_all= 0
> +--let $show_statement= SHOW BINLOG EVENTS IN "master-bin.000003"
> +--let $field= Info
> +--let $condition= = "master-bin.000003"
> +--source include/wait_show_condition.inc
> INSERT INTO t1 VALUES (102, REPEAT("x", 4100));
> +--let $wait_for_all= 0
> +--let $show_statement= SHOW BINLOG EVENTS IN "master-bin.000004"
> +--let $field= Info
> +--let $condition= = "master-bin.000004"
> +--source include/wait_show_condition.inc
>
> # Now start a bunch of transactions that span multiple binlog
> # files. Leave then in the state prepared-but-not-committed in the engine
> @@ -153,10 +169,19 @@ SET DEBUG_SYNC= "now SIGNAL con10_cont";
> connection con10;
> reap;
> connection default;
> +
> +# We need to sync the test case with the background processing of the
> +# commit checkpoint, otherwise we get nondeterministic results.
> +SET @old_dbug= @@global.DEBUG_DBUG;
> +SET GLOBAL debug_dbug="+d,binlog_background_checkpoint_processed";
> +
> SET DEBUG_SYNC= "now SIGNAL con12_cont";
> connection con12;
> reap;
> connection default;
> +SET DEBUG_SYNC= "now WAIT_FOR binlog_background_checkpoint_processed";
> +SET GLOBAL debug_dbug= @old_dbug;
> +
> SET DEBUG_SYNC= "now SIGNAL con11_cont";
> connection con11;
> reap;
> @@ -210,7 +235,20 @@ RESET MASTER;
> # crash recovery fails due to the error insert used for previous test.
> INSERT INTO t1 VALUES (21, REPEAT("x", 4100));
> INSERT INTO t1 VALUES (22, REPEAT("x", 4100));
> +# Wait for the master-bin.000003 binlog checkpoint to appear.
> +--let $wait_for_all= 0
> +--let $show_statement= SHOW BINLOG EVENTS IN "master-bin.000003"
> +--let $field= Info
> +--let $condition= = "master-bin.000003"
> +--source include/wait_show_condition.inc
> INSERT INTO t1 VALUES (23, REPEAT("x", 4100));
> +# Wait for the last (master-bin.000004) binlog checkpoint to appear.
> +--let $wait_for_all= 0
> +--let $show_statement= SHOW BINLOG EVENTS IN "master-bin.000004"
> +--let $field= Info
> +--let $condition= = "master-bin.000004"
> +--source include/wait_show_condition.inc
> +
> --write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
> wait-binlog_xa_recover.test
> EOF
>
> === modified file 'mysql-test/suite/perfschema/r/all_instances.result'
> --- a/mysql-test/suite/perfschema/r/all_instances.result 2012-06-22 09:46:28 +0000
> +++ b/mysql-test/suite/perfschema/r/all_instances.result 2012-09-14 12:44:53 +0000
> @@ -76,6 +76,7 @@ wait/synch/mutex/sql/Master_info::run_lo
> wait/synch/mutex/sql/Master_info::sleep_lock
> wait/synch/mutex/sql/MDL_map::mutex
> wait/synch/mutex/sql/MDL_wait::LOCK_wait_status
> +wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_binlog_thread
> wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_index
> wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_xid_list
> wait/synch/mutex/sql/MYSQL_RELAY_LOG::LOCK_index
> @@ -129,6 +130,8 @@ wait/synch/cond/sql/Master_info::sleep_c
> wait/synch/cond/sql/Master_info::start_cond
> wait/synch/cond/sql/Master_info::stop_cond
> wait/synch/cond/sql/MDL_context::COND_wait_status
> +wait/synch/cond/sql/MYSQL_BIN_LOG::COND_binlog_thread
> +wait/synch/cond/sql/MYSQL_BIN_LOG::COND_binlog_thread_end
> wait/synch/cond/sql/MYSQL_BIN_LOG::COND_queue_busy
> wait/synch/cond/sql/MYSQL_BIN_LOG::COND_xid_list
> wait/synch/cond/sql/MYSQL_BIN_LOG::update_cond
>
> === modified file 'mysql-test/suite/perfschema/r/relaylog.result'
> --- a/mysql-test/suite/perfschema/r/relaylog.result 2012-06-22 09:46:28 +0000
> +++ b/mysql-test/suite/perfschema/r/relaylog.result 2012-09-14 12:44:53 +0000
> @@ -56,8 +56,11 @@ where event_name like "%MYSQL_BIN_LOG%"
> and event_name not like "%MYSQL_BIN_LOG::update_cond"
> order by event_name;
> EVENT_NAME COUNT_STAR
> +wait/synch/cond/sql/MYSQL_BIN_LOG::COND_binlog_thread NONE
> +wait/synch/cond/sql/MYSQL_BIN_LOG::COND_binlog_thread_end NONE
> wait/synch/cond/sql/MYSQL_BIN_LOG::COND_queue_busy NONE
> wait/synch/cond/sql/MYSQL_BIN_LOG::COND_xid_list NONE
> +wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_binlog_thread MANY
> wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_index MANY
> wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_xid_list MANY
> "Expect no slave relay log"
> @@ -131,8 +134,11 @@ where event_name like "%MYSQL_BIN_LOG%"
> and event_name not like "%MYSQL_BIN_LOG::update_cond"
> order by event_name;
> EVENT_NAME COUNT_STAR
> +wait/synch/cond/sql/MYSQL_BIN_LOG::COND_binlog_thread MANY
> +wait/synch/cond/sql/MYSQL_BIN_LOG::COND_binlog_thread_end NONE
> wait/synch/cond/sql/MYSQL_BIN_LOG::COND_queue_busy NONE
> -wait/synch/cond/sql/MYSQL_BIN_LOG::COND_xid_list NONE
> +wait/synch/cond/sql/MYSQL_BIN_LOG::COND_xid_list MANY
> +wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_binlog_thread MANY
> wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_index MANY
> wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_xid_list MANY
> "Expect a slave relay log"
>
> === modified file 'sql/debug_sync.cc'
> --- a/sql/debug_sync.cc 2012-03-28 17:26:00 +0000
> +++ b/sql/debug_sync.cc 2012-09-14 12:44:53 +0000
> @@ -984,6 +984,7 @@ static bool debug_sync_eval_action(THD *
> DBUG_ENTER("debug_sync_eval_action");
> DBUG_ASSERT(thd);
> DBUG_ASSERT(action_str);
> + DBUG_PRINT("debug_sync", ("action_str='%s'", action_str));
>
> /*
> Get debug sync point name. Or a special command.
>
> === modified file 'sql/log.cc'
> --- a/sql/log.cc 2012-09-13 12:31:29 +0000
> +++ b/sql/log.cc 2012-09-14 12:44:53 +0000
> @@ -53,6 +53,7 @@
> #include "rpl_handler.h"
> #include "debug_sync.h"
> #include "sql_show.h"
> +#include "my_pthread.h"
>
> /* max size of the log message */
> #define MAX_LOG_BUFFER_SIZE 1024
> @@ -106,6 +107,14 @@ static SHOW_VAR binlog_status_vars_detai
> {NullS, NullS, SHOW_LONG}
> };
>
> +/* Variables for the binlog background thread. */
> +static bool binlog_thread_started= false;
> +static bool binlog_background_thread_stop= false;
> +static MYSQL_BIN_LOG::xid_count_per_binlog *
> + binlog_background_thread_queue= NULL;
> +
> +static bool start_binlog_background_thread();
> +
>
> /**
> purge logs, master and slave sides both, related error code
> @@ -2957,12 +2966,27 @@ void MYSQL_BIN_LOG::cleanup()
> my_free(b);
> }
>
> + /* Wait for the binlog thread to stop. */
> + if (!is_relay_log && binlog_thread_started)
> + {
> + mysql_mutex_lock(&LOCK_binlog_thread);
> + binlog_background_thread_stop= true;
> + mysql_cond_signal(&COND_binlog_thread);
> + while (binlog_background_thread_stop)
> + mysql_cond_wait(&COND_binlog_thread_end, &LOCK_binlog_thread);
> + mysql_mutex_unlock(&LOCK_binlog_thread);
> + binlog_thread_started= false;
> + }
> +
> mysql_mutex_destroy(&LOCK_log);
> mysql_mutex_destroy(&LOCK_index);
> mysql_mutex_destroy(&LOCK_xid_list);
> + mysql_mutex_destroy(&LOCK_binlog_thread);
> mysql_cond_destroy(&update_cond);
> mysql_cond_destroy(&COND_queue_busy);
> mysql_cond_destroy(&COND_xid_list);
> + mysql_cond_destroy(&COND_binlog_thread);
> + mysql_cond_destroy(&COND_binlog_thread_end);
> }
> DBUG_VOID_RETURN;
> }
> @@ -2988,6 +3012,11 @@ void MYSQL_BIN_LOG::init_pthread_objects
> mysql_cond_init(m_key_update_cond, &update_cond, 0);
> mysql_cond_init(m_key_COND_queue_busy, &COND_queue_busy, 0);
> mysql_cond_init(key_BINLOG_COND_xid_list, &COND_xid_list, 0);
> +
> + mysql_mutex_init(key_BINLOG_LOCK_binlog_thread,
> + &LOCK_binlog_thread, MY_MUTEX_INIT_FAST);
> + mysql_cond_init(key_BINLOG_COND_binlog_thread, &COND_binlog_thread, 0);
> + mysql_cond_init(key_BINLOG_COND_binlog_thread_end, &COND_binlog_thread_end, 0);
> }
>
>
> @@ -3085,6 +3114,10 @@ bool MYSQL_BIN_LOG::open(const char *log
> DBUG_ENTER("MYSQL_BIN_LOG::open");
> DBUG_PRINT("enter",("log_type: %d",(int) log_type_arg));
>
> + if (!is_relay_log && !binlog_thread_started &&
> + start_binlog_background_thread())
> + DBUG_RETURN(1);
> +
> if (init_and_set_log_file_name(log_name, new_name, log_type_arg,
> io_cache_type_arg))
> {
> @@ -5540,11 +5573,7 @@ bool general_log_write(THD *thd, enum en
> }
>
>
> -/*
> - I would like to make this function static, but this causes compiler warnings
> - when it is declared as friend function in log.h.
> -*/
> -void
> +static void
> binlog_checkpoint_callback(void *cookie)
> {
> MYSQL_BIN_LOG::xid_count_per_binlog *entry=
> @@ -8116,9 +8145,128 @@ int TC_LOG_BINLOG::unlog(ulong cookie, m
> void
> TC_LOG_BINLOG::commit_checkpoint_notify(void *cookie)
> {
> - mark_xid_done(((xid_count_per_binlog *)cookie)->binlog_id, true);
> + xid_count_per_binlog *entry= static_cast<xid_count_per_binlog *>(cookie);
> + mysql_mutex_lock(&LOCK_binlog_thread);
> + entry->next_in_queue= binlog_background_thread_queue;
> + binlog_background_thread_queue= entry;
> + mysql_cond_signal(&COND_binlog_thread);
> + mysql_mutex_unlock(&LOCK_binlog_thread);
> }
>
> +/*
> + Binlog service thread.
> +
> + This thread is used to log binlog checkpoints in the background, rather than
> + in the context of random storage engine threads that happen to call
> + commit_checkpoint_notify_ha() and may not like the delays while syncing
> + binlog to disk or may not be setup with all my_thread_init() and other
> + necessary stuff.
> +
> + In the future, this thread could also be used to do log rotation in the
> + background, which could elimiate all stalls around binlog rotations.
> +*/
> +pthread_handler_t
> +binlog_background_thread(void *arg __attribute__((unused)))
> +{
> + bool stop;
> + MYSQL_BIN_LOG::xid_count_per_binlog *queue, *next;
> + THD *thd;
> +
> + my_thread_init();
> + thd= new THD;
> + thd->system_thread= SYSTEM_THREAD_BINLOG_BACKGROUND;
> + my_pthread_setspecific_ptr(THR_THD, thd);
> + mysql_mutex_lock(&LOCK_thread_count);
> + thd->thread_id= thread_id++;
> + mysql_mutex_unlock(&LOCK_thread_count);
> +
> + for (;;)
> + {
> + /*
> + Wait until there is something in the queue to process, or we are asked
> + to shut down.
> + */
> + thd_proc_info(thd, "Waiting for background binlog tasks");
> + mysql_mutex_lock(&mysql_bin_log.LOCK_binlog_thread);
> + for (;;)
> + {
> + stop= binlog_background_thread_stop;
> + queue= binlog_background_thread_queue;
> + if (stop || queue)
> + break;
> + mysql_cond_wait(&mysql_bin_log.COND_binlog_thread,
> + &mysql_bin_log.LOCK_binlog_thread);
> + }
> + /* Grab the queue, if any. */
> + binlog_background_thread_queue= NULL;
> + mysql_mutex_unlock(&mysql_bin_log.LOCK_binlog_thread);
> +
> + /* Process any incoming commit_checkpoint_notify() calls. */
> + while (queue)
> + {
> + thd_proc_info(thd, "Processing binlog checkpoint notification");
> + /* Grab next pointer first, as mark_xid_done() may free the element. */
> + next= queue->next_in_queue;
> + mysql_bin_log.mark_xid_done(queue->binlog_id, true);
> + queue= next;
> +
> + DBUG_EXECUTE_IF("binlog_background_checkpoint_processed",
> + DBUG_ASSERT(!debug_sync_set_action(
> + thd,
> + STRING_WITH_LEN("now SIGNAL binlog_background_checkpoint_processed")));
> + );
> + }
> +
> + if (stop)
> + break;
> + }
> +
> + thd_proc_info(thd, "Stopping binlog background thread");
> +
> + mysql_mutex_lock(&LOCK_thread_count);
> + delete thd;
> + mysql_mutex_unlock(&LOCK_thread_count);
> +
> + my_thread_end();
> +
> + /* Signal that we are (almost) stopped. */
> + mysql_mutex_lock(&mysql_bin_log.LOCK_binlog_thread);
> + binlog_background_thread_stop= false;
> + mysql_cond_signal(&mysql_bin_log.COND_binlog_thread_end);
> + mysql_mutex_unlock(&mysql_bin_log.LOCK_binlog_thread);
> +
> + return 0;
> +}
> +
> +#ifdef HAVE_PSI_INTERFACE
> +static PSI_thread_key key_thread_binlog;
> +
> +static PSI_thread_info all_binlog_threads[]=
> +{
> + { &key_thread_binlog, "binlog_background", PSI_FLAG_GLOBAL},
> +};
> +#endif /* HAVE_PSI_INTERFACE */
> +
> +static bool
> +start_binlog_background_thread()
> +{
> + pthread_t th;
> +
> +#ifdef HAVE_PSI_INTERFACE
> + if (PSI_server)
> + PSI_server->register_thread("sql", all_binlog_threads,
> + array_elements(all_binlog_threads));
> +#endif
> +
> + if (mysql_thread_create(key_thread_binlog, &th, NULL,
> + binlog_background_thread, NULL))
> + return 1;
> +
> + binlog_thread_started= true;
> + return 0;
> +}
> +
> +
> int TC_LOG_BINLOG::recover(LOG_INFO *linfo, const char *last_log_name,
> IO_CACHE *first_log,
> Format_description_log_event *fdle)
>
> === modified file 'sql/log.h'
> --- a/sql/log.h 2012-09-13 12:31:29 +0000
> +++ b/sql/log.h 2012-09-14 12:44:53 +0000
> @@ -395,8 +395,6 @@ class MYSQL_QUERY_LOG: public MYSQL_LOG
> #define BINLOG_COOKIE_IS_DUMMY(c) \
> ( ((ulong)(c)>>1) == BINLOG_COOKIE_DUMMY_ID )
>
> -void binlog_checkpoint_callback(void *cookie);
> -
> class binlog_cache_mngr;
> class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG
> {
> @@ -451,27 +449,6 @@ class MYSQL_BIN_LOG: public TC_LOG, priv
> };
>
> /*
> - A list of struct xid_count_per_binlog is used to keep track of how many
> - XIDs are in prepared, but not committed, state in each binlog. And how
> - many commit_checkpoint_request()'s are pending.
> -
> - When count drops to zero in a binlog after rotation, it means that there
> - are no more XIDs in prepared state, so that binlog is no longer needed
> - for XA crash recovery, and we can log a new binlog checkpoint event.
> -
> - The list is protected against simultaneous access from multiple
> - threads by LOCK_xid_list.
> - */
> - struct xid_count_per_binlog : public ilink {
> - char *binlog_name;
> - uint binlog_name_len;
> - ulong binlog_id;
> - /* Total prepared XIDs and pending checkpoint requests in this binlog. */
> - long xid_count;
> - xid_count_per_binlog(); /* Give link error if constructor used. */
> - };
> - I_List<xid_count_per_binlog> binlog_xid_count_list;
> - /*
> When this is set, a RESET MASTER is in progress.
>
> Then we should not write any binlog checkpoints into the binlog (that
> @@ -480,7 +457,6 @@ class MYSQL_BIN_LOG: public TC_LOG, priv
> checkpoint arrives - when all have arrived, RESET MASTER will complete.
> */
> bool reset_master_pending;
> - friend void binlog_checkpoint_callback(void *cookie);
>
> /* LOCK_log and LOCK_index are inited by init_pthread_objects() */
> mysql_mutex_t LOCK_index;
> @@ -553,10 +529,35 @@ class MYSQL_BIN_LOG: public TC_LOG, priv
> int write_transaction_or_stmt(group_commit_entry *entry);
> bool write_transaction_to_binlog_events(group_commit_entry *entry);
> void trx_group_commit_leader(group_commit_entry *leader);
> - void mark_xid_done(ulong cookie, bool write_checkpoint);
> - void mark_xids_active(ulong cookie, uint xid_count);
>
> public:
> + /*
> + A list of struct xid_count_per_binlog is used to keep track of how many
> + XIDs are in prepared, but not committed, state in each binlog. And how
> + many commit_checkpoint_request()'s are pending.
> +
> + When count drops to zero in a binlog after rotation, it means that there
> + are no more XIDs in prepared state, so that binlog is no longer needed
> + for XA crash recovery, and we can log a new binlog checkpoint event.
> +
> + The list is protected against simultaneous access from multiple
> + threads by LOCK_xid_list.
> + */
> + struct xid_count_per_binlog : public ilink {
> + char *binlog_name;
> + uint binlog_name_len;
> + ulong binlog_id;
> + /* Total prepared XIDs and pending checkpoint requests in this binlog. */
> + long xid_count;
> + /* For linking in requests to the binlog background thread. */
> + xid_count_per_binlog *next_in_queue;
> + xid_count_per_binlog(); /* Give link error if constructor used. */
> + };
> + I_List<xid_count_per_binlog> binlog_xid_count_list;
> + mysql_mutex_t LOCK_binlog_thread;
> + mysql_cond_t COND_binlog_thread;
> + mysql_cond_t COND_binlog_thread_end;
> +
> using MYSQL_LOG::generate_name;
> using MYSQL_LOG::is_open;
>
> @@ -712,6 +713,8 @@ class MYSQL_BIN_LOG: public TC_LOG, priv
> bool appendv(const char* buf,uint len,...);
> bool append(Log_event* ev);
>
> + void mark_xids_active(ulong cookie, uint xid_count);
> + void mark_xid_done(ulong cookie, bool write_checkpoint);
> void make_log_name(char* buf, const char* log_ident);
> bool is_active(const char* log_file_name);
> bool can_purge_log(const char *log_file_name);
>
> === modified file 'sql/mysqld.cc'
> --- a/sql/mysqld.cc 2012-09-13 12:31:29 +0000
> +++ b/sql/mysqld.cc 2012-09-14 12:44:53 +0000
> @@ -724,6 +724,7 @@ PSI_mutex_key key_LOCK_des_key_file;
> #endif /* HAVE_OPENSSL */
>
> PSI_mutex_key key_BINLOG_LOCK_index, key_BINLOG_LOCK_xid_list,
> + key_BINLOG_LOCK_binlog_thread,
> key_delayed_insert_mutex, key_hash_filo_lock, key_LOCK_active_mi,
> key_LOCK_connection_count, key_LOCK_crypt, key_LOCK_delayed_create,
> key_LOCK_delayed_insert, key_LOCK_delayed_status, key_LOCK_error_log,
> @@ -766,6 +767,7 @@ static PSI_mutex_info all_server_mutexes
>
> { &key_BINLOG_LOCK_index, "MYSQL_BIN_LOG::LOCK_index", 0},
> { &key_BINLOG_LOCK_xid_list, "MYSQL_BIN_LOG::LOCK_xid_list", 0},
> + { &key_BINLOG_LOCK_binlog_thread, "MYSQL_BIN_LOG::LOCK_binlog_thread", 0},
> { &key_RELAYLOG_LOCK_index, "MYSQL_RELAY_LOG::LOCK_index", 0},
> { &key_delayed_insert_mutex, "Delayed_insert::mutex", 0},
> { &key_hash_filo_lock, "hash_filo::lock", 0},
> @@ -834,6 +836,7 @@ PSI_cond_key key_PAGE_cond, key_COND_act
> #endif /* HAVE_MMAP */
>
> PSI_cond_key key_BINLOG_COND_xid_list, key_BINLOG_update_cond,
> + key_BINLOG_COND_binlog_thread, key_BINLOG_COND_binlog_thread_end,
> key_COND_cache_status_changed, key_COND_manager,
> key_COND_rpl_status, key_COND_server_started,
> key_delayed_insert_cond, key_delayed_insert_cond_client,
> @@ -863,6 +866,8 @@ static PSI_cond_info all_server_conds[]=
> #endif /* HAVE_MMAP */
> { &key_BINLOG_COND_xid_list, "MYSQL_BIN_LOG::COND_xid_list", 0},
> { &key_BINLOG_update_cond, "MYSQL_BIN_LOG::update_cond", 0},
> + { &key_BINLOG_COND_binlog_thread, "MYSQL_BIN_LOG::COND_binlog_thread", 0},
> + { &key_BINLOG_COND_binlog_thread_end, "MYSQL_BIN_LOG::COND_binlog_thread_end", 0},
> { &key_BINLOG_COND_queue_busy, "MYSQL_BIN_LOG::COND_queue_busy", 0},
> { &key_RELAYLOG_update_cond, "MYSQL_RELAY_LOG::update_cond", 0},
> { &key_RELAYLOG_COND_queue_busy, "MYSQL_RELAY_LOG::COND_queue_busy", 0},
>
> === modified file 'sql/mysqld.h'
> --- a/sql/mysqld.h 2012-09-13 12:31:29 +0000
> +++ b/sql/mysqld.h 2012-09-14 12:44:53 +0000
> @@ -226,6 +226,7 @@ extern PSI_mutex_key key_LOCK_des_key_fi
> #endif
>
> extern PSI_mutex_key key_BINLOG_LOCK_index, key_BINLOG_LOCK_xid_list,
> + key_BINLOG_LOCK_binlog_thread,
> key_delayed_insert_mutex, key_hash_filo_lock, key_LOCK_active_mi,
> key_LOCK_connection_count, key_LOCK_crypt, key_LOCK_delayed_create,
> key_LOCK_delayed_insert, key_LOCK_delayed_status, key_LOCK_error_log,
> @@ -257,6 +258,7 @@ extern PSI_cond_key key_PAGE_cond, key_C
> #endif /* HAVE_MMAP */
>
> extern PSI_cond_key key_BINLOG_COND_xid_list, key_BINLOG_update_cond,
> + key_BINLOG_COND_binlog_thread, key_BINLOG_COND_binlog_thread_end,
> key_COND_cache_status_changed, key_COND_manager,
> key_COND_rpl_status, key_COND_server_started,
> key_delayed_insert_cond, key_delayed_insert_cond_client,
>
> === modified file 'sql/rpl_rli.cc'
> --- a/sql/rpl_rli.cc 2012-09-13 12:31:29 +0000
> +++ b/sql/rpl_rli.cc 2012-09-14 12:44:53 +0000
> @@ -58,6 +58,7 @@ Relay_log_info::Relay_log_info(bool is_s
> {
> DBUG_ENTER("Relay_log_info::Relay_log_info");
>
> + relay_log.is_relay_log= TRUE;
> #ifdef HAVE_PSI_INTERFACE
> relay_log.set_psi_keys(key_RELAYLOG_LOCK_index,
> key_RELAYLOG_update_cond,
> @@ -206,8 +207,6 @@ a file name for --relay-log-index option
> name_warning_sent= 1;
> }
>
> - rli->relay_log.is_relay_log= TRUE;
> -
> /*
> note, that if open() fails, we'll still have index file open
> but a destructor will take care of that
>
> === modified file 'sql/sql_class.h'
> --- a/sql/sql_class.h 2012-09-13 12:31:29 +0000
> +++ b/sql/sql_class.h 2012-09-14 12:44:53 +0000
> @@ -1244,7 +1244,8 @@ enum enum_thread_type
> SYSTEM_THREAD_SLAVE_SQL= 4,
> SYSTEM_THREAD_NDBCLUSTER_BINLOG= 8,
> SYSTEM_THREAD_EVENT_SCHEDULER= 16,
> - SYSTEM_THREAD_EVENT_WORKER= 32
> + SYSTEM_THREAD_EVENT_WORKER= 32,
> + SYSTEM_THREAD_BINLOG_BACKGROUND= 64
> };
>
> inline char const *
>
> === modified file 'storage/innobase/handler/ha_innodb.cc'
> --- a/storage/innobase/handler/ha_innodb.cc 2012-09-13 12:31:29 +0000
> +++ b/storage/innobase/handler/ha_innodb.cc 2012-09-14 12:44:53 +0000
> @@ -106,6 +106,7 @@ static ulong commit_threads = 0;
> static mysql_mutex_t commit_threads_m;
> static mysql_cond_t commit_cond;
> static mysql_mutex_t commit_cond_m;
> +static mysql_mutex_t pending_checkpoint_mutex;
> static bool innodb_inited = 0;
>
> #define INSIDE_HA_INNOBASE_CC
> @@ -222,11 +223,13 @@ static mysql_pfs_key_t innobase_share_mu
> static mysql_pfs_key_t commit_threads_m_key;
> static mysql_pfs_key_t commit_cond_mutex_key;
> static mysql_pfs_key_t commit_cond_key;
> +static mysql_pfs_key_t pending_checkpoint_mutex_key;
>
> static PSI_mutex_info all_pthread_mutexes[] = {
> {&commit_threads_m_key, "commit_threads_m", 0},
> {&commit_cond_mutex_key, "commit_cond_mutex", 0},
> - {&innobase_share_mutex_key, "innobase_share_mutex", 0}
> + {&innobase_share_mutex_key, "innobase_share_mutex", 0},
> + {&pending_checkpoint_mutex_key, "pending_checkpoint_mutex", 0}
> };
>
> static PSI_cond_info all_innodb_conds[] = {
> @@ -2592,6 +2595,9 @@ innobase_init(
> mysql_mutex_init(commit_cond_mutex_key,
> &commit_cond_m, MY_MUTEX_INIT_FAST);
> mysql_cond_init(commit_cond_key, &commit_cond, NULL);
> + mysql_mutex_init(pending_checkpoint_mutex_key,
> + &pending_checkpoint_mutex,
> + MY_MUTEX_INIT_FAST);
> innodb_inited= 1;
> #ifdef MYSQL_DYNAMIC_PLUGIN
> if (innobase_hton != p) {
> @@ -2639,6 +2645,7 @@ innobase_end(
> mysql_mutex_destroy(&commit_threads_m);
> mysql_mutex_destroy(&commit_cond_m);
> mysql_cond_destroy(&commit_cond);
> + mysql_mutex_destroy(&pending_checkpoint_mutex);
> }
>
> DBUG_RETURN(err);
> @@ -3008,6 +3015,16 @@ innobase_rollback_trx(
> DBUG_RETURN(convert_error_code_to_mysql(error, 0, NULL));
> }
>
> +
> +struct pending_checkpoint {
> + struct pending_checkpoint *next;
> + handlerton *hton;
> + void *cookie;
> + ib_uint64_t lsn;
> +};
> +static struct pending_checkpoint *pending_checkpoint_list;
> +static struct pending_checkpoint *pending_checkpoint_list_end;
> +
> /*****************************************************************//**
> Handle a commit checkpoint request from server layer.
> We simply flush the redo log immediately and do the notify call.*/
> @@ -3017,8 +3034,113 @@ innobase_checkpoint_request(
> handlerton *hton,
> void *cookie)
> {
> - log_buffer_flush_to_disk();
> - commit_checkpoint_notify_ha(hton, cookie);
> + ib_uint64_t lsn;
> + ib_uint64_t flush_lsn;
> + struct pending_checkpoint * entry;
> +
> + /* Do the allocation outside of lock to reduce contention. The normal
> + case is that not everything is flushed, so we will need to enqueue. */
> + entry = static_cast<struct pending_checkpoint *>
> + (my_malloc(sizeof(*entry), MYF(MY_WME)));
> + if (!entry) {
> + sql_print_error("Failed to allocate %u bytes."
> + " Commit checkpoint will be skipped.",
> + static_cast<unsigned>(sizeof(*entry)));
> + return;
> + }
> +
> + entry->next = NULL;
> + entry->hton = hton;
> + entry->cookie = cookie;
> +
> + mysql_mutex_lock(&pending_checkpoint_mutex);
> + lsn = log_get_lsn();
> + flush_lsn = log_get_flush_lsn();
> + if (lsn > flush_lsn) {
> + /* Put the request in queue.
> + When the log gets flushed past the lsn, we will remove the
> + entry from the queue and notify the upper layer. */
> + entry->lsn = lsn;
> + if (pending_checkpoint_list_end) {
> + pending_checkpoint_list_end->next = entry;
> + } else {
> + pending_checkpoint_list = entry;
> + }
> + pending_checkpoint_list_end = entry;
> + entry = NULL;
> + }
> + mysql_mutex_unlock(&pending_checkpoint_mutex);
> +
> + if (entry) {
> + /* We are already flushed. Notify the checkpoint immediately. */
> + commit_checkpoint_notify_ha(entry->hton, entry->cookie);
> + my_free(entry);
> + }
> +}
> +
> +/*****************************************************************//**
> +Log code calls this whenever log has been written and/or flushed up
> +to a new position. We use this to notify upper layer of a new commit
> +checkpoint when necessary.*/
> +extern "C" UNIV_INTERN
> +void
> +innobase_mysql_log_notify(
> +/*===============*/
> + ib_uint64_t write_lsn, /*!< in: LSN written to log file */
> + ib_uint64_t flush_lsn) /*!< in: LSN flushed to disk */
> +{
> + struct pending_checkpoint * pending;
> + struct pending_checkpoint * entry;
> + struct pending_checkpoint * last_ready;
> +
> + /* It is safe to do a quick check for NULL first without lock.
> + Even if we should race, we will at most skip one checkpoint and
> + take the next one, which is harmless. */
> + if (!pending_checkpoint_list)
> + return;
> +
> + mysql_mutex_lock(&pending_checkpoint_mutex);
> + pending = pending_checkpoint_list;
> + if (!pending)
> + {
> + mysql_mutex_unlock(&pending_checkpoint_mutex);
> + return;
> + }
> +
> + last_ready = NULL;
> + for (entry = pending; entry != NULL; entry = entry -> next)
> + {
> + if (entry->lsn > flush_lsn)
> + break;
> + last_ready = entry;
> + }
> +
> + if (last_ready)
> + {
> + /* We found some pending checkpoints that are now flushed to
> + disk. So remove them from the list. */
> + pending_checkpoint_list = entry;
> + if (!entry)
> + pending_checkpoint_list_end = NULL;
> + }
> +
> + mysql_mutex_unlock(&pending_checkpoint_mutex);
> +
> + if (!last_ready)
> + return;
> +
> + /* Now that we have released the lock, notify upper layer about all
> + commit checkpoints that have now completed. */
> + for (;;) {
> + entry = pending;
> + pending = pending->next;
> +
> + commit_checkpoint_notify_ha(entry->hton, entry->cookie);
> +
> + my_free(entry);
> + if (entry == last_ready)
> + break;
> + }
> }
>
> /*****************************************************************//**
>
> === modified file 'storage/innobase/include/ha_prototypes.h'
> --- a/storage/innobase/include/ha_prototypes.h 2011-04-26 17:55:52 +0000
> +++ b/storage/innobase/include/ha_prototypes.h 2012-09-14 12:44:53 +0000
> @@ -136,6 +136,17 @@ innobase_mysql_print_thd(
> uint max_query_len); /*!< in: max query length to print, or 0 to
> use the default max length */
>
> +/*****************************************************************//**
> +Log code calls this whenever log has been written and/or flushed up
> +to a new position. We use this to notify upper layer of a new commit
> +checkpoint when necessary.*/
> +UNIV_INTERN
> +void
> +innobase_mysql_log_notify(
> +/*===============*/
> + ib_uint64_t write_lsn, /*!< in: LSN written to log file */
> + ib_uint64_t flush_lsn); /*!< in: LSN flushed to disk */
> +
> /**************************************************************//**
> Converts a MySQL type to an InnoDB type. Note that this function returns
> the 'mtype' of InnoDB. InnoDB differentiates between MySQL's old <= 4.1
>
> === modified file 'storage/innobase/include/log0log.h'
> --- a/storage/innobase/include/log0log.h 2012-06-07 13:44:26 +0000
> +++ b/storage/innobase/include/log0log.h 2012-09-14 12:44:53 +0000
> @@ -151,6 +151,13 @@ UNIV_INLINE
> ib_uint64_t
> log_get_lsn(void);
> /*=============*/
> +/************************************************************//**
> +Gets the last lsn that is fully flushed to disk.
> +@return last flushed lsn */
> +UNIV_INLINE
> +ib_uint64_t
> +log_get_flush_lsn(void);
> +/*=============*/
> /****************************************************************
> Gets the log group capacity. It is OK to read the value without
> holding log_sys->mutex because it is constant.
>
> === modified file 'storage/innobase/include/log0log.ic'
> --- a/storage/innobase/include/log0log.ic 2011-04-05 07:18:43 +0000
> +++ b/storage/innobase/include/log0log.ic 2012-09-14 12:44:53 +0000
> @@ -411,6 +411,25 @@ log_get_lsn(void)
> return(lsn);
> }
>
> +/************************************************************//**
> +Gets the last lsn that is fully flushed to disk.
> +@return last flushed lsn */
> +UNIV_INLINE
> +ib_uint64_t
> +log_get_flush_lsn(void)
> +/*=============*/
> +{
> + ib_uint64_t lsn;
> +
> + mutex_enter(&(log_sys->mutex));
> +
> + lsn = log_sys->flushed_to_disk_lsn;
> +
> + mutex_exit(&(log_sys->mutex));
> +
> + return(lsn);
> +}
> +
> /****************************************************************
> Gets the log group capacity. It is OK to read the value without
> holding log_sys->mutex because it is constant.
>
> === modified file 'storage/innobase/log/log0log.c'
> --- a/storage/innobase/log/log0log.c 2012-03-21 03:48:12 +0000
> +++ b/storage/innobase/log/log0log.c 2012-09-14 12:44:53 +0000
> @@ -1353,6 +1353,8 @@ log_write_up_to(
> ulint loop_count = 0;
> #endif /* UNIV_DEBUG */
> ulint unlock;
> + ib_uint64_t write_lsn;
> + ib_uint64_t flush_lsn;
>
> if (recv_no_ibuf_operations) {
> /* Recovery is running and no operations on the log files are
> @@ -1530,8 +1532,13 @@ log_write_up_to(
>
> log_flush_do_unlocks(unlock);
>
> + write_lsn = log_sys->write_lsn;
> + flush_lsn = log_sys->flushed_to_disk_lsn;
> +
> mutex_exit(&(log_sys->mutex));
>
> + innobase_mysql_log_notify(write_lsn, flush_lsn);
> +
> return;
>
> do_waits:
>
> === modified file 'storage/xtradb/handler/ha_innodb.cc'
> --- a/storage/xtradb/handler/ha_innodb.cc 2012-09-13 12:31:29 +0000
> +++ b/storage/xtradb/handler/ha_innodb.cc 2012-09-14 12:44:53 +0000
> @@ -120,6 +120,7 @@ static ulong commit_threads = 0;
> static mysql_mutex_t commit_threads_m;
> static mysql_cond_t commit_cond;
> static mysql_mutex_t commit_cond_m;
> +static mysql_mutex_t pending_checkpoint_mutex;
> static bool innodb_inited = 0;
>
>
> @@ -253,11 +254,13 @@ static mysql_pfs_key_t innobase_share_mu
> static mysql_pfs_key_t commit_threads_m_key;
> static mysql_pfs_key_t commit_cond_mutex_key;
> static mysql_pfs_key_t commit_cond_key;
> +static mysql_pfs_key_t pending_checkpoint_mutex_key;
>
> static PSI_mutex_info all_pthread_mutexes[] = {
> {&commit_threads_m_key, "commit_threads_m", 0},
> {&commit_cond_mutex_key, "commit_cond_mutex", 0},
> - {&innobase_share_mutex_key, "innobase_share_mutex", 0}
> + {&innobase_share_mutex_key, "innobase_share_mutex", 0},
> + {&pending_checkpoint_mutex_key, "pending_checkpoint_mutex", 0}
> };
>
> static PSI_cond_info all_innodb_conds[] = {
> @@ -3060,6 +3063,9 @@ innobase_init(
> mysql_mutex_init(commit_cond_mutex_key,
> &commit_cond_m, MY_MUTEX_INIT_FAST);
> mysql_cond_init(commit_cond_key, &commit_cond, NULL);
> + mysql_mutex_init(pending_checkpoint_mutex_key,
> + &pending_checkpoint_mutex,
> + MY_MUTEX_INIT_FAST);
> innodb_inited= 1;
> #ifdef MYSQL_DYNAMIC_PLUGIN
> if (innobase_hton != p) {
> @@ -3107,6 +3113,7 @@ innobase_end(
> mysql_mutex_destroy(&commit_threads_m);
> mysql_mutex_destroy(&commit_cond_m);
> mysql_cond_destroy(&commit_cond);
> + mysql_mutex_destroy(&pending_checkpoint_mutex);
> }
>
> DBUG_RETURN(err);
> @@ -3500,6 +3507,16 @@ innobase_rollback_trx(
> DBUG_RETURN(convert_error_code_to_mysql(error, 0, NULL));
> }
>
> +
> +struct pending_checkpoint {
> + struct pending_checkpoint *next;
> + handlerton *hton;
> + void *cookie;
> + ib_uint64_t lsn;
> +};
> +static struct pending_checkpoint *pending_checkpoint_list;
> +static struct pending_checkpoint *pending_checkpoint_list_end;
> +
> /*****************************************************************//**
> Handle a commit checkpoint request from server layer.
> We simply flush the redo log immediately and do the notify call.*/
> @@ -3509,8 +3526,113 @@ innobase_checkpoint_request(
> handlerton *hton,
> void *cookie)
> {
> - log_buffer_flush_to_disk();
> - commit_checkpoint_notify_ha(hton, cookie);
> + ib_uint64_t lsn;
> + ib_uint64_t flush_lsn;
> + struct pending_checkpoint * entry;
> +
> + /* Do the allocation outside of lock to reduce contention. The normal
> + case is that not everything is flushed, so we will need to enqueue. */
> + entry = static_cast<struct pending_checkpoint *>
> + (my_malloc(sizeof(*entry), MYF(MY_WME)));
> + if (!entry) {
> + sql_print_error("Failed to allocate %u bytes."
> + " Commit checkpoint will be skipped.",
> + static_cast<unsigned>(sizeof(*entry)));
> + return;
> + }
> +
> + entry->next = NULL;
> + entry->hton = hton;
> + entry->cookie = cookie;
> +
> + mysql_mutex_lock(&pending_checkpoint_mutex);
> + lsn = log_get_lsn();
> + flush_lsn = log_get_flush_lsn();
> + if (lsn > flush_lsn) {
> + /* Put the request in queue.
> + When the log gets flushed past the lsn, we will remove the
> + entry from the queue and notify the upper layer. */
> + entry->lsn = lsn;
> + if (pending_checkpoint_list_end) {
> + pending_checkpoint_list_end->next = entry;
> + } else {
> + pending_checkpoint_list = entry;
> + }
> + pending_checkpoint_list_end = entry;
> + entry = NULL;
> + }
> + mysql_mutex_unlock(&pending_checkpoint_mutex);
> +
> + if (entry) {
> + /* We are already flushed. Notify the checkpoint immediately. */
> + commit_checkpoint_notify_ha(entry->hton, entry->cookie);
> + my_free(entry);
> + }
> +}
> +
> +/*****************************************************************//**
> +Log code calls this whenever log has been written and/or flushed up
> +to a new position. We use this to notify upper layer of a new commit
> +checkpoint when necessary.*/
> +extern "C" UNIV_INTERN
> +void
> +innobase_mysql_log_notify(
> +/*===============*/
> + ib_uint64_t write_lsn, /*!< in: LSN written to log file */
> + ib_uint64_t flush_lsn) /*!< in: LSN flushed to disk */
> +{
> + struct pending_checkpoint * pending;
> + struct pending_checkpoint * entry;
> + struct pending_checkpoint * last_ready;
> +
> + /* It is safe to do a quick check for NULL first without lock.
> + Even if we should race, we will at most skip one checkpoint and
> + take the next one, which is harmless. */
> + if (!pending_checkpoint_list)
> + return;
> +
> + mysql_mutex_lock(&pending_checkpoint_mutex);
> + pending = pending_checkpoint_list;
> + if (!pending)
> + {
> + mysql_mutex_unlock(&pending_checkpoint_mutex);
> + return;
> + }
> +
> + last_ready = NULL;
> + for (entry = pending; entry != NULL; entry = entry -> next)
> + {
> + if (entry->lsn > flush_lsn)
> + break;
> + last_ready = entry;
> + }
> +
> + if (last_ready)
> + {
> + /* We found some pending checkpoints that are now flushed to
> + disk. So remove them from the list. */
> + pending_checkpoint_list = entry;
> + if (!entry)
> + pending_checkpoint_list_end = NULL;
> + }
> +
> + mysql_mutex_unlock(&pending_checkpoint_mutex);
> +
> + if (!last_ready)
> + return;
> +
> + /* Now that we have released the lock, notify upper layer about all
> + commit checkpoints that have now completed. */
> + for (;;) {
> + entry = pending;
> + pending = pending->next;
> +
> + commit_checkpoint_notify_ha(entry->hton, entry->cookie);
> +
> + my_free(entry);
> + if (entry == last_ready)
> + break;
> + }
> }
>
> /*****************************************************************//**
>
> === modified file 'storage/xtradb/include/ha_prototypes.h'
> --- a/storage/xtradb/include/ha_prototypes.h 2012-02-21 19:51:56 +0000
> +++ b/storage/xtradb/include/ha_prototypes.h 2012-09-14 12:44:53 +0000
> @@ -136,6 +136,17 @@ innobase_mysql_print_thd(
> uint max_query_len); /*!< in: max query length to print, or 0 to
> use the default max length */
>
> +/*****************************************************************//**
> +Log code calls this whenever log has been written and/or flushed up
> +to a new position. We use this to notify upper layer of a new commit
> +checkpoint when necessary.*/
> +UNIV_INTERN
> +void
> +innobase_mysql_log_notify(
> +/*===============*/
> + ib_uint64_t write_lsn, /*!< in: LSN written to log file */
> + ib_uint64_t flush_lsn); /*!< in: LSN flushed to disk */
> +
> /**************************************************************//**
> Converts a MySQL type to an InnoDB type. Note that this function returns
> the 'mtype' of InnoDB. InnoDB differentiates between MySQL's old <= 4.1
>
> === modified file 'storage/xtradb/include/log0log.h'
> --- a/storage/xtradb/include/log0log.h 2012-08-27 16:13:17 +0000
> +++ b/storage/xtradb/include/log0log.h 2012-09-14 12:44:53 +0000
> @@ -151,6 +151,13 @@ UNIV_INLINE
> ib_uint64_t
> log_get_lsn(void);
> /*=============*/
> +/************************************************************//**
> +Gets the last lsn that is fully flushed to disk.
> +@return last flushed lsn */
> +UNIV_INLINE
> +ib_uint64_t
> +log_get_flush_lsn(void);
> +/*=============*/
> /****************************************************************
> Gets the log group capacity. It is OK to read the value without
> holding log_sys->mutex because it is constant.
>
> === modified file 'storage/xtradb/include/log0log.ic'
> --- a/storage/xtradb/include/log0log.ic 2011-07-14 19:22:41 +0000
> +++ b/storage/xtradb/include/log0log.ic 2012-09-14 12:44:53 +0000
> @@ -411,6 +411,25 @@ log_get_lsn(void)
> return(lsn);
> }
>
> +/************************************************************//**
> +Gets the last lsn that is fully flushed to disk.
> +@return last flushed lsn */
> +UNIV_INLINE
> +ib_uint64_t
> +log_get_flush_lsn(void)
> +/*=============*/
> +{
> + ib_uint64_t lsn;
> +
> + mutex_enter(&(log_sys->mutex));
> +
> + lsn = log_sys->flushed_to_disk_lsn;
> +
> + mutex_exit(&(log_sys->mutex));
> +
> + return(lsn);
> +}
> +
> /****************************************************************
> Gets the log group capacity. It is OK to read the value without
> holding log_sys->mutex because it is constant.
>
> === modified file 'storage/xtradb/log/log0log.c'
> --- a/storage/xtradb/log/log0log.c 2012-08-27 16:13:17 +0000
> +++ b/storage/xtradb/log/log0log.c 2012-09-14 12:44:53 +0000
> @@ -1390,6 +1390,8 @@ log_write_up_to(
> ulint loop_count = 0;
> #endif /* UNIV_DEBUG */
> ulint unlock;
> + ib_uint64_t write_lsn;
> + ib_uint64_t flush_lsn;
>
> if (recv_no_ibuf_operations) {
> /* Recovery is running and no operations on the log files are
> @@ -1568,8 +1570,13 @@ log_write_up_to(
>
> log_flush_do_unlocks(unlock);
>
> + write_lsn = log_sys->write_lsn;
> + flush_lsn = log_sys->flushed_to_disk_lsn;
> +
> mutex_exit(&(log_sys->mutex));
>
> + innobase_mysql_log_notify(write_lsn, flush_lsn);
> +
> return;
>
> do_waits:
>
> _______________________________________________
> commits mailing list
> commits(a)mariadb.org
> https://lists.askmonty.org/cgi-bin/mailman/listinfo/commits
2
2
[Maria-developers] review of the MDEV-377 Name support for dynamic columns
by Sergei Golubchik 14 Dec '12
by Sergei Golubchik 14 Dec '12
14 Dec '12
Hi, Sanja,
See my review comments below:
> === modified file 'include/ma_dyncol.h'
> --- include/ma_dyncol.h 2011-09-22 09:04:00 +0000
> +++ include/ma_dyncol.h 2012-11-12 15:11:23 +0000
> @@ -39,6 +39,12 @@
> */
> #define MAX_DYNAMIC_COLUMN_LENGTH 0X1FFFFFFFL
>
> +/*
> + Limits of implementation
> +*/
> +#define MAX_NAME_LENGTH 255
If we store only offsets, this limit can go away
> +#define MAX_TOTAL_NAME_LENGTH 65535
I'd suggest to store the offset length in the header, just as
you do for data offsets. You might hard-code the fixed offset of 2,
but if it's in the header, you can later change it, if needed.
> +
> /* NO and OK is the same used just to show semantics */
> #define ER_DYNCOL_NO ER_DYNCOL_OK
>
> @@ -81,6 +88,7 @@ struct st_dynamic_column_value
> struct {
> LEX_STRING value;
> CHARSET_INFO *charset;
> + my_bool nonfreeable;
Yuck. That doesn't look correct. Dynamic column code does not allocate
or frees values. The concept of "nonfreeable" values simply has
no place in the dynamic column universe.
I realize that ha_cassandra needs to know whether to free certain strings
or not. But it's the internal problem of ha_cassandra, it has nothing
to do with dynaic columns, besides the fact that these certain strings
are sometines stored in the struct st_dynamic_column_value.
> } string;
> struct {
> decimal_digit_t buffer[DECIMAL_BUFF_LENGTH];
> @@ -103,6 +111,20 @@ dynamic_column_create_many(DYNAMIC_COLUM
> DYNAMIC_COLUMN_VALUE *values);
>
> enum enum_dyncol_func_result
> +dynamic_column_create_many_fmt(DYNAMIC_COLUMN *str,
> + uint column_count,
> + uchar *column_keys,
> + DYNAMIC_COLUMN_VALUE *values,
> + my_bool names);
I think this should rather be
dynamic_column_create_many_named(DYNAMIC_COLUMN *str,
uint column_count,
LEX_STRING *column_keys,
DYNAMIC_COLUMN_VALUE *values);
> +enum enum_dyncol_func_result
> +dynamic_column_create_many_internal_fmt(DYNAMIC_COLUMN *str,
> + uint column_count,
> + void *column_keys,
> + DYNAMIC_COLUMN_VALUE *values,
> + my_bool new_str,
> + my_bool string_keys);
*internal* should not be in include/, it's not part of the API
> +
> +enum enum_dyncol_func_result
> dynamic_column_update(DYNAMIC_COLUMN *org, uint column_nr,
> DYNAMIC_COLUMN_VALUE *value);
> enum enum_dyncol_func_result
> @@ -110,16 +132,30 @@ dynamic_column_update_many(DYNAMIC_COLUM
> uint add_column_count,
> uint *column_numbers,
> DYNAMIC_COLUMN_VALUE *values);
> +enum enum_dyncol_func_result
> +dynamic_column_update_many_fmt(DYNAMIC_COLUMN *str,
> + uint add_column_count,
> + void *column_keys,
> + DYNAMIC_COLUMN_VALUE *values,
> + my_bool string_keys);
same as above, make it dynamic_column_update_many_named
>
> enum enum_dyncol_func_result
> dynamic_column_delete(DYNAMIC_COLUMN *org, uint column_nr);
>
> enum enum_dyncol_func_result
> dynamic_column_exists(DYNAMIC_COLUMN *org, uint column_nr);
> +enum enum_dyncol_func_result
> +dynamic_column_exists_str(DYNAMIC_COLUMN *str, LEX_STRING *name);
> +enum enum_dyncol_func_result
> +dynamic_column_exists_fmt(DYNAMIC_COLUMN *str, void *key, my_bool string_keys);
remove the second one, and rename the first s/_str/_named/
>
> /* List of not NULL columns */
> enum enum_dyncol_func_result
> dynamic_column_list(DYNAMIC_COLUMN *org, DYNAMIC_ARRAY *array_of_uint);
> +enum enum_dyncol_func_result
> +dynamic_column_list_str(DYNAMIC_COLUMN *str, DYNAMIC_ARRAY *array_of_lexstr);
> +enum enum_dyncol_func_result
> +dynamic_column_list_fmt(DYNAMIC_COLUMN *str, DYNAMIC_ARRAY *array, my_bool string_keys);
Same.
>
> /*
> if the column do not exists it is NULL
> @@ -127,10 +163,36 @@ dynamic_column_list(DYNAMIC_COLUMN *org,
> enum enum_dyncol_func_result
> dynamic_column_get(DYNAMIC_COLUMN *org, uint column_nr,
> DYNAMIC_COLUMN_VALUE *store_it_here);
> +enum enum_dyncol_func_result
> +dynamic_column_get_str(DYNAMIC_COLUMN *str, LEX_STRING *name,
> + DYNAMIC_COLUMN_VALUE *store_it_here);
s/_str/_named
> +
> +my_bool dynamic_column_has_names(DYNAMIC_COLUMN *str);
> +
> +enum enum_dyncol_func_result
> +dynamic_column_check(DYNAMIC_COLUMN *str);
> +
> +enum enum_dyncol_func_result
> +dynamic_column_json(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json);
>
> #define dynamic_column_initialize(A) memset((A), 0, sizeof(*(A)))
> #define dynamic_column_column_free(V) dynstr_free(V)
>
> +/* conversion of values to 3 base types */
> +enum enum_dyncol_func_result
> +dynamic_column_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val,
> + CHARSET_INFO *cs, my_bool quote);
instead of my_bool quote, better pass a char quote_char.
when it's 0 - no quoting. Otherwise it can be " or `
To make it less error prone, you can create an enum
NOT_QUOTED=0, QUOTED='`', ANSI_QUOTED='"'
> +enum enum_dyncol_func_result
> +dynamic_column_val_long(longlong *ll, DYNAMIC_COLUMN_VALUE *val);
> +enum enum_dyncol_func_result
> +dynamic_column_val_double(double *dbl, DYNAMIC_COLUMN_VALUE *val);
> +
> +
> +enum enum_dyncol_func_result
> +dynamic_column_vals(DYNAMIC_COLUMN *str,
> + DYNAMIC_ARRAY *names, DYNAMIC_ARRAY *vals,
> + char **free_names);
Eh. may be dynamic_column_unpack() ?
> +
> /***************************************************************************
> Internal functions, don't use if you don't know what you are doing...
> ***************************************************************************/
>
> === modified file 'mysql-test/t/dyncol.test'
> --- mysql-test/t/dyncol.test 2012-02-29 20:55:04 +0000
> +++ mysql-test/t/dyncol.test 2012-11-12 15:11:23 +0000
> @@ -550,3 +550,125 @@ select hex(COLUMN_CREATE(0, COLUMN_GET(@
>
> select hex(COLUMN_CREATE(0, COLUMN_GET(COLUMN_CREATE(0, 0.0 as decimal), 0 as decimal)));
> select hex(COLUMN_CREATE(0, 0.0 as decimal));
> +
> +--echo #
> +--echo # test of symbolic names
> +--echo #
> +--echo # creation test (names)
> +set names utf8;
> +select hex(column_create("адын", 1212));
> +select hex(column_create("1212", 1212));
> +select hex(column_create(1212, 2, "www", 3));
> +select hex(column_create("1212", 2, "www", 3));
> +select hex(column_create("1212", 2, 3, 3));
> +select hex(column_create("1212", 2, "адын", 1, 3, 3));
to test quoting, add a column with a ` (backtick) in the name
and few other strange names - with a single quote, double quote, backslash,
space, dot, comma, whatever
> +set names default;
...
> === modified file 'sql/sql_yacc.yy'
> --- sql/sql_yacc.yy 2012-06-13 23:28:47 +0000
> +++ sql/sql_yacc.yy 2012-11-12 15:11:23 +0000
> @@ -8799,6 +8801,13 @@ function_call_nonkeyword:
> MYSQL_YYABORT;
> }
> |
> + COLUMN_CHECK_SYM '(' expr ')'
> + {
> + $$= new (YYTHD->mem_root) Item_func_dyncol_check($3);
> + if ($$ == NULL)
> + MYSQL_YYABORT;
> + }
> + |
This should be removed completely. See, for example, how EXP function
is created (hint: in item_create.cc) and do the same
> COLUMN_EXISTS_SYM '(' expr ',' expr ')'
> {
> $$= new (YYTHD->mem_root) Item_func_dyncol_exists($3, $5);
> @@ -8820,6 +8829,13 @@ function_call_nonkeyword:
> MYSQL_YYABORT;
> }
> |
> + COLUMN_JSON_SYM '(' expr ')'
> + {
> + $$= create_func_dyncol_json(YYTHD, $3);
> + if ($$ == NULL)
> + MYSQL_YYABORT;
> + }
> + |
same. please, remove the dedicated rule for this and most of other
COLUMN_xxx functions.
> COLUMN_GET_SYM '(' expr ',' expr AS cast_type ')'
> {
> LEX *lex= Lex;
>
> === modified file 'mysys/ma_dyncol.c'
> --- mysys/ma_dyncol.c 2011-11-22 17:04:38 +0000
> +++ mysys/ma_dyncol.c 2012-11-12 15:11:23 +0000
> @@ -37,19 +41,42 @@
> */
> /* mask to get above bits */
> #define DYNCOL_FLG_OFFSET 3
> +#define DYNCOL_FLG_NAMES 4
> /* All known flags mask */
> -#define DYNCOL_FLG_KNOWN 3
> +#define DYNCOL_FLG_KNOWN 7
> +
> +/* formats */
> +#define DYNCOL_FMT_NUM 0
> +#define DYNCOL_FMT_STR 1
why not an enum?
>
> /* dynamic column size reserve */
> #define DYNCOL_SYZERESERVE 80
>
> +#define DYNCOL_OFFSET_ERROR 0xffffffff
> +
> /* length of fixed string header 1 byte - flags, 2 bytes - columns counter */
> #define FIXED_HEADER_SIZE 3
> +/*
> + length of fixed string header with names
> + 1 byte - flags, 2 bytes - columns counter, 2 bytes - name pool size
> +*/
> +#define FIXED_HEADER_SIZE_NM 5
>
> #define COLUMN_NUMBER_SIZE 2
> +/* 1 byte name length + 2 bytes offset from the name pool */
> +#define COLUMN_NAMEPTR_SIZE 3
>
> #define MAX_OFFSET_LENGTH 5
>
> +#define DYNCOL_NUM_CHAR 6
> +
> +my_bool dynamic_column_has_names(DYNAMIC_COLUMN *str)
> +{
> + if (str->length < 1)
> + return FALSE;
> + return test(str->str[0] & DYNCOL_FLG_NAMES);
> +}
> +
> static enum enum_dyncol_func_result
> dynamic_column_time_store(DYNAMIC_COLUMN *str,
> MYSQL_TIME *value);
> @@ -62,6 +89,311 @@ dynamic_column_time_read_internal(DYNAMI
> static enum enum_dyncol_func_result
> dynamic_column_date_read_internal(DYNAMIC_COLUMN_VALUE *store_it_here,
> uchar *data, size_t length);
> +static enum enum_dyncol_func_result
> +dynamic_column_get_internal(DYNAMIC_COLUMN *str,
> + DYNAMIC_COLUMN_VALUE *store_it_here,
> + uint num_key, LEX_STRING *str_key);
> +static enum enum_dyncol_func_result
> +dynamic_column_exists_internal(DYNAMIC_COLUMN *str, uint num_key,
> + LEX_STRING *str_key);
> +enum enum_dyncol_func_result
> +dynamic_column_update_many_fmt(DYNAMIC_COLUMN *str,
> + uint add_column_count,
> + void *column_keys,
> + DYNAMIC_COLUMN_VALUE *values,
> + my_bool string_keys);
> +static int plan_sort_num(const void *a, const void *b);
> +static int plan_sort_str(const void *a, const void *b);
> +
> +/*
> + Structure to hold information about dynamic columns record and
> + iterate through it.
> +*/
> +
> +struct st_dyn_header
> +{
> + uchar *header, *nmpool, *dtpool, *data_end;
> + size_t offset_size;
> + size_t entry_size;
> + size_t header_size;
> + size_t nmpool_size;
> + size_t data_size;
> + /* DYNCOL_FMT_NUM - numeric columns, DYNCOL_FMT_STR - column names */
> + uint format;
> + uint column_count;
> +
> + uchar *entry, *data, *name;
> + size_t offset;
> + uint length;
> + enum enum_dynamic_column_type type;
> +};
> +
> +typedef struct st_dyn_header DYN_HEADER;
> +
> +static inline my_bool read_fixed_header(DYN_HEADER *hdr,
> + DYNAMIC_COLUMN *str);
> +static void set_fixed_header(DYNAMIC_COLUMN *str,
> + uint offset_size,
> + uint column_count);
> +static my_bool type_and_offset_store(uchar *place, size_t offset_size,
> + DYNAMIC_COLUMN_TYPE type,
> + size_t offset);
> +
> +/*
> + Calculate entry size (E) and header size (H) by offset size (O) and column
> + count (C) and fixed part of entry size (F).
> +*/
> +
> +#define calc_param(E,H,F,O,C) do { \
> + (*(E))= (O) + F; \
> + (*(H))= (*(E)) * (C); \
> +}while(0);
> +
> +
> +/**
> + Name pool size functions, for numeric format it is 0
> +*/
> +
> +size_t name_size_num(void *keys __attribute__((unused)),
> + uint i __attribute__((unused)))
> +{
> + return 0;
> +}
> +
> +
> +/**
> + Name pool size functions.
> +*/
> +size_t name_size_str(void *keys, uint i)
> +{
> + return ((LEX_STRING *) keys)[i].length;
> +}
> +
> +
> +/**
> + Comparator function for references on column numbers for qsort
> + (numeric format)
> +*/
> +
> +static int column_sort_num(const void *a, const void *b)
> +{
> + return **((uint **)a) - **((uint **)b);
> +}
> +
> +
> +/**
> + Comparator function for references on column numbers for qsort
> + (names format)
> +*/
> +
> +static int column_sort_str(const void *a, const void *b)
> +{
> + LEX_STRING *s1= *((LEX_STRING **)a);
> + LEX_STRING *s2= *((LEX_STRING **)b);
> + int rc= s1->length - s2->length;
> + if (rc == 0)
> + rc= memcmp((void *)s1->str, (void *)s2->str, (size_t) s1->length);
> + return rc;
> +}
> +
> +
> +/**
> + Check limit function (numeric format)
> +*/
> +
> +static my_bool check_limit_num(const void *val)
> +{
> + return **((uint **)val) > UINT_MAX16;
> +}
> +
> +
> +/**
> + Check limit function (names format)
> +*/
> +
> +static my_bool check_limit_str(const void *val)
> +{
> + return (*((LEX_STRING **)val))->length > MAX_NAME_LENGTH;
> +}
> +
> +
> +/**
> + Write numeric format static header part.
> +*/
> +
> +void set_fixed_header_num(DYNAMIC_COLUMN *str, DYN_HEADER *hdr)
> +{
> + set_fixed_header(str, hdr->offset_size, hdr->column_count);
> + hdr->header= (uchar *)str->str + FIXED_HEADER_SIZE;
> + hdr->nmpool= hdr->dtpool= hdr->header + hdr->header_size;
> +}
> +
> +
> +/**
> + Write names format static header part.
> +*/
> +
> +void set_fixed_header_str(DYNAMIC_COLUMN *str, DYN_HEADER *hdr)
> +{
> + set_fixed_header(str, hdr->offset_size, hdr->column_count);
There's no need to write the column count there, you save two bytes per record.
a column count = (offset of the first name - size of the fized header) / (size of the fixed per column header)
> + str->str[0]|= DYNCOL_FLG_NAMES;
> + int2store(str->str + 3, hdr->nmpool_size);
> + hdr->header= (uchar *)str->str + FIXED_HEADER_SIZE_NM;
> + hdr->nmpool= hdr->header + hdr->header_size;
> + hdr->dtpool= hdr->nmpool + hdr->nmpool_size;
> +}
> +
> +
> +/**
> + Write numeric format header entry
> + 2 bytes - column number
> + 1-4 bytes - data offset combined with type
> +
> + @param hdr descriptor of dynamic column record
> + @param column_key pointer to uint (column number)
> + @param value value which will be written (only type used)
> + @param offset offset of the data
> +*/
> +
> +my_bool put_header_entry_num(DYN_HEADER *hdr,
this is and many other functions should be static
> + void *column_key,
> + DYNAMIC_COLUMN_VALUE *value,
> + size_t offset)
> +{
> + uint *column_number= (uint *)column_key;
> + int2store(hdr->entry, *column_number);
> + DBUG_ASSERT(hdr->nmpool_size == 0);
> + if (type_and_offset_store(hdr->entry, hdr->offset_size,
> + value->type,
> + offset))
> + return TRUE;
> + hdr->entry= hdr->entry + hdr->entry_size;
> + return FALSE;
> +}
> +
> +
> +/**
> + Write names format header entry
> + 1 byte - name length
> + 2 bytes - name offset in the name pool
as discussed on the irc, please store either lengths or offsets, but not both
> + 1-4 bytes - data offset combined with type
> +
> + @param hdr descriptor of dynamic column record
> + @param column_key pointer to LEX_STRING (column name)
> + @param value value which will be written (only type used)
> + @param offset offset of the data
> +*/
> +
> +my_bool put_header_entry_str(DYN_HEADER *hdr,
> + void *column_key,
> + DYNAMIC_COLUMN_VALUE *value,
> + size_t offset)
> +{
> + LEX_STRING *column_name= (LEX_STRING *)column_key;
> + DBUG_ASSERT(column_name->length <= MAX_NAME_LENGTH);
> + hdr->entry[0]= column_name->length;
> + DBUG_ASSERT(hdr->name - hdr->nmpool < (long) 0x10000L);
> + int2store(hdr->entry + 1, hdr->name - hdr->nmpool);
> + memcpy(hdr->name, column_name->str, column_name->length);
> + DBUG_ASSERT(hdr->nmpool_size != 0 || column_name->length == 0);
> + if (type_and_offset_store(hdr->entry + 1, hdr->offset_size,
> + value->type,
> + offset))
> + return TRUE;
> + hdr->entry+= hdr->entry_size;
> + hdr->name+= column_name->length;
> + return FALSE;
> +}
> +
> +
> +/**
> + Format descriptor, contain constants and function references for
> + format processing
> +*/
> +
> +struct st_service_funcs
> +{
> + /* size of fixed header */
> + uint fixed_hdr;
> + /* size of fixed part of header entry */
> + uint fixed_hdr_entry;
> +
> + /*size of array element which stores keys */
> + uint key_size_in_array;
> +
> + size_t (*name_size)
> + (void *, uint);
> + int (*column_sort)
> + (const void *a, const void *b);
> + my_bool (*check_limit)
> + (const void *val);
> + void (*set_fixed_hdr)
> + (DYNAMIC_COLUMN *str, DYN_HEADER *hdr);
> + my_bool (*put_header_entry)(DYN_HEADER *hdr,
> + void *column_key,
> + DYNAMIC_COLUMN_VALUE *value,
> + size_t offset);
> + int (*plan_sort)(const void *a, const void *b);
> +};
> +
> +
> +/**
> + Actual our 2 format descriptors
> +*/
> +
> +static struct st_service_funcs fmt_data[2]=
> +{
> + {
> + FIXED_HEADER_SIZE,
> + COLUMN_NUMBER_SIZE,
> + sizeof(uint),
> + &name_size_num,
> + &column_sort_num,
> + &check_limit_num,
> + &set_fixed_header_num,
> + &put_header_entry_num,
> + &plan_sort_num
> + },
> + {
> + FIXED_HEADER_SIZE_NM,
> + COLUMN_NAMEPTR_SIZE,
> + sizeof(LEX_STRING),
> + &name_size_str,
> + &column_sort_str,
> + &check_limit_str,
> + &set_fixed_header_str,
> + &put_header_entry_str,
> + &plan_sort_str
> + }
> +};
> +
> +
> +/**
> + Read dynamic column record header and fill the descriptor
> +
> + @param hdr dynamic columns record descriptor to fill
> + @param str dynamic columns record
> +
> + @return ER_DYNCOL_* return code
> +*/
> +
> +enum enum_dyncol_func_result
> +init_read_hdr(DYN_HEADER *hdr, DYNAMIC_COLUMN *str)
> +{
> + if (read_fixed_header(hdr, str))
> + return ER_DYNCOL_FORMAT;
> + hdr->header= (uchar*)str->str + fmt_data[hdr->format].fixed_hdr;
> + calc_param(&hdr->entry_size, &hdr->header_size,
> + fmt_data[hdr->format].fixed_hdr_entry, hdr->offset_size,
> + hdr->column_count);
> + hdr->nmpool= hdr->header + hdr->header_size;
> + hdr->dtpool= hdr->nmpool + hdr->nmpool_size;
> + hdr->data_size= str->length - fmt_data[hdr->format].fixed_hdr -
> + hdr->header_size - hdr->nmpool_size;
> + hdr->data_end= (uchar*)str->str + str->length;
> + return ER_DYNCOL_OK;
> +}
> +
>
> /**
> Initialize dynamic column string with (make it empty but correct format)
> @@ -1640,83 +2132,763 @@ dynamic_column_list(DYNAMIC_COLUMN *str,
>
>
> /**
> + List not-null columns in the packed string (any format)
> +
> + @param str The packed string
> + @param array_of_lexstr Where to put reference on created array
> +
> + @return ER_DYNCOL_* return code
> +*/
> +
> +enum enum_dyncol_func_result
> +dynamic_column_list_str(DYNAMIC_COLUMN *str, DYNAMIC_ARRAY *array_of_lexstr)
> +{
> + DYN_HEADER header;
> + uchar *read;
> + struct st_service_funcs *fmt;
> + uint i;
> + enum enum_dyncol_func_result rc;
> +
> + bzero(array_of_lexstr, sizeof(*array_of_lexstr)); /* In case of errors */
> + if (str->length == 0)
> + return ER_DYNCOL_OK; /* no columns */
> +
> + if ((rc= init_read_hdr(&header, str)) < 0)
> + return rc;
> +
> + fmt= fmt_data + header.format;
> +
> + if (header.entry_size * header.column_count + fmt->fixed_hdr >
> + str->length)
> + return ER_DYNCOL_FORMAT;
> +
> + if (init_dynamic_array(array_of_lexstr, sizeof(LEX_STRING),
> + header.column_count, 0))
> + return ER_DYNCOL_RESOURCE;
> +
> + for (i= 0, read= header.header;
> + i < header.column_count;
> + i++, read+= header.entry_size)
> + {
> + LEX_STRING tmp;
> + if (header.format == DYNCOL_FMT_NUM)
> + {
> + uint nm= uint2korr(read);
> + tmp.str= my_malloc(DYNCOL_NUM_CHAR, MYF(0));
ouch. do you really need to do header.column_count small mallocs here?
> + if (!tmp.str)
> + return ER_DYNCOL_RESOURCE;
> + tmp.length= snprintf(tmp.str, DYNCOL_NUM_CHAR, "%u", nm);
longlong2str or longlong10_to_str
> + }
> + else
> + {
> + tmp.length= read[0];
> + tmp.str= my_malloc(tmp.length + 1, MYF(0));
ouch. do you really need to do header.column_count small mallocs here?
> + if(!tmp.str)
> + return ER_DYNCOL_RESOURCE;
> + memcpy(tmp.str, (const void *)header.nmpool + uint2korr(read + 1),
> + tmp.length);
> + tmp.str[tmp.length]= '\0'; // just for safety
> + }
> + /* Insert can't never fail as it's pre-allocated above */
> + (void) insert_dynamic(array_of_lexstr, (uchar *)&tmp);
> + }
> + return ER_DYNCOL_OK;
> +}
> +
> +/**
> Find the place of the column in the header or place where it should be put
>
> - @param num Number of the column
> - @param header Pointer to the header
> - @param entry_size Size of a header entry
> - @param column_count Number of columns in the packed string
> - @param entry Return pointer to the entry or next entry
> + @param hdr descriptor of dynamic column record
> + @param key Name or number of column to fetch
> + (depends on string_key)
> + @param string_key True if we gave pointer to LEX_STRING.
>
> @retval TRUE found
> @retval FALSE pointer set to the next row
> */
>
> static my_bool
> -find_place(uint num, uchar *header, size_t entry_size,
> - uint column_count, uchar **entry)
> +find_place(DYN_HEADER *hdr, void *key, my_bool string_keys)
> {
> uint mid, start, end, val;
> int flag;
> + LEX_STRING str;
> + char buff[DYNCOL_NUM_CHAR];
> + my_bool need_conversion= ((string_keys ? DYNCOL_FMT_STR : DYNCOL_FMT_NUM) !=
> + hdr->format);
> LINT_INIT(flag); /* 100 % safe */
UNINIT_VAR is preferable, when possible (but it doesn't work with structures)
> + /* new format can't be numeric if the old one is names */
> + DBUG_ASSERT(string_keys ||
> + hdr->format == DYNCOL_FMT_NUM);
>
> start= 0;
> - end= column_count -1;
> + end= hdr->column_count -1;
> mid= 1;
> while (start != end)
> {
> - uint val;
> - mid= (start + end) / 2;
> - val= uint2korr(header + mid * entry_size);
> - if ((flag= CMP_NUM(num, val)) <= 0)
> - end= mid;
> - else
> - start= mid + 1;
> + uint val;
> + mid= (start + end) / 2;
> + hdr->entry= hdr->header + mid * hdr->entry_size;
> + if (!string_keys)
> + {
> + val= uint2korr(hdr->entry);
> + flag= CMP_NUM(*((uint *)key), val);
> + }
> + else
> + {
> + if (need_conversion)
> + {
> + str.str= backwritenum(buff + sizeof(buff), uint2korr(hdr->entry));
> + str.length= (buff + sizeof(buff)) - str.str;
> + }
> + else
> + {
> + DBUG_ASSERT(hdr->format == DYNCOL_FMT_STR);
> + str.length= hdr->entry[0];
> + str.str= (char *)hdr->nmpool + uint2korr(hdr->entry + 1);
> + }
> + flag= ((LEX_STRING *) key)->length - str.length;
> + if (flag == 0)
> + flag= memcmp(((LEX_STRING *) key)->str, str.str, str.length);
> + }
> + if (flag <= 0)
> + end= mid;
> + else
> + start= mid + 1;
> }
> + hdr->entry= hdr->header + start * hdr->entry_size;
> if (start != mid)
> {
> - val= uint2korr(header + start * entry_size);
> - flag= CMP_NUM(num, val);
> + if (!string_keys)
> + {
> + val= uint2korr(hdr->entry);
> + flag= CMP_NUM(*((uint *)key), val);
> + }
> + else
> + {
> + if (need_conversion)
> + {
> + str.str= backwritenum(buff + sizeof(buff), uint2korr(hdr->entry));
> + str.length= (buff + sizeof(buff)) - str.str;
> + }
> + else
> + {
> + DBUG_ASSERT(hdr->format == DYNCOL_FMT_STR);
> + str.length= hdr->entry[0];
> + str.str= (char*) hdr->nmpool + uint2korr(hdr->entry + 1);
> + }
> + flag= ((LEX_STRING *) key)->length - str.length;
> + if (flag == 0)
> + flag= memcmp(((LEX_STRING *) key)->str, str.str, str.length);
> + }
> }
> - *entry= header + start * entry_size;
> if (flag > 0)
> - *entry+= entry_size; /* Point at next bigger key */
> + hdr->entry+= hdr->entry_size; /* Point at next bigger key */
> return flag == 0;
> }
>
>
> /*
> - Description of plan of adding/removing/updating a packed string
> + It is internal structure which describes plan of chenging the record
s/chenging/changing/
what do you mean "a plan" ?
> + of dynamic columns
> */
>
> typedef enum {PLAN_REPLACE, PLAN_ADD, PLAN_DELETE, PLAN_NOP} PLAN_ACT;
>
> struct st_plan {
> DYNAMIC_COLUMN_VALUE *val;
> - uint *num;
> + void *key;
> uchar *place;
> size_t length;
> - int hdelta, ddelta;
> + int hdelta, ddelta, ndelta;
> + uint mv_offset, mv_length, mv_end;
> PLAN_ACT act;
> };
> typedef struct st_plan PLAN;
>
>
> -static int plan_sort(const void *a, const void *b)
> +/**
> + Sort function for plan by column number
> +*/
> +
> +static int plan_sort_num(const void *a, const void *b)
> {
> - return ((PLAN *)a)->num[0] - ((PLAN *)b)->num[0];
> + return *((uint *)((PLAN *)a)->key) - *((uint *)((PLAN *)b)->key);
> +}
> +
> +
> +/**
> + Sort function for plan by column name
> +*/
> +
> +static int plan_sort_str(const void *a, const void *b)
> +{
> + int res= (((LEX_STRING *)((PLAN *)a)->key)->length -
> + ((LEX_STRING *)((PLAN *)b)->key)->length);
> + if (res == 0)
> + res= memcmp(((LEX_STRING *)((PLAN *)a)->key)->str,
> + ((LEX_STRING *)((PLAN *)b)->key)->str,
> + ((LEX_STRING *)((PLAN *)a)->key)->length);
> + return res;
> +}
> +
> +#define DELTA_CHECK(S, D, C) \
> + if ((S) == 0) \
> + (S)= (D); \
> + else if (((S) > 0 && (D) < 0) || \
> + ((S) < 0 && (D) > 0)) \
> + { \
> + (C)= TRUE; \
> + }
> +
> +/**
> + Update dynamic column by copying in a new record (string).
> +
> + @param str Dynamic column record to change
> + @param plan Plan of changing the record
> + @param add_column_count number of records in the plan array.
> + @param hdr descriptor of old dynamic column record
> + @param new_hdr descriptor of new dynamic column record
> + @param convert need conversion from numeric to names format
> +
> + @return ER_DYNCOL_* return code
> +*/
> +
> +enum enum_dyncol_func_result
> +dynamic_column_update_copy(DYNAMIC_COLUMN *str, PLAN *plan,
> + uint add_column_count,
> + DYN_HEADER *hdr, DYN_HEADER *new_hdr,
> + my_bool convert)
> +{
> + DYNAMIC_COLUMN tmp;
> + struct st_service_funcs *fmt= fmt_data + hdr->format,
> + *new_fmt= fmt_data + new_hdr->format;
> + uint i, j, k;
> + size_t all_headers_size;
> +
> + if (dynamic_column_init_str(&tmp,
> + (new_fmt->fixed_hdr + new_hdr->header_size +
> + new_hdr->nmpool_size +
> + new_hdr->data_size + DYNCOL_SYZERESERVE)))
> + {
> + return ER_DYNCOL_RESOURCE;
> + }
> + bzero(tmp.str, new_fmt->fixed_hdr);
> + (*new_fmt->set_fixed_hdr)(&tmp, new_hdr);
> + /* Adjust tmp to contain whole the future header */
> + tmp.length= new_fmt->fixed_hdr + new_hdr->header_size + new_hdr->nmpool_size;
> +
> +
> + /*
> + Copy data to the new string
> + i= index in array of changes
> + j= index in packed string header index
> + */
> + new_hdr->entry= new_hdr->header;
> + new_hdr->name= new_hdr->nmpool;
> + all_headers_size= new_fmt->fixed_hdr +
> + new_hdr->header_size + new_hdr->nmpool_size;
> + for (i= 0, j= 0; i < add_column_count || j < hdr->column_count; i++)
> + {
> + size_t first_offset;
> + uint start= j, end;
> + LINT_INIT(first_offset);
> +
> + /*
> + Search in i and j for the next column to add from i and where to
> + add.
> + */
> +
> + while (i < add_column_count && plan[i].act == PLAN_NOP)
> + i++; /* skip NOP */
> +
> + if (i == add_column_count)
> + j= end= hdr->column_count;
> + else
> + {
> + /*
> + old data portion. We don't need to check that j < column_count
> + as plan[i].place is guaranteed to have a pointer inside the
> + data.
> + */
> + while (hdr->header + j * hdr->entry_size < plan[i].place)
> + j++;
> + end= j;
> + if ((plan[i].act == PLAN_REPLACE || plan[i].act == PLAN_DELETE))
> + j++; /* data at 'j' will be removed */
> + }
> +
> + /*
> + Adjust all headers since last loop.
> + We have to do this as the offset for data has moved
> + */
> + for (k= start; k < end; k++)
> + {
> + uchar *read= hdr->header + k * hdr->entry_size;
> + void *key;
> + LEX_STRING name;
> + size_t offs;
> + uint nm;
> + DYNAMIC_COLUMN_TYPE tp;
> + char buff[DYNCOL_NUM_CHAR];
> +
> + if (hdr->format == DYNCOL_FMT_NUM)
> + {
> + if (convert)
> + {
> + name.str= backwritenum(buff + sizeof(buff), uint2korr(read));
> + name.length= (buff + sizeof(buff)) - name.str;
> + key= &name;
> + }
> + else
> + {
> + nm= uint2korr(read); /* Column nummber */
> + key= &nm;
> + }
> + }
> + else
> + {
> + name.length= read[0];
> + name.str= (char *) hdr->nmpool + uint2korr(read + 1);
> + key= &name;
> + }
> + if (type_and_offset_read(&tp, &offs,
> + read + fmt->fixed_hdr_entry, hdr->offset_size))
> + goto err;
> + if (k == start)
> + first_offset= offs;
> + else if (offs < first_offset)
> + goto err;
> +
> + offs+= plan[i].ddelta;
> + {
> + DYNAMIC_COLUMN_VALUE val;
> + val.type= tp; // only the type used in the header
> + if ((*new_fmt->put_header_entry)(new_hdr, key, &val, offs))
> + goto err;
> + }
> + }
> +
> + /* copy first the data that was not replaced in original packed data */
> + if (start < end)
> + {
> + size_t data_size;
> + /* Add old data last in 'tmp' */
> + hdr->entry= hdr->header + start * hdr->entry_size;
> + data_size=
> + hdr_interval_length(hdr, hdr->header + end * hdr->entry_size);
> + if (data_size == DYNCOL_OFFSET_ERROR ||
> + (long) data_size < 0 ||
> + data_size > hdr->data_size - first_offset)
> + goto err;
> +
> + memcpy(tmp.str + tmp.length, (char *)hdr->dtpool + first_offset,
> + data_size);
> + tmp.length+= data_size;
> + }
> +
> + /* new data adding */
> + if (i < add_column_count)
> + {
> + if( plan[i].act == PLAN_ADD || plan[i].act == PLAN_REPLACE)
> + {
> + if ((*new_fmt->put_header_entry)(new_hdr, plan[i].key,
> + plan[i].val,
> + tmp.length - all_headers_size))
> + goto err;
> + data_store(&tmp, plan[i].val); /* Append new data */
> + }
> + }
> + }
> + dynamic_column_column_free(str);
> + *str= tmp;
> + return ER_DYNCOL_OK;
> +err:
> + dynamic_column_column_free(&tmp);
> + return ER_DYNCOL_FORMAT;
> +}
> +
> +enum enum_dyncol_func_result
> +dynamic_column_update_move_left(DYNAMIC_COLUMN *str, PLAN *plan,
> + size_t offset_size,
> + size_t entry_size,
> + size_t header_size,
> + size_t new_offset_size,
> + size_t new_entry_size,
> + size_t new_header_size,
> + uint column_count,
> + uint new_column_count,
> + uint add_column_count,
> + uchar *header_end,
> + size_t max_offset)
> +{
> + uchar *write;
> + uchar *header_base= (uchar *)str->str + FIXED_HEADER_SIZE;
> + uint i, j, k;
> + size_t curr_offset;
> +
> + write= (uchar *)str->str + FIXED_HEADER_SIZE;
> + set_fixed_header(str, new_offset_size, new_column_count);
> +
> + /*
> + Move headers first.
> + i= index in array of changes
> + j= index in packed string header index
> + */
> + for (curr_offset= 0, i= 0, j= 0;
> + i < add_column_count || j < column_count;
> + i++)
> + {
> + size_t first_offset;
> + uint start= j, end;
> + LINT_INIT(first_offset);
> +
> + /*
> + Search in i and j for the next column to add from i and where to
> + add.
> + */
> +
> + while (i < add_column_count && plan[i].act == PLAN_NOP)
> + i++; /* skip NOP */
> +
> + if (i == add_column_count)
> + j= end= column_count;
> + else
> + {
> + /*
> + old data portion. We don't need to check that j < column_count
> + as plan[i].place is guaranteed to have a pointer inside the
> + data.
> + */
> + while (header_base + j * entry_size < plan[i].place)
> + j++;
> + end= j;
> + if ((plan[i].act == PLAN_REPLACE || plan[i].act == PLAN_DELETE))
> + j++; /* data at 'j' will be removed */
> + }
> + plan[i].mv_end= end;
> +
> + {
> + DYNAMIC_COLUMN_TYPE tp;
> + if (type_and_offset_read(&tp, &first_offset,
> + header_base + start * entry_size +
> + COLUMN_NUMBER_SIZE, offset_size))
> + return ER_DYNCOL_FORMAT;
> + }
> + /* find data to be moved */
> + if (start < end)
> + {
> + size_t data_size=
> + get_length_interval(header_base + start * entry_size,
> + header_base + end * entry_size,
> + header_end, offset_size, max_offset);
> + if (data_size == DYNCOL_OFFSET_ERROR ||
> + (long) data_size < 0 ||
> + data_size > max_offset - first_offset)
> + {
> + str->length= 0; // just something valid
> + return ER_DYNCOL_FORMAT;
> + }
> + DBUG_ASSERT(curr_offset == first_offset + plan[i].ddelta);
> + plan[i].mv_offset= first_offset;
> + plan[i].mv_length= data_size;
> + curr_offset+= data_size;
> + }
> + else
> + {
> + plan[i].mv_length= 0;
> + plan[i].mv_offset= curr_offset;
> + }
> +
> + if (plan[i].ddelta == 0 && offset_size == new_offset_size &&
> + plan[i].act != PLAN_DELETE)
> + write+= entry_size * (end - start);
> + else
> + {
> + /*
> + Adjust all headers since last loop.
> + We have to do this as the offset for data has moved
> + */
> + for (k= start; k < end; k++)
> + {
> + uchar *read= header_base + k * entry_size;
> + size_t offs;
> + uint nm;
> + DYNAMIC_COLUMN_TYPE tp;
> +
> + nm= uint2korr(read); /* Column nummber */
> + if (type_and_offset_read(&tp, &offs, read + COLUMN_NUMBER_SIZE,
> + offset_size))
> + return ER_DYNCOL_FORMAT;
> +
> + if (k > start && offs < first_offset)
> + {
> + str->length= 0; // just something valid
> + return ER_DYNCOL_FORMAT;
> + }
> +
> + offs+= plan[i].ddelta;
> + int2store(write, nm);
> + /* write rest of data at write + COLUMN_NUMBER_SIZE */
> + type_and_offset_store(write, new_offset_size, tp, offs);
> + write+= new_entry_size;
> + }
> + }
> +
> + /* new data adding */
> + if (i < add_column_count)
> + {
> + if( plan[i].act == PLAN_ADD || plan[i].act == PLAN_REPLACE)
> + {
> + int2store(write, *((uint *)plan[i].key));
> + type_and_offset_store(write, new_offset_size,
> + plan[i].val[0].type,
> + curr_offset);
> + write+= new_entry_size;
> + curr_offset+= plan[i].length;
> + }
> + }
> + }
> +
> + /*
> + Move data.
> + i= index in array of changes
> + j= index in packed string header index
> + */
> + str->length= (FIXED_HEADER_SIZE + new_header_size);
> + for (i= 0, j= 0;
> + i < add_column_count || j < column_count;
> + i++)
> + {
> + uint start= j, end;
> +
> + /*
> + Search in i and j for the next column to add from i and where to
> + add.
> + */
> +
> + while (i < add_column_count && plan[i].act == PLAN_NOP)
> + i++; /* skip NOP */
> +
> + j= end= plan[i].mv_end;
> + if (i != add_column_count &&
> + (plan[i].act == PLAN_REPLACE || plan[i].act == PLAN_DELETE))
> + j++;
> +
> + /* copy first the data that was not replaced in original packed data */
> + if (start < end && plan[i].mv_length)
> + {
> + memmove((header_base + new_header_size +
> + plan[i].mv_offset + plan[i].ddelta),
> + header_base + header_size + plan[i].mv_offset,
> + plan[i].mv_length);
> + }
> + str->length+= plan[i].mv_length;
> +
> + /* new data adding */
> + if (i < add_column_count)
> + {
> + if( plan[i].act == PLAN_ADD || plan[i].act == PLAN_REPLACE)
> + {
> + data_store(str, plan[i].val); /* Append new data */
> + }
> + }
> + }
> + return ER_DYNCOL_OK;
> +}
> +
> +enum enum_dyncol_func_result
> +dynamic_column_update_move_right(DYNAMIC_COLUMN *str, PLAN *plan,
> + size_t offset_size,
> + size_t entry_size,
> + size_t header_size,
> + size_t new_offset_size,
> + size_t new_entry_size,
> + size_t new_header_size,
> + uint column_count,
> + uint new_column_count,
> + uint add_column_count,
> + uchar *header_end,
> + size_t max_offset)
> +{
> + uchar *write;
> + uchar *header_base= (uchar *)str->str + FIXED_HEADER_SIZE;
> + uint i, j, k;
> + size_t curr_offset;
> +
> + write= (uchar *)str->str + FIXED_HEADER_SIZE;
> + set_fixed_header(str, new_offset_size, new_column_count);
> +
> + /*
> + Move data first.
> + i= index in array of changes
> + j= index in packed string header index
> + */
> + for (curr_offset= 0, i= 0, j= 0;
> + i < add_column_count || j < column_count;
> + i++)
> + {
> + size_t first_offset;
> + uint start= j, end;
> + LINT_INIT(first_offset);
> +
> + /*
> + Search in i and j for the next column to add from i and where to
> + add.
> + */
> +
> + while (i < add_column_count && plan[i].act == PLAN_NOP)
> + i++; /* skip NOP */
> +
> + if (i == add_column_count)
> + j= end= column_count;
> + else
> + {
> + /*
> + old data portion. We don't need to check that j < column_count
> + as plan[i].place is guaranteed to have a pointer inside the
> + data.
> + */
> + while (header_base + j * entry_size < plan[i].place)
> + j++;
> + end= j;
> + if ((plan[i].act == PLAN_REPLACE || plan[i].act == PLAN_DELETE))
> + j++; /* data at 'j' will be removed */
> + }
> + plan[i].mv_end= end;
> +
> + {
> + DYNAMIC_COLUMN_TYPE tp;
> + type_and_offset_read(&tp, &first_offset,
> + header_base + start * entry_size + COLUMN_NUMBER_SIZE, offset_size);
> + }
> + /* find data to be moved */
> + if (start < end)
> + {
> + size_t data_size=
> + get_length_interval(header_base + start * entry_size,
> + header_base + end * entry_size,
> + header_end, offset_size, max_offset);
> + if (data_size == DYNCOL_OFFSET_ERROR ||
> + (long) data_size < 0 ||
> + data_size > max_offset - first_offset)
> + {
> + str->length= 0; // just something valid
> + return ER_DYNCOL_FORMAT;
> + }
> + DBUG_ASSERT(curr_offset == first_offset + plan[i].ddelta);
> + plan[i].mv_offset= first_offset;
> + plan[i].mv_length= data_size;
> + curr_offset+= data_size;
> + }
> + else
> + {
> + plan[i].mv_length= 0;
> + plan[i].mv_offset= curr_offset;
> + }
> +
> + if (plan[i].ddelta == 0 && offset_size == new_offset_size &&
> + plan[i].act != PLAN_DELETE)
> + write+= entry_size * (end - start);
> + else
> + {
> + /*
> + Adjust all headers since last loop.
> + We have to do this as the offset for data has moved
> + */
> + for (k= start; k < end; k++)
> + {
> + uchar *read= header_base + k * entry_size;
> + size_t offs;
> + uint nm;
> + DYNAMIC_COLUMN_TYPE tp;
> +
> + nm= uint2korr(read); /* Column nummber */
> + type_and_offset_read(&tp, &offs, read + COLUMN_NUMBER_SIZE, offset_size);
> + if (k > start && offs < first_offset)
> + {
> + str->length= 0; // just something valid
> + return ER_DYNCOL_FORMAT;
> + }
> +
> + offs+= plan[i].ddelta;
> + int2store(write, nm);
> + /* write rest of data at write + COLUMN_NUMBER_SIZE */
> + if (type_and_offset_store(write, new_offset_size, tp, offs))
> + {
> + str->length= 0; // just something valid
> + return ER_DYNCOL_FORMAT;
> + }
> + write+= new_entry_size;
> + }
> + }
> +
> + /* new data adding */
> + if (i < add_column_count)
> + {
> + if( plan[i].act == PLAN_ADD || plan[i].act == PLAN_REPLACE)
> + {
> + int2store(write, *((uint *)plan[i].key));
> + if (type_and_offset_store(write, new_offset_size,
> + plan[i].val[0].type,
> + curr_offset))
> + {
> + str->length= 0; // just something valid
> + return ER_DYNCOL_FORMAT;
> + }
> + write+= new_entry_size;
> + curr_offset+= plan[i].length;
> + }
> + }
> + }
> +
> + /*
> + Move headers.
> + i= index in array of changes
> + j= index in packed string header index
> + */
> + str->length= (FIXED_HEADER_SIZE + new_header_size);
> + for (i= 0, j= 0;
> + i < add_column_count || j < column_count;
> + i++)
> + {
> + uint start= j, end;
> +
> + /*
> + Search in i and j for the next column to add from i and where to
> + add.
> + */
> +
> + while (i < add_column_count && plan[i].act == PLAN_NOP)
> + i++; /* skip NOP */
> +
> + j= end= plan[i].mv_end;
> + if (i != add_column_count &&
> + (plan[i].act == PLAN_REPLACE || plan[i].act == PLAN_DELETE))
> + j++;
> +
> + /* copy first the data that was not replaced in original packed data */
> + if (start < end && plan[i].mv_length)
> + {
> + memmove((header_base + new_header_size +
> + plan[i].mv_offset + plan[i].ddelta),
> + header_base + header_size + plan[i].mv_offset,
> + plan[i].mv_length);
> + }
> + str->length+= plan[i].mv_length;
> +
> + /* new data adding */
> + if (i < add_column_count)
> + {
> + if( plan[i].act == PLAN_ADD || plan[i].act == PLAN_REPLACE)
> + {
> + data_store(str, plan[i].val); /* Append new data */
> + }
> + }
> + }
> + return ER_DYNCOL_OK;
> }
>
> -#define DELTA_CHECK(S, D, C) \
> - if ((S) == 0) \
> - (S)= (D); \
> - else if (((S) > 0 && (D) < 0) || \
> - ((S) < 0 && (D) > 0)) \
> - { \
> - (C)= TRUE; \
> - break; \
> - } \
> -
>
> /**
> Update the packed string with the given columns
> @@ -1826,26 +3044,36 @@ dynamic_column_update_many(DYNAMIC_COLUM
>
> /* Set common variables for all plans */
> plan[i].ddelta= data_delta;
> + plan[i].ndelta= name_delta;
> /* get header delta in entries */
> plan[i].hdelta= header_delta;
> plan[i].length= 0; /* Length if NULL */
>
> - if (find_place(plan[i].num[0],
> - (uchar *)str->str + FIXED_HEADER_SIZE,
> - entry_size, column_count, &entry))
> + if (find_place(&header, plan[i].key, string_keys))
> {
> - size_t entry_data_size;
> + size_t entry_data_size, entry_name_size= 0;
>
> /* Data existed; We have to replace or delete it */
>
> - entry_data_size= get_length(entry, header_end,
> - offset_size, max_offset);
> - if ((long) entry_data_size < 0)
> + entry_data_size= hdr_interval_length(&header, header.entry +
> + header.entry_size);
> + if (entry_data_size == DYNCOL_OFFSET_ERROR ||
> + (long) entry_data_size < 0)
> {
> rc= ER_DYNCOL_FORMAT;
> goto end;
> }
>
> + //get_length(header.entry, header.dtpool, header.offset_size,
> + //header.data_size);
did you forget to delete this?
> + if (new_header.format == DYNCOL_FMT_STR)
> + {
> + if (header.format == DYNCOL_FMT_STR)
> + entry_name_size= header.entry[0];
> + else
> + entry_name_size= numlen(uint2korr(header.entry));
> + }
> +
> if (plan[i].val->type == DYN_COL_NULL)
> {
> /* Inserting a NULL means delete the old data */
> @@ -1891,219 +3124,759 @@ dynamic_column_update_many(DYNAMIC_COLUM
> goto end;
> }
> data_delta+= plan[i].length;
> + if (new_header.format == DYNCOL_FMT_STR)
> + name_delta+= ((LEX_STRING *)plan[i].key)->length;
> }
> }
> - plan[i].place= entry;
> + plan[i].place= header.entry;
> }
> plan[add_column_count].hdelta= header_delta;
> plan[add_column_count].ddelta= data_delta;
> - new_column_count= column_count + header_delta;
> + plan[add_column_count].act= PLAN_NOP;
> + plan[add_column_count].place= header.dtpool;
> +
> + new_header.column_count= header.column_count + header_delta;
>
> /*
> Check if it is only "increasing" or only "decreasing" plan for (header
> and data separately).
> */
> - data_size= str->length - header_size - FIXED_HEADER_SIZE;
> - new_data_size= data_size + data_delta;
> - if ((new_offset_size= dynamic_column_offset_bytes(new_data_size)) >=
> + new_header.data_size= header.data_size + data_delta;
> + new_header.nmpool_size= new_header.nmpool_size + name_delta;
> + DBUG_ASSERT(new_header.format != DYNCOL_FMT_NUM ||
> + new_header.nmpool_size == 0);
> + if ((new_header.offset_size=
> + dynamic_column_offset_bytes(new_header.data_size)) >=
> MAX_OFFSET_LENGTH)
> {
> rc= ER_DYNCOL_LIMIT;
> goto end;
> }
>
> -#ifdef NOT_IMPLEMENTED
> - /* if (new_offset_size != offset_size) then we have to rewrite header */
> - header_delta_sign= new_offset_size - offset_size;
> + copy= ((header.format != new_header.format) ||
> + (new_header.format == DYNCOL_FMT_STR));
> + /* if (new_header.offset_size!=offset_size) then we have to rewrite header */
> + header_delta_sign=
> + ((int)new_header.offset_size + new_fmt->fixed_hdr_entry) -
> + ((int)header.offset_size + fmt->fixed_hdr_entry);
> data_delta_sign= 0;
> - for (i= 0; i < add_column_count; i++)
> + // plan[add_column_count] contains last deltas.
> + for (i= 0; i <= add_column_count && !copy; i++)
> {
> /* This is the check for increasing/decreasing */
> DELTA_CHECK(header_delta_sign, plan[i].hdelta, copy);
> DELTA_CHECK(data_delta_sign, plan[i].ddelta, copy);
> }
> -#endif
> - calc_param(&new_entry_size, &new_header_size,
> - new_offset_size, new_column_count);
> + calc_param(&new_header.entry_size, &new_header.header_size,
> + new_fmt->fixed_hdr_entry,
> + new_header.offset_size, new_header.column_count);
>
> /*
> - The following code always make a copy. In future we can do a more
> - optimized version when data is only increasing / decreasing.
> + Need copy because:
> + 1. Header/data parts moved in different directions.
> + 2. There is no enough allocated space in the string.
> + 3. Header and data moved in different directions.
> */
> + if (copy || /*1*/
forgot to delete /*1*/ ?
> + str->max_length < str->length + header_delta + data_delta || /*2*/
> + ((header_delta_sign < 0 && data_delta_sign > 0) ||
> + (header_delta_sign > 0 && data_delta_sign < 0))) /*3*/
> + rc= dynamic_column_update_copy(str, plan, add_column_count,
> + &header, &new_header,
> + convert);
> + else
> + if (header_delta_sign < 0)
> + rc= dynamic_column_update_move_left(str, plan, header.offset_size,
> + header.entry_size,
> + header.header_size,
> + new_header.offset_size,
> + new_header.entry_size,
> + new_header.header_size,
> + header.column_count,
> + new_header.column_count,
> + add_column_count, header.dtpool,
> + header.data_size);
> + else
> + /*
> + rc= dynamic_column_update_move_right(str, plan, offset_size,
> + entry_size, header_size,
> + new_header.offset_size,
> + new_header.entry_size,
> + new_heder.header_size, column_count,
> + new_header.column_count,
> + add_column_count, header_end,
> + header.data_size);
> + */
> + rc= dynamic_column_update_copy(str, plan, add_column_count,
> + &header, &new_header,
> + convert);
> +end:
> + my_free(alloc_plan);
> + return rc;
> +
> +create_new_string:
> + /* There is no columns from before, so let's just add the new ones */
> + rc= ER_DYNCOL_OK;
> + my_free(alloc_plan);
> + if (not_null != 0)
> + rc= dynamic_column_create_many_internal_fmt(str, add_column_count,
> + (uint*)column_keys, values,
> + str->str == NULL,
> + string_keys);
> + goto end;
> +}
> +
> +
> +/**
> + Update the packed string with the given column
> +
> + @param str String where to write the data
> + @param column_number Array of columns number
> + @param values Array of columns values
> +
> + @return ER_DYNCOL_* return code
> +*/
> +
> +
> +int dynamic_column_update(DYNAMIC_COLUMN *str, uint column_nr,
> + DYNAMIC_COLUMN_VALUE *value)
> +{
> + return dynamic_column_update_many(str, 1, &column_nr, value);
> +}
> +
> +
> +enum enum_dyncol_func_result
> +dynamic_column_check(DYNAMIC_COLUMN *str)
> +{
> + struct st_service_funcs *fmt;
> + enum enum_dyncol_func_result rc= ER_DYNCOL_FORMAT;
> + DYN_HEADER header;
> + uint i;
> + size_t data_offset= 0, name_offset= 0;
> + size_t prev_data_offset= 0, prev_name_offset= 0;
> + LEX_STRING name= {0,0}, prev_name= {0,0};
> + uint num= 0, prev_num= 0;
> + void *key, *prev_key;
> + enum enum_dynamic_column_type type= DYN_COL_NULL, prev_type= DYN_COL_NULL;
> +
> + DBUG_ENTER("dynamic_column_check");
>
> - /*if (copy) */
> + if (str->length == 0)
> {
> - DYNAMIC_COLUMN tmp;
> - uchar *header_base= (uchar *)str->str + FIXED_HEADER_SIZE,
> - *write;
> - if (dynamic_column_init_str(&tmp,
> - (FIXED_HEADER_SIZE + new_header_size +
> - new_data_size + DYNCOL_SYZERESERVE)))
> - {
> - rc= ER_DYNCOL_RESOURCE;
> - goto end;
> - }
> - write= (uchar *)tmp.str + FIXED_HEADER_SIZE;
> - /* Adjust tmp to contain whole the future header */
> - tmp.length= FIXED_HEADER_SIZE + new_header_size;
> - set_fixed_header(&tmp, new_offset_size, new_column_count);
> - data_delta= 0;
> + DBUG_PRINT("info", ("empty string is OK"));
> + DBUG_RETURN(ER_DYNCOL_OK);
> + }
>
> - /*
> - Copy data to the new string
> - i= index in array of changes
> - j= index in packed string header index
> - */
> + bzero(&header, sizeof(header));
>
> - for (i= 0, j= 0; i < add_column_count || j < column_count; i++)
> - {
> - size_t first_offset;
> - uint start= j, end;
> - LINT_INIT(first_offset);
> + /* Check that header is OK */
> + if (read_fixed_header(&header, str))
> + {
> + DBUG_PRINT("info", ("Reading fixed string header failed"));
> + goto end;
> + }
> + fmt= fmt_data + header.format;
> + calc_param(&header.entry_size, &header.header_size,
> + fmt->fixed_hdr_entry, header.offset_size,
> + header.column_count);
> + /* headers are out of string length (no space for data and part of headers) */
> + if (fmt->fixed_hdr + header.header_size + header.nmpool_size > str->length)
> + {
> + DBUG_PRINT("info", ("Fixed header: %u Header size: %u "
> + "Name pool size: %u but Strig length: %u",
> + (uint)fmt->fixed_hdr,
> + (uint)header.header_size,
> + (uint)header.nmpool_size,
> + (uint)str->length));
> + goto end;
> + }
> + header.header= (uchar*)str->str + fmt->fixed_hdr;
> + header.nmpool= header.header + header.header_size;
> + header.dtpool= header.nmpool + header.nmpool_size;
> + header.data_size= str->length - fmt->fixed_hdr -
> + header.header_size - header.nmpool_size;
>
> - /*
> - Search in i and j for the next column to add from i and where to
> - add.
> - */
> + /* read and check headers */
> + if (header.format == DYNCOL_FMT_NUM)
> + {
> + key= #
> + prev_key= &prev_num;
> + }
> + else
> + {
> + key= &name;
> + prev_key= &prev_name;
> + }
> + for (i= 0, header.entry= header.header;
> + i < header.column_count;
> + i++, header.entry+= header.entry_size)
> + {
>
> - while (i < add_column_count && plan[i].act == PLAN_NOP)
> - i++; /* skip NOP */
> - if (i == add_column_count)
> - j= end= column_count;
> - else
> + if (header.format == DYNCOL_FMT_NUM)
> + {
> + num= uint2korr(header.entry);
> + }
> + else
> + {
> + DBUG_ASSERT(header.format == DYNCOL_FMT_STR);
> + name.length= header.entry[0];
> + name_offset= uint2korr(header.entry + 1);
> + name.str= (char *)header.nmpool + name_offset;
> + }
> + if (type_and_offset_read(&type, &data_offset,
> + header.entry + fmt->fixed_hdr_entry,
> + header.offset_size))
> + goto end;
> +
> + DBUG_ASSERT(type != DYN_COL_NULL);
> + if (data_offset > header.data_size)
> + {
> + DBUG_PRINT("info", ("Field order: %u Data offset: %u"
> + " > Data pool size: %u",
> + (uint)i,
> + (uint)name_offset,
> + (uint)header.nmpool_size));
> + goto end;
> + }
> + if (name_offset > header.nmpool_size)
> + {
> + DBUG_PRINT("info", ("Field order: %u Name offset: %u"
> + " > Name pool size: %u",
> + (uint)i,
> + (uint)name_offset,
> + (uint)header.nmpool_size));
> + goto end;
> + }
> + if (prev_type != DYN_COL_NULL)
> + {
> + /* It is not first entry */
> + if (prev_data_offset >= data_offset)
> {
> - /*
> - old data portion. We don't need to check that j < column_count
> - as plan[i].place is guaranteed to have a pointer inside the
> - data.
> - */
> - while (header_base + j * entry_size < plan[i].place)
> - j++;
> - end= j;
> - if ((plan[i].act == PLAN_REPLACE || plan[i].act == PLAN_DELETE))
> - j++; /* data at 'j' will be removed */
> + DBUG_PRINT("info", ("Field order: %u Previous data offset: %u"
> + " >= Current data offset: %u",
> + (uint)i,
> + (uint)prev_data_offset,
> + (uint)data_offset));
> + goto end;
> }
> -
> - if (plan[i].ddelta == 0 && offset_size == new_offset_size)
> + if (prev_name_offset > name_offset)
> {
> - uchar *read= header_base + start * entry_size;
> - DYNAMIC_COLUMN_TYPE tp;
> - /*
> - It's safe to copy the header unchanged. This is usually the
> - case for the first header block before any changed data.
> - */
> - if (start < end) /* Avoid memcpy with 0 */
> - {
> - size_t length= entry_size * (end - start);
> - memcpy(write, read, length);
> - write+= length;
> - }
> - /* Read first_offset */
> - type_and_offset_read(&tp, &first_offset, read, offset_size);
> + DBUG_PRINT("info", ("Field order: %u Previous name offset: %u"
> + " > Current name offset: %u",
> + (uint)i,
> + (uint)prev_data_offset,
> + (uint)data_offset));
> + goto end;
> }
> - else
> + if ((*fmt->column_sort)(&prev_key, &key) >= 0)
> {
> - /*
> - Adjust all headers since last loop.
> - We have to do this as the offset for data has moved
> - */
> - for (k= start; k < end; k++)
> - {
> - uchar *read= header_base + k * entry_size;
> - size_t offs;
> - uint nm;
> - DYNAMIC_COLUMN_TYPE tp;
> + DBUG_PRINT("info", ("Field order: %u Previous key >= Current key",
> + (uint)i));
> + goto end;
> + }
> + }
> + prev_num= num;
> + prev_name= name;
> + prev_data_offset= data_offset;
> + prev_name_offset= name_offset;
> + prev_type= type;
> + }
> +
> + /* check data, which we can */
> + for (i= 0, header.entry= header.header;
> + i < header.column_count;
> + i++, header.entry+= header.entry_size)
> + {
> + DYNAMIC_COLUMN_VALUE store;
> + // already checked by previouse pass
> + type_and_offset_read(&header.type, &header.offset,
> + header.entry + fmt->fixed_hdr_entry,
> + header.offset_size);
> + header.length=
> + hdr_interval_length(&header, header.entry + header.entry_size);
> + header.data= header.dtpool + header.offset;
> + switch ((header.type)) {
> + case DYN_COL_INT:
> + rc= dynamic_column_sint_read(&store, header.data, header.length);
> + break;
> + case DYN_COL_UINT:
> + rc= dynamic_column_uint_read(&store, header.data, header.length);
> + break;
> + case DYN_COL_DOUBLE:
> + rc= dynamic_column_double_read(&store, header.data, header.length);
> + break;
> + case DYN_COL_STRING:
> + rc= dynamic_column_string_read(&store, header.data, header.length);
> + break;
> + case DYN_COL_DECIMAL:
> + rc= dynamic_column_decimal_read(&store, header.data, header.length);
> + break;
> + case DYN_COL_DATETIME:
> + rc= dynamic_column_date_time_read(&store, header.data,
> + header.length);
> + break;
> + case DYN_COL_DATE:
> + rc= dynamic_column_date_read(&store, header.data, header.length);
> + break;
> + case DYN_COL_TIME:
> + rc= dynamic_column_time_read(&store, header.data, header.length);
> + break;
> + case DYN_COL_NULL:
> + default:
> + rc= ER_DYNCOL_FORMAT;
> + goto end;
> + }
> + if (rc != ER_DYNCOL_OK)
> + {
> + DBUG_ASSERT(rc < 0);
> + DBUG_PRINT("info", ("Field order: %u Can't read data: %i",
> + (uint)i, (int) rc));
> + goto end;
> + }
> + }
>
> - nm= uint2korr(read); /* Column nummber */
> - type_and_offset_read(&tp, &offs, read, offset_size);
> - if (k == start)
> - first_offset= offs;
> - else if (offs < first_offset)
> + rc= ER_DYNCOL_OK;
> +end:
> + DBUG_RETURN(rc);
> +}
> +
> +
> +enum enum_dyncol_func_result
> +dynamic_column_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val,
> + CHARSET_INFO *cs, my_bool quote)
> +{
> + char buff[40];
> + int len;
> + switch (val->type) {
> + case DYN_COL_INT:
> + len= snprintf(buff, sizeof(buff), "%lld", val->x.long_value);
> + if (dynstr_append_mem(str, buff, len))
> + return ER_DYNCOL_RESOURCE;
> + break;
> + case DYN_COL_UINT:
> + len= snprintf(buff, sizeof(buff), "%llu", val->x.ulong_value);
> + if (dynstr_append_mem(str, buff, len))
> + return ER_DYNCOL_RESOURCE;
> + break;
> + case DYN_COL_DOUBLE:
> + len= snprintf(buff, sizeof(buff), "%lg", val->x.double_value);
> + if (dynstr_realloc(str, len + (quote ? 2 : 0)))
> + return ER_DYNCOL_RESOURCE;
> + if (quote)
> + str->str[str->length++]= '"';
> + dynstr_append_mem(str, buff, len);
> + if (quote)
> + str->str[str->length++]= '"';
> + break;
> + case DYN_COL_STRING:
> + {
> + char *alloc= NULL;
> + char *from= val->x.string.value.str;
> + uint bufflen;
> + my_bool conv= !my_charset_same(val->x.string.charset, cs);
> + my_bool rc;
> + len= val->x.string.value.length;
> + bufflen= (len * (conv ? cs->mbmaxlen : 1));
> + if (dynstr_realloc(str, bufflen))
> + return ER_DYNCOL_RESOURCE;
> +
> + // guaranty UTF-8 string for value
> + if (!my_charset_same(val->x.string.charset, cs))
> + {
> + uint dummy_errors;
> + if (!quote)
> {
> - dynamic_column_column_free(&tmp);
> - rc= ER_DYNCOL_FORMAT;
> - goto end;
> + /* convert to the destination */
> + str->length+= copy_and_convert_extended(str->str, bufflen,
> + cs,
> + from, len,
> + val->x.string.charset,
> + &dummy_errors);
> + return ER_DYNCOL_OK;
> }
> -
> - offs+= plan[i].ddelta;
> - int2store(write, nm);
> - /* write rest of data at write + COLUMN_NUMBER_SIZE */
> - type_and_offset_store(write, new_offset_size, tp, offs);
> - write+= new_entry_size;
> + if ((alloc= (char *)my_malloc(bufflen, MYF(0))))
> + {
> + len=
> + copy_and_convert_extended(alloc, bufflen, cs,
> + from, len, val->x.string.charset,
> + &dummy_errors);
> + from= alloc;
> + }
> + else
> + return ER_DYNCOL_RESOURCE;
> }
> + if (quote)
> + rc= dynstr_append_quoted(str, from, len);
> + else
> + rc= dynstr_append_mem(str, from, len);
> + if (alloc)
> + my_free(alloc);
> + if (rc)
> + return ER_DYNCOL_RESOURCE;
> + break;
> }
> + case DYN_COL_DECIMAL:
> + len= sizeof(buff);
> + decimal2string(&val->x.decimal.value, buff, &len,
> + 0, val->x.decimal.value.frac,
> + '0');
> + if (dynstr_append_mem(str, buff, len))
> + return ER_DYNCOL_RESOURCE;
> + break;
> + case DYN_COL_DATETIME:
> + case DYN_COL_DATE:
> + case DYN_COL_TIME:
> + len= my_TIME_to_str(&val->x.time_value, buff, AUTO_SEC_PART_DIGITS);
> + if (dynstr_realloc(str, len + (quote ? 2 : 0)))
> + return ER_DYNCOL_RESOURCE;
> + if (quote)
> + str->str[str->length++]= '"';
> + dynstr_append_mem(str, buff, len);
> + if (quote)
> + str->str[str->length++]= '"';
> + break;
> + case DYN_COL_NULL:
> + if (dynstr_append_mem(str, "null", 4))
> + return ER_DYNCOL_RESOURCE;
> + break;
> + default:
> + return(ER_DYNCOL_FORMAT);
> + }
> + return(ER_DYNCOL_OK);
> +}
>
> - /* copy first the data that was not replaced in original packed data */
> - if (start < end)
> +
> +enum enum_dyncol_func_result
> +dynamic_column_val_long(longlong *ll, DYNAMIC_COLUMN_VALUE *val)
> +{
> + enum enum_dyncol_func_result rc= ER_DYNCOL_OK;
> + *ll= 0;
> + switch (val->type) {
> + case DYN_COL_INT:
> + *ll= val->x.long_value;
> + break;
> + case DYN_COL_UINT:
> + *ll= (longlong)val->x.ulong_value;
> + if (val->x.ulong_value > ULONGLONG_MAX)
> + rc= ER_DYNCOL_TRUNCATED;
> + break;
> + case DYN_COL_DOUBLE:
> + *ll= (longlong)val->x.double_value;
> + if (((double) *ll) != val->x.double_value)
> + rc= ER_DYNCOL_TRUNCATED;
> + break;
> + case DYN_COL_STRING:
> {
> - /* Add old data last in 'tmp' */
> - size_t data_size=
> - get_length_interval(header_base + start * entry_size,
> - header_base + end * entry_size,
> - header_end, offset_size, max_offset);
> - if ((long) data_size < 0 ||
> - data_size > max_offset - first_offset)
> + longlong i= 0, sign= 1;
> + char *src= val->x.string.value.str;
> + uint len= val->x.string.value.length;
> +
> + while (len && my_isspace(&my_charset_latin1, *src)) src++,len--;
> +
> + if (len)
> {
> - dynamic_column_column_free(&tmp);
> - rc= ER_DYNCOL_FORMAT;
> - goto end;
> + if (*src == '-')
> + {
> + sign= -1;
> + src++;
> + } else if (*src == '-')
> + src++;
> + while(len && my_isdigit(&my_charset_latin1, *src))
> + {
> + i= i * 10 + (*src - '0');
> + src++;
> + }
> }
> -
> - memcpy(tmp.str + tmp.length, (char *)header_end + first_offset,
> - data_size);
> - tmp.length+= data_size;
> + else
> + rc= ER_DYNCOL_TRUNCATED;
> + if (len)
> + rc= ER_DYNCOL_TRUNCATED;
> + *ll= i * sign;
> + break;
> }
> + case DYN_COL_DECIMAL:
> + if (decimal2longlong(&val->x.decimal.value, ll) != E_DEC_OK)
> + rc= ER_DYNCOL_TRUNCATED;
> + break;
> + case DYN_COL_DATETIME:
> + *ll= (val->x.time_value.year * 10000000000L +
> + val->x.time_value.month * 100000000L +
> + val->x.time_value.day * 1000000 +
> + val->x.time_value.hour * 10000 +
> + val->x.time_value.minute * 100 +
> + val->x.time_value.second) *
> + (val->x.time_value.neg ? -1 : 1);
> + break;
> + case DYN_COL_DATE:
> + *ll= (val->x.time_value.year * 10000 +
> + val->x.time_value.month * 100 +
> + val->x.time_value.day) *
> + (val->x.time_value.neg ? -1 : 1);
> + break;
> + case DYN_COL_TIME:
> + *ll= (val->x.time_value.hour * 10000 +
> + val->x.time_value.minute * 100 +
> + val->x.time_value.second) *
> + (val->x.time_value.neg ? -1 : 1);
> + break;
> + case DYN_COL_NULL:
> + rc= ER_DYNCOL_TRUNCATED;
> + break;
> + default:
> + return(ER_DYNCOL_FORMAT);
> + }
> + return(rc);
> +}
> +
>
> - /* new data adding */
> - if (i < add_column_count)
> +enum enum_dyncol_func_result
> +dynamic_column_val_double(double *dbl, DYNAMIC_COLUMN_VALUE *val)
> +{
> + enum enum_dyncol_func_result rc= ER_DYNCOL_OK;
> + *dbl= 0;
> + switch (val->type) {
> + case DYN_COL_INT:
> + *dbl= (double)val->x.long_value;
> + if (((longlong) *dbl) != val->x.long_value)
> + rc= ER_DYNCOL_TRUNCATED;
> + break;
> + case DYN_COL_UINT:
> + *dbl= (double)val->x.ulong_value;
> + if (((ulonglong) *dbl) != val->x.ulong_value)
> + rc= ER_DYNCOL_TRUNCATED;
> + break;
> + case DYN_COL_DOUBLE:
> + *dbl= val->x.double_value;
> + break;
> + case DYN_COL_STRING:
> {
> - if( plan[i].act == PLAN_ADD || plan[i].act == PLAN_REPLACE)
> - {
> - int2store(write, plan[i].num[0]);
> - type_and_offset_store(write, new_offset_size,
> - plan[i].val[0].type,
> - tmp.length -
> - (FIXED_HEADER_SIZE + new_header_size));
> - write+= new_entry_size;
> - data_store(&tmp, plan[i].val); /* Append new data */
> - }
> - data_delta= plan[i].ddelta;
> + char *str, *end;
> + if ((str= malloc(val->x.string.value.length + 1)))
> + return ER_DYNCOL_RESOURCE;
> + memcpy(str, val->x.string.value.str, val->x.string.value.length);
> + str[val->x.string.value.length]= '\0';
> + *dbl= strtod(str, &end);
> + if (*end != '\0')
> + rc= ER_DYNCOL_TRUNCATED;
> }
> - }
> - dynamic_column_column_free(str);
> - *str= tmp;
> + case DYN_COL_DECIMAL:
> + if (decimal2double(&val->x.decimal.value, dbl) != E_DEC_OK)
> + rc= ER_DYNCOL_TRUNCATED;
> + break;
> + case DYN_COL_DATETIME:
> + *dbl= (double)(val->x.time_value.year * 10000000000L +
> + val->x.time_value.month * 100000000L +
> + val->x.time_value.day * 1000000 +
> + val->x.time_value.hour * 10000 +
> + val->x.time_value.minute * 100 +
> + val->x.time_value.second) *
> + (val->x.time_value.neg ? -1 : 1);
> + break;
> + case DYN_COL_DATE:
> + *dbl= (double)(val->x.time_value.year * 10000 +
> + val->x.time_value.month * 100 +
> + val->x.time_value.day) *
> + (val->x.time_value.neg ? -1 : 1);
> + break;
> + case DYN_COL_TIME:
> + *dbl= (double)(val->x.time_value.hour * 10000 +
> + val->x.time_value.minute * 100 +
> + val->x.time_value.second) *
> + (val->x.time_value.neg ? -1 : 1);
> + break;
> + case DYN_COL_NULL:
> + rc= ER_DYNCOL_TRUNCATED;
> + break;
> + default:
> + return(ER_DYNCOL_FORMAT);
> }
> + return(rc);
> +}
>
> - rc= ER_DYNCOL_OK;
>
> -end:
> - my_free(plan);
> - return rc;
> +/**
> + Convert to JSON
>
> -create_new_string:
> - /* There is no columns from before, so let's just add the new ones */
> - rc= ER_DYNCOL_OK;
> - if (not_null != 0)
> - rc= dynamic_column_create_many_internal(str, add_column_count,
> - column_numbers, values,
> - str->str == NULL);
> - goto end;
> + @param str The packed string
> + @param json Where to put json result
> +
> + @return ER_DYNCOL_* return code
> +*/
> +
> +enum enum_dyncol_func_result
> +dynamic_column_json(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json)
> +{
> + DYN_HEADER header;
> + uint i;
> + enum enum_dyncol_func_result rc;
> +
> + bzero(json, sizeof(DYNAMIC_STRING)); /* In case of errors */
> + if (str->length == 0)
> + return ER_DYNCOL_OK; /* no columns */
> +
> + if ((rc= init_read_hdr(&header, str)) < 0)
> + return rc;
> +
> + if (header.entry_size * header.column_count + FIXED_HEADER_SIZE >
> + str->length)
> + return ER_DYNCOL_FORMAT;
> +
> + if (init_dynamic_string(json, NULL, str->length * 2, 100))
> + return ER_DYNCOL_RESOURCE;
> +
> + if (dynstr_append_mem(json, "[", 1))
> + return ER_DYNCOL_RESOURCE;
> + rc= ER_DYNCOL_RESOURCE;
> + for (i= 0, header.entry= header.header;
> + i < header.column_count;
> + i++, header.entry+= header.entry_size)
> + {
> + DYNAMIC_COLUMN_VALUE val;
> + if (i != 0 && dynstr_append_mem(json, ",", 1))
> + goto err;
> + header.length=
> + hdr_interval_length(&header, header.entry + header.entry_size);
> + header.data= header.dtpool + header.offset;
> + /*
> + Check that the found data is withing the ranges. This can happen if
> + we get data with wrong offsets.
> + */
> + if (header.length == DYNCOL_OFFSET_ERROR ||
> + header.length > INT_MAX || header.offset > header.data_size)
> + {
> + rc= ER_DYNCOL_FORMAT;
> + goto err;
> + }
> + if ((rc= dynamic_column_get_value(&header, &val)) < 0 ||
> + dynstr_append_mem(json, "{", 1))
> + goto err;
> + if (header.format == DYNCOL_FMT_NUM)
> + {
> + uint nm= uint2korr(header.entry);
> + if (dynstr_realloc(json, DYNCOL_NUM_CHAR + 3))
> + goto err;
> + json->str[json->length++]= '"';
> + json->length+= (snprintf(json->str + json->length,
> + DYNCOL_NUM_CHAR, "%u", nm));
> + }
> + else
> + {
> + uint len= header.entry[0];
> + if (dynstr_realloc(json, len + 3))
> + goto err;
> + json->str[json->length++]= '"';
> + memcpy(json->str + json->length, (const void *)header.nmpool +
> + uint2korr(header.entry + 1), len);
> + json->length+= len;
> + }
> + json->str[json->length++]= '"';
> + json->str[json->length++]= ':';
> + if ((rc= dynamic_column_val_str(json, &val,
> + &my_charset_utf8_general_ci, TRUE)) < 0 ||
> + dynstr_append_mem(json, "}", 1))
> + goto err;
> + }
> + if (dynstr_append_mem(json, "]", 1))
> + return ER_DYNCOL_RESOURCE;
> + return ER_DYNCOL_OK;
> +
> +err:
> + json->length= 0;
> + return rc;
> }
>
>
> /**
> - Update the packed string with the given column
> + Convert to DYNAMIC_COLUMN_VALUE values and names (LEX_STING) dynamic array
>
> - @param str String where to write the data
> - @param column_number Array of columns number
> - @param values Array of columns values
> + @param str The packed string
> + @param names Where to put names
> + @param vals Where to put values
> + @param free_names pointer to free names buffer if there is it.
>
> @return ER_DYNCOL_* return code
> */
>
> -
> -int dynamic_column_update(DYNAMIC_COLUMN *str, uint column_nr,
> - DYNAMIC_COLUMN_VALUE *value)
> +enum enum_dyncol_func_result
> +dynamic_column_vals(DYNAMIC_COLUMN *str,
> + DYNAMIC_ARRAY *names, DYNAMIC_ARRAY *vals,
> + char **free_names)
> {
> - return dynamic_column_update_many(str, 1, &column_nr, value);
> + DYN_HEADER header;
> + char *nm;
> + uint i;
> + enum enum_dyncol_func_result rc;
> +
> + *free_names= 0;
> + bzero(names, sizeof(DYNAMIC_ARRAY)); /* In case of errors */
> + bzero(vals, sizeof(DYNAMIC_ARRAY)); /* In case of errors */
> + if (str->length == 0)
> + return ER_DYNCOL_OK; /* no columns */
> +
> + if ((rc= init_read_hdr(&header, str)) < 0)
> + return rc;
> +
> + if (header.entry_size * header.column_count + FIXED_HEADER_SIZE >
> + str->length)
> + return ER_DYNCOL_FORMAT;
> +
> + if (init_dynamic_array(names, sizeof(LEX_STRING),
> + header.column_count, 0) ||
> + init_dynamic_array(vals, sizeof(DYNAMIC_COLUMN_VALUE),
> + header.column_count, 0) ||
> + (header.format == DYNCOL_FMT_NUM &&
> + !(*free_names= (char *)malloc(DYNCOL_NUM_CHAR * header.column_count))))
why do you need a special malloc() for names, you can put them
in the buffer of 'names' dynarray. it'll be a lot more convenient for
the caller (no free_names to care about).
> + {
> + rc= ER_DYNCOL_RESOURCE;
> + goto err;
> + }
> + nm= *free_names;
> +
> + for (i= 0, header.entry= header.header;
> + i < header.column_count;
> + i++, header.entry+= header.entry_size)
> + {
> + DYNAMIC_COLUMN_VALUE val;
> + LEX_STRING name;
> + header.length=
> + hdr_interval_length(&header, header.entry + header.entry_size);
> + header.data= header.dtpool + header.offset;
> + /*
> + Check that the found data is withing the ranges. This can happen if
> + we get data with wrong offsets.
> + */
> + if (header.length == DYNCOL_OFFSET_ERROR ||
> + header.length > INT_MAX || header.offset > header.data_size)
> + {
> + rc= ER_DYNCOL_FORMAT;
> + goto err;
> + }
> + if ((rc= dynamic_column_get_value(&header, &val)) < 0)
> + goto err;
> +
> + if (header.format == DYNCOL_FMT_NUM)
> + {
> + uint num= uint2korr(header.entry);
> + name.str= nm;
> + name.length= snprintf(nm, DYNCOL_NUM_CHAR, "%u", num);
> + nm+= name.length + 1;
> + }
> + else
> + {
> + name.length= header.entry[0];
> + name.str= (char *)header.nmpool + uint2korr(header.entry + 1);
> + }
> + /* following is preallocated and so do not fail */
> + (void) insert_dynamic(names, (uchar *)&name);
> + (void) insert_dynamic(vals, (uchar *)&val);
> + }
> + return ER_DYNCOL_OK;
> +
> +err:
> + delete_dynamic(names);
> + delete_dynamic(vals);
> + if (*free_names)
> + my_free(*free_names);
> + *free_names= 0;
> + return rc;
> }
>
Regards,
Sergei
1
0
[Maria-developers] a mysterious (to me) block of code in the middle of ha_recover
by Rich Prohaska 13 Dec '12
by Rich Prohaska 13 Dec '12
13 Dec '12
Hello,
The ha_recover function in MySQL 5.5.28 has a block of code in the
middle of it labelled with WILL_BE_DELETED_LATER that gets compiled
into mysqld. The ha_recover function in Mariadb 5.5.28a does not have
this code in it. It appears that the code forces prepared
transactions to be rolled back in MySQL even when mysqld is past the
recover phase.
Does anyone know what this code does?
Does anyone know why this code exists in MySQL but not in Mariadb?
Thanks
2
1
[Maria-developers] a mysterious (to me) block of code in the middle of ha_recover
by Rich Prohaska 13 Dec '12
by Rich Prohaska 13 Dec '12
13 Dec '12
Hello,
The ha_recover function in MySQL 5.5.28 has a block of code in the middle
of it labelled with WILL_BE_DELETED_LATER that gets compiled into mysqld.
The ha_recover function in Mariadb 5.5.28a does not have this code in it.
It appears that the code forces prepared transactions to be rolled back in
MySQL.
Does anyone know what this code does?
Does anyone know why this code exists in MySQL but not in Mariadb?
Thanks
Rich Prohaska
1
0
Hi,
Thanks for the latest releases with security fixes.
While I appreciate that all of the development of these security fixes was in public (without mentioning it was a security fix - well at least the remote code exec), I'm wondering if security releases could occur on a weekday where sysadmins need not forsake part of their weekend to correct a public vulnerability. Just my thoughts and preferences. I appreciate others may consider things different.
It also appears that the fedora 17 mariadb galera updates are only partially pushed. Maybe its just my setup after switching from non-galera repo.
$ sudo yum update
[sudo] password for dan:
Loaded plugins: langpacks, presto, priorities, refresh-packagekit, security
38 packages excluded due to repository priority protections
Resolving Dependencies
--> Running transaction check
---> Package MariaDB-client.x86_64 0:5.5.25-1 will be updated
---> Package MariaDB-client.x86_64 0:5.5.27-1 will be an update
---> Package MariaDB-common.x86_64 0:5.5.25-1 will be updated
---> Package MariaDB-common.x86_64 0:5.5.27-1 will be an update
---> Package MariaDB-server.x86_64 0:5.5.25-1 will be updated
---> Package MariaDB-server.x86_64 0:5.5.27-1 will be obsoleting
---> Package mysql.x86_64 0:5.5.28-1.fc17 will be obsoleted
--> Finished Dependency Resolution
Dependencies Resolved
==============================================================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================================================
Installing:
MariaDB-server x86_64 5.5.27-1 mariadb 33 M
replacing mysql.x86_64 5.5.28-1.fc17
Updating:
MariaDB-client x86_64 5.5.27-1 mariadb 8.6 M
MariaDB-common x86_64 5.5.27-1 mariadb 23 k
Transaction Summary
==============================================================================================================================================================
Install 1 Package
Upgrade 2 Packages
Total size: 42 M
Total download size: 8.6 M
Is this ok [y/N]: y
Downloading Packages:
Setting up and reading Presto delta metadata
MariaDB-5.5.27-fedora17-x86_64 FAILED HTTP Error 404 - Not Found : http://yum.mariadb.org/5.5-galera/fedora17-amd64/rpms/MariaDB-5.5.27-fedora…
http://yum.mariadb.org/5.5-galera/fedora17-amd64/rpms/MariaDB-5.5.27-fedora…: [Errno 14] HTTP Error 404 - Not Found : http://yum.mariadb.org/5.5-galera/fedora17-amd64/rpms/MariaDB-5.5.27-fedora…
/etc/yum.repos.d/mariadb.repo :
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/5.5-galera/fedora17-amd64
gpgcheck=1
enabled=1
--
Daniel Black, Engineer @ Open Query (http://openquery.com)
Remote expertise & maintenance for MySQL/MariaDB server environments.
2
2
06 Dec '12
>Description:
<I'm using MariaDB with my gameservers. Server works with db through sourcemod.
In my db i'am using utf8 encoding, and all works fine on MariaDB 5.3.8 with params:
init-connect = "SET NAMES 'utf8' COLLATE 'utf8_general_ci'"
skip-character-set-client-handshake
But after upgrade to 5.5.27 i found a 'bug'.
When i'm send query from my game server, over time character_set_connection, character_set_client and character_set_results set to latin1.
After enable log i saw:
88 Connect login@domain as anonymous on sourcebans
88 Query SET NAMES 'utf8' COLLATE 'utf8_general_ci'
88 Query SET NAMES latin1
88 Query SHOW VARIABLES LIKE '%character_set%'
But my request is only show vars.
I assumed that sourcemod is guilty. But skip-character-set-client-handshake is set! I disable it, and try again.
At this time i send SET collation_connection = utf8_general_ci and SET NAMES utf8 after my query. But over time it set to latin1 again.
No errosr in error.log
Sorry for my english.>
>How-To-Repeat:
<I don't know how to repeat it manually (without sourcemod app)>
>Fix:
<It works fine in previous versions. Just not accept NAMES from client.>
>Submitter-Id: <submitter ID>
>Originator: spumer
>Organization:
<russian game servers>
>MySQL support: [ email support ]
>Synopsis: <skip-character-set-client-handshake not work correctly>
>Severity:
>Priority:
>Category: mysql
>Class:
>Release: mysql-5.5.28a (MariaDB Server)
>C compiler: gcc-4.5.3 (Gentoo 4.5.3-r1 p1.0, pie-0.4.5) 4.5.3
>C++ compiler: g++-4.5.3(Gentoo 4.5.3-r1 p1.0, pie-0.4.5) 4.5.3
>Environment:
<VMware ESXi 5, Gentoo, Glibc 2.15>
System: Linux localhost 3.6.1-gentoo #1 SMP Mon Oct 8 06:00:23 YEKT 2012 x86_64 Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz GenuineIntel GNU/Linux
Some paths: /usr/bin/perl /usr/bin/make /usr/bin/gmake /usr/bin/gcc /usr/bin/cc
GCC: Используются внутренние спецификации.
COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.5.3/gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.5.3/lto-wrapper
Целевая архитектура: x86_64-pc-linux-gnu
Параметры конфигурации: /var/tmp/portage/sys-devel/gcc-4.5.3-r1/work/gcc-4.5.3/configure --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.5.3 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/include/g++-v4 --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec --disable-fixed-point --without-ppl --without-cloog --disable-lto --enable-nls --without-included-gettext --with-system-zlib --disable-werror --enable-secureplt --enable-multilib --enable-libmudflap --disable-libssp --enable-libgomp --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/python --enable-checking=release --disable-libgcj --enable-languages=c,c++,fortran --enable-shared --enable-threads=posix --enable-__cxa_a!
texit --enable-clocale=gnu --enable-targets=all --with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.5.3-r1 p1.0, pie-0.4.5'
Модель многопоточности: posix
gcc версия 4.5.3 (Gentoo 4.5.3-r1 p1.0, pie-0.4.5)
Compilation info (call): CC='/usr/bin/gcc' CFLAGS='-Wall -O3 -g -static-libgcc -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF -DMY_PTHREAD_FASTMUTEX=1' CXX='/usr/bin/c++' CXXFLAGS='-Wall -Wno-unused-parameter -fno-implicit-templates -fno-exceptions -fno-rtti -O3 -g -static-libgcc -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF -DMY_PTHREAD_FASTMUTEX=1' LDFLAGS='' ASFLAGS=''
Compilation info (used): CC='/usr/bin/gcc' CFLAGS='-Wall -O3 -g -static-libgcc -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF -DMY_PTHREAD_FASTMUTEX=1' CXX='/usr/bin/c++' CXXFLAGS='-Wall -Wno-unused-parameter -fno-implicit-templates -fno-exceptions -fno-rtti -O3 -g -static-libgcc -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF -DMY_PTHREAD_FASTMUTEX=1' LDFLAGS='' ASFLAGS=''
LIBC:
lrwxrwxrwx 1 root root 12 дек. 2 12:43 /lib/libc.so.6 -> libc-2.15.so
-rwxr-xr-x 1 root root 1734576 дек. 2 12:42 /lib/libc-2.15.so
-rw-r--r-- 1 root root 4594916 дек. 2 12:42 /usr/lib/libc.a
-rwxr-xr-x 1 root root 253 дек. 2 12:42 /usr/lib/libc.so
Perl: This is perl 5, version 12, subversion 4 (v5.12.4) built for x86_64-linux-thread-multi
2
1
06 Dec '12
revision 3584 named the test case for mdev 3885 "test_mdev3855" (NOTE 3855).
2
1
Re: [Maria-developers] How to get JDBC launchpad branch to trigger build in buildbot?
by Kristian Nielsen 03 Dec '12
by Kristian Nielsen 03 Dec '12
03 Dec '12
"Vladislav Vaintroub" <wlad(a)montyprogram.com> writes:
> there is a change in the Launchpad repository . I have done some things
> that I hoped would help, but it looks like it does not help.
> I subscribed Buildbot user to the changes in branch
> https://code.launchpad.net/~maria-captains/mariadb-java-client/trunk
It seems to be subscribed as "Branch attribute notifications only". Check the
wiki page, it has to be "branch revision notifications only" (and it's
probably not very useful to send review requests to Buildbot :-)
> + "lp:~maria-captains/mariadb-java-client/trunk" : "jdbc",
As explained on the wiki page, the branch should be on Launchpad under some
name lp:~maria-captains/maria/XXX (for some XXX) for this to work.
> +f_win_jdbc = factory.BuildFactory()
> +f_win32_debug.addStep(ShellCommand(
^^^^^^^^^^^^^ copy-paste error? "f_win_jdbc" ?
> +f_win_rqg.addStep(ShellCommand(
^^^^^^^^^ "f_win_jdbc" ?
> + name = "bzr_checkout",
> + command=["dojob", "bzr" ,"checkout", "-r", WithProperties("%(revision)s"), WithProperties("lp:~maria-captains/maria/%(branch)s"), WithProperties("c:\\buildbot\\%(buildername)s\\build")],
Did you mean "lp:~maria-captains/mariadb-java-client/%(branch)s" here? Or did
you mean lp:~maria-captains/maria/jdbc in the branch declaration?
> + WithProperties("cd c:\\buildbot\\%(buildername)s\\build && C:\\buildscripts\\build_jdbc")
Did you consider putting this script into the source tree instead? That makes
it easier when you have to modify the script along with the code in the source
three: old branches continue to use the old version of the script with the old
source version, new branches can use the new script with the new source
changes.
(But it's up to you what works best in this particular case).
> + "nextBuild": myNextBuild,
The myNextBuild() function selects among mariadb branches, that's probably not
very useful for a jdbc builder?
> see. Maybe you can have a quick look, if you got time? Would be a great
> help.
Ok, I will go through it all and try to get everything working.
It's probably better to add a separate configuration (branch map, schedulers,
builders) for the jdbc driver to not get it mixed up with the mariadb source
builds.
- Kristian.
2
2
Hi,
I have a need for replicating data from multiple masters (independent
data going to different tables).
I have looked into the following with no success:
Tungsten:
Slow, CPU hungry, outrageously bloated, and unacceptably unreliable
(replication will stall silently at times, and the only way to resume it
is to offline and online the replication service).
mysql-replication-listener:
Just about got it to work with local binlogs, but haven't managed to get
it to connect via TCP to a MySQL server.
So what I was hoping to do is write something based on the existing
MySQL code since at least that should "just work". The problem is - I am
completely unfamiliar with MySQL internals, and I haven't found any
function level API documentation. So, would anyone here be kind enough
to point me at the specific bits of code in MySQL that handle:
1) Slave TCP connections to the master and binlog fetching
2) Binlog parsing
3) Config file parsing
In the longer term I'd like to write a patch that adds multiple-master
functionality into MySQL itself. For configuring it, I was thinking
about the following WRT configuration in my.cnf with multiple section
instances, e.g.:
[replicator]
server-id=12345
master-host=server1
master-port=3306
master-user=user1
master-password=password1
replicate-do-table=db1.table1
[replicator]
server-id=12345
master-host=server2
master-port=3306
master-user=user2
master-password=password2
replicate-do-table=db2.table2
etc.
Any pointers would be greatly appreciated. If somebody here is already
undertaking a similar effort, I would rather like to lend a hand.
TIA.
Gordan
4
9