mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 12:32:27 +01:00
f252f9248a
The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c BitKeeper/etc/ignore: added libmysqld/ha_ndbcluster_cond.cc --- added debian/defs.mk debian/control client/completion_hash.cc: Remove not needed casts client/my_readline.h: Remove some old types client/mysql.cc: Simplify types client/mysql_upgrade.c: Remove some old types Update call to dirname_part client/mysqladmin.cc: Remove some old types client/mysqlbinlog.cc: Remove some old types Change some buffers to be uchar to avoid casts client/mysqlcheck.c: Remove some old types client/mysqldump.c: Remove some old types Remove some not needed casts Change some string lengths to size_t client/mysqlimport.c: Remove some old types client/mysqlshow.c: Remove some old types client/mysqlslap.c: Remove some old types Remove some not needed casts client/mysqltest.c: Removed some old types Removed some not needed casts Updated hash-get-key function arguments Updated parameters to dirname_part() client/readline.cc: Removed some old types Removed some not needed casts Changed some string lengths to use size_t client/sql_string.cc: Removed some old types dbug/dbug.c: Removed some old types Changed some string lengths to use size_t Changed some prototypes to avoid casts extra/comp_err.c: Removed some old types extra/innochecksum.c: Removed some old types extra/my_print_defaults.c: Removed some old types extra/mysql_waitpid.c: Removed some old types extra/perror.c: Removed some old types extra/replace.c: Removed some old types Updated parameters to dirname_part() extra/resolve_stack_dump.c: Removed some old types extra/resolveip.c: Removed some old types include/config-win.h: Removed some old types include/decimal.h: Changed binary strings to be uchar* instead of char* include/ft_global.h: Removed some old types include/hash.h: Removed some old types include/heap.h: Removed some old types Changed records_under_level to be 'ulong' instead of 'uint' to clarify usage of variable include/keycache.h: Removed some old types include/m_ctype.h: Removed some old types Changed some string lengths to use size_t Changed character length functions to return uint unsigned char -> uchar include/m_string.h: Removed some old types Changed some string lengths to use size_t include/my_alloc.h: Changed some string lengths to use size_t include/my_base.h: Removed some old types include/my_dbug.h: Removed some old types Changed some string lengths to use size_t Changed db_dump() to take uchar * as argument for memory to reduce number of casts in usage include/my_getopt.h: Removed some old types include/my_global.h: Removed old types: my_size_t -> size_t byte -> uchar gptr -> uchar * include/my_list.h: Removed some old types include/my_nosys.h: Removed some old types include/my_pthread.h: Removed some old types include/my_sys.h: Removed some old types Changed MY_FILE_ERROR to be in line with new definitions of my_write()/my_read() Changed some string lengths to use size_t my_malloc() / my_free() now uses void * Updated parameters to dirname_part() & my_uncompress() include/my_tree.h: Removed some old types include/my_trie.h: Removed some old types include/my_user.h: Changed some string lengths to use size_t include/my_vle.h: Removed some old types include/my_xml.h: Removed some old types Changed some string lengths to use size_t include/myisam.h: Removed some old types include/myisammrg.h: Removed some old types include/mysql.h: Removed some old types Changed byte streams to use uchar* instead of char* include/mysql_com.h: Removed some old types Changed some string lengths to use size_t Changed some buffers to be uchar* to avoid casts include/queues.h: Removed some old types include/sql_common.h: Removed some old types include/sslopt-longopts.h: Removed some old types include/violite.h: Removed some old types Changed some string lengths to use size_t libmysql/client_settings.h: Removed some old types libmysql/libmysql.c: Removed some old types libmysql/manager.c: Removed some old types libmysqld/emb_qcache.cc: Removed some old types libmysqld/emb_qcache.h: Removed some old types libmysqld/lib_sql.cc: Removed some old types Removed some not needed casts Changed some buffers to be uchar* to avoid casts true -> TRUE, false -> FALSE mysys/array.c: Removed some old types mysys/charset.c: Changed some string lengths to use size_t mysys/checksum.c: Include zlib to get definition for crc32 Removed some old types mysys/default.c: Removed some old types Changed some string lengths to use size_t mysys/default_modify.c: Changed some string lengths to use size_t Removed some not needed casts mysys/hash.c: Removed some old types Changed some string lengths to use size_t Note: Prototype of hash_key() has changed which may cause problems if client uses hash_init() with a cast for the hash-get-key function. hash_element now takes 'ulong' as the index type (cleanup) mysys/list.c: Removed some old types mysys/mf_cache.c: Changed some string lengths to use size_t mysys/mf_dirname.c: Removed some old types Changed some string lengths to use size_t Added argument to dirname_part() to avoid calculation of length for 'to' mysys/mf_fn_ext.c: Removed some old types Updated parameters to dirname_part() mysys/mf_format.c: Removed some old types Changed some string lengths to use size_t mysys/mf_getdate.c: Removed some old types mysys/mf_iocache.c: Removed some old types Changed some string lengths to use size_t Changed calculation of 'max_length' to be done the same way in all functions mysys/mf_iocache2.c: Removed some old types Changed some string lengths to use size_t Clean up comments Removed not needed indentation mysys/mf_keycache.c: Removed some old types mysys/mf_keycaches.c: Removed some old types mysys/mf_loadpath.c: Removed some old types mysys/mf_pack.c: Removed some old types Changed some string lengths to use size_t Removed some not needed casts Removed very old VMS code Updated parameters to dirname_part() Use result of dirnam_part() to remove call to strcat() mysys/mf_path.c: Removed some old types mysys/mf_radix.c: Removed some old types mysys/mf_same.c: Removed some old types mysys/mf_sort.c: Removed some old types mysys/mf_soundex.c: Removed some old types mysys/mf_strip.c: Removed some old types mysys/mf_tempdir.c: Removed some old types mysys/mf_unixpath.c: Removed some old types mysys/mf_wfile.c: Removed some old types mysys/mulalloc.c: Removed some old types mysys/my_alloc.c: Removed some old types Changed some string lengths to use size_t Use void* as type for allocated memory area Removed some not needed casts Changed argument 'Size' to 'length' according coding guidelines mysys/my_chsize.c: Changed some buffers to be uchar* to avoid casts mysys/my_compress.c: More comments Removed some old types Changed string lengths to use size_t Changed arguments to my_uncompress() to make them easier to understand Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) Changed type of 'pack_data' argument to packfrm() to avoid casts. mysys/my_conio.c: Changed some string lengths to use size_t mysys/my_create.c: Removed some old types mysys/my_div.c: Removed some old types mysys/my_error.c: Removed some old types mysys/my_fopen.c: Removed some old types mysys/my_fstream.c: Removed some old types Changed some string lengths to use size_t writen -> written mysys/my_getopt.c: Removed some old types mysys/my_getwd.c: Removed some old types More comments mysys/my_init.c: Removed some old types mysys/my_largepage.c: Removed some old types Changed some string lengths to use size_t mysys/my_lib.c: Removed some old types mysys/my_lockmem.c: Removed some old types mysys/my_malloc.c: Removed some old types Changed malloc(), free() and related functions to use void * Changed all functions to use size_t mysys/my_memmem.c: Indentation cleanup mysys/my_once.c: Removed some old types Changed malloc(), free() and related functions to use void * mysys/my_open.c: Removed some old types mysys/my_pread.c: Removed some old types Changed all functions to use size_t Added comment for how my_pread() / my_pwrite() are supposed to work. Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. (If we ever would really need this, it should be enabled only with a flag argument) mysys/my_quick.c: Removed some old types Changed all functions to use size_t mysys/my_read.c: Removed some old types Changed all functions to use size_t mysys/my_realloc.c: Removed some old types Use void* as type for allocated memory area Changed all functions to use size_t mysys/my_static.c: Removed some old types mysys/my_static.h: Removed some old types mysys/my_vle.c: Removed some old types mysys/my_wincond.c: Removed some old types mysys/my_windac.c: Removed some old types mysys/my_write.c: Removed some old types Changed all functions to use size_t mysys/ptr_cmp.c: Removed some old types Changed all functions to use size_t mysys/queues.c: Removed some old types mysys/safemalloc.c: Removed some old types Changed malloc(), free() and related functions to use void * Changed all functions to use size_t mysys/string.c: Removed some old types Changed all functions to use size_t mysys/testhash.c: Removed some old types mysys/thr_alarm.c: Removed some old types mysys/thr_lock.c: Removed some old types mysys/tree.c: Removed some old types mysys/trie.c: Removed some old types mysys/typelib.c: Removed some old types plugin/daemon_example/daemon_example.cc: Removed some old types regex/reginit.c: Removed some old types server-tools/instance-manager/buffer.cc: Changed some string lengths to use size_t Changed buffer to be of type uchar* server-tools/instance-manager/buffer.h: Changed some string lengths to use size_t Changed buffer to be of type uchar* server-tools/instance-manager/commands.cc: Removed some old types Changed some string lengths to use size_t Changed buffer to be of type uchar* server-tools/instance-manager/instance_map.cc: Removed some old types Changed some string lengths to use size_t Changed buffer to be of type uchar* server-tools/instance-manager/instance_options.cc: Changed buffer to be of type uchar* Replaced alloc_root + strcpy() with strdup_root() server-tools/instance-manager/mysql_connection.cc: Changed buffer to be of type uchar* server-tools/instance-manager/options.cc: Removed some old types server-tools/instance-manager/parse.cc: Changed some string lengths to use size_t server-tools/instance-manager/parse.h: Removed some old types Changed some string lengths to use size_t server-tools/instance-manager/protocol.cc: Changed some buffers to be uchar* to avoid casts Changed some string lengths to use size_t server-tools/instance-manager/protocol.h: Changed some string lengths to use size_t server-tools/instance-manager/user_map.cc: Removed some old types Changed some string lengths to use size_t sql/derror.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Changed some string lengths to use size_t sql/discover.cc: Changed in readfrm() and writefrom() the type for argument 'frmdata' to uchar** to avoid casts Changed some string lengths to use size_t Changed some buffers to be uchar* to avoid casts sql/event_data_objects.cc: Removed some old types Added missing casts for alloc() and sprintf() sql/event_db_repository.cc: Changed some buffers to be uchar* to avoid casts Added missing casts for sprintf() sql/event_queue.cc: Removed some old types sql/field.cc: Removed some old types Changed memory buffers to be uchar* Changed some string lengths to use size_t Removed a lot of casts Safety fix in Field_blob::val_decimal() to not access zero pointer sql/field.h: Removed some old types Changed memory buffers to be uchar* (except of store() as this would have caused too many other changes). Changed some string lengths to use size_t Removed some not needed casts Changed val_xxx(xxx, new_ptr) to take const pointers sql/field_conv.cc: Removed some old types Added casts required because memory area pointers are now uchar* sql/filesort.cc: Initalize variable that was used unitialized in error conditions sql/gen_lex_hash.cc: Removed some old types Changed memory buffers to be uchar* Changed some string lengths to use size_t Removed a lot of casts Safety fix in Field_blob::val_decimal() to not access zero pointer sql/gstream.h: Added required cast sql/ha_ndbcluster.cc: Removed some old types Updated hash-get-key function arguments Changed some buffers to be uchar* to avoid casts Added required casts Removed some not needed casts sql/ha_ndbcluster.h: Removed some old types sql/ha_ndbcluster_binlog.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Replaced sql_alloc() + memcpy() + set end 0 with sql_strmake() Changed some string lengths to use size_t Added missing casts for alloc() and sprintf() sql/ha_ndbcluster_binlog.h: Removed some old types sql/ha_ndbcluster_cond.cc: Removed some old types Removed some not needed casts sql/ha_ndbcluster_cond.h: Removed some old types sql/ha_partition.cc: Removed some old types Changed prototype for change_partition() to avoid casts sql/ha_partition.h: Removed some old types sql/handler.cc: Removed some old types Changed some string lengths to use size_t sql/handler.h: Removed some old types Changed some string lengths to use size_t Changed type for 'frmblob' parameter for discover() and ha_discover() to get fewer casts sql/hash_filo.h: Removed some old types Changed all functions to use size_t sql/hostname.cc: Removed some old types sql/item.cc: Removed some old types Changed some string lengths to use size_t Use strmake() instead of memdup() to create a null terminated string. Updated calls to new Field() sql/item.h: Removed some old types Changed malloc(), free() and related functions to use void * Changed some buffers to be uchar* to avoid casts sql/item_cmpfunc.cc: Removed some old types Changed some buffers to be uchar* to avoid casts sql/item_cmpfunc.h: Removed some old types sql/item_create.cc: Removed some old types sql/item_func.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Removed some not needed casts Added test for failing alloc() in init_result_field() Remove old confusing comment Fixed compiler warning sql/item_func.h: Removed some old types sql/item_row.cc: Removed some old types sql/item_row.h: Removed some old types sql/item_strfunc.cc: Include zlib (needed becasue we call crc32) Removed some old types sql/item_strfunc.h: Removed some old types Changed some types to match new function prototypes sql/item_subselect.cc: Removed some old types sql/item_subselect.h: Removed some old types sql/item_sum.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Removed some not needed casts sql/item_sum.h: Removed some old types sql/item_timefunc.cc: Removed some old types Changed some string lengths to use size_t sql/item_timefunc.h: Removed some old types sql/item_xmlfunc.cc: Changed some string lengths to use size_t sql/item_xmlfunc.h: Removed some old types sql/key.cc: Removed some old types Removed some not needed casts sql/lock.cc: Removed some old types Added some cast to my_multi_malloc() arguments for safety sql/log.cc: Removed some old types Changed some string lengths to use size_t Changed some buffers to be uchar* to avoid casts Changed usage of pwrite() to not assume it holds the cursor position for the file Made usage of my_read() safer sql/log_event.cc: Removed some old types Added checking of return value of malloc() in pack_info() Changed some buffers to be uchar* to avoid casts Removed some 'const' to avoid casts Added missing casts for alloc() and sprintf() Added required casts Removed some not needed casts Added some cast to my_multi_malloc() arguments for safety sql/log_event.h: Removed some old types Changed some buffers to be uchar* to avoid casts sql/log_event_old.cc: Changed some buffers to be uchar* to avoid casts Removed some not needed casts sql/log_event_old.h: Changed some buffers to be uchar* to avoid casts sql/mf_iocache.cc: Removed some old types sql/my_decimal.cc: Changed memory area to use uchar* sql/my_decimal.h: Changed memory area to use uchar* sql/mysql_priv.h: Removed some old types Changed malloc(), free() and related functions to use void * Changed some string lengths to use size_t Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid long overflow Changed some buffers to be uchar* to avoid casts sql/mysqld.cc: Removed some old types sql/net_serv.cc: Removed some old types Changed some string lengths to use size_t Changed some buffers to be uchar* to avoid casts Ensure that vio_read()/vio_write() return values are stored in a size_t variable Removed some not needed casts sql/opt_range.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Removed some not needed casts sql/opt_range.h: Removed some old types Changed some buffers to be uchar* to avoid casts sql/opt_sum.cc: Removed some old types Removed some not needed casts sql/parse_file.cc: Removed some old types Changed some string lengths to use size_t Changed alloc_root + memcpy + set end 0 -> strmake_root() sql/parse_file.h: Removed some old types sql/partition_info.cc: Removed some old types Added missing casts for alloc() Changed some buffers to be uchar* to avoid casts sql/partition_info.h: Changed some buffers to be uchar* to avoid casts sql/protocol.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Removed some not needed casts sql/protocol.h: Removed some old types Changed some buffers to be uchar* to avoid casts Changed some string lengths to use size_t sql/records.cc: Removed some old types sql/repl_failsafe.cc: Removed some old types Changed some string lengths to use size_t Added required casts sql/rpl_filter.cc: Removed some old types Updated hash-get-key function arguments Changed some string lengths to use size_t sql/rpl_filter.h: Changed some string lengths to use size_t sql/rpl_injector.h: Removed some old types sql/rpl_record.cc: Removed some old types Removed some not needed casts Changed some buffers to be uchar* to avoid casts sql/rpl_record.h: Removed some old types Changed some buffers to be uchar* to avoid casts sql/rpl_record_old.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Removed some not needed casts sql/rpl_record_old.h: Removed some old types Changed some buffers to be uchar* to avoid cast sql/rpl_rli.cc: Removed some old types sql/rpl_tblmap.cc: Removed some old types sql/rpl_tblmap.h: Removed some old types sql/rpl_utility.cc: Removed some old types sql/rpl_utility.h: Removed some old types Changed type of m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length sql/set_var.cc: Removed some old types Updated parameters to dirname_part() sql/set_var.h: Removed some old types sql/slave.cc: Removed some old types Changed some string lengths to use size_t sql/slave.h: Removed some old types sql/sp.cc: Removed some old types Added missing casts for printf() sql/sp.h: Removed some old types Updated hash-get-key function arguments sql/sp_cache.cc: Removed some old types Added missing casts for printf() Updated hash-get-key function arguments sql/sp_head.cc: Removed some old types Added missing casts for alloc() and printf() Added required casts Updated hash-get-key function arguments sql/sp_head.h: Removed some old types sql/sp_pcontext.cc: Removed some old types sql/sp_pcontext.h: Removed some old types sql/sql_acl.cc: Removed some old types Changed some string lengths to use size_t Changed some buffers to be uchar* to avoid casts Removed some not needed casts Added required casts sql/sql_analyse.cc: Changed some buffers to be uchar* to avoid casts sql/sql_analyse.h: Changed some buffers to be uchar* to avoid casts sql/sql_array.h: Removed some old types sql/sql_base.cc: Removed some old types Updated hash-get-key function arguments sql/sql_binlog.cc: Removed some old types Added missing casts for printf() sql/sql_cache.cc: Removed some old types Updated hash-get-key function arguments Removed some not needed casts Changed some string lengths to use size_t sql/sql_cache.h: Removed some old types Removed reference to not existing function cache_key() Updated hash-get-key function arguments sql/sql_class.cc: Removed some old types Updated hash-get-key function arguments Added missing casts for alloc() Updated hash-get-key function arguments Moved THD::max_row_length() to table.cc (as it's not depending on THD) Removed some not needed casts sql/sql_class.h: Removed some old types Changed malloc(), free() and related functions to use void * Removed some not needed casts Changed some string lengths to use size_t Moved max_row_length and max_row_length_blob() to table.cc, as they are not depending on THD sql/sql_connect.cc: Removed some old types Added required casts sql/sql_db.cc: Removed some old types Removed some not needed casts Added some cast to my_multi_malloc() arguments for safety Added missing casts for alloc() sql/sql_delete.cc: Removed some old types sql/sql_handler.cc: Removed some old types Updated hash-get-key function arguments Added some cast to my_multi_malloc() arguments for safety sql/sql_help.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Removed some not needed casts sql/sql_insert.cc: Removed some old types Added missing casts for alloc() and printf() sql/sql_lex.cc: Removed some old types sql/sql_lex.h: Removed some old types Removed some not needed casts sql/sql_list.h: Removed some old types Removed some not needed casts sql/sql_load.cc: Removed some old types Removed compiler warning sql/sql_manager.cc: Removed some old types sql/sql_map.cc: Removed some old types sql/sql_map.h: Removed some old types sql/sql_olap.cc: Removed some old types sql/sql_parse.cc: Removed some old types Trivial move of code lines to make things more readable Changed some string lengths to use size_t Added missing casts for alloc() sql/sql_partition.cc: Removed some old types Removed compiler warnings about not used functions Changed some buffers to be uchar* to avoid casts Removed some not needed casts sql/sql_partition.h: Removed some old types Changed some buffers to be uchar* to avoid casts sql/sql_plugin.cc: Removed some old types Added missing casts for alloc() Updated hash-get-key function arguments sql/sql_prepare.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Added missing casts for alloc() and printf() sql-common/client.c: Removed some old types Changed some memory areas to use uchar* sql-common/my_user.c: Changed some string lengths to use size_t sql-common/pack.c: Changed some buffers to be uchar* to avoid casts sql/sql_repl.cc: Added required casts Changed some buffers to be uchar* to avoid casts Changed some string lengths to use size_t sql/sql_select.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Removed some old types sql/sql_select.h: Removed some old types Changed some buffers to be uchar* to avoid casts sql/sql_servers.cc: Removed some old types Updated hash-get-key function arguments sql/sql_show.cc: Removed some old types Added missing casts for alloc() Removed some not needed casts sql/sql_string.cc: Removed some old types Added required casts sql/sql_table.cc: Removed some old types Removed compiler warning about not used variable Changed some buffers to be uchar* to avoid casts Removed some not needed casts sql/sql_test.cc: Removed some old types sql/sql_trigger.cc: Removed some old types Added missing casts for alloc() sql/sql_udf.cc: Removed some old types Updated hash-get-key function arguments sql/sql_union.cc: Removed some old types sql/sql_update.cc: Removed some old types Removed some not needed casts sql/sql_view.cc: Removed some old types sql/sql_yacc.yy: Removed some old types Changed some string lengths to use size_t Added missing casts for alloc() sql/stacktrace.c: Removed some old types sql/stacktrace.h: Removed some old types sql/structs.h: Removed some old types sql/table.cc: Removed some old types Updated hash-get-key function arguments Changed some buffers to be uchar* to avoid casts Removed setting of LEX_STRING() arguments in declaration Added required casts More function comments Moved max_row_length() here from sql_class.cc/sql_class.h sql/table.h: Removed some old types Changed some string lengths to use size_t sql/thr_malloc.cc: Use void* as type for allocated memory area Changed all functions to use size_t sql/tzfile.h: Changed some buffers to be uchar* to avoid casts sql/tztime.cc: Changed some buffers to be uchar* to avoid casts Updated hash-get-key function arguments Added missing casts for alloc() Removed some not needed casts sql/uniques.cc: Removed some old types Removed some not needed casts sql/unireg.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Removed some not needed casts Added missing casts for alloc() storage/archive/archive_reader.c: Removed some old types storage/archive/azio.c: Removed some old types Removed some not needed casts storage/archive/ha_archive.cc: Removed some old types Changed type for 'frmblob' in archive_discover() to match handler Updated hash-get-key function arguments Removed some not needed casts storage/archive/ha_archive.h: Removed some old types storage/blackhole/ha_blackhole.cc: Removed some old types storage/blackhole/ha_blackhole.h: Removed some old types storage/csv/ha_tina.cc: Removed some old types Updated hash-get-key function arguments Changed some buffers to be uchar* to avoid casts storage/csv/ha_tina.h: Removed some old types Removed some not needed casts storage/csv/transparent_file.cc: Removed some old types Changed type of 'bytes_read' to be able to detect read errors Fixed indentation storage/csv/transparent_file.h: Removed some old types storage/example/ha_example.cc: Removed some old types Updated hash-get-key function arguments storage/example/ha_example.h: Removed some old types storage/federated/ha_federated.cc: Removed some old types Updated hash-get-key function arguments Removed some not needed casts storage/federated/ha_federated.h: Removed some old types storage/heap/_check.c: Changed some buffers to be uchar* to avoid casts storage/heap/_rectest.c: Removed some old types storage/heap/ha_heap.cc: Removed some old types storage/heap/ha_heap.h: Removed some old types storage/heap/heapdef.h: Removed some old types storage/heap/hp_block.c: Removed some old types Changed some string lengths to use size_t storage/heap/hp_clear.c: Removed some old types storage/heap/hp_close.c: Removed some old types storage/heap/hp_create.c: Removed some old types storage/heap/hp_delete.c: Removed some old types storage/heap/hp_hash.c: Removed some old types storage/heap/hp_info.c: Removed some old types storage/heap/hp_open.c: Removed some old types storage/heap/hp_rfirst.c: Removed some old types storage/heap/hp_rkey.c: Removed some old types storage/heap/hp_rlast.c: Removed some old types storage/heap/hp_rnext.c: Removed some old types storage/heap/hp_rprev.c: Removed some old types storage/heap/hp_rrnd.c: Removed some old types storage/heap/hp_rsame.c: Removed some old types storage/heap/hp_scan.c: Removed some old types storage/heap/hp_test1.c: Removed some old types storage/heap/hp_test2.c: Removed some old types storage/heap/hp_update.c: Removed some old types storage/heap/hp_write.c: Removed some old types Changed some string lengths to use size_t storage/innobase/handler/ha_innodb.cc: Removed some old types Updated hash-get-key function arguments Added missing casts for alloc() and printf() Removed some not needed casts storage/innobase/handler/ha_innodb.h: Removed some old types storage/myisam/ft_boolean_search.c: Removed some old types storage/myisam/ft_nlq_search.c: Removed some old types storage/myisam/ft_parser.c: Removed some old types Changed some buffers to be uchar* to avoid casts storage/myisam/ft_static.c: Removed some old types storage/myisam/ft_stopwords.c: Removed some old types storage/myisam/ft_update.c: Removed some old types Changed some buffers to be uchar* to avoid casts storage/myisam/ftdefs.h: Removed some old types Changed some buffers to be uchar* to avoid casts storage/myisam/fulltext.h: Removed some old types storage/myisam/ha_myisam.cc: Removed some old types storage/myisam/ha_myisam.h: Removed some old types storage/myisam/mi_cache.c: Removed some old types Changed some buffers to be uchar* to avoid casts storage/myisam/mi_check.c: Removed some old types storage/myisam/mi_checksum.c: Removed some old types storage/myisam/mi_close.c: Removed some old types storage/myisam/mi_create.c: Removed some old types storage/myisam/mi_delete.c: Removed some old types storage/myisam/mi_delete_all.c: Removed some old types storage/myisam/mi_dynrec.c: Removed some old types storage/myisam/mi_extra.c: Removed some old types storage/myisam/mi_key.c: Removed some old types storage/myisam/mi_locking.c: Removed some old types storage/myisam/mi_log.c: Removed some old types storage/myisam/mi_open.c: Removed some old types Removed some not needed casts Check argument of my_write()/my_pwrite() in functions returning int Added casting of string lengths to size_t storage/myisam/mi_packrec.c: Removed some old types Changed some buffers to be uchar* to avoid casts storage/myisam/mi_page.c: Removed some old types storage/myisam/mi_preload.c: Removed some old types storage/myisam/mi_range.c: Removed some old types storage/myisam/mi_rfirst.c: Removed some old types storage/myisam/mi_rkey.c: Removed some old types storage/myisam/mi_rlast.c: Removed some old types storage/myisam/mi_rnext.c: Removed some old types storage/myisam/mi_rnext_same.c: Removed some old types storage/myisam/mi_rprev.c: Removed some old types storage/myisam/mi_rrnd.c: Removed some old types storage/myisam/mi_rsame.c: Removed some old types storage/myisam/mi_rsamepos.c: Removed some old types storage/myisam/mi_scan.c: Removed some old types storage/myisam/mi_search.c: Removed some old types storage/myisam/mi_static.c: Removed some old types storage/myisam/mi_statrec.c: Removed some old types storage/myisam/mi_test1.c: Removed some old types storage/myisam/mi_test2.c: Removed some old types storage/myisam/mi_test3.c: Removed some old types storage/myisam/mi_unique.c: Removed some old types storage/myisam/mi_update.c: Removed some old types storage/myisam/mi_write.c: Removed some old types storage/myisam/myisam_ftdump.c: Removed some old types storage/myisam/myisamchk.c: Removed some old types storage/myisam/myisamdef.h: Removed some old types storage/myisam/myisamlog.c: Removed some old types Indentation fix storage/myisam/myisampack.c: Removed some old types storage/myisam/rt_index.c: Removed some old types storage/myisam/rt_split.c: Removed some old types storage/myisam/sort.c: Removed some old types storage/myisam/sp_defs.h: Removed some old types storage/myisam/sp_key.c: Removed some old types storage/myisammrg/ha_myisammrg.cc: Removed some old types storage/myisammrg/ha_myisammrg.h: Removed some old types storage/myisammrg/myrg_close.c: Removed some old types storage/myisammrg/myrg_def.h: Removed some old types storage/myisammrg/myrg_delete.c: Removed some old types storage/myisammrg/myrg_open.c: Removed some old types Updated parameters to dirname_part() storage/myisammrg/myrg_queue.c: Removed some old types storage/myisammrg/myrg_rfirst.c: Removed some old types storage/myisammrg/myrg_rkey.c: Removed some old types storage/myisammrg/myrg_rlast.c: Removed some old types storage/myisammrg/myrg_rnext.c: Removed some old types storage/myisammrg/myrg_rnext_same.c: Removed some old types storage/myisammrg/myrg_rprev.c: Removed some old types storage/myisammrg/myrg_rrnd.c: Removed some old types storage/myisammrg/myrg_rsame.c: Removed some old types storage/myisammrg/myrg_update.c: Removed some old types storage/myisammrg/myrg_write.c: Removed some old types storage/ndb/include/util/ndb_opts.h: Removed some old types storage/ndb/src/cw/cpcd/main.cpp: Removed some old types storage/ndb/src/kernel/vm/Configuration.cpp: Removed some old types storage/ndb/src/mgmclient/main.cpp: Removed some old types storage/ndb/src/mgmsrv/InitConfigFileParser.cpp: Removed some old types Removed old disabled code storage/ndb/src/mgmsrv/main.cpp: Removed some old types storage/ndb/src/ndbapi/NdbBlob.cpp: Removed some old types storage/ndb/src/ndbapi/NdbOperationDefine.cpp: Removed not used variable storage/ndb/src/ndbapi/NdbOperationInt.cpp: Added required casts storage/ndb/src/ndbapi/NdbScanOperation.cpp: Added required casts storage/ndb/tools/delete_all.cpp: Removed some old types storage/ndb/tools/desc.cpp: Removed some old types storage/ndb/tools/drop_index.cpp: Removed some old types storage/ndb/tools/drop_tab.cpp: Removed some old types storage/ndb/tools/listTables.cpp: Removed some old types storage/ndb/tools/ndb_config.cpp: Removed some old types storage/ndb/tools/restore/consumer_restore.cpp: Changed some buffers to be uchar* to avoid casts with new defintion of packfrm() storage/ndb/tools/restore/restore_main.cpp: Removed some old types storage/ndb/tools/select_all.cpp: Removed some old types storage/ndb/tools/select_count.cpp: Removed some old types storage/ndb/tools/waiter.cpp: Removed some old types strings/bchange.c: Changed function to use uchar * and size_t strings/bcmp.c: Changed function to use uchar * and size_t strings/bmove512.c: Changed function to use uchar * and size_t strings/bmove_upp.c: Changed function to use uchar * and size_t strings/ctype-big5.c: Changed functions to use size_t Changed character length functions to return uint strings/ctype-bin.c: Changed functions to use size_t strings/ctype-cp932.c: Changed functions to use size_t Changed character length functions to return uint strings/ctype-czech.c: Fixed indentation Changed functions to use size_t strings/ctype-euc_kr.c: Changed functions to use size_t Changed character length functions to return uint strings/ctype-eucjpms.c: Changed functions to use size_t Changed character length functions to return uint unsigned char -> uchar strings/ctype-gb2312.c: Changed functions to use size_t Changed character length functions to return uint strings/ctype-gbk.c: Changed functions to use size_t Changed character length functions to return uint strings/ctype-latin1.c: Changed functions to use size_t Changed character length functions to return uint unsigned char -> uchar strings/ctype-mb.c: Changed functions to use size_t Changed character length functions to return uint strings/ctype-simple.c: Changed functions to use size_t Simpler loops for caseup/casedown unsigned int -> uint unsigned char -> uchar strings/ctype-sjis.c: Changed functions to use size_t Changed character length functions to return uint strings/ctype-tis620.c: Changed functions to use size_t Changed character length functions to return uint unsigned char -> uchar strings/ctype-uca.c: Changed functions to use size_t unsigned char -> uchar strings/ctype-ucs2.c: Moved inclusion of stdarg.h to other includes usigned char -> uchar Changed functions to use size_t Changed character length functions to return uint strings/ctype-ujis.c: Changed functions to use size_t Changed character length functions to return uint unsigned char -> uchar strings/ctype-utf8.c: Changed functions to use size_t unsigned char -> uchar Indentation fixes strings/ctype-win1250ch.c: Indentation fixes Changed functions to use size_t strings/ctype.c: Changed functions to use size_t strings/decimal.c: Changed type for memory argument to uchar * strings/do_ctype.c: Indentation fixes strings/my_strtoll10.c: unsigned char -> uchar strings/my_vsnprintf.c: Changed functions to use size_t strings/r_strinstr.c: Removed some old types Changed functions to use size_t strings/str_test.c: Removed some old types strings/strappend.c: Changed functions to use size_t strings/strcont.c: Removed some old types strings/strfill.c: Removed some old types strings/strinstr.c: Changed functions to use size_t strings/strlen.c: Changed functions to use size_t strings/strmake.c: Changed functions to use size_t strings/strnlen.c: Changed functions to use size_t strings/strnmov.c: Changed functions to use size_t strings/strto.c: unsigned char -> uchar strings/strtod.c: Changed functions to use size_t strings/strxnmov.c: Changed functions to use size_t strings/xml.c: Changed functions to use size_t Indentation fixes tests/mysql_client_test.c: Removed some old types tests/thread_test.c: Removed some old types vio/test-ssl.c: Removed some old types vio/test-sslclient.c: Removed some old types vio/test-sslserver.c: Removed some old types vio/vio.c: Removed some old types vio/vio_priv.h: Removed some old types Changed vio_read()/vio_write() to work with size_t vio/viosocket.c: Changed vio_read()/vio_write() to work with size_t Indentation fixes vio/viossl.c: Changed vio_read()/vio_write() to work with size_t Indentation fixes vio/viosslfactories.c: Removed some old types vio/viotest-ssl.c: Removed some old types win/README: More explanations
1510 lines
41 KiB
C++
1510 lines
41 KiB
C++
/* Copyright (C) 2003 MySQL AB
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; version 2 of the License.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
/*
|
|
Make sure to look at ha_tina.h for more details.
|
|
|
|
First off, this is a play thing for me, there are a number of things
|
|
wrong with it:
|
|
*) It was designed for csv and therefore its performance is highly
|
|
questionable.
|
|
*) Indexes have not been implemented. This is because the files can
|
|
be traded in and out of the table directory without having to worry
|
|
about rebuilding anything.
|
|
*) NULLs and "" are treated equally (like a spreadsheet).
|
|
*) There was in the beginning no point to anyone seeing this other
|
|
then me, so there is a good chance that I haven't quite documented
|
|
it well.
|
|
*) Less design, more "make it work"
|
|
|
|
Now there are a few cool things with it:
|
|
*) Errors can result in corrupted data files.
|
|
*) Data files can be read by spreadsheets directly.
|
|
|
|
TODO:
|
|
*) Move to a block system for larger files
|
|
*) Error recovery, its all there, just need to finish it
|
|
*) Document how the chains work.
|
|
|
|
-Brian
|
|
*/
|
|
|
|
#ifdef USE_PRAGMA_IMPLEMENTATION
|
|
#pragma implementation // gcc: Class implementation
|
|
#endif
|
|
|
|
#include "mysql_priv.h"
|
|
|
|
#include "ha_tina.h"
|
|
|
|
#include <mysql/plugin.h>
|
|
|
|
/*
|
|
uchar + uchar + ulonglong + ulonglong + ulonglong + ulonglong + uchar
|
|
*/
|
|
#define META_BUFFER_SIZE sizeof(uchar) + sizeof(uchar) + sizeof(ulonglong) \
|
|
+ sizeof(ulonglong) + sizeof(ulonglong) + sizeof(ulonglong) + sizeof(uchar)
|
|
#define TINA_CHECK_HEADER 254 // The number we use to determine corruption
|
|
|
|
/* The file extension */
|
|
#define CSV_EXT ".CSV" // The data file
|
|
#define CSN_EXT ".CSN" // Files used during repair and update
|
|
#define CSM_EXT ".CSM" // Meta file
|
|
|
|
|
|
static TINA_SHARE *get_share(const char *table_name, TABLE *table);
|
|
static int free_share(TINA_SHARE *share);
|
|
static int read_meta_file(File meta_file, ha_rows *rows);
|
|
static int write_meta_file(File meta_file, ha_rows rows, bool dirty);
|
|
|
|
/* Stuff for shares */
|
|
pthread_mutex_t tina_mutex;
|
|
static HASH tina_open_tables;
|
|
static handler *tina_create_handler(handlerton *hton,
|
|
TABLE_SHARE *table,
|
|
MEM_ROOT *mem_root);
|
|
|
|
|
|
/*****************************************************************************
|
|
** TINA tables
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
Used for sorting chains with qsort().
|
|
*/
|
|
int sort_set (tina_set *a, tina_set *b)
|
|
{
|
|
/*
|
|
We assume that intervals do not intersect. So, it is enought to compare
|
|
any two points. Here we take start of intervals for comparison.
|
|
*/
|
|
return ( a->begin > b->begin ? 1 : ( a->begin < b->begin ? -1 : 0 ) );
|
|
}
|
|
|
|
static uchar* tina_get_key(TINA_SHARE *share, size_t *length,
|
|
my_bool not_used __attribute__((unused)))
|
|
{
|
|
*length=share->table_name_length;
|
|
return (uchar*) share->table_name;
|
|
}
|
|
|
|
static int tina_init_func(void *p)
|
|
{
|
|
handlerton *tina_hton;
|
|
|
|
tina_hton= (handlerton *)p;
|
|
VOID(pthread_mutex_init(&tina_mutex,MY_MUTEX_INIT_FAST));
|
|
(void) hash_init(&tina_open_tables,system_charset_info,32,0,0,
|
|
(hash_get_key) tina_get_key,0,0);
|
|
tina_hton->state= SHOW_OPTION_YES;
|
|
tina_hton->db_type= DB_TYPE_CSV_DB;
|
|
tina_hton->create= tina_create_handler;
|
|
tina_hton->flags= (HTON_CAN_RECREATE | HTON_SUPPORT_LOG_TABLES |
|
|
HTON_NO_PARTITION);
|
|
return 0;
|
|
}
|
|
|
|
static int tina_done_func(void *p)
|
|
{
|
|
hash_free(&tina_open_tables);
|
|
pthread_mutex_destroy(&tina_mutex);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
/*
|
|
Simple lock controls.
|
|
*/
|
|
static TINA_SHARE *get_share(const char *table_name, TABLE *table)
|
|
{
|
|
TINA_SHARE *share;
|
|
char meta_file_name[FN_REFLEN];
|
|
MY_STAT file_stat; /* Stat information for the data file */
|
|
char *tmp_name;
|
|
uint length;
|
|
|
|
pthread_mutex_lock(&tina_mutex);
|
|
length=(uint) strlen(table_name);
|
|
|
|
/*
|
|
If share is not present in the hash, create a new share and
|
|
initialize its members.
|
|
*/
|
|
if (!(share=(TINA_SHARE*) hash_search(&tina_open_tables,
|
|
(uchar*) table_name,
|
|
length)))
|
|
{
|
|
if (!my_multi_malloc(MYF(MY_WME | MY_ZEROFILL),
|
|
&share, sizeof(*share),
|
|
&tmp_name, length+1,
|
|
NullS))
|
|
{
|
|
pthread_mutex_unlock(&tina_mutex);
|
|
return NULL;
|
|
}
|
|
|
|
share->use_count= 0;
|
|
share->is_log_table= FALSE;
|
|
share->table_name_length= length;
|
|
share->table_name= tmp_name;
|
|
share->crashed= FALSE;
|
|
share->rows_recorded= 0;
|
|
share->update_file_opened= FALSE;
|
|
share->tina_write_opened= FALSE;
|
|
strmov(share->table_name, table_name);
|
|
fn_format(share->data_file_name, table_name, "", CSV_EXT,
|
|
MY_REPLACE_EXT|MY_UNPACK_FILENAME);
|
|
fn_format(meta_file_name, table_name, "", CSM_EXT,
|
|
MY_REPLACE_EXT|MY_UNPACK_FILENAME);
|
|
|
|
if (my_stat(share->data_file_name, &file_stat, MYF(MY_WME)) == NULL)
|
|
goto error;
|
|
share->saved_data_file_length= file_stat.st_size;
|
|
|
|
if (my_hash_insert(&tina_open_tables, (uchar*) share))
|
|
goto error;
|
|
thr_lock_init(&share->lock);
|
|
pthread_mutex_init(&share->mutex,MY_MUTEX_INIT_FAST);
|
|
|
|
/*
|
|
Open or create the meta file. In the latter case, we'll get
|
|
an error during read_meta_file and mark the table as crashed.
|
|
Usually this will result in auto-repair, and we will get a good
|
|
meta-file in the end.
|
|
*/
|
|
if ((share->meta_file= my_open(meta_file_name,
|
|
O_RDWR|O_CREAT, MYF(0))) == -1)
|
|
share->crashed= TRUE;
|
|
|
|
/*
|
|
If the meta file will not open we assume it is crashed and
|
|
mark it as such.
|
|
*/
|
|
if (read_meta_file(share->meta_file, &share->rows_recorded))
|
|
share->crashed= TRUE;
|
|
}
|
|
share->use_count++;
|
|
pthread_mutex_unlock(&tina_mutex);
|
|
|
|
return share;
|
|
|
|
error:
|
|
pthread_mutex_unlock(&tina_mutex);
|
|
my_free((uchar*) share, MYF(0));
|
|
|
|
return NULL;
|
|
}
|
|
|
|
|
|
/*
|
|
Read CSV meta-file
|
|
|
|
SYNOPSIS
|
|
read_meta_file()
|
|
meta_file The meta-file filedes
|
|
ha_rows Pointer to the var we use to store rows count.
|
|
These are read from the meta-file.
|
|
|
|
DESCRIPTION
|
|
|
|
Read the meta-file info. For now we are only interested in
|
|
rows counf, crashed bit and magic number.
|
|
|
|
RETURN
|
|
0 - OK
|
|
non-zero - error occurred
|
|
*/
|
|
|
|
static int read_meta_file(File meta_file, ha_rows *rows)
|
|
{
|
|
uchar meta_buffer[META_BUFFER_SIZE];
|
|
uchar *ptr= meta_buffer;
|
|
|
|
DBUG_ENTER("ha_tina::read_meta_file");
|
|
|
|
VOID(my_seek(meta_file, 0, MY_SEEK_SET, MYF(0)));
|
|
if (my_read(meta_file, (uchar*)meta_buffer, META_BUFFER_SIZE, 0)
|
|
!= META_BUFFER_SIZE)
|
|
DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE);
|
|
|
|
/*
|
|
Parse out the meta data, we ignore version at the moment
|
|
*/
|
|
|
|
ptr+= sizeof(uchar)*2; // Move past header
|
|
*rows= (ha_rows)uint8korr(ptr);
|
|
ptr+= sizeof(ulonglong); // Move past rows
|
|
/*
|
|
Move past check_point, auto_increment and forced_flushes fields.
|
|
They are present in the format, but we do not use them yet.
|
|
*/
|
|
ptr+= 3*sizeof(ulonglong);
|
|
|
|
/* check crashed bit and magic number */
|
|
if ((meta_buffer[0] != (uchar)TINA_CHECK_HEADER) ||
|
|
((bool)(*ptr)== TRUE))
|
|
DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE);
|
|
|
|
my_sync(meta_file, MYF(MY_WME));
|
|
|
|
DBUG_RETURN(0);
|
|
}
|
|
|
|
|
|
/*
|
|
Write CSV meta-file
|
|
|
|
SYNOPSIS
|
|
write_meta_file()
|
|
meta_file The meta-file filedes
|
|
ha_rows The number of rows we have in the datafile.
|
|
dirty A flag, which marks whether we have a corrupt table
|
|
|
|
DESCRIPTION
|
|
|
|
Write meta-info the the file. Only rows count, crashed bit and
|
|
magic number matter now.
|
|
|
|
RETURN
|
|
0 - OK
|
|
non-zero - error occurred
|
|
*/
|
|
|
|
static int write_meta_file(File meta_file, ha_rows rows, bool dirty)
|
|
{
|
|
uchar meta_buffer[META_BUFFER_SIZE];
|
|
uchar *ptr= meta_buffer;
|
|
|
|
DBUG_ENTER("ha_tina::write_meta_file");
|
|
|
|
*ptr= (uchar)TINA_CHECK_HEADER;
|
|
ptr+= sizeof(uchar);
|
|
*ptr= (uchar)TINA_VERSION;
|
|
ptr+= sizeof(uchar);
|
|
int8store(ptr, (ulonglong)rows);
|
|
ptr+= sizeof(ulonglong);
|
|
memset(ptr, 0, 3*sizeof(ulonglong));
|
|
/*
|
|
Skip over checkpoint, autoincrement and forced_flushes fields.
|
|
We'll need them later.
|
|
*/
|
|
ptr+= 3*sizeof(ulonglong);
|
|
*ptr= (uchar)dirty;
|
|
|
|
VOID(my_seek(meta_file, 0, MY_SEEK_SET, MYF(0)));
|
|
if (my_write(meta_file, (uchar *)meta_buffer, META_BUFFER_SIZE, 0)
|
|
!= META_BUFFER_SIZE)
|
|
DBUG_RETURN(-1);
|
|
|
|
my_sync(meta_file, MYF(MY_WME));
|
|
|
|
DBUG_RETURN(0);
|
|
}
|
|
|
|
bool ha_tina::check_and_repair(THD *thd)
|
|
{
|
|
HA_CHECK_OPT check_opt;
|
|
DBUG_ENTER("ha_tina::check_and_repair");
|
|
|
|
check_opt.init();
|
|
|
|
DBUG_RETURN(repair(thd, &check_opt));
|
|
}
|
|
|
|
|
|
int ha_tina::init_tina_writer()
|
|
{
|
|
DBUG_ENTER("ha_tina::init_tina_writer");
|
|
|
|
/*
|
|
Mark the file as crashed. We will set the flag back when we close
|
|
the file. In the case of the crash it will remain marked crashed,
|
|
which enforce recovery.
|
|
*/
|
|
(void)write_meta_file(share->meta_file, share->rows_recorded, TRUE);
|
|
|
|
if ((share->tina_write_filedes=
|
|
my_open(share->data_file_name, O_RDWR|O_APPEND, MYF(0))) == -1)
|
|
{
|
|
DBUG_PRINT("info", ("Could not open tina file writes"));
|
|
share->crashed= TRUE;
|
|
DBUG_RETURN(1);
|
|
}
|
|
share->tina_write_opened= TRUE;
|
|
|
|
DBUG_RETURN(0);
|
|
}
|
|
|
|
|
|
bool ha_tina::is_crashed() const
|
|
{
|
|
DBUG_ENTER("ha_tina::is_crashed");
|
|
DBUG_RETURN(share->crashed);
|
|
}
|
|
|
|
/*
|
|
Free lock controls.
|
|
*/
|
|
static int free_share(TINA_SHARE *share)
|
|
{
|
|
DBUG_ENTER("ha_tina::free_share");
|
|
pthread_mutex_lock(&tina_mutex);
|
|
int result_code= 0;
|
|
if (!--share->use_count){
|
|
/* Write the meta file. Mark it as crashed if needed. */
|
|
(void)write_meta_file(share->meta_file, share->rows_recorded,
|
|
share->crashed ? TRUE :FALSE);
|
|
if (my_close(share->meta_file, MYF(0)))
|
|
result_code= 1;
|
|
if (share->tina_write_opened)
|
|
{
|
|
if (my_close(share->tina_write_filedes, MYF(0)))
|
|
result_code= 1;
|
|
share->tina_write_opened= FALSE;
|
|
}
|
|
|
|
hash_delete(&tina_open_tables, (uchar*) share);
|
|
thr_lock_delete(&share->lock);
|
|
pthread_mutex_destroy(&share->mutex);
|
|
my_free((uchar*) share, MYF(0));
|
|
}
|
|
pthread_mutex_unlock(&tina_mutex);
|
|
|
|
DBUG_RETURN(result_code);
|
|
}
|
|
|
|
|
|
/*
|
|
This function finds the end of a line and returns the length
|
|
of the line ending.
|
|
|
|
We support three kinds of line endings:
|
|
'\r' -- Old Mac OS line ending
|
|
'\n' -- Traditional Unix and Mac OS X line ending
|
|
'\r''\n' -- DOS\Windows line ending
|
|
*/
|
|
|
|
off_t find_eoln_buff(Transparent_file *data_buff, off_t begin,
|
|
off_t end, int *eoln_len)
|
|
{
|
|
*eoln_len= 0;
|
|
|
|
for (off_t x= begin; x < end; x++)
|
|
{
|
|
/* Unix (includes Mac OS X) */
|
|
if (data_buff->get_value(x) == '\n')
|
|
*eoln_len= 1;
|
|
else
|
|
if (data_buff->get_value(x) == '\r') // Mac or Dos
|
|
{
|
|
/* old Mac line ending */
|
|
if (x + 1 == end || (data_buff->get_value(x + 1) != '\n'))
|
|
*eoln_len= 1;
|
|
else // DOS style ending
|
|
*eoln_len= 2;
|
|
}
|
|
|
|
if (*eoln_len) // end of line was found
|
|
return x;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
static handler *tina_create_handler(handlerton *hton,
|
|
TABLE_SHARE *table,
|
|
MEM_ROOT *mem_root)
|
|
{
|
|
return new (mem_root) ha_tina(hton, table);
|
|
}
|
|
|
|
|
|
ha_tina::ha_tina(handlerton *hton, TABLE_SHARE *table_arg)
|
|
:handler(hton, table_arg),
|
|
/*
|
|
These definitions are found in handler.h
|
|
They are not probably completely right.
|
|
*/
|
|
current_position(0), next_position(0), local_saved_data_file_length(0),
|
|
file_buff(0), chain_alloced(0), chain_size(DEFAULT_CHAIN_LENGTH),
|
|
records_is_known(0)
|
|
{
|
|
/* Set our original buffers from pre-allocated memory */
|
|
buffer.set((char*)byte_buffer, IO_SIZE, system_charset_info);
|
|
chain= chain_buffer;
|
|
file_buff= new Transparent_file();
|
|
}
|
|
|
|
|
|
/*
|
|
Encode a buffer into the quoted format.
|
|
*/
|
|
|
|
int ha_tina::encode_quote(uchar *buf)
|
|
{
|
|
char attribute_buffer[1024];
|
|
String attribute(attribute_buffer, sizeof(attribute_buffer),
|
|
&my_charset_bin);
|
|
|
|
my_bitmap_map *org_bitmap= dbug_tmp_use_all_columns(table, table->read_set);
|
|
buffer.length(0);
|
|
|
|
for (Field **field=table->field ; *field ; field++)
|
|
{
|
|
const char *ptr;
|
|
const char *end_ptr;
|
|
|
|
/*
|
|
CSV does not support nulls. Write quoted 0 to the buffer. In fact,
|
|
(*field)->val_str(&attribute,&attribute) would usually return 0
|
|
in this case but we write it explicitly here.
|
|
Basically this is a safety check, as no one ensures that the
|
|
field content is cleaned up every time we use Field::set_null()
|
|
in the code.
|
|
*/
|
|
if ((*field)->is_null())
|
|
{
|
|
buffer.append(STRING_WITH_LEN("\"0\","));
|
|
continue;
|
|
}
|
|
|
|
(*field)->val_str(&attribute,&attribute);
|
|
|
|
if ((*field)->str_needs_quotes())
|
|
{
|
|
ptr= attribute.ptr();
|
|
end_ptr= attribute.length() + ptr;
|
|
|
|
buffer.append('"');
|
|
|
|
while (ptr < end_ptr)
|
|
{
|
|
if (*ptr == '"')
|
|
{
|
|
buffer.append('\\');
|
|
buffer.append('"');
|
|
*ptr++;
|
|
}
|
|
else if (*ptr == '\r')
|
|
{
|
|
buffer.append('\\');
|
|
buffer.append('r');
|
|
*ptr++;
|
|
}
|
|
else if (*ptr == '\\')
|
|
{
|
|
buffer.append('\\');
|
|
buffer.append('\\');
|
|
*ptr++;
|
|
}
|
|
else if (*ptr == '\n')
|
|
{
|
|
buffer.append('\\');
|
|
buffer.append('n');
|
|
*ptr++;
|
|
}
|
|
else
|
|
buffer.append(*ptr++);
|
|
}
|
|
buffer.append('"');
|
|
}
|
|
else
|
|
{
|
|
buffer.append(attribute);
|
|
}
|
|
|
|
buffer.append(',');
|
|
}
|
|
// Remove the comma, add a line feed
|
|
buffer.length(buffer.length() - 1);
|
|
buffer.append('\n');
|
|
|
|
//buffer.replace(buffer.length(), 0, "\n", 1);
|
|
|
|
dbug_tmp_restore_column_map(table->read_set, org_bitmap);
|
|
return (buffer.length());
|
|
}
|
|
|
|
/*
|
|
chain_append() adds delete positions to the chain that we use to keep
|
|
track of space. Then the chain will be used to cleanup "holes", occurred
|
|
due to deletes and updates.
|
|
*/
|
|
int ha_tina::chain_append()
|
|
{
|
|
if ( chain_ptr != chain && (chain_ptr -1)->end == current_position)
|
|
(chain_ptr -1)->end= next_position;
|
|
else
|
|
{
|
|
/* We set up for the next position */
|
|
if ((off_t)(chain_ptr - chain) == (chain_size -1))
|
|
{
|
|
off_t location= chain_ptr - chain;
|
|
chain_size += DEFAULT_CHAIN_LENGTH;
|
|
if (chain_alloced)
|
|
{
|
|
/* Must cast since my_malloc unlike malloc doesn't have a void ptr */
|
|
if ((chain= (tina_set *) my_realloc((uchar*)chain,
|
|
chain_size, MYF(MY_WME))) == NULL)
|
|
return -1;
|
|
}
|
|
else
|
|
{
|
|
tina_set *ptr= (tina_set *) my_malloc(chain_size * sizeof(tina_set),
|
|
MYF(MY_WME));
|
|
memcpy(ptr, chain, DEFAULT_CHAIN_LENGTH * sizeof(tina_set));
|
|
chain= ptr;
|
|
chain_alloced++;
|
|
}
|
|
chain_ptr= chain + location;
|
|
}
|
|
chain_ptr->begin= current_position;
|
|
chain_ptr->end= next_position;
|
|
chain_ptr++;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
/*
|
|
Scans for a row.
|
|
*/
|
|
int ha_tina::find_current_row(uchar *buf)
|
|
{
|
|
off_t end_offset, curr_offset= current_position;
|
|
int eoln_len;
|
|
my_bitmap_map *org_bitmap;
|
|
int error;
|
|
DBUG_ENTER("ha_tina::find_current_row");
|
|
|
|
/*
|
|
We do not read further then local_saved_data_file_length in order
|
|
not to conflict with undergoing concurrent insert.
|
|
*/
|
|
if ((end_offset=
|
|
find_eoln_buff(file_buff, current_position,
|
|
local_saved_data_file_length, &eoln_len)) == 0)
|
|
DBUG_RETURN(HA_ERR_END_OF_FILE);
|
|
|
|
/* Avoid asserts in ::store() for columns that are not going to be updated */
|
|
org_bitmap= dbug_tmp_use_all_columns(table, table->write_set);
|
|
error= HA_ERR_CRASHED_ON_USAGE;
|
|
|
|
memset(buf, 0, table->s->null_bytes);
|
|
|
|
for (Field **field=table->field ; *field ; field++)
|
|
{
|
|
buffer.length(0);
|
|
if (curr_offset < end_offset &&
|
|
file_buff->get_value(curr_offset) == '"')
|
|
{
|
|
curr_offset++; // Incrementpast the first quote
|
|
|
|
for(;curr_offset < end_offset; curr_offset++)
|
|
{
|
|
// Need to convert line feeds!
|
|
if (file_buff->get_value(curr_offset) == '"' &&
|
|
((file_buff->get_value(curr_offset + 1) == ',') ||
|
|
(curr_offset == end_offset -1 )))
|
|
{
|
|
curr_offset+= 2; // Move past the , and the "
|
|
break;
|
|
}
|
|
if (file_buff->get_value(curr_offset) == '\\' &&
|
|
curr_offset != (end_offset - 1))
|
|
{
|
|
curr_offset++;
|
|
if (file_buff->get_value(curr_offset) == 'r')
|
|
buffer.append('\r');
|
|
else if (file_buff->get_value(curr_offset) == 'n' )
|
|
buffer.append('\n');
|
|
else if ((file_buff->get_value(curr_offset) == '\\') ||
|
|
(file_buff->get_value(curr_offset) == '"'))
|
|
buffer.append(file_buff->get_value(curr_offset));
|
|
else /* This could only happed with an externally created file */
|
|
{
|
|
buffer.append('\\');
|
|
buffer.append(file_buff->get_value(curr_offset));
|
|
}
|
|
}
|
|
else // ordinary symbol
|
|
{
|
|
/*
|
|
We are at final symbol and no last quote was found =>
|
|
we are working with a damaged file.
|
|
*/
|
|
if (curr_offset == end_offset - 1)
|
|
goto err;
|
|
buffer.append(file_buff->get_value(curr_offset));
|
|
}
|
|
}
|
|
}
|
|
else if (my_isdigit(system_charset_info,
|
|
file_buff->get_value(curr_offset)))
|
|
{
|
|
for(;curr_offset < end_offset; curr_offset++)
|
|
{
|
|
if (file_buff->get_value(curr_offset) == ',')
|
|
{
|
|
curr_offset+= 1; // Move past the ,
|
|
break;
|
|
}
|
|
|
|
if (my_isdigit(system_charset_info, file_buff->get_value(curr_offset)))
|
|
buffer.append(file_buff->get_value(curr_offset));
|
|
else if (file_buff->get_value(curr_offset) == '.')
|
|
buffer.append(file_buff->get_value(curr_offset));
|
|
else
|
|
goto err;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
goto err;
|
|
}
|
|
|
|
if (bitmap_is_set(table->read_set, (*field)->field_index))
|
|
(*field)->store(buffer.ptr(), buffer.length(), system_charset_info);
|
|
}
|
|
next_position= end_offset + eoln_len;
|
|
error= 0;
|
|
|
|
err:
|
|
dbug_tmp_restore_column_map(table->write_set, org_bitmap);
|
|
|
|
DBUG_RETURN(error);
|
|
}
|
|
|
|
/*
|
|
If frm_error() is called in table.cc this is called to find out what file
|
|
extensions exist for this handler.
|
|
*/
|
|
static const char *ha_tina_exts[] = {
|
|
CSV_EXT,
|
|
CSM_EXT,
|
|
NullS
|
|
};
|
|
|
|
const char **ha_tina::bas_ext() const
|
|
{
|
|
return ha_tina_exts;
|
|
}
|
|
|
|
/*
|
|
Three functions below are needed to enable concurrent insert functionality
|
|
for CSV engine. For more details see mysys/thr_lock.c
|
|
*/
|
|
|
|
void tina_get_status(void* param, int concurrent_insert)
|
|
{
|
|
ha_tina *tina= (ha_tina*) param;
|
|
tina->get_status();
|
|
}
|
|
|
|
void tina_update_status(void* param)
|
|
{
|
|
ha_tina *tina= (ha_tina*) param;
|
|
tina->update_status();
|
|
}
|
|
|
|
/* this should exist and return 0 for concurrent insert to work */
|
|
my_bool tina_check_status(void* param)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
Save the state of the table
|
|
|
|
SYNOPSIS
|
|
get_status()
|
|
|
|
DESCRIPTION
|
|
This function is used to retrieve the file length. During the lock
|
|
phase of concurrent insert. For more details see comment to
|
|
ha_tina::update_status below.
|
|
*/
|
|
|
|
void ha_tina::get_status()
|
|
{
|
|
if (share->is_log_table)
|
|
{
|
|
/*
|
|
We have to use mutex to follow pthreads memory visibility
|
|
rules for share->saved_data_file_length
|
|
*/
|
|
pthread_mutex_lock(&share->mutex);
|
|
local_saved_data_file_length= share->saved_data_file_length;
|
|
pthread_mutex_unlock(&share->mutex);
|
|
return;
|
|
}
|
|
local_saved_data_file_length= share->saved_data_file_length;
|
|
}
|
|
|
|
|
|
/*
|
|
Correct the state of the table. Called by unlock routines
|
|
before the write lock is released.
|
|
|
|
SYNOPSIS
|
|
update_status()
|
|
|
|
DESCRIPTION
|
|
When we employ concurrent insert lock, we save current length of the file
|
|
during the lock phase. We do not read further saved value, as we don't
|
|
want to interfere with undergoing concurrent insert. Writers update file
|
|
length info during unlock with update_status().
|
|
|
|
NOTE
|
|
For log tables concurrent insert works different. The reason is that
|
|
log tables are always opened and locked. And as they do not unlock
|
|
tables, the file length after writes should be updated in a different
|
|
way. For this purpose we need is_log_table flag. When this flag is set
|
|
we call update_status() explicitly after each row write.
|
|
*/
|
|
|
|
void ha_tina::update_status()
|
|
{
|
|
/* correct local_saved_data_file_length for writers */
|
|
share->saved_data_file_length= local_saved_data_file_length;
|
|
}
|
|
|
|
|
|
bool ha_tina::check_if_locking_is_allowed(uint sql_command,
|
|
ulong type, TABLE *table,
|
|
uint count, uint current,
|
|
uint *system_count,
|
|
bool called_by_privileged_thread)
|
|
{
|
|
if (!called_by_privileged_thread)
|
|
return check_if_log_table_locking_is_allowed(sql_command, type, table);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
/*
|
|
Open a database file. Keep in mind that tables are caches, so
|
|
this will not be called for every request. Any sort of positions
|
|
that need to be reset should be kept in the ::extra() call.
|
|
*/
|
|
int ha_tina::open(const char *name, int mode, uint open_options)
|
|
{
|
|
DBUG_ENTER("ha_tina::open");
|
|
|
|
if (!(share= get_share(name, table)))
|
|
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
|
|
|
|
if (share->crashed && !(open_options & HA_OPEN_FOR_REPAIR))
|
|
{
|
|
free_share(share);
|
|
DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE);
|
|
}
|
|
|
|
if ((data_file= my_open(share->data_file_name, O_RDONLY, MYF(0))) == -1)
|
|
DBUG_RETURN(0);
|
|
|
|
/*
|
|
Init locking. Pass handler object to the locking routines,
|
|
so that they could save/update local_saved_data_file_length value
|
|
during locking. This is needed to enable concurrent inserts.
|
|
*/
|
|
thr_lock_data_init(&share->lock, &lock, (void*) this);
|
|
ref_length=sizeof(off_t);
|
|
|
|
share->lock.get_status= tina_get_status;
|
|
share->lock.update_status= tina_update_status;
|
|
share->lock.check_status= tina_check_status;
|
|
|
|
DBUG_RETURN(0);
|
|
}
|
|
|
|
|
|
/*
|
|
Close a database file. We remove ourselves from the shared strucutre.
|
|
If it is empty we destroy it.
|
|
*/
|
|
int ha_tina::close(void)
|
|
{
|
|
int rc= 0;
|
|
DBUG_ENTER("ha_tina::close");
|
|
rc= my_close(data_file, MYF(0));
|
|
DBUG_RETURN(free_share(share) || rc);
|
|
}
|
|
|
|
/*
|
|
This is an INSERT. At the moment this handler just seeks to the end
|
|
of the file and appends the data. In an error case it really should
|
|
just truncate to the original position (this is not done yet).
|
|
*/
|
|
int ha_tina::write_row(uchar * buf)
|
|
{
|
|
int size;
|
|
DBUG_ENTER("ha_tina::write_row");
|
|
|
|
if (share->crashed)
|
|
DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE);
|
|
|
|
ha_statistic_increment(&SSV::ha_write_count);
|
|
|
|
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
|
|
table->timestamp_field->set_time();
|
|
|
|
size= encode_quote(buf);
|
|
|
|
if (!share->tina_write_opened)
|
|
if (init_tina_writer())
|
|
DBUG_RETURN(-1);
|
|
|
|
/* use pwrite, as concurrent reader could have changed the position */
|
|
if (my_write(share->tina_write_filedes, (uchar*)buffer.ptr(), size,
|
|
MYF(MY_WME | MY_NABP)))
|
|
DBUG_RETURN(-1);
|
|
|
|
/* update local copy of the max position to see our own changes */
|
|
local_saved_data_file_length+= size;
|
|
|
|
/* update shared info */
|
|
pthread_mutex_lock(&share->mutex);
|
|
share->rows_recorded++;
|
|
/* update status for the log tables */
|
|
if (share->is_log_table)
|
|
update_status();
|
|
pthread_mutex_unlock(&share->mutex);
|
|
|
|
stats.records++;
|
|
DBUG_RETURN(0);
|
|
}
|
|
|
|
|
|
int ha_tina::open_update_temp_file_if_needed()
|
|
{
|
|
char updated_fname[FN_REFLEN];
|
|
|
|
if (!share->update_file_opened)
|
|
{
|
|
if ((update_temp_file=
|
|
my_create(fn_format(updated_fname, share->table_name,
|
|
"", CSN_EXT,
|
|
MY_REPLACE_EXT | MY_UNPACK_FILENAME),
|
|
0, O_RDWR | O_TRUNC, MYF(MY_WME))) < 0)
|
|
return 1;
|
|
share->update_file_opened= TRUE;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
This is called for an update.
|
|
Make sure you put in code to increment the auto increment, also
|
|
update any timestamp data. Currently auto increment is not being
|
|
fixed since autoincrements have yet to be added to this table handler.
|
|
This will be called in a table scan right before the previous ::rnd_next()
|
|
call.
|
|
*/
|
|
int ha_tina::update_row(const uchar * old_data, uchar * new_data)
|
|
{
|
|
int size;
|
|
DBUG_ENTER("ha_tina::update_row");
|
|
|
|
ha_statistic_increment(&SSV::ha_read_rnd_next_count);
|
|
|
|
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE)
|
|
table->timestamp_field->set_time();
|
|
|
|
size= encode_quote(new_data);
|
|
|
|
if (chain_append())
|
|
DBUG_RETURN(-1);
|
|
|
|
if (open_update_temp_file_if_needed())
|
|
DBUG_RETURN(-1);
|
|
|
|
if (my_write(update_temp_file, (uchar*)buffer.ptr(), size,
|
|
MYF(MY_WME | MY_NABP)))
|
|
DBUG_RETURN(-1);
|
|
|
|
/* UPDATE should never happen on the log tables */
|
|
DBUG_ASSERT(!share->is_log_table);
|
|
|
|
DBUG_RETURN(0);
|
|
}
|
|
|
|
|
|
/*
|
|
Deletes a row. First the database will find the row, and then call this
|
|
method. In the case of a table scan, the previous call to this will be
|
|
the ::rnd_next() that found this row.
|
|
The exception to this is an ORDER BY. This will cause the table handler
|
|
to walk the table noting the positions of all rows that match a query.
|
|
The table will then be deleted/positioned based on the ORDER (so RANDOM,
|
|
DESC, ASC).
|
|
*/
|
|
int ha_tina::delete_row(const uchar * buf)
|
|
{
|
|
DBUG_ENTER("ha_tina::delete_row");
|
|
ha_statistic_increment(&SSV::ha_delete_count);
|
|
|
|
if (chain_append())
|
|
DBUG_RETURN(-1);
|
|
|
|
stats.records--;
|
|
|
|
/* DELETE should never happen on the log table */
|
|
DBUG_ASSERT(!share->is_log_table);
|
|
|
|
DBUG_RETURN(0);
|
|
}
|
|
|
|
|
|
/*
|
|
All table scans call this first.
|
|
The order of a table scan is:
|
|
|
|
ha_tina::store_lock
|
|
ha_tina::external_lock
|
|
ha_tina::info
|
|
ha_tina::rnd_init
|
|
ha_tina::extra
|
|
ENUM HA_EXTRA_CACHE Cash record in HA_rrnd()
|
|
ha_tina::rnd_next
|
|
ha_tina::rnd_next
|
|
ha_tina::rnd_next
|
|
ha_tina::rnd_next
|
|
ha_tina::rnd_next
|
|
ha_tina::rnd_next
|
|
ha_tina::rnd_next
|
|
ha_tina::rnd_next
|
|
ha_tina::rnd_next
|
|
ha_tina::extra
|
|
ENUM HA_EXTRA_NO_CACHE End cacheing of records (def)
|
|
ha_tina::external_lock
|
|
ha_tina::extra
|
|
ENUM HA_EXTRA_RESET Reset database to after open
|
|
|
|
Each call to ::rnd_next() represents a row returned in the can. When no more
|
|
rows can be returned, rnd_next() returns a value of HA_ERR_END_OF_FILE.
|
|
The ::info() call is just for the optimizer.
|
|
|
|
*/
|
|
|
|
int ha_tina::rnd_init(bool scan)
|
|
{
|
|
DBUG_ENTER("ha_tina::rnd_init");
|
|
|
|
/* set buffer to the beginning of the file */
|
|
file_buff->init_buff(data_file);
|
|
if (share->crashed)
|
|
DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE);
|
|
|
|
current_position= next_position= 0;
|
|
stats.records= 0;
|
|
records_is_known= 0;
|
|
chain_ptr= chain;
|
|
|
|
DBUG_RETURN(0);
|
|
}
|
|
|
|
/*
|
|
::rnd_next() does all the heavy lifting for a table scan. You will need to
|
|
populate *buf with the correct field data. You can walk the field to
|
|
determine at what position you should store the data (take a look at how
|
|
::find_current_row() works). The structure is something like:
|
|
0Foo Dog Friend
|
|
The first offset is for the first attribute. All space before that is
|
|
reserved for null count.
|
|
Basically this works as a mask for which rows are nulled (compared to just
|
|
empty).
|
|
This table handler doesn't do nulls and does not know the difference between
|
|
NULL and "". This is ok since this table handler is for spreadsheets and
|
|
they don't know about them either :)
|
|
*/
|
|
int ha_tina::rnd_next(uchar *buf)
|
|
{
|
|
int rc;
|
|
DBUG_ENTER("ha_tina::rnd_next");
|
|
|
|
if (share->crashed)
|
|
DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE);
|
|
|
|
ha_statistic_increment(&SSV::ha_read_rnd_next_count);
|
|
|
|
current_position= next_position;
|
|
|
|
/* don't scan an empty file */
|
|
if (!local_saved_data_file_length)
|
|
DBUG_RETURN(HA_ERR_END_OF_FILE);
|
|
|
|
if ((rc= find_current_row(buf)))
|
|
DBUG_RETURN(rc);
|
|
|
|
stats.records++;
|
|
DBUG_RETURN(0);
|
|
}
|
|
|
|
/*
|
|
In the case of an order by rows will need to be sorted.
|
|
::position() is called after each call to ::rnd_next(),
|
|
the data it stores is to a byte array. You can store this
|
|
data via my_store_ptr(). ref_length is a variable defined to the
|
|
class that is the sizeof() of position being stored. In our case
|
|
its just a position. Look at the bdb code if you want to see a case
|
|
where something other then a number is stored.
|
|
*/
|
|
void ha_tina::position(const uchar *record)
|
|
{
|
|
DBUG_ENTER("ha_tina::position");
|
|
my_store_ptr(ref, ref_length, current_position);
|
|
DBUG_VOID_RETURN;
|
|
}
|
|
|
|
|
|
/*
|
|
Used to fetch a row from a posiion stored with ::position().
|
|
my_get_ptr() retrieves the data for you.
|
|
*/
|
|
|
|
int ha_tina::rnd_pos(uchar * buf, uchar *pos)
|
|
{
|
|
DBUG_ENTER("ha_tina::rnd_pos");
|
|
ha_statistic_increment(&SSV::ha_read_rnd_next_count);
|
|
current_position= (off_t)my_get_ptr(pos,ref_length);
|
|
DBUG_RETURN(find_current_row(buf));
|
|
}
|
|
|
|
/*
|
|
::info() is used to return information to the optimizer.
|
|
Currently this table handler doesn't implement most of the fields
|
|
really needed. SHOW also makes use of this data
|
|
*/
|
|
int ha_tina::info(uint flag)
|
|
{
|
|
DBUG_ENTER("ha_tina::info");
|
|
/* This is a lie, but you don't want the optimizer to see zero or 1 */
|
|
if (!records_is_known && stats.records < 2)
|
|
stats.records= 2;
|
|
DBUG_RETURN(0);
|
|
}
|
|
|
|
/*
|
|
Grab bag of flags that are sent to the able handler every so often.
|
|
HA_EXTRA_RESET and HA_EXTRA_RESET_STATE are the most frequently called.
|
|
You are not required to implement any of these.
|
|
*/
|
|
int ha_tina::extra(enum ha_extra_function operation)
|
|
{
|
|
DBUG_ENTER("ha_tina::extra");
|
|
if (operation == HA_EXTRA_MARK_AS_LOG_TABLE)
|
|
{
|
|
pthread_mutex_lock(&share->mutex);
|
|
share->is_log_table= TRUE;
|
|
pthread_mutex_unlock(&share->mutex);
|
|
}
|
|
DBUG_RETURN(0);
|
|
}
|
|
|
|
/*
|
|
Set end_pos to the last valid byte of continuous area, closest
|
|
to the given "hole", stored in the buffer. "Valid" here means,
|
|
not listed in the chain of deleted records ("holes").
|
|
*/
|
|
bool ha_tina::get_write_pos(off_t *end_pos, tina_set *closest_hole)
|
|
{
|
|
if (closest_hole == chain_ptr) /* no more chains */
|
|
*end_pos= file_buff->end();
|
|
else
|
|
*end_pos= min(file_buff->end(),
|
|
closest_hole->begin);
|
|
return (closest_hole != chain_ptr) && (*end_pos == closest_hole->begin);
|
|
}
|
|
|
|
|
|
/*
|
|
Called after each table scan. In particular after deletes,
|
|
and updates. In the last case we employ chain of deleted
|
|
slots to clean up all of the dead space we have collected while
|
|
performing deletes/updates.
|
|
*/
|
|
int ha_tina::rnd_end()
|
|
{
|
|
char updated_fname[FN_REFLEN];
|
|
off_t file_buffer_start= 0;
|
|
DBUG_ENTER("ha_tina::rnd_end");
|
|
|
|
records_is_known= 1;
|
|
|
|
if ((chain_ptr - chain) > 0)
|
|
{
|
|
tina_set *ptr= chain;
|
|
|
|
/*
|
|
Re-read the beginning of a file (as the buffer should point to the
|
|
end of file after the scan).
|
|
*/
|
|
file_buff->init_buff(data_file);
|
|
|
|
/*
|
|
The sort is needed when there were updates/deletes with random orders.
|
|
It sorts so that we move the firts blocks to the beginning.
|
|
*/
|
|
qsort(chain, (size_t)(chain_ptr - chain), sizeof(tina_set),
|
|
(qsort_cmp)sort_set);
|
|
|
|
off_t write_begin= 0, write_end;
|
|
|
|
/* create the file to write updated table if it wasn't yet created */
|
|
if (open_update_temp_file_if_needed())
|
|
DBUG_RETURN(-1);
|
|
|
|
/* write the file with updated info */
|
|
while ((file_buffer_start != -1)) // while not end of file
|
|
{
|
|
bool in_hole= get_write_pos(&write_end, ptr);
|
|
|
|
/* if there is something to write, write it */
|
|
if ((write_end - write_begin) &&
|
|
(my_write(update_temp_file,
|
|
(uchar*)(file_buff->ptr() +
|
|
(write_begin - file_buff->start())),
|
|
write_end - write_begin, MYF_RW)))
|
|
goto error;
|
|
|
|
if (in_hole)
|
|
{
|
|
/* skip hole */
|
|
while (file_buff->end() <= ptr->end && file_buffer_start != -1)
|
|
file_buffer_start= file_buff->read_next();
|
|
write_begin= ptr->end;
|
|
ptr++;
|
|
}
|
|
else
|
|
write_begin= write_end;
|
|
|
|
if (write_end == file_buff->end())
|
|
file_buffer_start= file_buff->read_next(); /* shift the buffer */
|
|
|
|
}
|
|
|
|
if (my_sync(update_temp_file, MYF(MY_WME)) ||
|
|
my_close(update_temp_file, MYF(0)))
|
|
DBUG_RETURN(-1);
|
|
|
|
share->update_file_opened= FALSE;
|
|
|
|
if (share->tina_write_opened)
|
|
{
|
|
if (my_close(share->tina_write_filedes, MYF(0)))
|
|
DBUG_RETURN(-1);
|
|
/*
|
|
Mark that the writer fd is closed, so that init_tina_writer()
|
|
will reopen it later.
|
|
*/
|
|
share->tina_write_opened= FALSE;
|
|
}
|
|
|
|
/*
|
|
Close opened fildes's. Then move updated file in place
|
|
of the old datafile.
|
|
*/
|
|
if (my_close(data_file, MYF(0)) ||
|
|
my_rename(fn_format(updated_fname, share->table_name, "", CSN_EXT,
|
|
MY_REPLACE_EXT | MY_UNPACK_FILENAME),
|
|
share->data_file_name, MYF(0)))
|
|
DBUG_RETURN(-1);
|
|
|
|
/* Open the file again */
|
|
if (((data_file= my_open(share->data_file_name, O_RDONLY, MYF(0))) == -1))
|
|
DBUG_RETURN(-1);
|
|
/*
|
|
The datafile is consistent at this point and the write filedes is
|
|
closed, so nothing worrying will happen to it in case of a crash.
|
|
Here we record this fact to the meta-file.
|
|
*/
|
|
(void)write_meta_file(share->meta_file, share->rows_recorded, FALSE);
|
|
}
|
|
|
|
DBUG_RETURN(0);
|
|
error:
|
|
my_close(update_temp_file, MYF(0));
|
|
share->update_file_opened= FALSE;
|
|
DBUG_RETURN(-1);
|
|
}
|
|
|
|
|
|
/*
|
|
Repair CSV table in the case, it is crashed.
|
|
|
|
SYNOPSIS
|
|
repair()
|
|
thd The thread, performing repair
|
|
check_opt The options for repair. We do not use it currently.
|
|
|
|
DESCRIPTION
|
|
If the file is empty, change # of rows in the file and complete recovery.
|
|
Otherwise, scan the table looking for bad rows. If none were found,
|
|
we mark file as a good one and return. If a bad row was encountered,
|
|
we truncate the datafile up to the last good row.
|
|
|
|
TODO: Make repair more clever - it should try to recover subsequent
|
|
rows (after the first bad one) as well.
|
|
*/
|
|
|
|
int ha_tina::repair(THD* thd, HA_CHECK_OPT* check_opt)
|
|
{
|
|
char repaired_fname[FN_REFLEN];
|
|
uchar *buf;
|
|
File repair_file;
|
|
int rc;
|
|
ha_rows rows_repaired= 0;
|
|
off_t write_begin= 0, write_end;
|
|
DBUG_ENTER("ha_tina::repair");
|
|
|
|
/* empty file */
|
|
if (!share->saved_data_file_length)
|
|
{
|
|
share->rows_recorded= 0;
|
|
goto end;
|
|
}
|
|
|
|
/* Don't assert in field::val() functions */
|
|
table->use_all_columns();
|
|
if (!(buf= (uchar*) my_malloc(table->s->reclength, MYF(MY_WME))))
|
|
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
|
|
|
|
/* position buffer to the start of the file */
|
|
file_buff->init_buff(data_file);
|
|
|
|
/*
|
|
Local_saved_data_file_length is initialized during the lock phase.
|
|
Sometimes this is not getting executed before ::repair (e.g. for
|
|
the log tables). We set it manually here.
|
|
*/
|
|
local_saved_data_file_length= share->saved_data_file_length;
|
|
/* set current position to the beginning of the file */
|
|
current_position= next_position= 0;
|
|
|
|
/* Read the file row-by-row. If everything is ok, repair is not needed. */
|
|
while (!(rc= find_current_row(buf)))
|
|
{
|
|
rows_repaired++;
|
|
current_position= next_position;
|
|
}
|
|
|
|
my_free((char*)buf, MYF(0));
|
|
|
|
if (rc == HA_ERR_END_OF_FILE)
|
|
{
|
|
/*
|
|
All rows were read ok until end of file, the file does not need repair.
|
|
If rows_recorded != rows_repaired, we should update rows_recorded value
|
|
to the current amount of rows.
|
|
*/
|
|
share->rows_recorded= rows_repaired;
|
|
goto end;
|
|
}
|
|
|
|
/*
|
|
Otherwise we've encountered a bad row => repair is needed.
|
|
Let us create a temporary file.
|
|
*/
|
|
if ((repair_file= my_create(fn_format(repaired_fname, share->table_name,
|
|
"", CSN_EXT,
|
|
MY_REPLACE_EXT|MY_UNPACK_FILENAME),
|
|
0, O_RDWR | O_TRUNC,MYF(MY_WME))) < 0)
|
|
DBUG_RETURN(HA_ERR_CRASHED_ON_REPAIR);
|
|
|
|
file_buff->init_buff(data_file);
|
|
|
|
|
|
/* we just truncated the file up to the first bad row. update rows count. */
|
|
share->rows_recorded= rows_repaired;
|
|
|
|
/* write repaired file */
|
|
while (1)
|
|
{
|
|
write_end= min(file_buff->end(), current_position);
|
|
if ((write_end - write_begin) &&
|
|
(my_write(repair_file, (uchar*)file_buff->ptr(),
|
|
write_end - write_begin, MYF_RW)))
|
|
DBUG_RETURN(-1);
|
|
|
|
write_begin= write_end;
|
|
if (write_end== current_position)
|
|
break;
|
|
else
|
|
file_buff->read_next(); /* shift the buffer */
|
|
}
|
|
|
|
/*
|
|
Close the files and rename repaired file to the datafile.
|
|
We have to close the files, as on Windows one cannot rename
|
|
a file, which descriptor is still open. EACCES will be returned
|
|
when trying to delete the "to"-file in my_rename().
|
|
*/
|
|
if (my_close(data_file,MYF(0)) || my_close(repair_file, MYF(0)) ||
|
|
my_rename(repaired_fname, share->data_file_name, MYF(0)))
|
|
DBUG_RETURN(-1);
|
|
|
|
/* Open the file again, it should now be repaired */
|
|
if ((data_file= my_open(share->data_file_name, O_RDWR|O_APPEND,
|
|
MYF(0))) == -1)
|
|
DBUG_RETURN(-1);
|
|
|
|
/* Set new file size. The file size will be updated by ::update_status() */
|
|
local_saved_data_file_length= (size_t) current_position;
|
|
|
|
end:
|
|
share->crashed= FALSE;
|
|
DBUG_RETURN(HA_ADMIN_OK);
|
|
}
|
|
|
|
/*
|
|
DELETE without WHERE calls this
|
|
*/
|
|
|
|
int ha_tina::delete_all_rows()
|
|
{
|
|
int rc;
|
|
DBUG_ENTER("ha_tina::delete_all_rows");
|
|
|
|
if (!records_is_known)
|
|
DBUG_RETURN(my_errno=HA_ERR_WRONG_COMMAND);
|
|
|
|
if (!share->tina_write_opened)
|
|
if (init_tina_writer())
|
|
DBUG_RETURN(-1);
|
|
|
|
/* Truncate the file to zero size */
|
|
rc= my_chsize(share->tina_write_filedes, 0, 0, MYF(MY_WME));
|
|
|
|
stats.records=0;
|
|
DBUG_RETURN(rc);
|
|
}
|
|
|
|
/*
|
|
Called by the database to lock the table. Keep in mind that this
|
|
is an internal lock.
|
|
*/
|
|
THR_LOCK_DATA **ha_tina::store_lock(THD *thd,
|
|
THR_LOCK_DATA **to,
|
|
enum thr_lock_type lock_type)
|
|
{
|
|
if (lock_type != TL_IGNORE && lock.type == TL_UNLOCK)
|
|
lock.type=lock_type;
|
|
*to++= &lock;
|
|
return to;
|
|
}
|
|
|
|
/*
|
|
Create a table. You do not want to leave the table open after a call to
|
|
this (the database will call ::open() if it needs to).
|
|
*/
|
|
|
|
int ha_tina::create(const char *name, TABLE *table_arg,
|
|
HA_CREATE_INFO *create_info)
|
|
{
|
|
char name_buff[FN_REFLEN];
|
|
File create_file;
|
|
DBUG_ENTER("ha_tina::create");
|
|
|
|
if ((create_file= my_create(fn_format(name_buff, name, "", CSM_EXT,
|
|
MY_REPLACE_EXT|MY_UNPACK_FILENAME), 0,
|
|
O_RDWR | O_TRUNC,MYF(MY_WME))) < 0)
|
|
DBUG_RETURN(-1);
|
|
|
|
write_meta_file(create_file, 0, FALSE);
|
|
my_close(create_file, MYF(0));
|
|
|
|
if ((create_file= my_create(fn_format(name_buff, name, "", CSV_EXT,
|
|
MY_REPLACE_EXT|MY_UNPACK_FILENAME),0,
|
|
O_RDWR | O_TRUNC,MYF(MY_WME))) < 0)
|
|
DBUG_RETURN(-1);
|
|
|
|
my_close(create_file, MYF(0));
|
|
|
|
DBUG_RETURN(0);
|
|
}
|
|
|
|
int ha_tina::check(THD* thd, HA_CHECK_OPT* check_opt)
|
|
{
|
|
int rc= 0;
|
|
uchar *buf;
|
|
const char *old_proc_info;
|
|
ha_rows count= share->rows_recorded;
|
|
DBUG_ENTER("ha_tina::check");
|
|
|
|
old_proc_info= thd_proc_info(thd, "Checking table");
|
|
if (!(buf= (uchar*) my_malloc(table->s->reclength, MYF(MY_WME))))
|
|
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
|
|
|
|
/* position buffer to the start of the file */
|
|
file_buff->init_buff(data_file);
|
|
|
|
/*
|
|
Local_saved_data_file_length is initialized during the lock phase.
|
|
Check does not use store_lock in certain cases. So, we set it
|
|
manually here.
|
|
*/
|
|
local_saved_data_file_length= share->saved_data_file_length;
|
|
/* set current position to the beginning of the file */
|
|
current_position= next_position= 0;
|
|
/* Read the file row-by-row. If everything is ok, repair is not needed. */
|
|
while (!(rc= find_current_row(buf)))
|
|
{
|
|
count--;
|
|
current_position= next_position;
|
|
}
|
|
|
|
my_free((char*)buf, MYF(0));
|
|
thd_proc_info(thd, old_proc_info);
|
|
|
|
if ((rc != HA_ERR_END_OF_FILE) || count)
|
|
{
|
|
share->crashed= TRUE;
|
|
DBUG_RETURN(HA_ADMIN_CORRUPT);
|
|
}
|
|
else
|
|
DBUG_RETURN(HA_ADMIN_OK);
|
|
}
|
|
|
|
|
|
bool ha_tina::check_if_incompatible_data(HA_CREATE_INFO *info,
|
|
uint table_changes)
|
|
{
|
|
return COMPATIBLE_DATA_YES;
|
|
}
|
|
|
|
struct st_mysql_storage_engine csv_storage_engine=
|
|
{ MYSQL_HANDLERTON_INTERFACE_VERSION };
|
|
|
|
mysql_declare_plugin(csv)
|
|
{
|
|
MYSQL_STORAGE_ENGINE_PLUGIN,
|
|
&csv_storage_engine,
|
|
"CSV",
|
|
"Brian Aker, MySQL AB",
|
|
"CSV storage engine",
|
|
PLUGIN_LICENSE_GPL,
|
|
tina_init_func, /* Plugin Init */
|
|
tina_done_func, /* Plugin Deinit */
|
|
0x0100 /* 1.0 */,
|
|
NULL, /* status variables */
|
|
NULL, /* system variables */
|
|
NULL /* config options */
|
|
}
|
|
mysql_declare_plugin_end;
|
|
|