Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
picodata
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
core
picodata
Commits
50f047ef
Commit
50f047ef
authored
1 year ago
by
Yaroslav Dynnikov
Browse files
Options
Downloads
Patches
Plain Diff
doc: finalize lua help enhancements
parent
760cbb3b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!575
doc: advance lua help
Pipeline
#19886
passed
1 year ago
Stage: test
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/luamod.rs
+137
-95
137 additions, 95 deletions
src/luamod.rs
test/int/test_uninitialized.py
+3
-0
3 additions, 0 deletions
test/int/test_uninitialized.py
with
140 additions
and
95 deletions
src/luamod.rs
+
137
−
95
View file @
50f047ef
...
@@ -48,7 +48,7 @@ pub(crate) fn setup(args: &args::Run) {
...
@@ -48,7 +48,7 @@ pub(crate) fn setup(args: &args::Run) {
A string variable (not a function) contatining Picodata version
A string variable (not a function) contatining Picodata version
which follows the Calendar Versioning convention with the
which follows the Calendar Versioning convention with the
`YY.0M.MICRO` scheme
.
`YY.0M.MICRO` scheme
:
https://calver.org/#scheme
https://calver.org/#scheme
...
@@ -216,7 +216,8 @@ pub(crate) fn setup(args: &args::Run) {
...
@@ -216,7 +216,8 @@ pub(crate) fn setup(args: &args::Run) {
(table)
(table)
or
or
(nil) if the raft node is not initialized yet
(nil, string) in case of an error, if the raft node is
not initialized yet
Fields:
Fields:
...
@@ -238,7 +239,7 @@ pub(crate) fn setup(args: &args::Run) {
...
@@ -238,7 +239,7 @@ pub(crate) fn setup(args: &args::Run) {
id: 1
id: 1
...
...
"
},
"
},
tlua
::
function0
(||
traft
::
node
::
global
()
.
ok
()
.
map
(|
n
|
n
.status
())),
tlua
::
function0
(||
traft
::
node
::
global
()
.map
(|
n
|
n
.status
())),
);
);
luamod_set
(
luamod_set
(
...
@@ -285,9 +286,10 @@ pub(crate) fn setup(args: &args::Run) {
...
@@ -285,9 +286,10 @@ pub(crate) fn setup(args: &args::Run) {
(number)
(number)
or
or
(nil) if the raft node is not initialized yet
(nil, string) in case of an error, if the raft node is
not initialized yet
"
},
"
},
tlua
::
function0
(||
traft
::
node
::
global
()
.
ok
()
.
map
(|
n
|
n
.get_index
())),
tlua
::
function0
(||
traft
::
node
::
global
()
.map
(|
n
|
n
.get_index
())),
);
);
luamod_set
(
luamod_set
(
&
l
,
&
l
,
...
@@ -776,7 +778,8 @@ pub(crate) fn setup(args: &args::Run) {
...
@@ -776,7 +778,8 @@ pub(crate) fn setup(args: &args::Run) {
============================
============================
Trims raft log up to the given index (excluding the index itself).
Trims raft log up to the given index (excluding the index itself).
Returns the new `first_index` after the log compaction.
Returns the new first_index after the log compaction. Returns when
transaction is committed to the local storage.
Params:
Params:
...
@@ -803,18 +806,22 @@ pub(crate) fn setup(args: &args::Run) {
...
@@ -803,18 +806,22 @@ pub(crate) fn setup(args: &args::Run) {
pico.cas(dml[, predicate])
pico.cas(dml[, predicate])
==========================
==========================
Performs a clusterwide compare and swap operation.
Performs a clusterwide compare-and-swap operation. Works for global
spaces only.
E.g. it checks the `predicate` on leader and if no conflicting entries were found
E.g. it checks the `predicate` on leader and if no conflicting entries
appends the `op` to the raft log and returns its index (number). If predicate
were found appends the `op` to the raft log and returns its index. If
is not supplied, it will be auto generated with `index` and `term` taken from the
predicate is not supplied, it will be auto generated with `index` and
current instance and with empty `ranges`.
`term` taken from the current instance and with empty `ranges`.
Returns when the operation is appended to the raft log on a leader.
Returns the index of the corresponding Op::Dml.
Params:
Params:
1. dml (table)
1. dml (table)
- kind (string), one of 'insert' | 'replace' | 'update' | 'delete'
- kind (string), one of 'insert' | 'replace' | 'update' | 'delete'
- space (string)
- space (string
Lua
)
- tuple (optional table), mandatory for insert and replace, see [1, 2]
- tuple (optional table), mandatory for insert and replace, see [1, 2]
- key (optional table), mandatory for udate and delete, see [3, 4]
- key (optional table), mandatory for udate and delete, see [3, 4]
- ops (optional table), mandatory for update see [3]
- ops (optional table), mandatory for update see [3]
...
@@ -825,6 +832,12 @@ pub(crate) fn setup(args: &args::Run) {
...
@@ -825,6 +832,12 @@ pub(crate) fn setup(args: &args::Run) {
- ranges (optional table {table CasRange,...}), see pico.help('table CasRange'),
- ranges (optional table {table CasRange,...}), see pico.help('table CasRange'),
default: {} (empty table)
default: {} (empty table)
Returns:
(number)
or
(nil, string) in case of an error
See also:
See also:
[1]: https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_space/insert/
[1]: https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_space/insert/
...
@@ -840,53 +853,49 @@ pub(crate) fn setup(args: &args::Run) {
...
@@ -840,53 +853,49 @@ pub(crate) fn setup(args: &args::Run) {
-- Insert a tuple {1, 'Suzy'} into this space. This will fail
-- Insert a tuple {1, 'Suzy'} into this space. This will fail
-- if the term of the current instance is outdated.
-- if the term of the current instance is outdated.
local op_insert =
{
pico.cas(
{
kind = 'insert',
kind = 'insert',
space = 'friends_of_peppa',
space = 'friends_of_peppa',
tuple = {1, 'Suzy'},
tuple = {1, 'Suzy'},
}
})
pico.cas(op_insert)
-- Add Rebecca, but only if no other friends were added after
-- Add Rebecca, but only if no other friends were added after Suzy.
-- Suzy.
pico.cas({
local unbounded = {
space = 'friends_of_peppa',
key_min = { kind = 'excluded', key = {1,} }
key_max = { kind = 'unbounded' }
}
local op_replace = {
kind = 'replace',
kind = 'replace',
space = 'friends_of_peppa',
space = 'friends_of_peppa',
tuple = {2, 'Rebecca'},
tuple = {2, 'Rebecca'},
}
}, {
pico.cas(op_replace, {ranges = {unbounded}})
-- Check that there were no other updates, and update the tuple
-- by primary key {2}, replacing 'Rebecca' with 'Emily'.
local predicate = {
ranges = {{
ranges = {{
space = 'friends_of_peppa',
space = 'friends_of_peppa',
key_min = { kind = '
in
cluded', key = {
2
} }
key_min = { kind = '
ex
cluded', key = {
1,
} }
,
key_max = { kind = '
included', key = {2} }
key_max = { kind = '
unbounded' },
}},
}},
}
})
local op_update = {
-- Check that there were no other updates, and update the second
-- Peppa friend, replacing 'Rebecca' with 'Emily'.
pico.cas({
kind = 'update',
kind = 'update',
space = 'friends_of_peppa',
space = 'friends_of_peppa',
key = {2},
key = {2},
ops = {'=', 2, 'Emily'},
ops = {'=', 2, 'Emily'},
}
}, {
pico.cas(op_update, predicate)
ranges = {{
space = 'friends_of_peppa',
key_min = { kind = 'included', key = {2} },
key_max = { kind = 'included', key = {2} },
}},
})
-- Delete the second Peppa friend, specifying index and term
-- Delete the second Peppa friend, specifying index and term
-- explicitly. It's necessary when there are some yileding
-- explicitly. It's necessary when there are some yileding
-- operations between reading and writing.
-- operations between reading and writing.
local
index, term = {
index, term = {
assert(pico.raft_get_index()),
assert(pico.raft_get_index()),
assert(pico.raft_status()).term,
assert(pico.raft_status()).term,
}
}
local
emily = box.space.friends_of_peppa.index.name:get('Emily')
emily = box.space.friends_of_peppa.index.name:get('Emily')
fiber.sleep(1) -- do someting yielding
fiber.sleep(1) -- do somet
h
ing yielding
pico.cas({
pico.cas({
kind = 'delete',
kind = 'delete',
...
@@ -897,8 +906,8 @@ pub(crate) fn setup(args: &args::Run) {
...
@@ -897,8 +906,8 @@ pub(crate) fn setup(args: &args::Run) {
term = term,
term = term,
ranges = {{
ranges = {{
space = 'friends_of_peppa',
space = 'friends_of_peppa',
key_min = { kind = 'included', key = {emily.id} }
key_min = { kind = 'included', key = {emily.id} }
,
key_max = { kind = 'included', key = {emily.id} }
key_max = { kind = 'included', key = {emily.id} }
,
}},
}},
})
})
"
},
"
},
...
@@ -970,55 +979,80 @@ pub(crate) fn setup(args: &args::Run) {
...
@@ -970,55 +979,80 @@ pub(crate) fn setup(args: &args::Run) {
&
l
,
&
l
,
"create_space"
,
"create_space"
,
indoc!
{
"
indoc!
{
"
pico.create_space {
pico.create_space(opts)
id = ..., -- number
=======================
name = ..., -- string
format = ..., -- {Field, ...}, see pico.help('Field')
Creates a space.
primary_key = ..., -- {string, ...}
distribution = ..., -- string, one of 'global' | 'sharded'
Returns when the space is created globally and becomes operable on the
timeout = ..., -- number, in seconds
current instance. Returns the index of the corresponding Op::DdlCommit
}
raft entry. It's necessary for syncing with other instances.
========================
Params:
Creates a space. Returns a raft index (number) at which a newly created space
has to exist on all peers.
1. opts (table)
- name (string)
If 'distribution' is set to 'sharded' then one of the following sets
- format (table {table SpaceField,...}), see pico.help('table SpaceField')
of params should be specified:
- primary_key (table {string,...}), with field names
- For implicit sharding:
- id (optional number), default: implicitly generated
- sharding_key - {string, ...}
- distribution (string), one of 'global' | 'sharded'
- sharding_fn - optional string one of 'crc32' | 'murmur3' | 'xxhash' | 'md5'
in case it's sharded, either `by_field` (for explicit sharding)
- For explicit sharding:
or `sharding_key`+`sharding_fn` (for implicit sharding) options
- by_field - string
must be supplied.
- by_field (optional string), usually 'bucket_id'
- sharding_key (optional table {string,...}) with field names
- sharding_fn (optional string), only default 'murmur3' is supported for now
- timeout (number), in seconds
Returns:
(number)
or
(nil, string) in case of an error
Example:
Example:
-- Creates a global space '
wonderland
' with fields
key and value
-- Creates a global space '
friends_of_peppa
' with
two
fields
:
--
which are of string and unsigned types correspond
ing
ly
.
--
id (unsigned) and name (str
ing
)
.
pico.create_space{
pico.create_space
(
{
name = '
wonderland
',
name = '
friends_of_peppa
',
format = {
format = {
{name
='key
', type
='string
', is_nullable
=
false},
{name
= 'id
', type
= 'unsigned
', is_nullable
=
false},
{name
='valu
e', type
='unsigned
', is_nullable
=tru
e}
{name
= 'nam
e', type
= 'string
', is_nullable
= fals
e}
,
},
},
primary_key = {
'key'
},
primary_key = {
'id'
},
distribution = 'global',
distribution = 'global',
timeout = 3
.0
timeout = 3
,
}
}
)
-- Creates an implicitly sharded space 'faraway' with fields key and value
-- Global spaces are updated with compare-and-swap, see pico.help('cas')
-- which are of string and unsigned types correspondingly.
pico.cas({
pico.create_space{
kind = 'insert',
name = 'faraway',
space = 'friends_of_peppa',
key = {1, 'Suzy'},
})
-- Creates an implicitly sharded space 'wonderland' with two fields:
-- property (string) and value (any).
pico.create_space({
name = 'wonderland',
format = {
format = {
{name
='ke
y', type
=
'string', is_nullable
=
false},
{name
= 'propert
y', type
=
'string', is_nullable
=
false},
{name
=
'value', type
='unsigned
', is_nullable
=
true}
{name
=
'value', type
= 'any
', is_nullable
=
true}
},
},
primary_key = {
'ke
y'
},
primary_key = {
'propert
y'},
distribution = 'sharded',
distribution = 'sharded',
sharding_key = { 'key' }
sharding_key = {'property'},
timeout = 3.0
timeout = 3,
}
})
-- Sharded spaces are updated via vshard api, see [1]
local bucket_id = vshard.router.bucket_id_mpcrc32('unicorns')
vshard.router.callrw(bucket_id, 'box.space.wonderland:insert', {{'unicorns', 12}})
See also:
[1]: https://www.tarantool.io/en/doc/latest/reference/reference_rock/vshard/vshard_router/
"
},
"
},
{
{
tlua
::
function1
(|
params
:
CreateSpaceParams
|
->
traft
::
Result
<
RaftIndex
>
{
tlua
::
function1
(|
params
:
CreateSpaceParams
|
->
traft
::
Result
<
RaftIndex
>
{
...
@@ -1039,16 +1073,22 @@ pub(crate) fn setup(args: &args::Run) {
...
@@ -1039,16 +1073,22 @@ pub(crate) fn setup(args: &args::Run) {
"abort_ddl"
,
"abort_ddl"
,
indoc!
{
"
indoc!
{
"
pico.abort_ddl(timeout)
pico.abort_ddl(timeout)
=======================
=
=======================
Aborts a pending
DDL operation
.
Aborts a pending
schema change
.
Returns an index of the corresponding DdlAbort raft entry
, or an error if
Returns an index of the corresponding
Op::
DdlAbort raft entry
.
there is no pending
DDL
operation.
Returns an error if
there is no pending
schema change
operation.
Params:
Params:
1. timeout - number, in seconds
1. timeout (number), in seconds
Returns:
(numer)
or
(nil, string) in case of an error
"
},
"
},
{
{
tlua
::
function1
(|
timeout
:
f64
|
->
traft
::
Result
<
RaftIndex
>
{
tlua
::
function1
(|
timeout
:
f64
|
->
traft
::
Result
<
RaftIndex
>
{
...
@@ -1058,26 +1098,28 @@ pub(crate) fn setup(args: &args::Run) {
...
@@ -1058,26 +1098,28 @@ pub(crate) fn setup(args: &args::Run) {
);
);
luamod_set_help_only
(
luamod_set_help_only
(
&
l
,
&
l
,
"Field"
,
"
table Space
Field"
,
indoc!
{
"
indoc!
{
"
Field (table)
table SpaceField
=============
=============
===
D
escrib
es
a field in a space.
A Lua table d
escrib
ing
a field in a space
, see [1]
.
Fields:
Fields:
- name (
number
)
- name (
string
)
- type (string)
- type (string)
, see [2]
- is_nullable (boolean)
- is_nullable (boolean)
Example:
Example:
local new_field = {
{name = 'id', type = 'unsigned', is_nullable = false}
name = 'id',
{name = 'value', type = 'unsigned', is_nullable = false}
type = 'unsigned',
is_nullable = false
See also:
}
[1]: https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_space/format/
[2]: https://docs.rs/tarantool/latest/tarantool/space/enum.FieldType.html
"
},
"
},
);
);
}
}
This diff is collapsed.
Click to expand it.
test/int/test_uninitialized.py
+
3
−
0
View file @
50f047ef
...
@@ -30,6 +30,9 @@ def uninitialized_instance(cluster: Cluster) -> Generator[Instance, None, None]:
...
@@ -30,6 +30,9 @@ def uninitialized_instance(cluster: Cluster) -> Generator[Instance, None, None]:
def
test_raft_api
(
uninitialized_instance
:
Instance
):
def
test_raft_api
(
uninitialized_instance
:
Instance
):
functions
:
list
[
Callable
[[
Instance
],
Any
]]
=
[
functions
:
list
[
Callable
[[
Instance
],
Any
]]
=
[
lambda
i
:
i
.
_raft_status
(),
lambda
i
:
i
.
_raft_status
(),
lambda
i
:
i
.
raft_get_index
(),
lambda
i
:
i
.
raft_read_index
(),
lambda
i
:
i
.
raft_wait_index
(
0
),
lambda
i
:
i
.
call
(
"
pico.raft_propose_nop
"
),
lambda
i
:
i
.
call
(
"
pico.raft_propose_nop
"
),
lambda
i
:
i
.
call
(
"
pico.whoami
"
),
lambda
i
:
i
.
call
(
"
pico.whoami
"
),
lambda
i
:
i
.
call
(
"
pico.instance_info
"
,
"
i1
"
),
lambda
i
:
i
.
call
(
"
pico.instance_info
"
,
"
i1
"
),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment