summaryrefslogtreecommitdiff
path: root/storage/tokudb/doc/handlerton-lock
blob: 433380fdfa4cbcf7bca205f25219dee71216000d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
== Introduction ==

MySQL interfaces with TokuDB through a set of plugins, which, at
the time of this writing (October 2011) includes the tokudb storage
engine plugin, the user data information schema plugin, and the 
user data exact information schema plugin. Each plugin has its own
initialize and de-initialize functions for mysql to call when
clients install and uninstall them. 

== Problem == 

It was originally discovered that the two information schema plugins
would crash mysqld if the tokudb storage engine failed to init
properly. A quick fix for this problem was to have the storage engine
plugin's init function set a global flag, call it tokudb_hton_initialized,
which would be set if intialize succeeded. Other plugins could then check
it before proceeding. The original problem is fixed, but the following
still remain:

    * a client connects, uninstalls tokudb storage engine, accesses 
      the tokudb user data/exact table.

    * uninstall the tokudb engine plugin, drop a table, select from
      it to see that it does not exist, then install the tokudb engine
      to see that it has reappeared.

    * any situation where one client is using any plugin while another 
      client modifies one.

== Proposed solution ==

Use a reader-writer lock in the handlerton to protect the existing
tokudb_hton_initialized variable. All accesses to the handlerton (storage
engine, information schema, or otherwise) grab a read lock before
checking the initialized flag. Plugin initializers and de-initializers
grab a write lock on the initialized flag before writing to it, ensuring
no client is under the assumption that the handlerton is usable while
it is being brought offline.

== Implementation ==

{{{
#!c
tokudb_hton_init_func 
{
    grab_hton_init_writelock();
    ...
    tokudb_hton_initialized = 1;
error:
    release_hton_init_writelock();
}

tokudb_hton_done_func
{
    grab_hton_init_writelock();
    ...
    tokudb_hton_initialized = 0;
    release_hton_init_writelock();
}

tokudb_user_data_init_func
{
    grab_hton_init_readlock();
    ...
    release_hton_init_readlock();
}

tokudb_user_data_fill
{
    grab_hton_init_readlock();
    if (!tokudb_hton_initialized) {
        return error;
    }
    ...
error:
    release_hton_init_readlock();
}

tokudb_user_data_done_func
{
    grab_hton_init_readlock();
    ...
    release_hton_init_readlock();
}
}}}