Commit graph

33126 commits

Author SHA1 Message Date
unknown
dcb3650d63 MDEV-4506: Parallel replication
MDEV-5217: Incorrect MyISAM event execution order causing incorrect parallel replication

In parallel replication, if transactions A,B group-commit together on the
master, we can execute them in parallel on a replication slave. But then, if
transaction C follows on the master, on the slave, we need to be sure that
both A and B have completed before starting on C to be sure to avoid
conflicts.

The necessary wait is implemented such that B waits for A to commit before it
commits itself (thus preserving commit order). And C waits for B to commit
before it itself can start executing. This way C does not start until both A
and B have completed.

The wait for B's commit on A happens inside the commit processing. However, in
the case of MyISAM with no binlog enabled on the slave, it appears that no
commit processing takes place (since MyISAM is non-transactional), and thus
the wait of B for A was not done. This allowed C to start before A, which can
lead to conflicts and incorrect replication.

Fixed by doing an extra wait for A at the end of B before signalling C.
2013-11-06 14:51:06 +01:00
unknown
c90f4f0212 MDEV-4506: Parallel replication
MDEV-5217: Unlock of de-allocated mutex

There was a race in the code for wait_for_commit::wakeup().

Since the waiter does a dirty read of the waiting_for_commit
flag, it was possible for the waiter to complete and deallocate
the wait_for_commit object while the waitee was still running
inside wakeup(). This would cause the waitee to access invalid
memory.

Fixed by putting an extra lock/unlock in the destructor for
wait_for_commit, to ensure that waitee has finished with the
object before it is deallocated.
2013-11-06 11:29:07 +01:00
unknown
bdbf90b969 MDEV-4506: Parallel replication
MDEV-5217: Incorrect event pos update leading to corruption of reading of events from relay log

The rli->event_relay_log_pos was sometimes undated incorrectly when using
parallel replication, especially around relay log rotates. This could cause
the SQL thread to seek into an invalid position in the relay log, resulting in
errors about invalid events or even random corruption in some cases.
2013-11-06 10:18:04 +01:00
Seppo Jaakola
2b4183f10b bzr merge -r3890..3891 lp:codership-mysql/5.5 2013-11-06 00:29:37 +02:00
Seppo Jaakola
9129c8f1d3 bzr merge -r3889..3890 lp:codership-mysql/5.5 2013-11-06 00:02:22 +02:00
unknown
b0391d1b83 MDEV-4506: Parallel replication.
MDEV-5217: Last_sql_error lost in parallel replication.

For some reason, the query execution code in log_event.cc call
rli->clear_error for each event (part of clear_all_errors()).
This causes a problem in parallel replication, where the
execution in one worker thread could clear the error set by
another thread, causing the SQL thread to stop but leaving no
error visible in SHOW SLAVE STATUS.

There seems to be no reason to clear the global error code
in Relay_log_info for each event execution, from code review
and from running the test suite. So remove this clearing of
the error code to make things work also in the parallel case.
2013-11-05 14:49:57 +01:00
unknown
c834242ad4 MDEV-4506: Parallel replication
MDEV-5217: SQL thread hangs during stop if error occurs in the middle of an event group

Normally, when we stop the slave SQL thread in parallel replication, we want
the worker threads to continue processing events until the end of the current
event group. But if we stop due to an error that prevents further events from
being queued, such as an error reading the relay log, no more events can be
queued for the workers, so they have to abort even if they are in the middle
of an event group. There was a bug that we would deadlock, the workers
waiting for more events to be queued for the event group, the SQL thread
stopped and waiting for the workers to complete their current event group
before exiting.

Fixed by now signalling from the SQL thread to all workers when it is about
to exit, and cleaning up in all workers when so signalled.

This patch fixes one of multiple problems reported in MDEV-5217.
2013-11-05 12:01:26 +01:00
Sergey Vojtovich
fd9f1638ea MDEV-5205 - MariaDB does not start if more than 128 cpu's are available
- thread_pool_size command line option upper limit increased to 100 000
  (same as for max_connections)
- thread_pool_size system variable upper limit is maximum of 128 or
  the value given at command line
- thread groups are now allocated dynamically

