Transactions

Manticore supports basic transactions when performing deleting and insertion into real-time and percolate tables. That is: each change to a table is first saved into an internal changeset, and then is actually committed to the table. By default each command is wrapped into an individual automatic transaction, making it transparent: you just ‘insert’ something, and can see the inserted result after it completes, having no care about transactions. However that behaviour can be explicitly managed by starting and committing transactions manually.

Transactions are supported for the following commands:

Transactions are not supported for:

Please also note, that transactions in Manticore do not aim to provide isolation. The idea of transactions in Manticore is to let you accumulate a number of writes and run them at once at commit or rollback them all if needed. Transactions are integrated with binary log which gives durability and consistency.

Automatic and manual mode

  1. SET AUTOCOMMIT = {0 | 1}

SET AUTOCOMMIT controls the autocommit mode in the active session. AUTOCOMMIT is set to 1 by default. With default you have not to care about transactions, since every statement that performs any changes on any table is implicitly wrapped into separate transaction. Setting it to 0 allows you to manage transactions manually. I.e., they will not be visible until you explicitly commit them.

Transactions are limited to a single RT or percolate table, and also limited in size. They are atomic, consistent, overly isolated, and durable. Overly isolated means that the changes are not only invisible to the concurrent transactions but even to the current session itself.

BEGIN, COMMIT, and ROLLBACK

  1. START TRANSACTION | BEGIN
  2. COMMIT
  3. ROLLBACK

BEGIN statement (or its START TRANSACTION alias) forcibly commits pending transaction, if any, and begins a new one.

COMMIT statement commits the current transaction, making all its changes permanent.

ROLLBACK statement rolls back the current transaction, canceling all its changes.

Examples

Automatic commits (default)

  1. insert into indexrt (id, content, title, channel_id, published) values (1, 'aa', 'blabla', 1, 10);
  2. Query OK, 1 rows affected (0.00 sec)
  3. select * from indexrt where id=1;
  4. +------+------------+-----------+--------+
  5. | id | channel_id | published | title |
  6. +------+------------+-----------+--------+
  7. | 1 | 1 | 10 | blabla |
  8. +------+------------+-----------+--------+
  9. 1 row in set (0.00 sec)

Inserted value immediately visible by following ‘select’ statement.

Manual commits (autocommit=0)

  1. set autocommit=0;
  2. Query OK, 0 rows affected (0.00 sec)
  3. insert into indexrt (id, content, title, channel_id, published) values (3, 'aa', 'bb', 1, 1);
  4. Query OK, 1 row affected (0.00 sec)
  5. insert into indexrt (id, content, title, channel_id, published) values (4, 'aa', 'bb', 1, 1);
  6. Query OK, 1 row affected (0.00 sec)
  7. select * from indexrt where id=3;
  8. Empty set (0.01 sec)
  9. select * from indexrt where id=4;
  10. Empty set (0.00 sec)

Here changes is NOT automatically committed. So, insertion is not visible even in the same session, since they’re not committed. Also, despite absent BEGIN statement, transaction is implicitly started.

So, let’s finally commit it:

  1. commit;
  2. Query OK, 0 rows affected (0.00 sec)
  3. select * from indexrt where id=4;
  4. +------+------------+-----------+-------+
  5. | id | channel_id | published | title |
  6. +------+------------+-----------+-------+
  7. | 4 | 1 | 1 | bb |
  8. +------+------------+-----------+-------+
  9. 1 row in set (0.00 sec)
  10. select * from indexrt where id=3;
  11. +------+------------+-----------+-------+
  12. | id | channel_id | published | title |
  13. +------+------------+-----------+-------+
  14. | 3 | 1 | 1 | bb |
  15. +------+------------+-----------+-------+
  16. 1 row in set (0.00 sec)

Now it is finished and visible.

Manual transaction

Using BEGIN and COMMIT you can define bounds of transaction explicitly, so no need to care about autocommit in this case.

  1. begin;
  2. Query OK, 0 rows affected (0.00 sec)
  3. insert into indexrt (id, content, title, channel_id, published) values (2, 'aa', 'bb', 1, 1);
  4. Query OK, 1 row affected (0.00 sec)
  5. select * from indexrt where id=2;
  6. Empty set (0.01 sec)
  7. commit;
  8. Query OK, 0 rows affected (0.01 sec)
  9. select * from indexrt where id=2;
  10. +------+------------+-----------+-------+
  11. | id | channel_id | published | title |
  12. +------+------------+-----------+-------+
  13. | 2 | 1 | 1 | bb |
  14. +------+------------+-----------+-------+
  15. 1 row in set (0.01 sec)

SET TRANSACTION

  1. SET TRANSACTION ISOLATION LEVEL { READ UNCOMMITTED
  2. | READ COMMITTED
  3. | REPEATABLE READ
  4. | SERIALIZABLE }

SET TRANSACTION statement does nothing. It was implemented to maintain compatibility with 3rd party MySQL client libraries, connectors, and frameworks that may need to run this statement when connecting. They just goes across syntax parser and then returns ‘ok’. Nothing usable for your own programs, just a stubs to make third-party clients happy.

  1. mysql> SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
  2. Query OK, 0 rows affected (0.00 sec)

✔ Searching

Introduction into searching with Manticore Search

Search is a key functionality of Manticore Search. You can:

General syntax

SQL:

  1. SELECT ... [OPTION <optionname>=<value> [ , ... ]]

HTTP:

  1. POST /search
  2. {
  3. "index" : "index_name",
  4. "options":
  5. {
  6. ...
  7. }
  8. }