Commit graph

678 commits

Author SHA1 Message Date
Yuchen Pei
d524cb5b3d
MDEV-34002 Initialise fields in spider_db_handler
Otherwise it may result in nonsensical values like 190 for a boolean.
2024-06-11 09:18:42 +10:00
Yuchen Pei
042a0d85ad
MDEV-27186 spider/partition: Report error on info() failure
Like MDEV-28105, spider may attempt to connect to remote server in
info(), and it may emit an error upon failure to connect. In this
case, the downstream caller ha_partition::open() should return the
error to avoid inconsistency.

This fixes MDEV-27186, MDEV-27237, MDEV-27334, MDEV-28241, MDEV-34101.
2024-06-05 10:13:30 +10:00
Yuchen Pei
581712b989
MDEV-33490 MENT-1504 Fix some english strings in spider. 2024-06-04 12:25:08 +10:00
Yuchen Pei
25476ba1ae
MDEV-29027 ASAN errors in spider_db_free_result after partition DDL
Spider calls ha_spider::close() at least twice on ALTER TABLE ... ADD
PARTITION. The first call frees wide_handler and the second call
accesses wide_handler->trx->thd (heap-use-after-free).

In general, there seems to be no problem with using THD obtained by
the macro current_thd() except in background threads. Thus, we simply
replace wide_handler->trx->thd with current_thd().

Original author: Nayuta Yanagasawa
2024-05-31 09:06:55 +10:00
Nayuta Yanagisawa
6d0c9872d9
MDEV-28522 Delete constant SPIDER_SQL_TYPE_*_HS
The HandlerSocket support of Spider has been deleted by MDEV-26858.
Thus, the constants, SPIDER_SQL_TYPE_*_HS, are no longer necessary.
2024-05-31 09:06:55 +10:00
Yuchen Pei
6c30220780
MDEV-26858 Spider: Remove dead code related to HandlerSocket
Remove the dead-code, in Spider, which is related to the Spider's
HandlerSocket support. The code has been disabled for a long time
and it is unlikely that the code will be enabled.