Different limit for command line option and system variable was done to
avoid additional mutex for all_groups and threadpool_max_size.
2013-11-05 09:18:59 +04:00
Sergei Golubchik
0150dc6ed9 10.0-base merge 2013-11-04 21:47:54 +01:00
Sergei Golubchik
1ef87c5578 MDEV-5080 Assertion `strcmp(share->unique_file_name,filename) || share->last_version' fails at /storage/myisam/mi_open.c:67
extend table names discovery (ha_discover_table_names() and Discovered_table_list) to return
or optionally filter out temporary tables ("#sql..."). SHOW commands and I_S tables
typically want temp table filtered out, while DROP DATABASE wants to see them too.

additonally, remove the supression for the warning "Invalid (old?) table or database name"
from mtr, and add it to .test files as needed (we need to test that this warning
does *not* happen in drop.test)
2013-11-04 21:37:29 +01:00
Sergei Golubchik
032a61fc0a restore the condition in filename_to_tablename()
(broken in the revid:sergii@pisem.net-20130615170931-bn2h8j30vu5bfp0t)
2013-11-04 13:40:20 +01:00
Sergei Golubchik
79d2e6c82f MDEV-5232 SET ROLE checks privileges differently from check_access()
use the same inconsistent priv_user@host pair for SET ROLE privilege checks,
just as check_access() does
2013-11-04 13:37:39 +01:00
Sergei Golubchik
a30e87414c merge 10.0-base into 10.0 2013-11-04 08:43:56 +01:00
Sergei Golubchik
ba55e5e02b merge mdev-4506 into 10.0 2013-11-04 00:45:27 +01:00
Sergei Golubchik
00ba619106 merge mdev-4506-base into 10.0-base 2013-11-03 23:46:57 +01:00
Michael Widenius
de9d9792ab Fixed things missing in merge between 10.0-base and 10.0
Updated --help text to declare --slave-parallel-threads as an alpha feature

mysql-test/r/mysqld--help.result:
  Updated --help text
sql/slave.cc:
  Added missing trans_retries++ that caused rpl_deadlock_innodb.test to fail.
  This is safe as this part is never run in parallel.
sql/sql_base.cc:
  Fixed temporary table handling (part of merge)
sql/sys_vars.cc:
  Updated --help text to declare --slave-parallel-threads as an alpha feature
2013-11-03 22:26:44 +02:00
Sergei Golubchik
5c9d2c6c9f MDEV-4332 Increase username length from 16 characters
10.0 part of the task, fix system tables
2013-11-03 16:31:52 +01:00
Sergei Golubchik
ed4a31e8d5 10.0-base merge 2013-11-02 17:59:16 +01:00
Sergei Golubchik
320b85286b grant/revoke ... to/from current_role 2013-11-02 16:26:35 +01:00
Sergei Golubchik
1f0368658b MDEV-5225 Server crashes on CREATE USER|ROLE CURRENT_ROLE or DROP ROLE CURRENT_ROLE 2013-11-02 16:26:01 +01:00
unknown
57a267a8c0 Merge from 10.0-base to 10.0 the feature MDEV-4506: Parallel replication.
The merge is still missing a few hunks related to temporary tables and
InnoDB log file size. The associated code did not seem to exist in
10.0, so the merge of that needs more work. Until this is fixed, there
are a number of test failures as a result.
2013-11-01 12:00:11 +01:00
unknown
cb86ce60b9 Merge MDEV-4506: Parallel replication into 10.0-base. 2013-11-01 09:17:06 +01:00
unknown
39df665a33 MDEV-5206: Incorrect slave old-style position in MDEV-4506, parallel replication.
In parallel replication, there are two kinds of events which are
executed in different ways.

Normal events that are part of event groups/transactions are executed
asynchroneously by being queued for a worker thread.

Other events like format description and rotate and such are executed
directly in the driver SQL thread.

If the direct execution of the other events were to update the old-style
position, then the position gets updated too far ahead, before the normal
events that have been queued for a worker thread have been executed. So
this patch adds some special cases to prevent such position updates ahead
of time, and instead queues dummy events for the worker threads, so that
they will at an appropriate time do the position updates instead.

(Also fix a race in a test case that happened to trigger while running
tests for this patch).
2013-10-31 14:11:41 +01:00
unknown
9c8da4ed76 MDEV-5196: Server hangs or assertion `!thd->wait_for_commit_ptr' fails on MASTER_POS_WAIT with slave-parallel-threads > 0
Fix a couple of issues in MDEV-4506, Parallel replication:

 - Missing mysql_cond_signal(), which could cause hangs.

 - Fix incorrect update of old-style replication position.

 - Change assertion to error handling (can trigger on manipulated/
   corrupt binlog).
2013-10-30 07:52:30 +01:00
unknown
97ecffc8ee merge 10.0-base -> 10.0 2013-10-29 22:20:45 +02:00
unknown
f4d5d849fd merge 5.5->10.0-base 2013-10-29 20:53:05 +02:00
unknown
52dea41052 Merge 5.3->5.5 2013-10-29 18:50:36 +02:00
unknown
5ce11d8b4c MariaDB made be compiled by gcc 4.8.1
There was 2 problems:
  1) coping/moving of the same type (usually casting) as sizeof() (solved in different ways depends on the cause);
  2) using 'const' in SSL_CTX::getVerifyCallback() which return object (not reference) and so copy of the object will be created and 'const' has no sens.
2013-10-29 17:50:13 +02:00
Sergei Golubchik
0fdb3bcfdb 10.0-base merge (roles) 2013-10-29 15:08:44 +01:00
unknown
f2799c6828 MDEV-5195: Race when switching relay log causing crash
In parallel replication, when the IO thread switches relay log,
the SQL thread re-opens the current relaylog and seeks to the
current position. There was a race that would cause it to
sometimes seek to the wrong position, causing corruption and
crash.
2013-10-29 11:52:16 +01:00
timour@askmonty.org
883af99e7d MDEV-5104 crash in Item_field::used_tables with broken order by
Analysis:
st_select_lex_unit::prepare() computes can_skip_order_by as TRUE.
As a result join->prepare() gets called with order == NULL, and
doesn't do name resolution for the inner ORDER clause. Due to this
the prepare phase doesn't detect that the query references non-exiting
function and field.
  
Later join->optimize() calls update_used_tables() for a non-resolved
Item_field, which understandably has no Field object. This call results
in a crash.

Solution:
Resolve unnecessary ORDER BY clauses to detect if they reference non-exising
objects. Then remove such clauses from the JOIN object.
2013-10-29 12:39:03 +02:00
unknown
2fbd1c7307 MDEV-4506: Parallel replication.
MDEV-5189: Error handling in parallel replication.

Fix error handling in parallel worker threads when a query fails:

 - Report the error to the error log.

 - Return the error back, and set rli->abort_slave.

 - Stop executing more events after the error.
2013-10-28 13:24:56 +01:00
Alexander Barkov
9290a5805b Merging more ctype_* tests from MySQL-5.6. 2013-10-28 12:17:46 +04:00
Sergei Golubchik
fef4166990 Don't allow authentication clauses for roles, in particular:
GRANT ... IDENTIFIED BY [ PASSWORD ] ...
  GRANT ... IDENTIFIED VIA ... [ USING ... ]
  GRANT ... REQUIRE ...
  GRANT ... MAX_xxx ...
  SET PASSWORD FOR ... = ...
