Skip to content
Snippets Groups Projects
Commit 21ae9723 authored by Konstantin Osipov's avatar Konstantin Osipov
Browse files

Merge remote-tracking branch 'origin/stable'

Conflicts:
	doc/user/connectors.xml
	doc/user/language-reference.xml
	doc/user/stored-procedures.xml
parents b76b5280 96fc989d
No related branches found
No related tags found
No related merge requests found
......@@ -76,3 +76,124 @@ Display version information and exit.
=back
=head1 DESCRIPTION
Statements in alphabetical order
Although an initial statement may be entered on the tarantool command line, generally they are entered following the prompt in interactive mode while tarantool is running. (A prompt will be the name of the host and a greater-than sign, for example localhost>). The end-of-statement marker is a newline (line feed).
=over
=item CALL
Syntax: CALL procedure-identifier (). Effect: The client tells the server to execute the procedure identified by procedure-identifier. Example: CALL proc50(). Notes: The client sends to the server's read/write data port.
=item DELETE
Syntax: DELETE FROM tuple-set-name WHERE field-name = literal. Effect: Client tells server to delete the tuple identified by the WHERE clause. Example: DELETE FROM t0 WHERE k0='a'. Notes: field-name must identify the primary key. The client sends to the server's read/write data port after converting from SQL to binary protocol.
=item EXIT
Syntax: E[XIT]. Effect: The tarantool program stops. Example: EXIT. Notes: The QUIT statement does the same thing. The client sends nothing to the server.
=item HELP
Syntax: H[ELP]. Effect: Client displays a message including a list of possible statements. Example: HELP. Notes: The client sends nothing to the server.
=item INSERT
Syntax: INSERT [INTO] tuple-set-identifier VALUES (literal [,literal...]). Effect: The client tells the server to add the tuple consisting of the literal values. Example: INSERT INTO t0 VALUES ('a',0). Notes: The client sends to the server's read/write data port after converting from SQL to binary protocol.
=item LOADFILE
Syntax: LOADFILE string-literal. Effect: The client loads instructions from the file identified by string-literal. Example: LOADFILE '/home/tarantool_user/file5.txt'.
=item LUA
Syntax: LUA token [token...]. Effect: The client tells the server to execute the tokens as Lua statements. Example: LUA "hello".." world". Notes: The client sends to the server's administrative port.
=item PING
Syntax: PING. Effect: The client sends a ping to the server. Example: PING. Notes: The client sends to the server's read/write data port.
=item QUIT
Syntax: Q[UIT]. Effect: The client stops. This statement is handled entirely by the client. Example: QUIT. Notes: The EXIT statement does the same thing. The client sends nothing to the server.
=item RELOAD
Syntax: RELOAD CONFIGURATION. Effect: The client tells the server to re-read the configuration file. Example: RELOAD CONFIGURATION. Notes: The client sends to the server's administrative port.
=item REPLACE
Syntax; REPLACE [INTO] tuple-set-identifier VALUES (literal [,literal...]). Effect: The client tells the server to add the tuple consisting of the literal values. Example: REPLACE INTO t0 VALUES ('a',0). Notes: REPLACE and INSERT are the same, except that INSERT will return an error if a tuple already exists with the same primary key. The client sends to the server's read/write data port after converting from SQL to binary protocol.
=item SAVE
Syntax: SAVE COREDUMP | SNAPSHOT. Effect: The client tells the server to save the designated object. Example: SAVE SNAPSHOT. Notes: The client sends to the server's administrative port.
=item SELECT
Syntax: SELECT * FROM tuple-set-identifier WHERE field-identifier = literal [AND|OR field-identifier = literal...] [LIMIT numeric-literal [,numeric-literal]]. Effect: Client tells server to find the tuple or tuples identified in the WHERE clause. Example: SELECT * FROM t0 WHERE k0 = 5 AND k1 = 7 LIMIT 1. Notes: The client sends to the server's read/write data port.
=item SET
Syntax: SET INJECTION name-token state-token. Effect: In normal mode: error. Notes: This statement is only available in debug mode.
=item SETOPT
Syntax: SETOPT DELIMITER = string-literal. The string must be a value in single quotes. Effect: string becomes end-of-statement delimiter, so newline alone is not treated as end of statement. Example: SETOPT DELIMITER = '!'. Notes: The client sends nothing to the server.
Syntax: SETOPT PAGER = string-literal. The string must be a value in single quotes. Effect: string becomes the pager that will be invoked for subsequent commands; usually the values are '/usr/bin/less' or '/bin/more' for the common Linux pagers. Example: SETOPT PAGER = '/usr/bin/less'. Notes: The client sends nothing to the server.
=item SHOW
Syntax: SHOW CONFIGURATION | FIBER | INFO | INJECTIONS | PALLOC | PLUGINS | SLAB | STAT. Effect: The client asks the server for information about environment or statistics. Example: SHOW INFO. Notes: The client sends to the server's administrative port. SHOW INJECTIONS is only available in debug mode.
=item UPDATE
Syntax: UPDATE tuple-set-identifier SET field-identifier = literal [,field-identifier = literal...] WHERE field-identifier = literal. Effect: Client tells server to change the tuple identified in the WHERE clause. Example: UPDATE t1 SET k1= 'K', k2 = 7 WHERE k0 = 0. Notes: The client sends to the server's read/write data port after converting from SQL to binary protocol.
For a condensed Backus-Naur Form [BNF] description of some of the statements, see doc/box-protocol.txt and doc/sql.txt.
=back
=head1 EXAMPLES
Depending how one combines the tarantool client's options, there are in effect three modes of operation: "interactive", "print and play", or "replication" mode.
In interactive mode, one types statements and gets results. One can specify a statement file when starting (tarantool < file_name) or one can specify a statement file with the LOADFILE statement: (LOADFILE file_name), but typically the statements are typed in by the user following prompts. Here is an example of an interactive-mode tarantool client session:
$ tarantool
localhost> INSERT INTO t0 VALUES ('X-1',100)
Insert OK, 1 rows affected
localhost> INSERT INTO t0 VALUES ('X-2',200,'On Order')
Insert OK, 1 rows affected
localhost> INSERT INTO t0 VALUES ('X-3',300,'')
Insert OK, 1 rows affected
localhost> UPDATE t0 SET k1 = 300 WHERE k0 = 'X-1'
Update OK, 1 rows affected
localhost> DELETE FROM t0 WHERE k0 = 'X-2'
Delete OK, 1 rows affected
localhost> SELECT * FROM t0 WHERE k0 = 'X-1'
Select OK, 1 rows affected
['X-1', 300]
localhost> EXIT
$
In print and play mode, one uses --cat and --play and --from and --to and --space options to print write-ahead-log contents, or to send write-ahead-log contents to the server. Here is an example of a print-and-play-mode tarantool client session:
$ tarantool --cat /home/user1/tarantool_test/work_dir/00000000000000000005.xlog --from 22 --to 26
Insert, lsn: 22, time: 1385327353.345869, len: 33, space: 0, cookie: 127.0.0.1:44787 ['X-1', 100]
Insert, lsn: 23, time: 1385327353.346745, len: 42, space: 0, cookie: 127.0.0.1:44787 ['X-2', 200, 8243105135088135759]
Insert, lsn: 24, time: 1385327353.347352, len: 34, space: 0, cookie: 127.0.0.1:44787 ['X-3', 300, '']
Update, lsn: 25, time: 1385327353.348209, len: 42, space: 0, cookie: 127.0.0.1:44787 ['X-1']
Delete, lsn: 26, time: 1385327353.348879, len: 28, space: 0, cookie: 127.0.0.1:44787 ['X-2']
$
In replication mode, one connects as a replica, and then writes a binary log to a file.
This diff is collapsed.
......@@ -18,6 +18,9 @@ The Tarantool API exists so that a client program can send a request packet
to the server, and receive a response. Here is an example of a what the client
would send for <command>INSERT INTO t0 VALUES ('A','BB')</command>. The BNF description of the components
is in file <link xlink:href="https://github.com/tarantool/tarantool/blob/master/doc/box-protocol.txt" xlink:title="A complete BNF of Tarantool client/server protocol">doc/box-protocol.txt</link>.
A third-party contribution written in Lua for unpacking Tarantool messages is in file
<link xlink:href="https://github.com/negram/Tnt-dissector/blob/master/tarantool.dis.lua" xlink:title="tarantool.dis.lua">Tnt-dissector</link>.
</para>
<informaltable frame='topbot'>
<tgroup cols='5' align='left' colsep='1' rowsep='1'>
......@@ -345,33 +348,31 @@ catch (Exception $e) {
<section xml:id="connector-python">
<title>Python</title>
<para>
Here is a complete Python program that inserts ['A','BB'] into space[0] via the high-level Python API.
To prepare, paste the code into a file named example.py and say:<code>
export PYTHONPATH=<replaceable>tarantool-directory</replaceable>/test/lib</code>
where <replaceable>tarantool-directory</replaceable>/test/lib = the directory that contains
the necessary file <filename>box_connection.py</filename>. This will be
the directory where Tarantool Python library files were placed at installation time
for a source download.
Here is a complete Python program that inserts [99999,'BB'] into space[0] via the high-level Python API.
To prepare, paste the code into a file named example.py and install tarantool-python with either
<userinput><code>pip install tarantool</code></userinput> to install in <filename>/usr</filename> (requires root privilege)
or
<userinput><code>pip install tarantool --user</code></userinput> to install in <filename>~</filename> i.e. user's default directory.
Before trying to run, check that the server (tarantool_box) is running on localhost (127.0.0.1) and its primary port
is the default (33013) and space[0]'s primary key type is string (space[0].index[0].key_field[0].type = "STR" in configuration file).
To run, say <code>python example.py</code>.
The program will connect to the server, send the request, and display <quote>Insert OK, 1 row affected</quote> if all went well.
If the row already exists, the program will print <quote>Duplicate key exists in unique index 0</quote>.
The program will connect to the server, will send the request, and will not throw an exception if all went well.
If the row already exists, the program will throw DatabaseException(“Duplicate key exists in unique index 0”).
</para>
<programlisting language="python">
#!/usr/bin/python2
from box_connection import BoxConnection
#!/usr/bin/python
from tarantool import Connection
c = BoxConnection("127.0.0.1", 33013)
result = c.execute("INSERT INTO t0 VALUES ('A','BB')")
c = Connection("127.0.0.1", 33013)
result = c.insert(0,(99999,'BB'))
print result
</programlisting>
<para>
The example program only shows one command and does not show all that's necessary for
good practice. For that, please see
<link xlink:href="https://github.com/mailru/tarantool-python"><filename>http://github.com/mailru/tarantool-python</filename></link> and
<link xlink:href="https://github.com/zlobspb/txtarantool"><filename>https://github.com/zlobspb/txtarantool</filename></link>.
<link xlink:href="http://tarantool-python.readthedocs.org/en/latest/"><filename>http://tarantool-python.readthedocs.org/en/latest/</filename></link>.
For an example of a Python API for <link xlink:href="https://github.com/tarantool/queue">Queue managers on Tarantool</link>, see
<link xlink:href="https://github.com/tarantool/tarantool-queue-python"><filename>https://github.com/tarantool/tarantool-queue-python</filename></link>.
</para>
</section>
......
......@@ -236,13 +236,14 @@ fail: can't save snapshot, errno 17 (File exists)
</term>
<listitem><para>
<programlisting>
localhost> box.info()
<prompt>localhost&gt;</prompt> <userinput>show info</userinput>
---
info:
version: "1.4.5-128-ga91962c"
version: "1.5.2-8-g54a279d"
uptime: 441524
pid: 12315
logger_pid: 12316
snapshot_pid: 0
lsn: 15481913304
recovery_lag: 0.000
recovery_last_update: 1306964594.980
......@@ -273,8 +274,17 @@ info:
</varlistentry>
<varlistentry>
<term xml:id="box.stat.show" xreflabel="box.stat()">
<emphasis role="tntadmin">box.stat()</emphasis>
<term xml:id="show-index" xreflabel="SHOW INDEX">
<emphasis role="tntadmin">show index</emphasis>
</term>
<listitem><para>
Show the number of keys and the amount of memory used by each each index.
</para></listitem>
</varlistentry>
<varlistentry>
<term xml:id="box.stat.show" xreflabel="box.stat.show()">
<emphasis role="tntadmin">box.stat.show()</emphasis>
</term>
<listitem><para>
Show the average number of requests per second, and the
......@@ -314,6 +324,11 @@ statistics:
the % of <olink targetptr="slab_alloc_arena"/> that is
already distributed to the slab allocator.
</para>
<para>
<emphasis role="strong">bytes_waste</emphasis> contains
the amount of memory wasted by the slab allocator due to
internal fragmentation.
</para>
<para>
</para>
</listitem>
......
......@@ -37,7 +37,7 @@ a runnning tarantool_box server, and a running tarantool client.
<para>
<bridgehead renderas="sect4">Delimiter</bridgehead>
We'll be making functions which go over one line. We don't want the client to send to the server after every line.
So we <link linkend="client-reference-delim">declare a delimiter</link>.
So we <link linkend="utility-tarantool-delim">declare a delimiter</link>.
This means <quote>Do not send to the server until you see an exclamation mark.</quote>
<programlisting>
......@@ -56,7 +56,7 @@ lua function string_function()
return "hello world"
end!
</programlisting>
The word <link linkend="client-reference-lua">LUA</link>
The word <link linkend="utility-tarantool-lua">LUA</link>
is a Tarantool keyword that means <quote>we're about to go into Lua.</quote>
The function name is string_function.
The function has one executable statement, <code>return "hello world"</code>.
......@@ -69,7 +69,7 @@ To confirm that the function works, we can say
<programlisting>
call string_function()!
</programlisting>
The word <link linkend="client-reference-call">CALL</link> is a Tarantool keyword that means <quote>invoke the Lua function.</quote>
The word <link linkend="utility-tarantool-call">CALL</link> is a Tarantool keyword that means <quote>invoke the Lua function.</quote>
The effect is that the string which the function returns will end up on the screen.
</para>
......@@ -323,7 +323,7 @@ field will be 1. The second field will be a random 10-letter string.
Once again the string_function() can be invoked from main_function() which can be invoked with
call main_function(). But main_function() won't tell the whole story, because it does not
return t, it only puts t into the database. To confirm that something got inserted, we'll
use a <link linkend="client-reference-select">SELECT statement</link>.
use a <link linkend="utility-tarantool-select">SELECT statement</link>.
<programlisting>
call main_function()!
......
......@@ -19,7 +19,7 @@ two plugins that have already been created: the "SQL DBMS plugins" for
MySQL and PostgreSQL.
</para>
<para>
<para xml:id="plugin-sql-dbms-plugins">
<bridgehead renderas="sect4">SQL DBMS Plugins</bridgehead>
To call another DBMS from Tarantool, the essential requirements are:
another DBMS, and Tarantool.
......@@ -44,16 +44,22 @@ can work on both SQL and Tarantool inside the same Lua routine.
</para>
<para>
The connection method is
<code>box.net.sql.connect('mysql'|'postgresql', <replaceable>host</replaceable>, <replaceable>port</replaceable>, <replaceable>user</replaceable>, <replaceable>password</replaceable>, <replaceable>database</replaceable>)</code>.
The methods for select/insert/etc. are the same as the ones in <olink targetptr="sp-box-net-box">the box.net library</olink>.
</para>
<para xml:id="plugin-mysql-example">
<bridgehead renderas="sect4">MySQL Example</bridgehead>
This example assumes that MySQL 5.5 or MySQL 5.6 has been installed
(recent MariaDB versions should also work), and the mysqld server has
been started on the local host 127.0.0.1.
(recent MariaDB versions should also work).
</para>
<para>
The example was run on a Linux machine where the base directory
had a copy of the Tarantool source on ~/tarantool-stable, and
a copy of MySQL on ~/mysql-5.5. The mysqld server is already running.
a copy of MySQL on ~/mysql-5.5. The mysqld server is already running
on the local host 127.0.0.1.
</para>
<programlisting>
......@@ -93,7 +99,6 @@ Bye
<prompt>$ </prompt><userinput>rm CMakeCache.txt</userinput>
<prompt>$ </prompt><userinput>cmake . -DWITH_MYSQL=on -DMYSQL_INCLUDE_DIR=~/mysql-5.5/include -DMYSQL_LIBRARIES=~/mysql-5.5/lib/libmysqlclient.so -DENABLE_CLIENT=true</userinput>
...
-- PostgreSQL client not found, box.net.sql(pg) disabled
-- Found MySQL includes: ~/mysql-5.5/include/mysql.h
-- Found MySQL library: ~/mysql-5.5/lib/libmysqlclient.so
-- box.net.sql(mysql) INC=~/mysql-5.5/include
......@@ -161,10 +166,134 @@ plugins:
Call OK, 0 rows affected
# Observe the result. It contains "MySQL row".
# So this is the row that was inserted with the mysql client.
# So this is the row that was inserted into the MySQL database.
# And now it's been selected with the Tarantool client.
</programlisting>
<para xml:id="plugin-postgresql-example">
<bridgehead renderas="sect4">PostgreSQL Example</bridgehead>
This example assumes that a recent version of PostgreSQL has been installed.
The PostgreSQL library library and include files are also necessary.
On Ubuntu they can be installed with <programlisting><prompt>$ </prompt><userinput>sudo apt-get install libpq-dev</userinput></programlisting>
If that works, then cmake will find the necessary files without requiring any special user input.
However, because not all platforms are alike, for this example the assumption is
that the user must check that the appropriate PostgreSQL files are present and
must explicitly state where they are when building Tarantool from source.
</para>
<para>
The example was run on a Linux machine where the base directory
had a copy of the Tarantool source on ~/tarantool-stable, and
a copy of PostgreSQL on /usr. The postgres server is already running
on the local host 127.0.0.1.
</para>
<programlisting>
# Check that the include subdirectory exists by looking for /usr/include/postgresql/libpq-fe-h.
<prompt>$ </prompt><userinput>[ -f /usr/include/postgresql/libpq-fe.h ] &amp;&amp; echo "OK" || echo "Error"</userinput>
OK
# Check that the library subdirectory exists and has the necessary .so file.
<prompt>$ </prompt><userinput>[ -f /usr/lib/libpq.so ] &amp;&amp; echo "OK" || echo "Error"</userinput>
OK
# Check that the psql client can connect using some factory defaults:
# port = 5432, user = 'postgres', user password = 'postgres', database = 'postgres'.
# These can be changed, provided one changes them in all places.
# Insert a row in database postgres, and quit.
<prompt>$ </prompt><userinput>~psql -h 127.0.0.1 -p 5432 -U postgres -d postgres</userinput>
Password for user postgres:
psql (9.3.0, server 9.3.2)
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
Type "help" for help.
<prompt>postgres=#</prompt> <userinput>CREATE TABLE test (s1 INT, s2 VARCHAR(50));</userinput>
CREATE TABLE
<prompt>postgres=#</prompt> <userinput>INSERT INTO test VALUES (1,'PostgreSQL row');</userinput>
INSERT 0 1
<prompt>postgres=#</prompt> <userinput>\q</userinput>
<prompt>$ </prompt>
# Build the Tarantool server. Make certain that "cmake" gets the right
# paths for the PostgreSQL include directory and the PostgreSQL libpq
# library which were checked earlier.
<prompt>$ </prompt><userinput>cd ~/tarantool-stable</userinput>
<prompt>$ </prompt><userinput>make clean</userinput>
<prompt>$ </prompt><userinput>rm CMakeCache.txt</userinput>
<prompt>$ </prompt><userinput>cmake . -DWITH_POSTGRESQL=on -DPostgreSQL_LIBRARY=/usr/lib/libpq.so -DPostgreSQL_INCLUDE_DIR=/usr/include/postgresql -DENABLE_CLIENT=true</userinput>
...
-- Found PostgreSQL: /usr/lib/libpq.so
-- box.net.sql(pg): INC=/usr/include/postgresql;/usr/include/postgresql
-- box.net.sql(pg): LIBS=pq
...
-- Configuring done
-- Generating done
-- Build files have been written to: ~/tarantool-stable
<prompt>$ </prompt><userinput>make</userinput>
...
[ 49%] Built target core
[ 50%] Building CXX object src/plugin/pg/CMakeFiles/pg.dir/pg.cc.o
Linking CXX shared library libpg.so
[ 50%] Built target pg
...
[100%] Built target xlog
[100%] Built target man
<prompt>$ </prompt>
# Before starting Tarantool server, tell it where the PostgreSQL plugin is.
<prompt>$ </prompt><userinput>export TARANTOOL_PLUGIN_DIR=~/tarantool-stable/src/plugin/pg</userinput>
<prompt>$ </prompt>
# Start the Tarantool server.
# Run it in the background but let the initial display be in the foreground.
# So it's possible to see the message that the plugin was loaded.
<prompt>$ </prompt><userinput>~/tarantool-stable/src/box/tarantool_box&amp;</userinput>
2013-12-06 13:01:51.518 [23978] 1/sched C> version 1.5.1-290-g45b93e7
2013-12-06 13:01:51.520 [23978] 1/sched I> Loading plugin: ~/tarantool-stable/src/plugin/pg/libpg.so
2013-12-06 13:01:51.527 [23978] 1/sched I> Plugin 'postgresql' was loaded, version: 1
...
2013-12-06 13:01:51.531 [23978] 1/sched C> entering event loop
# Type 'Enter' and then start the Tarantool client.
<prompt>$ </prompt><userinput>~/tarantool-stable/client/tarantool/tarantool</userinput>
<prompt>localhost&gt; </prompt>
# Say <quote>show plugins</quote>. Since all has gone well, this is certain to work.
<prompt>localhost&gt; </prompt> <userinput>show plugins</userinput>
---
plugins:
- { name: "postgresql", version: 1 }
...
# Create a Lua function that will connect to the PostgreSQL server,
# retrieve one row, and display the row.
# For explanations of the statement types used here, read the
# Lua tutorial in the Tarantool user manual.
<prompt>localhost&gt; </prompt><userinput>SETOPT delimiter = '!'</userinput>
<prompt>localhost&gt; </prompt><userinput>lua function postgresql_select ()</userinput>
<prompt>-&gt; </prompt><userinput> local dbh = box.net.sql.connect('pg', '127.0.0.1', 5432, 'postgres', 'postgres', 'postgres')</userinput>
<prompt>-&gt; </prompt><userinput> local test = dbh:select('SELECT * FROM test WHERE s1 = 1')</userinput>
<prompt>-&gt; </prompt><userinput> for i, card in pairs(test) do</userinput>
<prompt>-&gt; </prompt><userinput> print(card.s2)</userinput>
<prompt>-&gt; </prompt><userinput> end</userinput>
<prompt>-&gt; </prompt><userinput> end!</userinput>
---
...
<prompt>localhost&gt; </prompt><userinput>SETOPT delimiter = ''!</userinput>
<prompt>localhost&gt; </prompt>
# Execute the Lua function.
<prompt>localhost&gt; </prompt><userinput>CALL postgresql_select()</userinput>
2013-12-06 13:07:45.893 [23978] 102/iproto I> PostgreSQL row
Call OK, 0 rows affected
# Observe the result. It contains "PostgreSQL row".
# So this is the row that was inserted into the PostgreSQL database.
# And now it's been selected with the Tarantool client.
</programlisting>
</appendix>
<!--
......
This diff is collapsed.
This diff is collapsed.
......@@ -392,6 +392,12 @@ These example scripts assume that the intent is to download from the master bran
the server and the client (but not the documentation), and run tests after build.
</para>
<para>
To build with SUSE 13.1, the steps are as described above, except that the appropriate YaST2 package names are:
binutils-devel, libuuid-devel, cmake, ncurses-devel, lynx, jing, libxml2-devel, docbook_5, saxon, libxslt-devel.
The python connector can be installed with <code>sudo easy_install pip</code> and <code>sudo pip install tarantool</code>.
</para>
</section>
<section xml:id="getting-started-start-stop">
<title>Starting Tarantool and making your first database</title>
......
......@@ -19,7 +19,6 @@
<xi:include href="proctitle.xml"/>
<xi:include href="errcode.xml"/>
<xi:include href="limitations.xml"/>
<xi:include href="client-reference.xml"/>
<xi:include href="lua-tutorial.xml"/>
<xi:include href="plugins.xml"/>
<!--
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment