### Install vshard Module Example (Ubuntu) Source: https://github.com/tarantool/doc/blob/latest/doc/admin/modules.rst Example command to install the 'vshard' module on Ubuntu using apt-get. ```console $ sudo apt-get install tarantool-vshard ``` -------------------------------- ### Start Anonymous Replica Instances Source: https://github.com/tarantool/doc/blob/latest/doc/code_snippets/snippets/replication/instances.enabled/anonymous_replica/README.md Execute this command to start all instances for the anonymous replica setup. Ensure you are in the correct directory. ```bash tt start anonymous_replica ``` -------------------------------- ### Example of Global Options Preceding Command Source: https://github.com/tarantool/doc/blob/latest/doc/tooling/tt_cli/global_options.rst Global options for 'tt' must be passed before its commands and other options. This example shows the configuration file option preceding the 'start app' command. ```console $ tt --cfg tt-conf.yaml start app ``` -------------------------------- ### Install HTTP Module Source: https://github.com/tarantool/doc/blob/latest/doc/code_snippets/snippets/config/instances.enabled/application_role_http_api/README.md Install the necessary http module before starting the application. This command is run from the config directory. ```shell tt rocks install http ``` -------------------------------- ### MySQL Client Setup and Test Source: https://github.com/tarantool/doc/blob/latest/doc/reference/reference_rock/dbms.rst This example demonstrates setting up environment variables and checking for necessary MySQL client files and libraries on an Ubuntu system. It then shows how to connect to a MySQL server using the command-line client, create a table, insert data, and quit. ```console $ export TMDIR=~/mysql-5.5 $ # Check that the include subdirectory exists by looking $ # for .../include/mysql.h. (If this fails, there's a chance $ # that it's in .../include/mysql/mysql.h instead.) $ [ -f $TMDIR/include/mysql.h ] && echo "OK" || echo "Error" OK $ # Check that the library subdirectory exists and has the $ # necessary .so file. $ [ -f $TMDIR/lib/libmysqlclient.so ] && echo "OK" || echo "Error" OK $ # Check that the mysql client can connect using some factory $ # defaults: port = 3306, user = 'root', user password = '', $ # database = 'test'. These can be changed, provided one uses $ # the changed values in all places. $ $TMDIR/bin/mysql --port=3306 -h 127.0.0.1 --user=root \ --password= --database=test Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 25 Server version: 5.5.35 MySQL Community Server (GPL) ... Type 'help;' or '\h' for help. Type '\c' to clear ... $ # Insert a row in database test, and quit. mysql> CREATE TABLE IF NOT EXISTS test (s1 INT, s2 VARCHAR(50)); Query OK, 0 rows affected (0.13 sec) mysql> INSERT INTO test.test VALUES (1,'MySQL row'); Query OK, 1 row affected (0.02 sec) mysql> QUIT Bye $ # Install luarocks $ sudo apt-get -y install luarocks | grep -E "Setting up|already" Setting up luarocks (2.0.8-2) ... $ # Set up the Tarantool rock list in ~/.luarocks, $ # following instructions at rocks.tarantool.org $ mkdir ~/.luarocks $ echo "rocks_servers = {[[http://rocks.tarantool.org/]]}" >> \ ~/.luarocks/config.lua ``` -------------------------------- ### Start TCM with Environment Variables Source: https://github.com/tarantool/doc/blob/latest/doc/tooling/tcm/tcm_configuration.rst Example of setting TCM configuration parameters using environment variables and then starting the TCM executable. This method allows for dynamic configuration without modifying files. ```console $ export TCM_HTTP_HOST=0.0.0.0 $ export TCM_HTTP_PORT=8888 $ tcm ``` -------------------------------- ### Start TCM with Command-Line Arguments Source: https://github.com/tarantool/doc/blob/latest/doc/tooling/tcm/tcm_configuration.rst Example of starting TCM with configuration parameters passed directly as command-line arguments. This is useful for overriding other configuration sources or for one-off runs. ```console $ tcm --storage.etcd.embed.enabled --addon.enabled --http.host=0.0.0.0 --http.port=8888 ``` -------------------------------- ### Start all instances Source: https://github.com/tarantool/doc/blob/latest/doc/code_snippets/snippets/replication/instances.enabled/manual_leader/README.md Execute this command to start all instances for the manual leader configuration. ```console $ tt start manual_leader ``` -------------------------------- ### Tarantool startup console output Source: https://github.com/tarantool/doc/blob/latest/doc/platform/configuration/configuration_code.rst Example console output when starting Tarantool with an initialization file and arguments. This shows the configuration being applied and the server ready to accept requests. ```console $ export LISTEN_URI=3301 $ tarantool init.lua ARG ... main/101/init.lua C> Tarantool 2.8.3-0-g01023dbc2 ... main/101/init.lua C> log level 5 ... main/101/init.lua I> mapping 33554432 bytes for memtx tuple arena... ... main/101/init.lua I> recovery start ... main/101/init.lua I> recovering from './00000000000000000000.snap' ... main/101/init.lua I> set 'listen' configuration option to "3301" ... main/102/leave_local_hot_standby I> ready to accept requests Starting ARG ... main C> entering the event loop ``` -------------------------------- ### Detailed Initial Cluster Configuration with Etcd Source: https://github.com/tarantool/doc/blob/latest/doc/tooling/tcm/tcm_configuration.rst Provides a comprehensive example of configuring a cluster with etcd storage and Tarantool connection details for initial setup. ```yaml initial-settings: clusters: - name: My cluster description: Cluster description urls: - label: Test url: http://example.com storage-connection: provider: etcd etcd-connection: endpoints: - http://127.0.0.1:2379 username: "" password: "" prefix: /cluster1 tarantool-connection: username: guest password: "" ``` -------------------------------- ### Start All Instances Source: https://github.com/tarantool/doc/blob/latest/doc/code_snippets/snippets/replication/instances.enabled/auto_leader/README.md Execute this command to start all instances for the auto_leader configuration. ```bash tt start auto_leader ``` -------------------------------- ### Start Application Source: https://github.com/tarantool/doc/blob/latest/doc/code_snippets/snippets/replication/instances.enabled/supervised_failover/README.md Starts the application using the `tt start` command with the specified application name. ```console tt start supervised_failover ``` -------------------------------- ### Example Development Build Versions Source: https://github.com/tarantool/doc/blob/latest/doc/release/policy.rst Examples of development build version strings. ```text 2.10.2-149-g1575f3c07-dev 3.0.0-alpha1-14-gxxxxxxxxx-dev 3.0.0-entrypoint-17-gxxxxxxxxx-dev 3.1.2-5-gxxxxxxxxx-dev ``` -------------------------------- ### SET SESSION Output Example Source: https://github.com/tarantool/doc/blob/latest/doc/reference/reference_sql/sql_statements_and_clauses.rst Example output from a SET SESSION command. ```none --- - row_count: 1 ... ``` -------------------------------- ### Server-side push setup and client-side synchronous message reception Source: https://github.com/tarantool/doc/blob/latest/doc/reference/reference_lua/box_session/push.rst This example demonstrates setting up a server function that pushes a message using `box.session.push()` and a client that receives this message synchronously using `conn:call` with `on_push` and `on_push_ctx` options. The `fiber.sleep(1)` simulates work on the server before pushing the message. ```lua -- Make two shells. On Shell#1 set up a "server", and -- in it have a function that includes box.session.push: box.cfg{listen=3301} box.schema.user.grant('guest','read,write,execute','universe') x = 0 fiber = require('fiber') function server_function() x=x+1; fiber.sleep(1); box.session.push(x); end -- On Shell#2 connect to this server as a "client" that -- can handle Lua (such as another Tarantool server operating -- as a client), and initialize a table where we'll get messages: net_box = require('net.box') conn = net_box.connect(3301) messages_from_server = {} -- On Shell#2 remotely call the server function and receive -- a SYNCHRONOUS out-of-band message: conn:call('server_function', {}, {is_async = false, on_push = table.insert, on_push_ctx = messages_from_server}) messages_from_server -- After a 1-second pause that is caused by the fiber.sleep() -- request inside server_function, the result in the ``` -------------------------------- ### Start Master-Master Replication Source: https://github.com/tarantool/doc/blob/latest/doc/code_snippets/snippets/replication/instances.enabled/master_master/README.md Execute this command to start all instances configured for master-master replication. ```bash tt start master_master ``` -------------------------------- ### Run Go Sample Application Source: https://github.com/tarantool/doc/blob/latest/doc/code_snippets/snippets/connectors/go/README.md Execute this command in the `go` directory to start the sample application after setting up the database. ```bash go run . ``` -------------------------------- ### Verify Tarantool Installation Source: https://github.com/tarantool/doc/blob/latest/doc/contributing/building_from_source.rst Commands to start Tarantool in interactive mode after building from source, depending on whether it was installed locally. ```bash $ # if you installed tarantool locally after build $ tarantool ``` ```bash $ # - OR - $ # if you didn't install tarantool locally after build $ ./src/tarantool ``` -------------------------------- ### Start the application Source: https://github.com/tarantool/doc/blob/latest/doc/code_snippets/snippets/config/instances.enabled/metrics_plugins/README.md Start the sample application that exposes metrics. This command should be run from the config directory. ```shell tt start metrics_plugins ``` -------------------------------- ### Start All Instances of an Application Source: https://github.com/tarantool/doc/blob/latest/doc/tooling/tt_cli/start.rst Starts all instances of the 'app' application, adhering to its 'instances.yml' configuration. ```console $ tt start app ``` -------------------------------- ### Get HTTP Response Headers Source: https://github.com/tarantool/doc/blob/latest/doc/reference/reference_lua/http.rst Retrieve response headers using the `response_object.headers` option. This example shows how to get the 'ETag' header. ```lua local response = http.client.get(url) response.headers['ETag'] ``` -------------------------------- ### Start Sample DB Application Source: https://github.com/tarantool/doc/blob/latest/doc/code_snippets/snippets/connectors/instances.enabled/sample_db/README.md Execute this command to start the sample database application for testing connectors. ```console tt start sample_db ``` -------------------------------- ### Start and monitor OpenRC-managed Tarantool instance Source: https://github.com/tarantool/doc/blob/latest/doc/admin/os_notes.rst Start the OpenRC-managed Tarantool instance and monitor its logs. This is useful for verifying the instance is running correctly after setup. ```console $ /etc/init.d/your_service_name start $ tail -f -n 100 /var/log/tarantool/your_service_name.log ``` -------------------------------- ### Get Specific Instance Configuration Source: https://github.com/tarantool/doc/blob/latest/doc/release/3.1.0.rst Use config:get() with an instance name to retrieve its specific configuration values. This example fetches the 'iproto' configuration for 'storage-b-001'. ```tarantoolsession require('config'):get('iproto', {instance = 'storage-b-001'}) ``` -------------------------------- ### Start Instances for Bootstrap Strategy Source: https://github.com/tarantool/doc/blob/latest/doc/code_snippets/snippets/replication/instances.enabled/bootstrap_strategy/README.md Execute this command to start all instances configured for the bootstrap strategy. ```console tt start bootstrap_strategy ``` -------------------------------- ### Start Tarantool Instances Source: https://github.com/tarantool/doc/blob/latest/doc/code_snippets/snippets/replication/instances.enabled/box_info_synchro/README.md Use this command to start all instances defined in the box_info_synchro configuration. ```bash $ tt start box_info_synchro ``` -------------------------------- ### Start Tarantool Instance with Environment Variable Credentials Source: https://github.com/tarantool/doc/blob/latest/doc/code_snippets/snippets/config/instances.enabled/credentials_context_env/README.md After setting the necessary environment variables, start the Tarantool application using the 'tt start' command with the application name. ```bash $ tt start credentials_context_env ``` -------------------------------- ### Get Monotonic Time - Tarantool Lua Source: https://github.com/tarantool/doc/blob/latest/doc/reference/reference_lua/clock.rst Use clock.monotonic64() to get the number of nanoseconds since the start of the clock. This is useful for measuring elapsed time intervals. ```lua -- This will print nanoseconds since the start. clock = require('clock') print(clock.monotonic64()) ``` -------------------------------- ### Start Credentials Application Source: https://github.com/tarantool/doc/blob/latest/doc/code_snippets/snippets/config/instances.enabled/credentials/README.md Execute this command to start the application with the credentials configuration. Ensure you are in the correct directory. ```bash tt start credentials ``` -------------------------------- ### Start Specific Instance of an Application Source: https://github.com/tarantool/doc/blob/latest/doc/tooling/tt_cli/start.rst Starts the 'router' instance of the 'app' application. ```console $ tt start app:router ``` -------------------------------- ### Replicasets Setup Source: https://github.com/tarantool/doc/blob/latest/doc/tooling/tt_cli/cartridge.rst Sets up replica sets using a configuration file. Optionally bootstraps vshard during setup. ```console $ tt cartridge replicasets setup [--file FILEPATH] [--bootstrap-vshard] ``` -------------------------------- ### Get CPU Seconds Since Program Start using OS Module Source: https://github.com/tarantool/doc/blob/latest/doc/reference/reference_lua/osmodule.rst Measure the CPU time consumed by the program since its start using `os.clock()`. ```tarantoolsession tarantool> os.clock() --- - 0.05 ... ``` -------------------------------- ### Start New Instances Source: https://github.com/tarantool/doc/blob/latest/doc/platform/ddl_dml/migrations/extend_migrations_tt.rst Execute `tt start` to bring up the newly added instances in the cluster. ```console $ tt start myapp • The instance myapp:router-001-a (PID = 61631) is already running. • The instance myapp:storage-001-a (PID = 61632) is already running. • The instance myapp:storage-001-b (PID = 61634) is already running. • The instance myapp:storage-002-a (PID = 61639) is already running. • The instance myapp:storage-002-b (PID = 61640) is already running. • Starting an instance [myapp:storage-003-a]... • Starting an instance [myapp:storage-003-b]... ``` -------------------------------- ### Setting up and Running a Tarantool Application Source: https://github.com/tarantool/doc/blob/latest/doc/platform/app/creating_app/logging.rst This sequence demonstrates how to prepare your environment by listing files, installing necessary Tarantool modules, and then launching your application script. Ensure all dependencies are met before execution. ```console $ ls game.lua pokemon.lua $ sudo apt-get install tarantool-gis $ sudo apt-get install tarantool-avro-schema $ tarantool game.lua ``` -------------------------------- ### Get compat setup with compat.dump() Source: https://github.com/tarantool/doc/blob/latest/doc/reference/reference_lua/compat/compat_tutorial.rst Configures compat options and then serializes the setup. Obsolete options are not returned in serialization by default but can be included based on the argument passed to dump(). ```lua tarantool> compat({ > > obsolete_set_explicitly = 'new', > option_set_old = 'old', > option_set_new = 'new' > }) --- ``` ```lua tarantool> compat --- - - option_set_old: old - - option_set_new: new - - option_default_old: default (old) - - option_default_new: default (new) ... ``` ```lua # Obsolete options are not returned in serialization, but have the following values: # - obsolete_option_default: default (new) # - obsolete_set_explicitly: new # nil does output obsolete unset options as 'default' tarantool> compat.dump() --- - require('compat')({ option_set_old = 'old', option_set_new = 'new', option_default_old = 'default', option_default_new = 'default', obsolete_option_default = 'default', -- obsolete since X.Y obsolete_set_explicitly = 'default', -- obsolete since X.Y }) ``` ```lua # 'current' is the same as nil with default set to current values tarantool> compat.dump('current') --- - require('compat')({ option_set_old = 'old', option_set_new = 'new', option_default_old = 'old', option_default_new = 'new', obsolete_option_default = 'new', -- obsolete since X.Y obsolete_set_explicitly = 'new', -- obsolete since X.Y }) ``` ```lua # 'new' outputs obsolete as 'new'. tarantool> compat.dump('new') --- - require('compat')({ option_set_old = 'new', option_set_new = 'new', option_default_old = 'new', option_default_new = 'new', obsolete_option_default = 'new', -- obsolete since X.Y obsolete_set_explicitly = 'new', -- obsolete since X.Y }) ``` ```lua # 'old' outputs obsolete options as 'new'. tarantool> compat.dump('old') --- - require('compat')({ option_set_old = 'old', option_set_new = 'old', option_default_old = 'old', option_default_new = 'old', obsolete_option_default = 'new', -- obsolete since X.Y obsolete_set_explicitly = 'new', -- obsolete since X.Y }) ``` ```lua # 'default' does output obsolete options as default. tarantool> dump('default') --- - require('compat')({ option_set_old = 'default', option_set_new = 'default', option_default_old = 'default', option_default_new = 'default', obsolete_option_default = 'default', -- obsoleted since X.Y obsolete_set_explicitly = 'default', -- obsoleted since X.Y }) ``` -------------------------------- ### Start etcd Config Etcd Instance Source: https://github.com/tarantool/doc/blob/latest/doc/code_snippets/snippets/centralized_config/instances.enabled/config_etcd/README.md Execute this command to start the etcd-based configuration storage instance for the sample application. ```bash tt start config_etcd ``` -------------------------------- ### Good Git Commit Message Examples Source: https://github.com/tarantool/doc/blob/latest/doc/contributing/docs/git.rst Examples of effective commit messages that are concise, imperative, and start with a capital letter. These messages clearly convey the nature of the change without unnecessary details. ```git git commit -m "Expand section on msgpack" ``` ```git git commit -m "Add details on IPROTO_BALLOT" ``` ```git git commit -m "Create new structure" ``` ```git git commit -m "Improve grammar" ``` -------------------------------- ### Start Tarantool configuration storage Source: https://github.com/tarantool/doc/blob/latest/doc/platform/configuration/configuration_etcd.rst Use the 'tt start' command to initiate instances of the configured storage. ```console $ tt start tarantool_config_storage ``` -------------------------------- ### Example Cartridge Application Fix Source: https://github.com/tarantool/doc/blob/latest/doc/admin/upgrades/2.10.4.rst This example demonstrates how to integrate the illegal type name fixing logic within a Cartridge application. It shows where to place the trigger setup and how to remove them after the instance is configured. ```lua -- <..define before_replace function..> -- <..define on_schema_init function..> -- Set the trigger on _space. box.ctl.on_schema_init(on_schema_init) -- Init cartridge. The snapshot is recovered while configuration. cartridge.cfg(<...>) -- Delete the triggers. box.space._space:before_replace(nil, before_replace) box.ctl.on_schema_init(nil, on_schema_init) ``` -------------------------------- ### Create and Start a Fiber with fiber.create() Source: https://github.com/tarantool/doc/blob/latest/doc/reference/reference_lua/fiber.rst Use `fiber.create()` to immediately create and start a new fiber. The fiber begins execution as soon as it's created. This example demonstrates creating a fiber to print a greeting. ```lua -- app.lua -- fiber = require('fiber') function greet(name) print('Hello, '..name) end greet_fiber = fiber.create(greet, 'John') print('Fiber already started') ``` ```console $ tarantool app.lua Hello, John Fiber already started ``` -------------------------------- ### Run PHP Example Source: https://github.com/tarantool/doc/blob/latest/doc/connector/community/php.rst Command to execute the PHP example script. Ensure the tarantool PHP extension is loaded. ```console $ php -d extension=~/tarantool-php/modules/tarantool.so example.php ``` -------------------------------- ### Lua Configuration Get Method Example Source: https://github.com/tarantool/doc/blob/latest/doc/reference/reference_lua/config/utils_schema.rst This Lua snippet demonstrates how to retrieve configuration values using the schema object's get() method. It requires the configuration data and the full path to the desired node. ```lua local function apply -- Apply logic end local function stop -- Stop logic end ``` -------------------------------- ### Example instances.yaml for Development Source: https://github.com/tarantool/doc/blob/latest/doc/tooling/tt_cli/instance_config.rst This configuration file might include all instances defined in the cluster configuration for a developer's machine. ```yaml --- ``` -------------------------------- ### Start Custom Metrics Application Source: https://github.com/tarantool/doc/blob/latest/doc/code_snippets/snippets/config/instances.enabled/metrics_collect_custom/README.md Execute this command to start the sample application for collecting custom metrics. Ensure you are in the correct directory. ```shell tt start metrics_collect_custom ``` -------------------------------- ### Debug Example Execution Source: https://github.com/tarantool/doc/blob/latest/doc/reference/reference_lua/debug_facilities.rst Demonstrates the usage of debug.sourcedir(), debug.sourcefile(), debug.traceback(), and debug.getinfo() in a simple Lua script. This example shows how to obtain file paths, generate a stack traceback, and get the current line number. ```lua function w() print(debug.sourcedir()) print(debug.sourcefile()) print(debug.traceback()) print(debug.getinfo(1)['currentline']) end w() ``` -------------------------------- ### Initialize Database and Start Console Source: https://github.com/tarantool/doc/blob/latest/doc/platform/app/cookbook.rst Initializes the database using box.once() if it's the first run, creates a space and an index, and then starts the interactive console. ```lua #!/usr/bin/env tarantool -- Configure database box.cfg { listen = 3313 } box.once("bootstrap", function() box.schema.space.create('tweedledum') box.space.tweedledum:create_index('primary', { type = 'TREE', parts = {1, 'unsigned'}}) end) require('console').start() ``` -------------------------------- ### SQL COMMIT Statement Example Source: https://github.com/tarantool/doc/blob/latest/doc/reference/reference_sql/sql-features.rst Shows the COMMIT statement. Note that in Tarantool, START TRANSACTION must be issued before COMMIT. ```sql COMMIT; ``` -------------------------------- ### Get HTTP Response Cookies Source: https://github.com/tarantool/doc/blob/latest/doc/reference/reference_lua/http.rst Obtain response cookies using `response_object.cookies`. This example retrieves the 'session_id' cookie value. ```lua local response = http.client.get(url) response.cookies['session_id'] ``` -------------------------------- ### Get bucket information Source: https://github.com/tarantool/doc/blob/latest/doc/reference/reference_rock/vshard/vshard_storage.rst Retrieves detailed information about each bucket in storage. This example shows how to call the function and the expected output format. ```tarantoolsession tarantool> vshard.storage.buckets_info(1) --- - 1: status: active ref_rw: 1 ref_ro: 1 ro_lock: true rw_lock: true id: 1 ``` -------------------------------- ### Running the Net.box Sample Application Source: https://github.com/tarantool/doc/blob/latest/doc/code_snippets/snippets/connectors/net_box/README.md Execute this command to start the interactive session for the net.box sample application. Ensure a sample database is running and accessible remotely. ```console $ tt run -i net_box/myapp.lua ``` -------------------------------- ### Get OS Error Number and Message Source: https://github.com/tarantool/doc/blob/latest/doc/reference/reference_lua/errno.rst This example demonstrates how to capture and display the error number, its string representation, and its symbolic name after an OS-related operation fails. It uses `errno()` to get the last error code and `errno.strerror()` to get the corresponding message. It also shows how to find the symbolic name of the error by iterating through the errno metatable. ```tarantoolsession tarantool> function f() > local fio = require('fio') > local errno = require('errno') > fio.open('no_such_file') > print('errno() = ' .. errno()) > print('errno.strerror() = ' .. errno.strerror()) > local t = getmetatable(errno).__index > for k, v in pairs(t) do > if v == errno() then > print('errno() constant = ' .. k) > end > end > end --- ... tarantool> f() errno() = 2 errno.strerror() = No such file or directory errno() constant = ENOENT --- ... ``` -------------------------------- ### Start Tarantool Configuration Storage Instances Source: https://github.com/tarantool/doc/blob/latest/doc/code_snippets/snippets/centralized_config/instances.enabled/tarantool_config_storage/README.md Execute this command to start all instances of the configuration storage. Ensure you are in the correct directory. ```bash tt start tarantool_config_storage ``` -------------------------------- ### Start Tarantool Instance with Configuration File Source: https://github.com/tarantool/doc/blob/latest/doc/reference/tarantool_cli_options.rst Use this syntax to start a Tarantool instance configured via a YAML file. Specify the instance name and the path to the configuration file. ```console $ tarantool [OPTION ...] --name INSTANCE_NAME --config CONFIG_FILE_PATH ``` ```console $ tarantool --name router-a-001 --config config.yaml ``` -------------------------------- ### Profile Lua Code with Jit Off Source: https://github.com/tarantool/doc/blob/latest/doc/tooling/luajit_memprof.rst This example profiles specific Lua functions, ensuring allocations are captured by disabling JIT compilation before starting the profiler. It collects garbage, starts the profiler, runs payload code, collects garbage again, and stops the profiler. ```lua -- Prevent allocations on new traces. jit.off() local function concat(a) local nstr = a.."a" return nstr end local function format(a) local nstr = string.format("%sa", a) return nstr end collectgarbage() local binfile = "/tmp/memprof_"..(arg[0]):match("([^/]*).lua")..".bin" local st, err = misc.memprof.start(binfile) assert(st, err) -- Payload. for i = 1, 10000 do local f = format(i) local c = concat(i) end collectgarbage() local st, err = misc.memprof.stop() assert(st, err) os.exit() ``` -------------------------------- ### Full autoexpel Configuration Example Source: https://github.com/tarantool/doc/blob/latest/doc/reference/configuration/configuration_reference.rst This example demonstrates a complete configuration file including authentication, replication with autoexpel enabled, iproto listener, and group/replicaset definitions. It sets up instances that will be managed by the autoexpel logic. ```yaml credentials: users: guest: roles: [super] replication: failover: manual autoexpel: enabled: true by: prefix prefix: '{{ replicaset_name }}' iprot o: listen: - uri: 'unix/:./var/run/{{ instance_name }}.iproto' groups: g-001: replicasets: r-001: leader: r-001-i-001 instances: r-001-i-001: {} r-001-i-002: {} r-001-i-003: {} ``` -------------------------------- ### Docker Compose Log Output Example Source: https://github.com/tarantool/doc/blob/latest/doc/platform/app/creating_app/non-blockng_io.rst This is an example of the log output you might see when running the Docker Compose setup. It shows the sequence of operations performed by the client script, including creating a pokemon, making catch requests, and querying the map. ```console pclient_1 | Create pokemon <...> pclient_1 | {"result":true} pclient_1 | {"map":[{"id":1,"status":"active","location":{"y":2,"x":1},"name":"Pikachu","chance":99.100000}]} pclient_1 | Catch pokemon by player 2 pclient_1 | Catch pokemon by player 1 pclient_1 | Player 1 result: {"result":true} pclient_1 | Player 2 result: {"result":false} pclient_1 | {"map":[]} pokemon_pclient_1 exited with code 0 ``` -------------------------------- ### Beta Versioning Example Source: https://github.com/tarantool/doc/blob/latest/doc/release/policy.rst Illustrates the versioning format for beta releases in Tarantool. ```text MAJOR.MINOR.PATCH-betaN 3.0.0-beta1 3.0.0-beta2 ``` -------------------------------- ### Install Tarantool Go Connector Dependencies Source: https://github.com/tarantool/doc/blob/latest/doc/connector/go.rst Execute these go get commands to update the necessary dependencies for the Tarantool Go connector in your go.mod file. ```console $ go get github.com/tarantool/go-tarantool/v2 $ go get github.com/tarantool/go-tarantool/v2/decimal $ go get github.com/tarantool/go-tarantool/v2/uuid ``` -------------------------------- ### HTTP GET Request in Lua Source: https://github.com/tarantool/doc/blob/latest/doc/platform/app/cookbook.rst Use the http module to fetch data from a URL. Ensure the http rock is installed. Handles non-200 status codes. ```lua #!/usr/bin/env tarantool local http_client = require('http.client') local json = require('json') local r = http_client.get('https://api.frankfurter.app/latest?to=USD%2CRUB') if r.status ~= 200 then print('Failed to get currency ', r.reason) return end local data = json.decode(r.body) print(data.base, 'rate of', data.date, 'is', data.rates.RUB, 'RUB or', data.rates.USD, 'USD') ``` -------------------------------- ### SQL Modulus Operator Example Source: https://github.com/tarantool/doc/blob/latest/doc/reference/reference_sql/sql_user_guide.rst Calculates the remainder of the division of the first numeric operand by the second. Operands must be INTEGER or UNSIGNED starting from Tarantool version 2.10.1. ```sql 5 % 2 ``` -------------------------------- ### Configure Audit Log Pipe Destination Source: https://github.com/tarantool/doc/blob/latest/doc/reference/configuration/configuration_reference.rst Configure the audit log to be sent to a pipe, starting a specified program. This example uses 'cronolog' to manage log rotation. ```yaml audit_log: to: pipe pipe: 'cronolog audit_tarantool.log' ``` -------------------------------- ### Start Instances for SSL Replication Source: https://github.com/tarantool/doc/blob/latest/doc/code_snippets/snippets/replication/instances.enabled/ssl_without_ca/README.md Execute this command to start all instances configured for SSL replication without a CA. Ensure you are in the correct directory. ```bash tt start ssl_without_ca ``` -------------------------------- ### Display _space Contents (Tarantool Session) Source: https://github.com/tarantool/doc/blob/latest/doc/reference/reference_lua/box_space/_space.rst This is the output of the example() function in a typical Tarantool installation, showing the formatted string representation of fields from the _space system space. ```tarantoolsession tarantool> example() --- - - '272 1 _schema memtx 0 ' - '280 1 _space memtx 0 ' - '281 1 _vspace sysview 0 ' - '288 1 _index memtx 0 ' - '296 1 _func memtx 0 ' - '304 1 _user memtx 0 ' - '305 1 _vuser sysview 0 ' - '312 1 _priv memtx 0 ' - '313 1 _vpriv sysview 0 ' - '320 1 _cluster memtx 0 ' - '512 1 tester memtx 0 ' - '513 1 origin vinyl 0 ' - '514 1 archive memtx 0 ' ... ``` -------------------------------- ### SQL Example Session: Create, Insert, Select Source: https://github.com/tarantool/doc/blob/latest/doc/reference/reference_sql/sql_plus_lua.rst This example shows a complete SQL session for creating tables, inserting data, defining a view based on a join, and selecting data with filtering and ordering. It covers basic DDL and DML operations. ```sql CREATE TABLE t1 (c1 INTEGER PRIMARY KEY, c2 STRING); ``` ```sql CREATE TABLE t2 (c1 INTEGER PRIMARY KEY, x2 STRING); ``` ```sql INSERT INTO t1 VALUES (1, 'A'), (2, 'B'), (3, 'C'); ``` ```sql INSERT INTO t1 VALUES (4, 'D'), (5, 'E'), (6, 'F'); ``` ```sql INSERT INTO t2 VALUES (1, 'C'), (4, 'A'), (6, NULL); ``` ```sql CREATE VIEW v AS SELECT * FROM t1 NATURAL JOIN t2; ``` ```sql SELECT * FROM v WHERE c2 IS NOT NULL ORDER BY c1; ``` -------------------------------- ### Iterating after a specific tuple Source: https://github.com/tarantool/doc/blob/latest/doc/reference/reference_lua/box_index/pairs.rst This example shows how to iterate over tuples in the primary index starting from the one immediately after a specified tuple. It uses the 'after' option with the pairs() iterator. ```APIDOC ## Select all tuples after the specified tuple tarantool> for _, tuple in bands.index.primary:pairs({}, {after={7, 'The Doors', 1965}}) do print(tuple) end ``` -------------------------------- ### Systemd unit parameters example Source: https://github.com/tarantool/doc/blob/latest/doc/tooling/tt_cli/pack.rst An example of a systemd-unit-params.yml file, demonstrating how to set FdLimit and instance-env variables for systemd unit customization. ```yaml FdLimit: 200 instance-env: INSTANCE: "inst:%i" TARANTOOL_WORKDIR: "/tmp" ``` -------------------------------- ### Start Instance Source: https://github.com/tarantool/doc/blob/latest/doc/platform/replication/replication_tutorials/repl_bootstrap_auto.rst Use this command to start a specific Tarantool instance. Ensure you provide the correct instance name, including its project path if applicable. ```console $ tt start auto_leader:instance002 • Starting an instance [auto_leader:instance002]... ``` -------------------------------- ### HEX Function Example Source: https://github.com/tarantool/doc/blob/latest/doc/reference/reference_sql/sql_statements_and_clauses.rst Shows how to use the HEX function to get the hexadecimal representation of a byte sequence. Requires Tarantool version 2.10.0 or later for VARBINARY input. ```sql HEX(X'41') ``` ```sql HEX(CAST('Д' AS VARBINARY)) ``` -------------------------------- ### Prometheus scrape configuration Source: https://github.com/tarantool/doc/blob/latest/doc/admin/monitoring/getting_started.rst Example Prometheus scrape configuration to collect metrics from multiple Tarantool instances. This setup defines how Prometheus should discover and scrape metrics endpoints. ```yaml scrape_configs: - job_name: 'tarantool' static_configs: - targets: ['localhost:8081', 'localhost:8082'] ``` -------------------------------- ### Create table, insert data, and select rows Source: https://github.com/tarantool/doc/blob/latest/doc/reference/reference_sql/sql_user_guide.rst Demonstrates creating a table, inserting a record, and then querying the data using SQL statements executed via box.execute. ```lua box.execute([[CREATE TABLE things (id INTEGER PRIMARY key, remark STRING);]]) box.execute([[INSERT INTO things VALUES (55, 'Hello SQL world!');]]) box.execute([[SELECT * FROM things WHERE id > 0;]]) ``` -------------------------------- ### Pre-build script example Source: https://github.com/tarantool/doc/blob/latest/doc/tooling/tt_cli/build.rst This bash script runs before `tt rocks make` during the application build. It is useful for building non-standard rocks modules or installing dependencies from local projects. ```bash #!/bin/sh # The main purpose of this script is to build non-standard rocks modules. # The script will run before `tt rocks make` during application build. tt rocks make --chdir ./third_party/proj ``` -------------------------------- ### Start replica set instances Source: https://github.com/tarantool/doc/blob/latest/doc/platform/replication/replication_tutorials/repl_bootstrap_auto.rst Command to start all instances defined in the 'auto_leader' tt environment. ```console $ tt start auto_leader • Starting an instance [auto_leader:instance001]... • Starting an instance [auto_leader:instance002]... • Starting an instance [auto_leader:instance003]... ``` -------------------------------- ### Get Instance Configuration Info (Errors) Source: https://github.com/tarantool/doc/blob/latest/doc/reference/reference_lua/config.rst Retrieves the instance's configuration state when applied with errors. This example highlights an error due to an invalid value for the 'log.level' option. ```tarantoolsession app:instance001> require('config'):info('v2') --- - status: check_errors meta: last: [] active: [] alerts: - type: error message: '[cluster_config] log.level: Got 8, but only the following values are allowed: 0, fatal, 1, syserror, 2, error, 3, crit, 4, warn, 5, info, 6, verbose, 7, debug' timestamp: 2024-07-03T18:13:19.755454+0300 hierarchy: group: group-001 replicaset: replicaset-001 instance: instance-001 ... ``` -------------------------------- ### Create application with variables via --vars-file Source: https://github.com/tarantool/doc/blob/latest/doc/tooling/tt_cli/create.rst Example of creating an application from a template using the --vars-file option to provide variables from a file. ```console $ tt create template app --vars-file variables.txt ``` -------------------------------- ### Get Instance Configuration Info (Warnings) Source: https://github.com/tarantool/doc/blob/latest/doc/reference/reference_lua/config.rst Retrieves the instance's configuration state when applied with warnings. This example shows a warning related to granting privileges before a space is created. ```tarantoolsession app:instance001> require('config'):info('v2') --- - status: check_warnings meta: last: &0 [] active: *0 alerts: - type: warn message: box.schema.user.grant("sampleuser", "read,write", "space", "bands") has failed because either the object has not been created yet, a database schema upgrade has not been performed, or the privilege write has failed (separate alert reported) timestamp: 2024-07-03T18:09:18.826138+0300 hierarchy: group: group-001 replicaset: replicaset-001 instance: instance-001 ... ``` -------------------------------- ### SQL LIMIT Clause Examples Source: https://github.com/tarantool/doc/blob/latest/doc/reference/reference_sql/sql_statements_and_clauses.rst Illustrates the use of the LIMIT clause to specify the maximum number of rows and an optional OFFSET to start from. It also shows how LIMIT is applied to UNIONed results. ```sql -- simple case: SELECT * FROM t LIMIT 3; -- both limit and order: SELECT * FROM t LIMIT 3 OFFSET 1; -- applied to a UNIONed result (LIMIT clause must be the final clause): SELECT column1 FROM table1 UNION SELECT column1 FROM table2 ORDER BY 1 LIMIT 1; ``` -------------------------------- ### vshard.router.bootstrap() Source: https://github.com/tarantool/doc/blob/latest/doc/reference/reference_rock/vshard/vshard_router.rst Initializes the vshard router. This is a foundational step before other router operations can be performed. ```APIDOC ## vshard.router.bootstrap() ### Description Initializes the vshard router. ### Method Call ### Parameters None ### Response None ``` -------------------------------- ### Get Thread CPU Time - Tarantool Lua Source: https://github.com/tarantool/doc/blob/latest/doc/reference/reference_lua/clock.rst Use clock.thread64() to measure the CPU time spent by the current thread since its start. This is useful for analyzing thread-specific CPU consumption. ```lua -- This will print seconds in the thread since the start. clock = require('clock') print(clock.thread64()) ``` -------------------------------- ### Tarantool C# Hello World Example Source: https://github.com/tarantool/doc/blob/latest/doc/connector/community/csharp.rst A basic C# program demonstrating connection to a Tarantool server, fetching schema, accessing a space, and inserting a tuple. Ensure Tarantool is running on 127.0.0.1:3301 and the 'examples' space exists. ```csharp using System; using System.Threading.Tasks; using ProGaudi.Tarantool.Client; public class HelloWorld { static public void Main () { Test().GetAwaiter().GetResult(); } static async Task Test() { var box = await Box.Connect("127.0.0.1:3301"); var schema = box.GetSchema(); var space = await schema.GetSpace("examples"); await space.Insert((99999, "BB")); } } ``` -------------------------------- ### Get Processor CPU Time - Tarantool Lua Source: https://github.com/tarantool/doc/blob/latest/doc/reference/reference_lua/clock.rst Use clock.proc64() to measure the CPU time spent by the processor since the start. This is ideal for benchmarks that need to quantify CPU usage. ```lua -- This will print nanoseconds in the CPU since the start. clock = require('clock') print(clock.proc64()) ``` -------------------------------- ### Launch Tarantool Tutorial Source: https://github.com/tarantool/doc/blob/latest/doc/platform/app/launching_app.rst To launch the interactive Tarantool tutorial, use the 'tutorial()' command in the Tarantool console. ```tarantoolsession tarantool> tutorial() --- - | Tutorial -- Screen #1 -- Hello, Moon ==================================== Welcome to the Tarantool tutorial. It will introduce you to Tarantool’s Lua application server and database server, which is what’s running what you’re seeing. This is INTERACTIVE -- you’re expected to enter requests based on the suggestions or examples in the screen’s text. <...> ``` -------------------------------- ### Get the Next Value from a Sequence Source: https://github.com/tarantool/doc/blob/latest/doc/platform/ddl_dml/sequences.rst Retrieve the next value from the 'my_sequence' sequence. The first call returns the 'start' value, and subsequent calls increment by the 'step' value (default is 1). ```lua local next_val = box.schema.sequence.next('my_sequence') ``` -------------------------------- ### Iterate Tuples After a Specific Tuple Source: https://github.com/tarantool/doc/blob/latest/doc/reference/reference_lua/box_index/pairs.rst This example demonstrates how to retrieve all tuples that appear after a specified tuple in the primary index. It uses an empty table `{}` as the key and the `after` option to define the starting point for iteration. ```tarantoolsession -- Select all tuples after the specified tuple -- toolantool> for _, tuple in bands.index.primary:pairs({}, {after={7, 'The Doors', 1965}}) do print(tuple) end [8, 'Nirvana', 1987] [9, 'Led Zeppelin', 1968] [10, 'Queen', 1970] --- ... ``` -------------------------------- ### Finding rST Comments with grep Source: https://github.com/tarantool/doc/blob/latest/doc/contributing/docs/markup/intro.rst A console command example using 'grep' to find lines starting with the rST comment marker '.. //'. Useful for locating comments in source files. ```console $ grep -n "\.\. //" doc/reference/**/*.rst doc/reference/reference_lua/box.rst:47:.. // moved to "User Guide > 5. Server administration": doc/reference/reference_lua/box.rst:48:.. // /book/box/triggers ... ``` -------------------------------- ### Example: Using popen.shell, write, shutdown, read, and close Source: https://github.com/tarantool/doc/blob/latest/doc/reference/reference_lua/popen.rst Demonstrates a common workflow: creating a shell process, writing data to its stdin, shutting down stdin to signal EOF, reading the processed output, and finally closing the process handle. ```lua local popen = require('popen') local ph = popen.shell('sed s/foo/bar/', 'rw') ph:write('lorem foo ipsum') ph:shutdown({stdin = true}) local res = ph:read() ph:close() print(res) -- lorem bar ipsum ``` -------------------------------- ### LuaJIT: Get metrics for jit_trace_num and jit_trace_abort (no issues) Source: https://github.com/tarantool/doc/blob/latest/doc/tooling/luajit_getmetrics.rst This example demonstrates how to use misc.getmetrics() to retrieve jit_trace_num and jit_trace_abort values. It shows a baseline where the code does not cause significant JIT compilation issues. ```lua function f() jit.flush() for i = 1, 10 do collectgarbage("collect") end local oldm = misc.getmetrics() collectgarbage("collect") local sum = 0 for i = 1, 57 do sum = sum + 57 end for i = 1, 10 do collectgarbage("collect") end local newm = misc.getmetrics() print("trace_num = " .. newm.jit_trace_num - oldm.jit_trace_num) print("trace_abort = " .. newm.jit_trace_abort - oldm.jit_trace_abort) end f() ``` -------------------------------- ### Create Merger from Table Source Source: https://github.com/tarantool/doc/blob/latest/doc/reference/reference_lua/merger.rst Example demonstrating the creation of a merger object using `new_table_source` with a custom generator function. This setup is useful for processing data that can be iterated over, such as from a database or an external source. ```lua merger=require('merger') k=0 function merger_function(param) k = k + 1 if param[k] == nil then return nil end return box.NULL, param[k] end chunks={} chunks[1] = {{100}} chunks[2] = {{200}} chunks[3] = nil s = merger.new_table_source(merger_function, chunks) ```