2013-10-28 07:46:17 +01:00
Sergei Golubchik
d5c9712225 post-review cleanup 2013-10-27 08:19:21 +01:00
Sergei Golubchik
e46eea8660 remove inherited routine grants when a routine is dropped 2013-10-26 15:52:29 +02:00
Vicențiu Ciorbaru
2eed3b7d07 Implemented REVOKE ALL FROM for Roles and role grants. 2013-10-26 15:38:48 +02:00
unknown
6a38b59475 MDEV-5189: Incorrect parallel apply in parallel replication
Two problems were fixed:

1. When not in GTID mode (master_use_gtid=no), then we must not apply events
   in different domains in parallel (in non-GTID mode we are not capable of
   restarting at different points in different domains).

2. When transactions B and C group commit together, but after and separate
   from A, we can apply B and C in parallel, but both B and C must not start
   until A has committed. Fix sub_id to be globally increasing (not just
   per-domain increasing) so that this wait (which is based on sub_id) can be
   done correctly.
2013-10-25 21:17:14 +02:00
Alexander Barkov
71f8ca654e MDEV-5180 Data type for WEIGHT_STRING is too short in some cases
(a bug in upstream)
2013-10-25 15:01:03 +04:00
unknown
80d0dd7bab MDEV-4506: Parallel replication.
Do not update relay-log.info and master.info on disk after every event
when using GTID mode:

 - relay-log.info and master.info are not crash-safe, and are not used
   when slave restarts in GTID mode (slave connects with GTID position
   instead and immediately rewrites the file with the new, correct
   information found).

 - When using GTID and parallel replication, the position in
   relay-log.info is misleading at best and simply wrong at worst.

 - When using parallel replication, the fact that every single
   transaction needs to do a write() syscall to the same file is
   likely to become a serious bottleneck.

The files are still written at normal slave stop.

In non-GTID mode, the files are written as normal (this is needed to
be able to restart after slave crash, even if such restart is then not
crash-safe, no change).
2013-10-25 12:56:12 +02:00
unknown
7a22b6a655 MDEV-4506: Parallel replication.
Fix uninitialised variable.
2013-10-24 14:37:45 +02:00
unknown
ee8a816208 MDEV-4506: Parallel replication.
Implement --slave-parallel-max-queue to limit memory usage
of SQL thread read-ahead in the relay log.
2013-10-24 12:44:21 +02:00
Sergey Petrunya
86901216fd MDEV-5102 : MySQL Bug 69851
- Backport MySQL's fix: do set ha_partition::m_pkey_is_clustered for ha_partition 
  objects created with handler->clone() call.
- Also, include a testcase.
2013-10-24 11:24:37 +04:00
unknown
96a4f1f628 MDEV-4506: Parallel replication: Update some comments. 2013-10-24 08:53:48 +02:00
Sergei Golubchik
65eee0be5f MDEV-5176 Server crashes in fill_schema_applicable_roles on select from APPLICABLE_ROLES after a suicide
Don't assume that thd->security_ctx->priv_user is an actually existing user account
2013-10-23 09:54:10 -07:00
Sergei Golubchik
7761a278f6 MDEV-5170 Assertion `(&(&acl_cache->lock)->m_mutex)->count > 0 && pthread_equal(pthread_self(), (&(&acl_cache->lock)->m_mutex)->thread)' fails after restarting server with a pre-created role grants
lock acl_cache->lock mutex for the duration of acl_load
2013-10-23 09:49:47 -07:00
unknown
a09d2b105f MDEV-4506: Parallel replication.
Fix some more parts of old-style position updates.
Now we save in rgi some coordinates for master log and relay log, so
that in do_update_pos() we can use the right set of coordinates with
the right events.

The Rotate_log_event::do_update_pos() is fixed in the parallel case
to not directly update relay-log.info (as Rotate event runs directly
in the driver SQL thread, ahead of actual event execution). Instead,
group_master_log_file is updated as part of do_update_pos() in each
event execution.

In the parallel case, position updates happen in parallel without
any ordering, but taking care that position is not updated backwards.
Since position update happens only after event execution this leads
to the right result.

Also fix an access-after-free introduced in an earlier commit.
2013-10-23 15:03:03 +02:00
Sergei Golubchik
f6b8f6d156 reset the db privilege cache when revoking db priviges on DROP ROLE 2013-10-23 05:09:17 -07:00
Sergei Golubchik
614478921f MDEV-5172 safe_mutex: Trying to lock mutex when the mutex was already locked on using a role and I_S role tables
don't forget to unlock if the current role isn't found
2013-10-23 03:28:41 -07:00
Sergei Golubchik
fd826cc3bd properly propagate privilege changes on DROP ROLE 2013-10-23 03:26:09 -07:00
Sergei Golubchik
82037f9c0e don't rebuild all parent_grantees/role_grants arrays when a role is dropped,
only remove this role from the arrays where it is present.
2013-10-23 03:25:24 -07:00
unknown
94ad392fd8 MDEV-5143: update of a joined table with a nested subquery with a syntax error crashes mysqld with signal 11
Added check of SELECT_LEX::handle_derived() result.
2013-10-21 13:45:49 +03:00
Alexander Barkov
a06cd2cbe5 Merge 5.3 -> 5.5 2013-10-21 13:37:17 +04:00
Alexander Barkov
046fe91161 Merge 5.2 -> 5.3 2013-10-21 13:36:29 +04:00
Alexander Barkov
c63b72c968 Merge 5.1 -> 5.2 2013-10-21 13:35:43 +04:00
Alexander Barkov
11d141004a A clean-up for DEV-4890 Valgrind warnings on shutdown on a build with openSSL 2013-10-21 13:34:18 +04:00
Sergei Golubchik
779693f409 fixes for builbot 1 2013-10-20 16:39:51 -07:00
Sergei Golubchik
af3079589f fix a misplaced #endif that was confusing ctags 2013-10-20 16:39:44 -07:00
Sergei Golubchik
c1c0a83772 ACL_USER methods for comparing ACL_USER objects 2013-10-20 08:51:49 +02:00
Sergei Golubchik
ce68878947 fixes for embedded 2013-10-18 18:56:28 -07:00
Sergei Golubchik
cb9d3bec46 post-review changes 2013-10-18 15:54:41 -07:00
Sergei Golubchik
40c43c395b remove old incorrect bugfix that moved reading of procs_priv table into a separate function.
FLUSH PRIVILEGES no longer returns an error, when it was successful.
LOCK_grant is no longed unlocked/relocked between tables_priv and procs_priv
2013-10-18 15:52:33 -07:00
Sergei Golubchik
f74b9eca6e remove ER_RESERVED_ROLE.
Only allow NONE instead of a role name in SET ROLE.
Don't allow PUBLIC as a role name anywhere (to be fixed later)
Fix db_access calculations on SET ROLE
Reduce the size of role_grants and parent_grantee per-user/role arrays.
Fix the wording and specify the correct sqlstate for ER_INVALID_ROLE
2013-10-18 15:52:26 -07:00
Sergei Golubchik
4ec26a7c2d replication of GRANT role statement 2013-10-18 13:18:03 -07:00
Sergei Golubchik
4d3e4c2984 make functions static, remove unused constructors, other small cleanups 2013-10-18 13:17:42 -07:00
Sergei Golubchik
d2c683527f recursive privilege propagation for roles.
functions for traversing the role graph in either direction.
merging of global, database, table, column, routine privileges.
debug status variables for counting number of privilege merges.
tests.
2013-10-18 13:06:41 -07:00
Sergei Golubchik
7fba8e5164 find() method for Hash_set<>.
Move key function from template parameter to the constructor
2013-10-18 12:36:03 -07:00
Sergei Golubchik
3098b6cf5b qsort2, pop, push methods for Dynamic_array<> 2013-10-18 12:35:22 -07:00
Sergei Golubchik
b221ec6529 enforce privileges for GRANT role 2013-10-18 12:34:59 -07:00
Sergei Golubchik
2f2699f97b cleanup.
mainly to avoid the pattern of
* get username/hostname/rolename
* optionally find the corresponding ACL_USER and ACL_ROLE
* allocate memory, concatenate username/hostname/rolename
* call a function passing only this memory as an argument
** use concatenated username/etc to find ACL_USER and ACL_ROLE again
** do something
* free the object

Also to undo push_dynamic we use pop_dynamic now,
not a linear search/scan through the dynamic array.

as a bonus, role@ is now an invalid way to refer to a role.
2013-10-18 12:34:44 -07:00
Sergei Golubchik
f1a71b6815 bugfix: missing restore_record when modifying roles_mapping() table.
(and an assert in myisam to catch these bugs easier in the future)
update tests/results
2013-10-18 12:27:07 -07:00
Sergei Golubchik
e5211e0cde information_schema.applicable_roles.is_grantable column 2013-10-18 12:26:43 -07:00
Sergei Golubchik
67985b283a require SUPER to specify an arbitrary admin 2013-10-18 12:26:29 -07:00
Sergei Golubchik
7fb978c793 auto-grant a role to its admin on CREATE ROLE 2013-10-18 12:26:05 -07:00
Sergei Golubchik
46622dbea2 load with_admin flag from the mysql.roles_mapping table 2013-10-18 12:25:52 -07:00
Sergei Golubchik
9d6e9c242e store ADMIN OPTION in the roles_mapping hash and table 2013-10-18 12:25:39 -07:00
Sergei Golubchik
66f0c2e308 small cleanup 2013-10-18 12:25:23 -07:00
Sergei Golubchik
0c303b52a9 New syntax:
CREATE ROLE xxx WITH ADMIN yyy
  GRANT xxx TO yyy WITH ADMIN OPTION
  REVOKE ADMIN OPTION FOR xxx FROM yyy
2013-10-18 12:23:15 -07:00
Sergei Golubchik
c28bf2a344 bugfix: propagate grant changes through the role graph after table/column/routine grants 2013-10-18 12:21:37 -07:00
Sergei Golubchik
d0db4f2261 add Admin_option column to mysql.roles_mapping. update tests/results 2013-10-18 12:21:10 -07:00
Sergei Golubchik
7dda698734 rename columns in mysql.roles_mapping to be consistent with other privilege tables 2013-10-18 12:19:37 -07:00
Sergei Golubchik
b2f16628cf support DEFINER=role and DEFINER=current_role 2013-10-18 12:17:49 -07:00
Sergei Golubchik
b054700619 speed up fill_effective_table_privileges() - avoid calling expensive acl_get() 2013-10-18 11:46:43 -07:00
Sergei Golubchik
02a7291954 cleanup
sql/sp.cc:
  don't split "user@host" string in db_load_routine, because the caller needs to
  generate it from user and host. instead pass user and host directly into db_load_routine
sql/sql_parse.cc:
  1. REVOKE ALL doesn't need invoker.
  2. make sp_process_definer() reusable
sql/sql_trigger.cc:
  don't duplicate the code from sp_process_definer(), reuse it
sql/sql_view.cc:
  don't duplicate the code from sp_process_definer(), reuse it
2013-10-18 11:46:30 -07:00
Sergei Golubchik
ac6877d420 SET PASSWORD bugfixes:
* work as documented, use CURRENT_USER()
* move the check for ER_PASSWORD_ANONYMOUS_USER where it can actually work
2013-10-18 11:41:40 -07:00
Sergei Golubchik
4cc8cda346 Remove the very old historical but never documented behavior,
than an empty host '' is the same as any-host wildcard '%'.

Replace '' with '%' in the parser (for GRANT ... foo@'') and when loading grant tables.

Side effect: one cannot have foo@'' and foo@'%' both at the same time
(but one can have foo@'%' and foo@'%%')
2013-10-18 11:38:13 -07:00
Vicențiu Ciorbaru
5630967dd5 Fixed GRANT ROLE TO ROLE not updating acl_roles_mappings hash.
Also fixed possible memory exploit by repeteadly calling:
GRANT role to user; where role was already granted to user.
2013-10-18 09:26:02 -07:00
Vicențiu Ciorbaru
a34dff8825 Removed redundant code in update_acl_user. User related functions
should deal with users, while role related functions should deal
with roles.
2013-10-18 09:25:53 -07:00
Vicențiu Ciorbaru
60f19cbc9a Added GRANT ROLE TO ... and REVOKE ROLE FROM ... functionality.
TODO:

Privilege checks are not done upon executing the command.
2013-10-18 09:25:42 -07:00
Vicențiu Ciorbaru
df48f63684 Fixed rolenames case insensitivity bug. Also cleared compiler warning.
Fixed segmentation fault caused in traverse_role_graph by previous commit
2013-10-18 09:20:59 -07:00
Vicențiu Ciorbaru
507c4be955 Fixed bug that caused the ROLE_VISITED flag to remain set if the exploration
was halted on a cycle detect. Now the to_clear array is populated during
the open event and not the close event.
2013-10-18 09:19:53 -07:00
Sergei Golubchik
fe2d265704 INFORMATION_SCHEMA.APPLICABLE_ROLES table 2013-10-18 09:15:55 -07:00
Sergei Golubchik
7f0965f490 information_schema.enabled_roles table 2013-10-18 09:15:46 -07:00
Sergei Golubchik
8993984342 CURRENT_ROLE() should return NULL, not "NONE" 2013-10-18 09:09:08 -07:00
Sergei Golubchik
97c3989409 remove DROP ROLE IF EXISTS and CREATE ROLE IF NOT EXISTS syntax 2013-10-18 09:08:55 -07:00
Sergei Golubchik
353576f3d3 GRANT/REVOKE should specify role name as 'role' not as 'role'@'%' 2013-10-18 09:08:42 -07:00
Sergei Golubchik
06e16b8c97 cannot use lex->grant_user= &current_user, where LEX_USER current_user is a global constant,
because parser might modify the lex->user (e.g. set lex->user-password).
switch to use LEX_STRING current_user string, and also change other similar constants
to be LEX_STRING's for consistency.
2013-10-18 08:17:56 -07:00
Sergei Golubchik
72d8b533cc Fixes for mysql-test failures
mysql-test/r/acl_roles_show_grants.result:
  one can do SHOW GRANTS for himself
mysql-test/t/acl_roles_set_role-table-column-priv.test:
  correct error message
mysql-test/t/acl_roles_show_grants.test:
  one can SHOW GRANTS for himself
sql/sql_acl.cc:
  bugfixing:
  * don't assign with && - it can shortcut and the second assignment won't be executed
  * correct the test in check_grant_all_columns() - want_access should not be modified
  *
sql/sql_cmd.h.OTHER:
  add new commands at the end
sql/sql_db.cc:
  don't call acl_get() if all privileges are already satisfied
  (crashes when run with --skip-grants, because acl data stuctures aren't initialized)
sql/sql_parse.cc:
  * test for current_user in get_current_user()
  * map explicitly specified user@host to current_user
2013-10-18 08:10:51 -07:00
Sergei Golubchik
8122996a59 CURRENT_ROLE() function 2013-10-18 06:55:26 -07:00
Vicențiu Ciorbaru
1ac0b920d5 Added GRANT ROLE TO ROLE | USER functionality.
The command only currenty affects in memory data structures. Writing to
the roles_mapping table needs to be implemented.
2013-10-18 06:49:53 -07:00
Vicențiu Ciorbaru
95ef78e432 SET ROLE now works recursively for routines.
The warnings present in the set_role_routine-simple testcase will
be removed when reworking the grant privilege to call.
2013-10-18 06:49:38 -07:00
Vicențiu Ciorbaru
bbc2771d24 SET ROLE now works recursively for table and column level privileges 2013-10-18 06:47:49 -07:00
Vicențiu Ciorbaru
1aedd4a585 Removed init_hash_columns hash and instead added an init_rights field
to the hash_columns' original elements (GRANT_COLUMN)
2013-10-18 06:45:36 -07:00
Vicențiu Ciorbaru
6f9d26f09f Show grants now correctly prints procedure privileges. 2013-10-18 06:42:59 -07:00
Vicențiu Ciorbaru
d83bbc1ffc Initialize init_access fields for all privilege data structures. 2013-10-18 06:42:03 -07:00
Vicențiu Ciorbaru
4a58599930 Implemented SHOW GRANTS functionality 2013-10-18 06:40:25 -07:00
Vicențiu Ciorbaru
d24ead2c6f Various bug fixes.
Also updated tests to reflect new show grants functionality.
2013-10-18 06:34:27 -07:00
Vicențiu Ciorbaru
8c7ca88a6c Added comment for database privilege checks. 2013-10-18 06:34:18 -07:00
Vicențiu Ciorbaru
f2ab661999 Added SHOW GRANTS recursive role print.
The output is not completely correct due to recursive role grants not
being completly implemented. However, this will help with testing the
implementation of set role with recursive grants.
2013-10-18 06:34:07 -07:00
Vicențiu Ciorbaru
3436691899 Refactored get_role_access into a generic traverse function.
The function now performs a DEPTH FIRST SEARCH on the role graph.

At various key points: on_start, on_open, on_cycle, on_finish,
the function calls one of the corresponding functions passed as parameters.
2013-10-18 06:22:17 -07:00
Vicențiu Ciorbaru
1bfc610dc7 Added show role grants functionality to the mysql_show_grants function. 2013-10-18 06:17:47 -07:00
Vicențiu Ciorbaru
0fea3316dd Refactored mysql_show_grants table and column privilege print into a separate
function.

The function will be used to help print roles privileges recursively.
2013-10-18 06:17:19 -07:00
Vicențiu Ciorbaru
d611407529 Refactored mysql_show_grants database privilege print into a separate
function.

The function will be used to help print roles privileges recursively.
2013-10-18 06:15:50 -07:00
Vicențiu Ciorbaru
4a9832680c Refactored mysql_show_grants global privilege print into a separate
function.

The function will be used to help print roles privileges recursively.
2013-10-18 06:09:30 -07:00
Vicențiu Ciorbaru
daf0345a7b Added recursive database roles privilege propagation.
The privileges are not correctly updated via grant commands yet.
2013-10-18 06:00:48 -07:00
Vicențiu Ciorbaru
766ae81aa4 Fixed bug that caused rename user test case to fail.
The bug was caused by not renaming the role if it was previously
modified by the handle_grant_struct(ROLE_ACL,...) call.

The same function used find_acl_role and would search for the already
renamed role when it handled ROLES_MAPPINGS_HASH. This caused it to not rename
the role/user correctly.
2013-10-18 05:41:52 -07:00
Vicențiu Ciorbaru
1fe9272479 Removed no longer used error message. 2013-10-18 05:41:43 -07:00
Vicențiu Ciorbaru
3fa2cb2126 Updated error message in case the user table's format is not up to date and can
not support roles
2013-10-18 05:41:34 -07:00
Vicențiu Ciorbaru
ce4851c3d0 Reworked the implementation of create role and drop role.
Also fixed issue with drop role not clearing internal memory entry
for that role. The issue was due to a condition introduced in handle_grant_data

Updated testsuite to also check the possible error conditions.
2013-10-18 05:41:25 -07:00
Vicențiu Ciorbaru
db850c525f Added CREATE ROLE support as well as DROP ROLE support. 2013-10-18 05:41:13 -07:00
Vicențiu Ciorbaru
81b2856e10 Refactored yacc grammar to make use of named constants. 2013-10-18 05:16:38 -07:00
Vicențiu Ciorbaru
ccd0c39cf4 Fixed crash caused by dereferencing null pointer. The comparison is no longer necessary there. 2013-10-18 05:13:22 -07:00
Vicențiu Ciorbaru
84a2f06fb2 Fixed always true condition that caused crash on database initialisation. 2013-10-18 05:11:40 -07:00
Vicențiu Ciorbaru
c4c09afb18 Fixed _always_ true condition 2013-10-18 05:11:31 -07:00
Vicențiu Ciorbaru
fe521dc28e Implemented _non recursive_ role specific grants for table/column level privileges 2013-10-18 05:11:16 -07:00
Vicențiu Ciorbaru
2060937353 Grant privilege on *.* to role@''; now updates in memory data structures;
Revoke privilege on *.* to role@''; also works
2013-10-18 04:47:55 -07:00
Vicențiu Ciorbaru
3d17d94cd6 Added GRANT privilege ON database.table TO role; functionality 2013-10-18 04:43:09 -07:00
Vicențiu Ciorbaru
01d4f47ef5 Added GRANT privilege ON database.* TO role; functionality 2013-10-18 04:41:18 -07:00
Vicențiu Ciorbaru
dcc9fd4c8e Implemented syntax recognition for REVOKE ROLE 2013-10-18 04:41:06 -07:00
Vicențiu Ciorbaru
ec92a4e0ff Implemented syntax recognition for DROP ROLE 2013-10-18 04:36:25 -07:00
Vicențiu Ciorbaru
fac8c9ef43 Added optional if not exists for create role. 2013-10-18 04:35:36 -07:00
Vicențiu Ciorbaru
51c631c2ae Implemented syntax recognition for CREATE ROLE 2013-10-18 04:35:18 -07:00
Vicențiu Ciorbaru
a57cdcd69a Changed GRANT ROLE to use SQLCOM_GRANT_ROLE 2013-10-18 04:29:40 -07:00
Vicențiu Ciorbaru
336ec901f4 Removed not needed GRANT privilege TO 2013-10-18 04:29:22 -07:00
Vicențiu Ciorbaru
d40d356606 Added syntax detection for the GRANT role TO {user | role } command.
Also added syntax for GRANT privilege TO { role } command
2013-10-18 04:29:01 -07:00
Vicențiu Ciorbaru
871f6e1631 Removed leftover comment. 2013-10-17 20:52:12 -07:00
Vicențiu Ciorbaru
9fa7f1fcd6 Added cascading role renames to the roles_mappings table.
TODO: Use an index search on the table, instead of scanning through it.
2013-10-17 20:51:55 -07:00
Vicențiu Ciorbaru
1007b9232b Added cascading updates from role renames. Also works if a role has been granted to a role.
This change only updates _in memory_ structures.
2013-10-17 20:51:46 -07:00
Vicențiu Ciorbaru
2755c342e6 Added extra comments to explain the ACL_USER_BASE flags usage, as well as fix an issue with get_role_access.
The bug caused roles rights to not be propagated if a push on the stack happened. The newly finished neighbour
was never reevaluated.
2013-10-17 20:51:37 -07:00
Vicențiu Ciorbaru
f37168d40b Split ACL_USER into ACL_USER_BASE and ACL_USER
ACL_ROLE now inherits ACL_USER_BASE
2013-10-17 20:51:28 -07:00
Vicențiu Ciorbaru
68214d21a0 Fixed failing tests due to wrong delete in the testsuite. 2013-10-17 20:51:10 -07:00
Vicențiu Ciorbaru
540673f046 Fixed comment indentation 2013-10-17 20:51:01 -07:00
Vicențiu Ciorbaru
221558efd5 Extended ACL_USER to create ACL_ROLE.
Moved fields corresponding to role entries to the ACL_ROLE class.
2013-10-17 20:50:51 -07:00
Vicențiu Ciorbaru
7faba82bab Fixed wrong IS_ROLE check. 2013-10-17 20:50:42 -07:00
Vicențiu Ciorbaru
0624020a76 Implemented the detection of the final access bits of a role via a DEPTH FIRST SEARCH
from the grant role to role graph.
2013-10-17 20:50:33 -07:00
Vicențiu Ciorbaru
f22a50b2f9 Added rights propagation for granting a role to a role 2013-10-17 20:50:15 -07:00
Vicențiu Ciorbaru
82a5464a6c Removed unused hash search. 2013-10-17 20:50:06 -07:00
Vicențiu Ciorbaru
9dcc6430b8 Modified add_role_user_mapping to also handle granting a role to a role. 2013-10-17 20:49:56 -07:00
Vicențiu Ciorbaru
c968a59d6e Added a reset_role_grants function specific for roles. The function also
resets the initial role access bits.
2013-10-17 20:49:47 -07:00
Vicențiu Ciorbaru
aa4657f872 Added comment to justify error message 2013-10-17 20:49:38 -07:00
Vicențiu Ciorbaru
a5b8939807 Added initial_role_grants variable to ACL_USER 2013-10-17 20:45:49 -07:00
Vicențiu Ciorbaru
45903359bf Fixed USER INVALID error when using anonymous user to login and calling
SET ROLE NONE;
2013-10-17 20:45:00 -07:00
Vicențiu Ciorbaru
cf9ebd72c4 Refactored find_mpvio_user. The loop that searches for the user is now a
separate function.
2013-10-17 20:44:51 -07:00
Vicențiu Ciorbaru
e8d6425875 Renamed find_acl_user -> find_user_no_anon 2013-10-17 20:39:43 -07:00
Vicențiu Ciorbaru
db25d8f977 Modified set_role_var to implement both a role check in the check() function,
as well as only set privileges in the update() function.
2013-10-17 20:39:23 -07:00
Sergei Golubchik
494f011799 fix the code to compile 2013-10-17 20:38:49 -07:00
Vicențiu Ciorbaru
7d4bfba91a Added error message for invalid role 2013-10-17 15:14:11 -07:00
Vicențiu Ciorbaru
0254c9a4bd Added the SET ROLE command to the grammar 2013-10-17 15:11:29 -07:00
Vicențiu Ciorbaru
6062e87f54 Created new set_var_role class to handle the SET ROLE command 2013-10-17 15:11:21 -07:00
Vicențiu Ciorbaru
7ec24435b3 Added acl_setrole function. The function enables/disables role privileges to
the current user via the current security_context
2013-10-17 15:11:13 -07:00
Vicențiu Ciorbaru
6680bb14a4 Removed no longer used label 2013-10-17 15:11:05 -07:00
Vicențiu Ciorbaru
096e7aa1e0 Fix bug with inserting _pointers_ to ACL_USER in the DYNAMIC_ARRAY of granted
roles
2013-10-17 15:10:57 -07:00
Vicențiu Ciorbaru
0d103a6f62 Add a check if user_to is valid to handle_roles_mappings_table 2013-10-17 15:10:49 -07:00
Vicențiu Ciorbaru
fb3e3b9440 Fixed typo 2013-10-17 15:10:40 -07:00
Vicențiu Ciorbaru
22ca077ac4 Removed all tabs from sql_acl.h. Replaced with spaces 2013-10-17 15:10:32 -07:00
Vicențiu Ciorbaru
565c6c5a1f Cascading updates for roles_mappings are now fully functional.
Renaming a user via RENAME USER command causes either the user columns
to update, or the role columns.
2013-10-17 15:10:24 -07:00
Vicențiu Ciorbaru
6bddb93e3c Implemented half of handle_roles_mappings_table.
The function now handles user updates/deletions correctly.
2013-10-17 15:10:15 -07:00
Vicențiu Ciorbaru
13a1f6fd72 Changed a call to handle_roles_mappings_table: first parameter is now more readable 2013-10-17 15:10:07 -07:00
Vicențiu Ciorbaru
9506a07159 Added debug info to rebuild_roles_mappings
Also fixed a bug regarding the HASH iteration. It previously got
the stop condition from a different hashtable and this caused errors
when the hash sizes were different.
2013-10-17 15:09:58 -07:00
Vicențiu Ciorbaru
0a9428cffc Added debug warning to add_role_user_mapping. 2013-10-17 15:09:50 -07:00
Vicențiu Ciorbaru
df53ed13ac Renamed variables in init_role_grant_pair to make the code more
consistent.
2013-10-17 15:09:39 -07:00
Vicențiu Ciorbaru
2f94e542bd Whitespace + comment fix 2013-10-17 15:09:31 -07:00
Vicențiu Ciorbaru
7842ef3052 Added logic to handle the in-memory roles_mappings struct in handle_data_struct.
The logic is not complete yet.
2013-10-17 15:09:22 -07:00
Vicențiu Ciorbaru
de472770d3 Removed no longer needed hash_walk_action. The function was used to delete
no longer valid entries in the roles_mappings HASH. This job will be delegated
to handle_grant_* functions
2013-10-17 15:09:14 -07:00
Vicențiu Ciorbaru
6988e6c56a The acl_roles_mappings in-memory structure holds the following invariant:
It will only hold _valid_ entries for as long as it held in memory. Any change
regarding acl_users or acl_roles in memory should update the structure
immediately. This is why the rebuild_roles_mappings no longer removes invalid
entries.

In order to keep things consistent with the existing code, the following jobs
are assigned to each function:

The role of rebuild_roles_mappings is to recreate the links between users and
roles. Any other updates are to be done in the functions:

handle_grant_*

This change prepares the code for the next step, which is cascading updates.
2013-10-17 15:09:06 -07:00
Vicențiu Ciorbaru
ba43f3551b Refactored some code in acl_load to make use of the new init_role_grant_pair
function
2013-10-17 15:06:39 -07:00
Vicențiu Ciorbaru
f8d944a6a0 Added a init_role_mapping function to be used for later 2013-10-17 15:06:29 -07:00
Vicențiu Ciorbaru
573c73225e open_grant_tables now also opens roles_mapping table 2013-10-17 15:06:20 -07:00
Vicențiu Ciorbaru
071c4ce88b Removed no longer needed RoleHostFK as it is not used to link to a Role.
Also removed code that loads that column into memory.
2013-10-17 15:06:09 -07:00
Vicențiu Ciorbaru
ee1e66468f Removed no longer required TODO 2013-10-17 15:05:06 -07:00
Vicențiu Ciorbaru
5acc057879 Roles mappings are now being kept consistent when acl_users gets modified.
No cascading changes take place during a user rename. This needs to be
addressed.
2013-10-17 15:03:58 -07:00
Vicențiu Ciorbaru
e876aa2b3b Fixed memory leak caused by user deletion, aswell as invalid free caused by
user creation.
2013-10-17 15:03:49 -07:00
Vicențiu Ciorbaru
7e18b8f1d6 Moved comment in code to correct place for rebuild_role_grants 2013-10-17 15:03:40 -07:00
Vicențiu Ciorbaru
de523f7fad Refactored function to allow for better code clarity. 2013-10-17 15:03:30 -07:00
Vicențiu Ciorbaru
887a1ac862 Implemented Roles Mappings association between users and roles.
No more memory leaks in the code.
2013-10-17 15:03:21 -07:00
Vicențiu Ciorbaru
deffce1ace Free some memory leaks
Still problems with hashtable acl_roles
Need to create a copy of grant_roles, currently it uses the same buffer
2013-10-17 15:03:12 -07:00
Vicențiu Ciorbaru
9e7228dc4a Added implementation for DYNAMIC_ARRAY in ACL_USER
TODO:
Memory allocated for the array is never freed
2013-10-17 15:02:55 -07:00
Vicențiu Ciorbaru
ba42300be0 Stripped whitespaces on all lines from sql/sql_acl.cc 2013-10-17 15:02:38 -07:00
Vicențiu Ciorbaru
71a504ca16 Whitespace fixes 2013-10-17 15:02:29 -07:00
Vicențiu Ciorbaru
dc4126657f Refactored ACL_USER:
Changed ACL_USER.user from char * to LEX_STRING.
Refactored every section that made use of ACL_USER.user as a char*.

This was done so as to be able to quickly check the hash_key of the acl_user.
2013-10-17 15:02:18 -07:00
Vicențiu Ciorbaru
fdc1669793 Fixed memory leaks.
role_grants is no longer used as it will be added to the ACL_USER class
2013-10-17 15:00:30 -07:00
Vicențiu Ciorbaru
aa465ac3ba Removed redundant #include "sql_hset.h"
It was a leftover from attempting to use Hash_set
2013-10-17 14:58:37 -07:00
Vicențiu Ciorbaru
dd5a98da35 Fixed key search in HASH table 2013-10-17 14:58:07 -07:00
Vicențiu Ciorbaru
e0c908ebe7 Changed acl_roles to be stored into a HASH.
There is an issue with correct searching of keys in the HASH.
2013-10-17 14:57:58 -07:00
Vicențiu Ciorbaru
334860cccf Added roles mapping internal structure creation
TODO: Free structures on flush
2013-10-17 14:57:49 -07:00
Vicențiu Ciorbaru
875617c089 Added separation between roles and users in the mysql.user table 2013-10-17 14:57:39 -07:00
Vicențiu Ciorbaru
9f512dca3c Initialized roles_mapping table. Performed a check to see if a mapping exists. 2013-10-17 14:57:22 -07:00
timour@askmonty.org
929466401e Removed extra empty line 2013-10-18 12:09:35 +03:00
timour@askmonty.org
afed809297 MDEV-5123 Remove duplicated conditions pushed both to join_tab->select_cond and join_tab->cache_select->cond for blocked joins.
BNL and BNLH joins pre-filter the records from a joined table via JOIN_TAB::cache_select->cond.
There is no need to re-evaluate the same conditions via JOIN_TAB::select_cond. This patch removes
the duplicated conditions from the top-level conjuncts of each pushed condition.

The added "Using where" in few EXPLAINs is due to taking into account tab->cache_select->cond
in addition to tab->select_cond in JOIN::save_explain_data_intern.
2013-10-18 11:45:25 +03:00
Alexander Barkov
adbb439358 Merge 5.5 -> 10.0-base 2013-10-21 13:43:45 +04:00