Skip to content

Instantly share code, notes, and snippets.

View ochaton's full-sized avatar

Vladislav Grubov ochaton

View GitHub Profile
@ochaton
ochaton / replicator.lua
Last active October 29, 2020 23:05
Online parser of Tarantool 1.5 replication (working draft)
---
-- TODO:
-- Support all ops for update
-- Create separate module
local ffi = require 'ffi'
local fiber = require 'fiber'
ffi.cdef[[
struct header_v11 {
uint32_t header_crc32c;
@ochaton
ochaton / fibergc.lua
Last active November 3, 2020 21:03
Fibers collected by gc even if they still alive
#!/usr/bin/env tarantool
print(_G._TARANTOOL)
-- box.cfg{}
require 'jit.dump'.start("hotloop=1")
local fiber = require 'fiber'
local log = require 'log'
local json = require 'json'
json.cfg{ encode_use_tostring = true }
@ochaton
ochaton / orm_example.lua
Created November 14, 2020 12:31
Tarantool ORM interface
box.orm = require 'orm' . configure {
users = {
format = {
{ name = 'uid', type = 'unsigned' },
{ name = 'email', type = 'string' },
},
indexes = {
{ name = 'primary', parts = { 'uid' } },
{ name = 'email', parts = { 'email', 'uid' } },
},
@ochaton
ochaton / graph.lua
Created January 9, 2021 08:58
Dijkstra implementation
local type Distance = number
local type VertexId = number
local record Node
preds: {VertexId:Distance}
succs: {VertexId:Distance}
end
local node_mt: metatable<Node> = {
__index = Node,
@ochaton
ochaton / build_tarantool.sh
Last active January 16, 2021 10:48
Rebuilds all major tarantool versions
mkdir "$HOME/tarantool";
git clone --recurse-submodules https://github.com/tarantool/tarantool.git && cd tarantool;
for tag in $(git tag | sort | perl -lnE '$h{$mj}=$_ if (($mj) = $_=~m{^(1\.10|2\.\d+)\.\d+$});}{say join " ", sort keys %h'); do
echo "================== Installing $tag ================";
git clean -xdf .;
git checkout "$tag" \
&& git clean -xdf . \
&& git pull origin "$tag" \
&& git reset --hard "origin/$tag" \
&& git submodule update --init --recursive --force \
@ochaton
ochaton / basket.lua
Last active January 18, 2021 22:01
Eventually consistent Master-Master basket
#!/usr/bin/env tarantool
local uuid = require 'uuid'
local fun = require 'fun'
local fiber = require 'fiber'
local instance_name = assert(arg[1], "instance_name is required")
local config = {
replication = {'127.0.0.1:3301', '127.0.0.1:3302', '127.0.0.1:3303'},
replication_connect_quorum = 2,
@ochaton
ochaton / fun.d.tl
Created March 10, 2021 06:45
Teal: luafun
local record fun
record iterator<T>
sum: function(iterator<number>): number
reduce: function<R>(iterator<T>, (function(R, T): R), R): R
end
iter: function<T>({T}): iterator<T>
sum: function({number}): number
reduce: function<T,R>({T}, (function(R,T):R), R): R
@ochaton
ochaton / bench_ip_str_to_int.lua
Created June 2, 2021 08:33
convert ip from string to integer (LE) Benchmarks
local ffi = require 'ffi'
local ip = "127.1.2.3"
local p = ffi.cast('const uint8_t *', ip)
local ffi_string = ffi.string
local tonumber = tonumber
local getaddr_ffi = function(ip)
local prev = 0
@ochaton
ochaton / bad_tarantool.sh
Created July 6, 2021 16:45
Monitoring fiber of latency of single ev_once
> tarantool -l fiber -l clock -e 'fiber.create(function() while true do while clock.time() < fiber.time()+0.1 do end fiber.sleep(0.01) end end)' test.lua
entering the event loop
e:100.011µs p:0.017µs t:99.998µs
e:100.042µs p:0.010µs t:100.035µs
e:100.013µs p:0.015µs t:100.004µs
e:100.005µs p:0.006µs t:99.994µs
e:100.007µs p:0.004µs t:99.996µs
e:100.010µs p:0.009µs t:99.993µs
e:100.012µs p:0.016µs t:100.000µs
e:100.009µs p:0.050µs t:99.999µs
@ochaton
ochaton / .tarantoolctl
Created September 9, 2021 18:14
PoC: Tarantool logical replication ?
local workdir = './.tnt/'
require('fio').mkdir(workdir)
default_cfg = {
pid_file = workdir,
wal_dir = workdir,
snap_dir = workdir,
vinyl_dir = workdir,
logger = workdir,
}