mysql key value 引擎_mysql集成的key-value引擎-个人翻译
正如上文提到的,我們只是釋放出了一個技術預覽版。此功能目前只是mysql的一個插件,使用memcached協議。
If you would just like to get a brief introduction on the
setup steps, there is a “README-innodb_memcached” in the
mysql-5.6.2-labs-innodb-memcached package. This is a more
elaborated description on these steps.
如果你想獲取到更多關于安裝的介紹步驟,請查看README-innodb_memcached文件,這個文件在
mysql-5.6.2-labs-innodb-memcached內。里面有更詳細的介紹
1) Prerequisite:服務需求
Currently, the Memcached Daemon Plugin prototype is only
supported on Linux platform. And as a prerequisite, you must have
libevent installed, since it is required by memcached.
目前為止memcached守護進程插件只支持linux平臺,并且你需要安裝libevent,因為這個是memcached所需的
If you have the source code release, then there is a libevent
1.4.3 included in the package (plugin/innodb_memcached/libevent).
You can go to the directory and do autoconf, ./configure, make and
make install to make the libevent installed.
如果需要你可以去plugin/innodb_memcached/libevent來安裝libevent
1.4.3,只需配置./configure 然后make &make
install
2) Build the server編譯服務
Assuming you would like to build the server yourself
(otherwise, you can just skip this section), once libevent is
installed, you can just build the MySQL server as usual.
考慮到你可以更喜歡自己編譯源代碼來構建服務器,當然,如果不是可以跳過此章節,只要安裝了libevent,你可以按之前方式編譯mysql
Our source code is in the “plugin/innodb_memcached”
directory. As part of server build, it will generate two shared
libraries:
1) libmemcached.so: this is the memcached daemon plugin to
MySQL
2) innodb_engine.so: this is an InnoDB API plugin to
memcached
在plugin/innodb_memcached目錄下的文件編譯后會生成兩個公共庫
1) libmemcached.so 這個是mysql內的memcached插件
2)innodb_engine.so 這個是innodb調用memcached 的api插件
Make sure above two shared libraries are put in the MySQL
plugin directory. You can find MySQL plugin directory by doing
“select @@plugin_dir”:
確認將這兩個文件拷貝到mysql的插件目錄,你可以在mysql命令行下執行以下語句查找mysql插件保存地址
mysql> select @@plugin_dir;
+——————————————————————————-+
|
@@plugin_dir?|
+——————————————————————————-+
| /home/jy/work2/mysql-5.6-memcached-labs/lib/plugin |
+——————————————————————————-+
1 row in set (0.00 sec)
3) Install configuration tables:安裝創建表
Next, the memcached plugin needs a bit configuration to know
how to interact with InnoDB table. We have a configuration script
in “scripts/innodb_memcached_config.sql”. You can just install the
necessary configure tables by running?“mysql
< scripts/innodb_memcached_config.sql”. If you do
not like to know the detail of these configuration tables, you can
just skip this section.
下一步,memcached插件需要一些配置。我們有一個配置腳本在scripts/innodb_memcached_config.sql,你可以直接用mysql執行他即可完成所有的配置。下面我們會介紹他都添加了哪些表,如果你對此沒有興趣可以跳過此章節
This configure script installs 3 tables needed by the InnoDB
Memcached. These tables are created in a dedicated database
“innodb_memcache”. We will go over these three tables
in?a bit more detail:
這個腳本會添加三個表,這三個表是memcached插件所必須的,下面我們會詳細介紹下這三個表的用途
1) “containers” – This table is the most important table for
“Memcached – InnoDB mapping”. It describes the table used to store
the memcached values. Currently, we can only map memcached to one
table at a time. So essentially, there will be only one row in the
table. In the future, we would consider making this configuration
more flexible and dynamic, or user can map memcached operations to
multiple tables.
1)container 數據存儲表,這個表用于memcached -
innodb映射,這里將保存所有memcached的映射相關值,目前這個表只有一個,且數據只有一行。未來我們會考慮將這個配置的更靈活,比如用戶可以根據自定規則將值存儲到多個指定表。
The mapping is done through specifying corresponding column
values in the table:
“db_schema” and “db_table” columns describe the database and
table name for storing the memcached value.
“key_columns” describes the column (single column) name for
the column being used as “key” for the memcached operation
“value_columns” describes the columns (can be multiple) used
as “values” for the memcached operation. User can specify multiple
columns by separating them by comma (such as “col1, col2″
etc.)
“unique_idx_name_on_key” is the name of the index on the
“key” column. It must be a unique index. It can be primary or
secondary.
這個映射配置內有很多設置對應如下:
db_schema and
db_table行用來說明存儲memcached的值,table是指保存數據的表,而schema是存儲數據庫名
key_column 表內哪列用于key標識
value_columns 表內哪列用于保存key對應的值
unique_idx_name_on_key
這個是key_column指定的數據表內的key的索引名,必須是唯一索引,當然可以使用主鍵或二級索引
Above 5 column values (table name, key column, value column
and index) must be supplied. Otherwise, the setup will
fail.
Following are optional values, however, to fully comply with
memcached protocol, you will need these column values supplied
too.
“flags” describes the columns used as “flag” for memcached. It
also used as “column specifier” for some operations (such as incr,
prepend) if memcached “value” is mapped to multiple columns. So the
operation would be done on specified column. For example, if you
have mapped value to 3 columns, and only want the “increment”
operation performed on one of these columns, you can use flags to
specify which column will be used for these operations.
“cas_column” and “exp_column” are used specifically to store
the “cas” and “exp” value of memcached.
上面的5個設置必須提供,否則會失敗,下面的幾個選項可以選填
flag表示類似memcached的flag,他的用途用來表示某“列”比方說當memcached
映射的值包含多列。比如我們有三列,我們只想incr操作其中的一列,你可以通過flags指定哪行進行此操作
case_column以及exp_column是用來保存cas以及exp設置(這倆你知道的……查下cas以及超時)
2. Table “cache_policies” specifies whether we’ll use InnoDB
as the data store of memcached (innodb_only) or use memcached’s
“default engine” as the backstore (cache-only) or both (caching).
In the last case, only if the default engine operation fails, the
operation will be forwarded to InnoDB (for example, we cannot find
a key in the memory, then it will search InnoDB).
2.
表“cache_policies”制定了我們是否使用innodb保存數據,我們可以指定使用那種方式進行數據保存,如:使用innodb(innodb_only),使用memcached默認引擎(default
engine)并且不保存在innodb,或者使用memcached保存并使用innodb保存(caching)。在最后一個選項內,當默認引擎查詢失敗,查詢將會在innodb內查詢(如內存內沒有這個key的數據,他將會自動查詢innodb)
3) Table “config_options”, currently, we only support one
config option through this table. It is the “separator” used to
separate values of a long string into smaller values for multiple
columns values. For example, if you defined “col1, col2″ as value
columns. And you define “|” as separate, you could issue following
command in memcached to insert values into col1 and col2
respectively:
set keyx 10 0 19
valuecolx|valuecoly
So “valuecol1x” will send to col1 and valuecoly will send to
col2.
3.表"config_options"目前我們只在這提供了一個配置選項,此選項用于拆分"separator",當我們有一個很長的字符串,我們可以通過此功能把他拆分成多列內保存。比如定義“列1,列2”為value_COLUMNS
。"|"符號為分隔符的時候,我們可以使用下面命令把列1和列2內容分別插入
set keyx 10 0 19
列1|列2
這時列1值和列2值將會分別存在兩個對應順序的字段內
4) Example tables
Finally, as part of the configuration script, we created a
“demo_test” in the “test” database as an example. It also allows
the Daemon Memcached to work out of box, and no need to for any
additional configurations.
As you would notice, this “demo_test” table has more columns
than needed, so it would need the entries in the “container” table
to tell which column is used for what purpose as described
above.
4)示例表
最后,在我們的配置腳本內,他會自動建立一個 demo_test在test數據庫內。
當然這個可以直接使用,無需其他特殊配置
可能你會發現,這個表內有很多列超過了我們的需要。我們可以再container內自行更改下配置只保留我們用的
4) Install the Daemon Plugin(安裝守護插件)
The final step would be installing the daemon plugin. It is
the same as installing any other MySQL plugin:
最后一步就是安裝守護插件,這個步驟和安裝其他mysql插件一樣執行以下命令
mysql> install plugin daemon_memcached soname
“libmemcached.so”;
If you have any memcached specific configure parameters,
although it takes effect when the plugin is installed, you would
need to specify it during MySQL?server boot time
or enter them in the MySQL configure files.
如果你有任何附加的memcached插件配置參數,你可以把他放在mysql的配置文件。重啟mysql即可生效
For example, if you would like the memcached to listen on
port “11222″ instead of the default port “11211″, then you would
need to add “-p11222″ to MySQL system configure variable
“daemon_memcached_option”:
比如你想讓memcached監聽11222端口而非默認的11211端口,你需要指定
-p111222參數,到my.cnf內的daemon_memcached_option字段內寫法如下
mysqld …. –loose-daemon_memcached_option=”-p11222″.
Of course, you can add other memcached command line options
to “daemon_memcached_option” string.
The other configure options are:
1) daemon_memcached_engine_lib_name (default
“innodb_engine.so”)指定默認存儲引擎so文件
2) daemon_memcached_engine_lib_path (default NULL, the plugin
directory).指定memcached插件lib地址
當然,你可以增加其他命令行參數到配置內如上
By default, you do not need to set/change anything with these
two configure option. We have above two configure options because
they allow you to load any other storage engine for memcached (such
as NDB memcached engine). This opens door for more interesting
exploration.
總的來說你不需要改變上面兩個參數。我們提供者兩個參數是為了提供其他存儲引擎給memcached,如NDB
存儲引擎,這樣可以提供更多有趣的體驗。
3) daemon_memcached_r_batch_size, batch commit size for read
operation (get operations. It specifies after how many ops we will
do a commit. By default, this is set as a very large number,
1048576.
守護進程的讀取操作批量更新(每多少次操作后將會做一次數據提交到存儲引擎,默認會設置很大如1048576)
4) daemon_memcached_w_batch_size, batch commit for any write
operations (set, replace, append, prepend, incr, decr etc.) By
default, this is set as 32.
多少次寫操作后才會更新存儲引擎,默認32
Again, please note that you will have these configuration
parameter in your MySQL configure file or MySQL boot command line.
And they will take effect when you load the memcached
plugin.
另外,注意,當你在命令行啟動mysql服務或者在配置文件內指定,都會改變memcached插件的配置
5) Start to play:
Now you have everything set up, you can start to
play:
現在我們可以玩一下拉~
telnet 127.0.0.1 11211
使用telnet連11211端口(memcached協議都可以直接這么玩)
set a11 10 0 9
123456789
STORED
get a11
VALUE a11 0 9
123456789
END
You can access the InnoDB table (“demo_test”) through the
standard SQL interfaces. However, there are some catches:
1) If you would like to take a look at what’s in the
“demo_test” table, please remember we had batched the commits (32
ops by default) by default. So you will need to do “read
uncommitted” select to find the just inserted rows:
這時你可以訪問innodb表“demo_test”去看下里面的內容,另外要注意,我們上面設置了寫操作執行了32次后才會保存同步一次數據到存儲引擎,所以你必須使用讀取未提交數據來列出
mysql> set session TRANSACTION ISOLATION
LEVEL
-> read uncommitted;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from demo_test;
+——+——+——+——+———–+——+——+——+——+——+——+
| cx?|
cy?|
c1?|
cz?|
c2?| ca?|
CB?|
c3?|
cu?|
c4?|
C5?|
+——+——+——+——+———–+——+——+——+——+——+——+
| NULL | NULL | a11?| NULL | 123456789 | NULL |
NULL |?10 | NULL
|?3 | NULL
|
+——+——+——+——+———–+——+——+——+——+——+——+
1 row in set (0.00 sec)
2) The InnoDB table would be IS (shared intention) or IX
(exclusive intentional) locked for all operations in a transaction.
So unless you change “daemon_memcached_r_batch_size” and
“daemon_memcached_w_batch_size” to small number (like 1), the table
is most likely intentionally locked between each operations. So you
cannot do any DDL on the table.
當innodb在提交同步事務中,他將會使用鎖鎖定表,所以當你把“daemon_memcached_r_batch_size”
and
“daemon_memcached_w_batch_size”設置的值十分低的時候(如1)將會導致innodb頻繁的鎖表,所以你無法做任何DDL操作到表上
Summary
Now you have everything setup. And you can directly interact
with InnoDB storage engine through Memcached interfaces. In
addition, as you might notice while going through this extended
“README”, we still have a lot interesting options open for
exploration and enhancement. This is the beginning
of?opening InnoDB to the outside world, and NoSQL
is a perfect place for it to play.
總結
沒啥了……
總結
以上是生活随笔為你收集整理的mysql key value 引擎_mysql集成的key-value引擎-个人翻译的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 安装破解VS2015(破解使用秘钥)
- 下一篇: 尼康相机报错err_数码相机遇到这12种