@@ -44,6 +44,8 @@ struct version_token_st {
44
44
};
45
45
46
46
47
+ #define VTOKEN_LOCKS_NAMESPACE " version_token_locks"
48
+
47
49
static HASH version_tokens_hash;
48
50
49
51
static MYSQL_THDVAR_ULONG (session_number,
@@ -169,18 +171,18 @@ PLUGIN_EXPORT my_bool version_tokens_delete_init(UDF_INIT *initid,
169
171
PLUGIN_EXPORT char *version_tokens_delete (UDF_INIT *initid, UDF_ARGS *args,
170
172
char *result, unsigned long *length,
171
173
char *null_value, char *error);
172
- PLUGIN_EXPORT my_bool vtoken_get_read_locks_init (UDF_INIT *initid, UDF_ARGS *args,
173
- char *message);
174
- PLUGIN_EXPORT long long vtoken_get_read_locks (UDF_INIT *initid, UDF_ARGS *args,
175
- char *is_null, char *error);
176
- PLUGIN_EXPORT my_bool vtoken_get_write_locks_init (UDF_INIT *initid, UDF_ARGS *args,
177
- char *message);
178
- PLUGIN_EXPORT long long vtoken_get_write_locks (UDF_INIT *initid, UDF_ARGS *args,
179
- char *is_null, char *error);
180
- PLUGIN_EXPORT my_bool vtoken_release_locks_init (UDF_INIT *initid, UDF_ARGS *args,
181
- char *message);
182
- PLUGIN_EXPORT long long vtoken_release_locks (UDF_INIT *initid, UDF_ARGS *args,
183
- char *is_null, char *error);
174
+ PLUGIN_EXPORT my_bool version_tokens_lock_shared_init (
175
+ UDF_INIT *initid, UDF_ARGS *args, char *message);
176
+ PLUGIN_EXPORT long long version_tokens_lock_shared (
177
+ UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error);
178
+ PLUGIN_EXPORT my_bool version_tokens_lock_exclusive_init (
179
+ UDF_INIT *initid, UDF_ARGS *args, char *message);
180
+ PLUGIN_EXPORT long long version_tokens_lock_exclusive (
181
+ UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error);
182
+ PLUGIN_EXPORT my_bool version_tokens_unlock_init (
183
+ UDF_INIT *initid, UDF_ARGS *args, char *message);
184
+ PLUGIN_EXPORT long long version_tokens_unlock (
185
+ UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error);
184
186
185
187
enum command {
186
188
SET_VTOKEN= 0 ,
@@ -335,7 +337,7 @@ static int parse_vtokens(char *input, enum command type)
335
337
{
336
338
version_token_st *token_obj;
337
339
char error_str[MYSQL_ERRMSG_SIZE];
338
- if (!mysql_acquire_locking_service_locks (NULL , " version_token_locks " ,
340
+ if (!mysql_acquire_locking_service_locks (NULL , VTOKEN_LOCKS_NAMESPACE ,
339
341
(const char **) &(token_name.str ), 1 ,
340
342
LOCKING_SERVICE_READ, 1 ) && !vtokens_unchanged)
341
343
{
@@ -443,7 +445,7 @@ static void version_token_check(MYSQL_THD thd,
443
445
}
444
446
case MYSQL_AUDIT_GENERAL_STATUS:
445
447
{
446
- mysql_release_locking_service_locks (NULL , " version_token_locks " );
448
+ mysql_release_locking_service_locks (NULL , VTOKEN_LOCKS_NAMESPACE );
447
449
break ;
448
450
}
449
451
default :
@@ -517,7 +519,7 @@ mysql_declare_plugin(version_tokens)
517
519
PLUGIN_LICENSE_GPL,
518
520
version_tokens_init, /* init function (when loaded) */
519
521
version_tokens_deinit, /* deinit function (when unloaded) */
520
- 0x0100 , /* version */
522
+ 0x0101 , /* version */
521
523
NULL , /* status variables */
522
524
system_variables, /* system variables */
523
525
NULL ,
@@ -943,45 +945,61 @@ static inline my_bool init_acquire(UDF_INIT *initid, UDF_ARGS *args, char *messa
943
945
return FALSE ;
944
946
}
945
947
946
- PLUGIN_EXPORT my_bool vtoken_get_read_locks_init (UDF_INIT *initid, UDF_ARGS *args,
947
- char *message)
948
+ PLUGIN_EXPORT my_bool version_tokens_lock_shared_init (
949
+ UDF_INIT *initid, UDF_ARGS *args, char *message)
948
950
{
949
951
return init_acquire (initid, args, message);
950
952
}
951
953
952
954
953
- PLUGIN_EXPORT long long vtoken_get_read_locks (UDF_INIT *initid, UDF_ARGS *args,
954
- char *is_null, char *error)
955
+ PLUGIN_EXPORT long long version_tokens_lock_shared (
956
+ UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
955
957
{
956
958
long long timeout= *((long long *)args->args [args->arg_count - 1 ]);
959
+
960
+ if (timeout < 0 || timeout > ULONG_MAX)
961
+ {
962
+ my_error (ER_DATA_OUT_OF_RANGE, MYF (0 ), " timeout" ,
963
+ " version_tokens_lock_shared" );
964
+ *error= 1 ;
965
+ }
966
+
957
967
// For the UDF 1 == success, 0 == failure.
958
- return !acquire_locking_service_locks (NULL , " version_token_locks " ,
968
+ return !acquire_locking_service_locks (NULL , VTOKEN_LOCKS_NAMESPACE ,
959
969
const_cast <const char **>(&args->args [0 ]),
960
970
args->arg_count - 1 ,
961
- LOCKING_SERVICE_READ, timeout);
971
+ LOCKING_SERVICE_READ, ( unsigned long ) timeout);
962
972
}
963
973
964
974
965
- PLUGIN_EXPORT my_bool vtoken_get_write_locks_init (UDF_INIT *initid, UDF_ARGS *args,
966
- char *message)
975
+ PLUGIN_EXPORT my_bool version_tokens_lock_exclusive_init (
976
+ UDF_INIT *initid, UDF_ARGS *args, char *message)
967
977
{
968
978
return init_acquire (initid, args, message);
969
979
}
970
980
971
981
972
- PLUGIN_EXPORT long long vtoken_get_write_locks (UDF_INIT *initid, UDF_ARGS *args,
973
- char *is_null, char *error)
982
+ PLUGIN_EXPORT long long version_tokens_lock_exclusive (
983
+ UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
974
984
{
975
985
long long timeout= *((long long *)args->args [args->arg_count - 1 ]);
986
+
987
+ if (timeout < 0 || timeout > ULONG_MAX)
988
+ {
989
+ my_error (ER_DATA_OUT_OF_RANGE, MYF (0 ), " timeout" ,
990
+ " version_tokens_lock_exclusive" );
991
+ *error= 1 ;
992
+ }
993
+
976
994
// For the UDF 1 == success, 0 == failure.
977
- return !acquire_locking_service_locks (NULL , " version_token_locks " ,
995
+ return !acquire_locking_service_locks (NULL , VTOKEN_LOCKS_NAMESPACE ,
978
996
const_cast <const char **>(&args->args [0 ]),
979
997
args->arg_count - 1 ,
980
- LOCKING_SERVICE_WRITE, timeout);
998
+ LOCKING_SERVICE_WRITE, ( unsigned long ) timeout);
981
999
}
982
1000
983
- PLUGIN_EXPORT my_bool vtoken_release_locks_init (UDF_INIT *initid, UDF_ARGS *args,
984
- char *message)
1001
+ PLUGIN_EXPORT my_bool version_tokens_unlock_init (
1002
+ UDF_INIT *initid, UDF_ARGS *args, char *message)
985
1003
{
986
1004
THD *thd= current_thd;
987
1005
@@ -1001,11 +1019,11 @@ PLUGIN_EXPORT my_bool vtoken_release_locks_init(UDF_INIT *initid, UDF_ARGS *args
1001
1019
}
1002
1020
1003
1021
1004
- long long vtoken_release_locks (UDF_INIT *initid, UDF_ARGS *args,
1022
+ long long version_tokens_unlock (UDF_INIT *initid, UDF_ARGS *args,
1005
1023
char *is_null, char *error)
1006
1024
{
1007
1025
// For the UDF 1 == success, 0 == failure.
1008
- return !release_locking_service_locks (NULL , " version_token_locks " );
1026
+ return !release_locking_service_locks (NULL , VTOKEN_LOCKS_NAMESPACE );
1009
1027
}
1010
1028
1011
1029
0 commit comments