Skip to content
Snippets Groups Projects
Commit bda72033 authored by ocelot-inc's avatar ocelot-inc
Browse files

trigger list, error.last, box.once

parent 3661ec6f
No related branches found
No related tags found
No related merge requests found
......@@ -62,10 +62,13 @@ be presented to the client as ``ER_PROC_LUA``.
.. function:: box.error.last()
Returns a description of the last error, as a Lua table
with three members: "type" (string) error's C++ class,
"message" (string) error's message, "code" (numeric) error's number.
with five members: "line" (number) Tarantool source file line number,
"code" (number) error's number,
"type", (string) error's C++ class,
"message" (string) error's message,
"file" (string) Tarantool source file.
Additionally, if the error is a system error (for example due to a
failure in socket or file io), there is a fourth member:
failure in socket or file io), there may be a sixth member:
"errno" (number) C standard error number.
rtype: table
......@@ -82,13 +85,18 @@ be presented to the client as ``ER_PROC_LUA``.
| :codenormal:`- error: Arbitrary message`
| :codenormal:`..`
|
| :codenormal:`tarantool>` :codebold:`box.schema.space.create('#')`
| :codenormal:`---`
| :codenormal:`- error: Invalid identifier '#' (expected letters, digits or an underscore)`
| :codenormal:`...`
| :codenormal:`tarantool>` :codebold:`box.error.last()`
| :codenormal:`---`
| :codenormal:`- type: ClientError`
| :codenormal:`message: Arbitrary message`
| :codenormal:`code: 555`
| :codenormal:`- line: 278`
| |nbsp| |nbsp| :codenormal:`code: 70`
| |nbsp| |nbsp| :codenormal:`type: ClientError`
| |nbsp| |nbsp| :codenormal:`message: Invalid identifier '#' (expected letters, digits or an underscore)`
| |nbsp| |nbsp| :codenormal:`file: /tmp/buildd/tarantool-1.6.6.252.g1654e31~precise/src/box/key_def.cc`
| :codenormal:`...`
|
| :codenormal:`tarantool>` :codebold:`box.error.clear()`
| :codenormal:`---`
| :codenormal:`...`
......
......@@ -30,8 +30,8 @@ All triggers have the following characteristics.
order that they were defined in.
* They must work `within the event context`. If the function contains requests
which normally could not occur immediately after the event but before the
return from the event, effects are undefined. For example, defining a trigger
function as ``os.exit()`` or ``box.rollback()`` would be bringing in requests
return from the event, effects are undefined. For example, putting
``os.exit()`` or ``box.rollback()`` in a trigger function would be bringing in requests
outside the event context.
* They are `replaceable`. The request to "redefine a trigger" consists of passing
the names of a new trigger function and an old trigger function to one of the
......@@ -194,7 +194,7 @@ is executed once after each insert.
The following series of requests will associate an existing function named F
with an existing space named T, associate the function a second time with the
same space (so it will be called twice), disable all triggers of T, and destroy
same space (so it will be called twice), disable all triggers of T, and delete
each trigger by replacing with ``nil``.
.. code-block:: lua
......@@ -210,14 +210,15 @@ each trigger by replacing with ``nil``.
===========================================================
The code :code:`on_connect()` -- with no arguments --
lists all connect-trigger functions;
:code:`on_auth()` lists all authentication-trigger functions;
:code:`on_disconnect()` lists all disconnect-trigger functions;
:code:`on_replace()` lists all replace-trigger functions.
returns a table of all connect-trigger functions;
:code:`on_auth()` returns all authentication-trigger functions;
:code:`on_disconnect()` returns all disconnect-trigger functions;
:code:`on_replace()` returns all replace-trigger functions.
In the following example a user finds that there are
three functions associated with :code:`on_connect`
triggers, and executes the third function, which happens to
contain the line "print('function #3')".
Then it deletes the third trigger.
| :codenormal:`tarantool>` :codebold:`box.session.on_connect()`
| :codenormal:`---`
......@@ -230,6 +231,9 @@ contain the line "print('function #3')".
| :codenormal:`function #3`
| :codenormal:`---`
| :codenormal:`...`
| :codenormal:`tarantool>` :codebold:`box.session.on_connect(nil,box.session.on_connect()[3])`
| :codenormal:`---`
| :codenormal:`...`
......
......@@ -143,6 +143,26 @@ If a primary server is started with :codenormal:`box.cfg{...logger =` :codeitali
then there will be lines in the log file, containing the word "relay",
when a replica connects or disconnects.
=====================================================================
Preventing Duplicate Actions
=====================================================================
Suppose that the replica tries to do something
that the master has already done. For example: |br|
:code:`box.schema.space.create('X')` |br|
This would cause an error, "Space X exists".
For this particular situation, the code could be changed to: |br|
:code:`box.schema.space.create('X',{if_not_exists=true})` |br|
But there is a more general solution: the
:samp:`box.once({key},{function})` method.
If :code:`box.once()` has been called before with the
same :codeitalic:`key` value, then :codeitalic:`function`
is ignored; otherwise :codeitalic:`function` is executed.
Therefore, actions which should only occur once during the
life of a replicated session should be placed in a function
which is executed via :code:`box.once()`. For example: |br|
:codebold:`function f() box.schema.space.create('X'); end` |br|
:codebold:`box.once('space_creator',f)`
=====================================================================
Master-Master Replication
......
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