- rm all files under storage/spider/hs_client/ except hs_compat.h
- rm storage/spider/spd_db_handlersocket.*
- unifdef -UHS_HAS_SQLCOM -UHAVE_HANDLERSOCKET \
  -m storage/spider/spd_* storage/spider/ha_spider.* storage/spider/hs_client/*
- remove relevant files from storage/spider/CMakeLists.txt
2024-05-31 09:06:55 +10:00
Yuchen Pei
698dae54ef
MDEV-31475 Spider: only reset wide_handler when owning it
A wide_handler is shared among ha_spider of partitions of the same
spider table, where the last partition is designated the owner of the
wide_handler, and is responsible for its deallocation. Therefore in
case of failure, we only reset wide_handler in error handling if the
current ha_spider is the owner of the wide_handler, otherwise it will
result in segv in the destructor of ha_spider, or during
ha_spider::close().
2024-05-21 09:17:12 +10:00
Yuchen Pei
86adee3806
MDEV-31475 remove unnecessary assignment to spider share init_error
The init, init_error, and init_error_time fields of a SPIDER_SHARE
should only be assigned when actually doing the initialisation of a
SPIDER_SHARE, otherwise they could result in spurious failures from
spider_get_share() in a subsequent statement.
2024-05-21 09:17:12 +10:00
Yuchen Pei
fd76746234
MDEV-28105 Return error in ha_spider::write_row() if info(HA_STATUS_AUTO) fails
Spider calls info with HA_STATUS_AUTO to update auto increment info,
which may attempt to connect the data node. If the connection fails,
it may emit an error and return the same error. This error should not
be of lower priority than any possible error from the later call to
handler::update_auto_increment().

Without this change, certain errors from update_auto_increment() such
as HA_ERR_AUTOINC_ERANGE may get ignored, causing my_insert() to call
my_ok(), which fails the assertion because the error was emitted in
the info() call (Diagnostics_area::is_set() returns true).
2024-05-14 15:50:29 +10:00
Yuchen Pei
10a7599286 MDEV-34036 Reset spider_hton_ptr in spider_db_done()
Otherwise spider_direct_sql may still think the spider plugin is
available even after spider_db_done() was called.
2024-05-07 10:56:02 +02:00
Yuchen Pei
bca366e4a1
MDEV-34098 source start_slave.inc in spider suites
The spider suite should --source include/start_slave.inc to make sure
the slave is up before proceeding.
2024-05-07 10:16:38 +10:00
Sergei Golubchik
22b3ba9312 MDEV-25102 UNIQUE USING HASH error after ALTER ... DISABLE KEYS
on disable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE) the engine does
not know that the long unique is logically unique, because on the
engine level it is not. And the engine disables it,

Change the disable_indexes/enable_indexes API. Instead of the enum
mode, send a key_map of indexes that should be enabled. This way the
server will decide what is unique, not the engine.
2024-05-06 17:16:10 +02:00
Julius Goryavsky
b88c20ce1b Merge branch 10.4 into 10.5 2024-05-06 13:55:42 +02:00
Sergei Golubchik
03295f0c20 MDEV-30727 Check spider_hton_ptr in spider udfs
UDF isn't supposed to use my_error(), it should return
the error message in the provided error message buffer

Fixes valgrind:

==93993== Conditional jump or move depends on uninitialised value(s)
==93993==    at 0x484ECCD: strnlen (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==93993==    by 0x1AD2B2C: process_str_arg (my_vsnprintf.c:259)
==93993==    by 0x1AD47E0: my_vsnprintf_ex (my_vsnprintf.c:696)
==93993==    by 0x1A3B91E: my_error (my_error.c:120)
==93993==    by 0xF87BE8: udf_handler::fix_fields(THD*, Item_func_or_sum*, unsigned int, Item**) (item_func.cc:3638)

followup for 267dd5a993
2024-05-05 21:37:07 +02:00
Yuchen Pei
b84d335d9d
MDEV-33538 make auxiliary spider plugins init depend on actual spider
The two I_S plugins SPIDER_ALLOC_MEM and SPIDER_WRAPPER_PROTOCOL
only makes sense if the main SPIDER plugin is installed. Further,
SPIDER_ALLOC_MEM requires a mutex that requires SPIDER init to fill
the table.

We also update the spider init query to override
--transaction_read_only=on so that it does not affect the spider init.

Also fixed error handling in spider_db_init() so that failure in
spider table init does not result in memory leak
2024-05-03 14:47:54 +10:00
Yuchen Pei
3f2a5b28c6
MDEV-34003 Add testcase spider/bugfix.mdev_34003
MDEV-34003 appears to be a duplicate of MDEV-33742, and no code change
is needed. Nevertheless we add the testcase reported in the former.
2024-04-29 16:42:46 +10:00
Yuchen Pei
267dd5a993
MDEV-30727 Check spider_hton_ptr in spider udfs
We have to #undef my_error and find it from udfs when spider is not
installed.
2024-04-29 16:17:22 +10:00
Oleksandr Byelkin
9b18275623 Merge branch '10.4' into 10.5 2024-04-16 11:04:14 +02:00
Kristian Nielsen
16aa4b5f59 Merge from 10.4 to 10.5
Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
2024-04-15 17:46:49 +02:00
Yuchen Pei
051a1fa0e9
MDEV-33777 Spider: Correct checks for show index column numbers
It was updated for 10.6+ in MDEV-7317. Because a lower version spider
node may connect to a higher version data node, we need to change this
for 10.4 and 10.5 as well.
2024-04-15 09:59:24 +10:00
Yuchen Pei
18b93d6eb0
MDEV-28993 Spider: Push down CASE statement 2024-04-15 09:56:24 +10:00
Yuchen Pei
99dc0f030f
MDEV-28993 spider: revert removal of ITEM_FUNC_CASE_PARAMS_ARE_PUBLIC
It was done in MDEV-29447.
2024-04-15 09:56:23 +10:00
Yuchen Pei
662bb176b4
MDEV-33661 MENT-1591 Keep spider in memory until exit in ASAN builds
Same as MDEV-29579. For some reason, libodbc does not clean up
properly if unloaded too early with the dlclose() of spider. So we add
UNIQUE symbols to spider so the spider does not reload in dlclose().

This change, however, uncovers some hidden problems in the spider
codebase, for which we move the initialisation of some spider global
variables into the initialisation of spider itself.

Spider has some global variables. Their initialisation should be done
in the initialisation of spider itself, otherwise, if spider were
re-initialised without these symbol being unloaded, the values could
be inconsistent and causing issues.

One such issue is caused by the variables
spider_mon_table_cache_version and spider_mon_table_cache_version_req.
They are used for resetting the spider monitoring table cache and have
initial values of 0 and 1 respectively. We have that always
spider_mon_table_cache_version_req >= spider_mon_table_cache_version,
and when the relation is strict, the cache is reset,
spider_mon_table_cache_version is brought to be equal to
spider_mon_table_cache_version_req, and the cache is searched for
matching table_name, db_name and link_idx. If the relation is equal,
no reset would happen and the cache would be searched directly.

When spider is re-inited without resetting the values of
spider_mon_table_cache_version and spider_mon_table_cache_version_req
that were set to be equal in the previous cache reset action, the
cache was emptied in the previous spider deinit, which would result in
HA_ERR_KEY_NOT_FOUND unexpectedly.

An alternative way to fix this issue would be to call the spider udf
spider_flush_mon_cache_table(), which increments
spider_mon_table_cache_version_req thus making sure the inequality is
strict. However, there's no reason for spider to initialise these
global variables on dlopen(), rather than on spider init, which is
cleaner and "purer".

To reproduce this issue, simply revert the changes involving the two
variables and then run:

mtr --no-reorder spider.ha{,_part}
2024-04-10 10:10:30 +10:00
Yuchen Pei
b7b58a2310
MDEV-33731 Only iterate over m_locked_partitions in update_next_auto_inc_val()
Only locked will participate in the query in this case. Chances are
that not-locked partitions were not opened, which is the cause of the
crash in the added test case spider/bugfix.mdev_33731 without this
patch.
2024-04-09 09:24:48 +10:00
Yuchen Pei
f9e0ebeca4
MDEV-33742 Do not create group by handler when all tables are constant 2024-04-08 14:35:36 +10:00
Yuchen Pei
e865ef6a04
MDEV-33742 Remove macro PARTITION_HAS_GET_CHILD_HANDLERS
Similar to MDEV-27658.

Also fixing the positioning of #ifdef WITH_PARTITION_STORAGE_ENGINE
blocks and add missing ones.
2024-04-08 14:35:36 +10:00
Yuchen Pei
860c1ca9ad
MDEV-33679 Spider group by handler: skip on multiple equalities
The spider group by handler is created in
JOIN::make_aggr_tables_info(), by which time calls to
substitute_for_best_equal_field() should have already removed all the
multiple equalities (i.e. Item_equal, with MULT_EQUAL_FUNC func_type).
Therefore, if there is still such items, it is deemed as an optimizer
bug and should be skipped.
2024-04-08 14:35:35 +10:00
Yuchen Pei
9c93d41ad7
MDEV-33728 spider: remove use of MYSQL_VERSION_ID and MARIADB_BASE_VERSION
change created by:

unifdef -DMYSQL_VERSION_ID=100400 -DMARIADB_BASE_VERSION -m storage/spider/spd_* storage/spider/ha_spider.* storage/spider/hs_client/*

basically MDEV-27637, MDEV-27641, MDEV-27655
2024-04-08 14:35:35 +10:00
Yuchen Pei
44c88faeca
MDEV-28992 Spider group by handler: Push down TIMESTAMPDIFF function
Also removed ITEM_FUNC_TIMESTAMPDIFF_ARE_PUBLIC.

Similar to pr#2225, with the testcase adapted from that patch:

--8<---------------cut here---------------start------------->8---
From 884f7c6df1 Mon Sep 17 00:00:00 2001
From: "Norio Akagi (norakagi)" <norakagi@amazon.com>
Date: Wed, 3 Aug 2022 23:30:34 -0700
Subject: [PATCH] [MDEV-28992] Push down TIMESTAMP_DIFF in spider

This changes so that TIMESTAMP_DIFF function in a query is pushed down and works natively in Spider.
Instead of directly accessing item's member, now we can rely on a public accessor method to make it work.
Unit tests are added under spider.pushdown_timestamp_diff.

All new code of the whole pull request, including one or several files
that are either new files or modified ones, are contributed under the
BSD-new license. I am contributing on behalf of my employer
Amazon Web Services, Inc.
--8<---------------cut here---------------end--------------->8---
2024-04-08 14:35:35 +10:00
Yuchen Pei
11fe2ee0af
MDEV-33493 Spider: Make a symlink result file a normal file 2024-04-08 14:35:35 +10:00
Yuchen Pei
504925c416
MDEV-33434 spider direct sql: Check length before memcpy
similar to MDEV-30981
2024-04-08 14:35:34 +10:00
Yuchen Pei
e6d12bb459
MDEV-33661 MENT-1591 Fix spider/bugfix.mdev_28856 because of MDEV-29718.
The failure should be table not found, rather than no spider same
server link
2024-03-28 09:32:59 +11:00
Yuchen Pei
0b627377a9
MDEV-33661 MENT-1591 Documenting spider_mon_table_cache and friends.
Partial documentation due to time constraints. Will improve over time.

Also removed a redundant parameter link_idx from
spider_get_sys_tables_connect_info().

And deleted some commented out code.
2024-03-28 09:32:53 +11:00
Yuchen Pei
db0b9ec37b
MDEV-33584 Use the default SQL_MODE for spider init queries
This should fix all future problems caused by a non-default global
sql_mode from the server where spider is to be installed.
2024-03-27 11:40:41 +11:00
Yuchen Pei
9d34939c6e
MDEV-33494 fix spider init with no_zero_date global sql mode
Like the fix for MDEV-32753 and MDEV-33242, spider init queries
creates new connections that use the global sql_mode of the existing
connection.
2024-03-27 11:35:23 +11:00
Yuchen Pei
ef9cdacf51
MDEV-33220 Fix -wmaybe-uninitialized warnings for g++-13 2024-03-25 12:56:00 +11:00
Yuchen Pei
1b568fb917
MDEV-33539 spider: remove some unused code in self reference checks 2024-03-04 11:52:13 +11:00
Yuchen Pei
d37c51b805
MDEV-33494 fix spider init with no_zero_date global sql mode
Like the fix for MDEV-32753 and MDEV-33242, spider init queries
creates new connections that use the global sql_mode of the existing
connection.
2024-03-04 10:51:56 +11:00
Yuchen Pei
0f0da95db0
MDEV-33493 Spider: Make a symlink result file a normal file 2024-02-21 14:18:53 +11:00
Yuchen Pei
c492c34f67
MDEV-33434 spider direct sql: Check length before memcpy
similar to MDEV-30981
2024-02-19 15:12:16 +11:00
Marko Mäkelä
b770633e07 Merge 10.4 into 10.5 2024-02-13 14:25:21 +02:00
Yuchen Pei
c37216de64 MDEV-33441 Do not deinit plugin variables when retry requested
After MDEV-31400, plugins are allowed to ask for retries when failing
initialisation. However, such failures also cause plugin system
variables to be deleted (plugin_variables_deinit()) before retrying
and are not re-added during retry.

We fix this by checking that if the plugin has requested a retry the
variables are not deleted. Because plugin_deinitialize() also calls
plugin_variables_deinit(), if the retry fails, the variables will
still be deleted.

Alternatives considered:

- remove the plugin_variables_deinit() from plugin_initialize() error
handling altogether. We decide to take a more conservative approach
here.

- re-add the system variables during retry. It is more complicated
than simply iterating over plugin->system_vars and call
my_hash_insert(). For example we will need to assign values to
the test_load field and extract more code from test_plugin_options(),
if that is possible.
2024-02-12 16:36:36 +01:00
Yuchen Pei
d40eaf2dab
MDEV-33174 Fixing nondeterministic self-referencing test result 2024-02-07 17:34:15 +11:00
Sergei Golubchik
01f6abd1d4 Merge branch '10.4' into 10.5 2024-01-31 17:32:53 +01:00
Sergei Golubchik
d1744ee7a2 MDEV-33343 spider.mdev_28739_simple fails in buildbot
test disabled, until fixed
2024-01-31 15:32:37 +01:00
Yuchen Pei
1070575a89
MDEV-33191 spider: fix dbton_id when iterating over links
There are two array fields in spider_share with similar names:

share->use_sql_dbton_ids that maps from i to the i-th dbton used by
share. Thus it should be used only when i iterates over all distinct
dbtons used by share.

share->sql_dbton_ids that maps from i to the dbton used by the i-th
link of the share. Thus it should be used only when i iterates over
all links of a share.

We correct instances where share->sql_dbton_ids should be used instead
of share->use_sql_dbton_ids.
2024-01-25 12:33:52 +11:00
Yuchen Pei
9c059a4f1c
Spider: no need to check for ubsan when running ubsan tests
It's ok to run these tests without ubsan too, and we get some tests
for free.
2024-01-17 10:33:02 +11:00
Alexander Barkov
fa3171df08 MDEV-27666 User variable not parsed as geometry variable in geometry function
Adding GEOMETRY type user variables.
2024-01-16 18:53:23 +04:00
Yuchen Pei
88c46aba75
MDEV-32997 Disable spider/bugfix.mdev_27575 until we find a solution
The failure described in MDEV-32997 is happening a bit too often and
polluting the CI results.
2024-01-11 12:46:31 +11:00
Yuchen Pei
d277a63c74
MDEV-31101 Re-enable spider/bugfix.mdev_29904
The spider init bug fixes remove any race conditions during spider
init.

Also remove the add_suppressions in spider/bugfix.mdev_27575 which is
a similar issue.
2024-01-11 12:44:30 +11:00