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
e118feef
Commit
e118feef
authored
2 years ago
by
Georgy Moshkin
Committed by
Georgy Moshkin
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
wip: sharding stored procedure
parent
cfdead8e
No related branches found
No related tags found
1 merge request
!299
Feat/poor mans vshard
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/main.rs
+1
-0
1 addition, 0 deletions
src/main.rs
src/traft/error.rs
+4
-0
4 additions, 0 deletions
src/traft/error.rs
src/traft/rpc/sharding.rs
+65
-0
65 additions, 0 deletions
src/traft/rpc/sharding.rs
src/traft/storage.rs
+1
-0
1 addition, 0 deletions
src/traft/storage.rs
with
71 additions
and
0 deletions
src/main.rs
+
1
−
0
View file @
e118feef
...
@@ -396,6 +396,7 @@ fn init_handlers() {
...
@@ -396,6 +396,7 @@ fn init_handlers() {
declare_cfunc!
(
traft
::
node
::
raft_sync_raft
);
declare_cfunc!
(
traft
::
node
::
raft_sync_raft
);
declare_cfunc!
(
traft
::
failover
::
raft_update_peer
);
declare_cfunc!
(
traft
::
failover
::
raft_update_peer
);
declare_cfunc!
(
traft
::
rpc
::
replication
::
proc_replication
);
declare_cfunc!
(
traft
::
rpc
::
replication
::
proc_replication
);
declare_cfunc!
(
traft
::
rpc
::
sharding
::
proc_sharding
);
}
}
fn
rm_tarantool_files
(
data_dir
:
&
str
)
{
fn
rm_tarantool_files
(
data_dir
:
&
str
)
{
...
...
This diff is collapsed.
Click to expand it.
src/traft/error.rs
+
4
−
0
View file @
e118feef
...
@@ -29,6 +29,8 @@ pub enum Error {
...
@@ -29,6 +29,8 @@ pub enum Error {
instance_rsid
:
String
,
instance_rsid
:
String
,
requested_rsid
:
String
,
requested_rsid
:
String
,
},
},
#[error(
"operation request from non leader {actual}, current leader is {expected}"
)]
LeaderIdMismatch
{
expected
:
RaftId
,
actual
:
RaftId
},
#[error(
"error during execution of lua code: {0}"
)]
#[error(
"error during execution of lua code: {0}"
)]
Lua
(
#[from]
LuaError
),
Lua
(
#[from]
LuaError
),
#[error(
"{0}"
)]
#[error(
"{0}"
)]
...
@@ -37,6 +39,8 @@ pub enum Error {
...
@@ -37,6 +39,8 @@ pub enum Error {
NoPeerWithRaftId
(
RaftId
),
NoPeerWithRaftId
(
RaftId
),
#[error(
"peer with id
\"
{0}
\"
not found"
)]
#[error(
"peer with id
\"
{0}
\"
not found"
)]
NoPeerWithInstanceId
(
InstanceId
),
NoPeerWithInstanceId
(
InstanceId
),
#[error(
"leader is uknown yet"
)]
LeaderUnknown
,
#[error(
"other error: {0}"
)]
#[error(
"other error: {0}"
)]
Other
(
Box
<
dyn
std
::
error
::
Error
>
),
Other
(
Box
<
dyn
std
::
error
::
Error
>
),
}
}
...
...
This diff is collapsed.
Click to expand it.
src/traft/rpc/sharding.rs
+
65
−
0
View file @
e118feef
use
::
tarantool
::{
proc
,
tlua
};
use
crate
::
traft
::
storage
::
StateKey
;
use
crate
::
traft
::{
error
::
Error
,
node
,
RaftId
,
RaftTerm
};
#[proc(packed_args)]
fn
proc_sharding
(
req
:
Request
)
->
Result
<
Response
,
Error
>
{
let
node
=
node
::
global
()
?
;
let
leader_id
=
node
.status
()
.leader_id
.ok_or
(
Error
::
LeaderUnknown
)
?
;
if
req
.leader_id
!=
leader_id
{
return
Err
(
Error
::
LeaderIdMismatch
{
expected
:
leader_id
,
actual
:
req
.leader_id
,
});
}
// TODO: check term matches
let
_
=
req
.term
;
let
storage
=
&
node
.storage
;
let
cfg
=
cfg
::
Cfg
::
from_storage
(
&
storage
.peers
)
?
;
let
lua
=
::
tarantool
::
lua_state
();
// TODO: fix user's permissions
lua
.exec
(
"box.session.su('admin')"
)
?
;
// TODO: only done on instances with corresponding roles
lua
.exec_with
(
"vshard.storage.cfg(..., box.info.uuid)"
,
&
cfg
)
.map_err
(
tlua
::
LuaError
::
from
)
?
;
// TODO: only done on instances with corresponding roles
lua
.exec_with
(
"vshard.router.cfg(...)"
,
&
cfg
)
.map_err
(
tlua
::
LuaError
::
from
)
?
;
// TODO: governor should decide who does this, and propose a OpDML entry
// afterwards
if
!
storage
.state
.get
(
StateKey
::
VshardBootstrapped
)
?
.unwrap_or
(
false
)
{
lua
.exec
(
"vshard.router.bootstrap()"
)
?
;
storage
.state
.put
(
StateKey
::
VshardBootstrapped
,
&
true
)
?
;
}
Ok
(
Response
{})
}
/// Request to configure vshard.
#[derive(Clone,
Debug,
serde::Serialize,
serde::Deserialize)]
pub
struct
Request
{
pub
leader_id
:
RaftId
,
pub
term
:
RaftTerm
,
}
impl
::
tarantool
::
tuple
::
Encode
for
Request
{}
/// Response to [`sharding::Request`].
///
/// [`sharding::Request`]: Request
#[derive(Clone,
Debug,
serde::Serialize,
serde::Deserialize)]
pub
struct
Response
{}
impl
::
tarantool
::
tuple
::
Encode
for
Response
{}
impl
super
::
Request
for
Request
{
const
PROC_NAME
:
&
'static
str
=
crate
::
stringify_cfunc!
(
proc_sharding
);
type
Response
=
Response
;
}
#[rustfmt::skip]
#[rustfmt::skip]
pub
mod
cfg
{
pub
mod
cfg
{
use
crate
::
traft
::
error
::
Error
;
use
crate
::
traft
::
error
::
Error
;
...
...
This diff is collapsed.
Click to expand it.
src/traft/storage.rs
+
1
−
0
View file @
e118feef
...
@@ -77,6 +77,7 @@ define_str_enum! {
...
@@ -77,6 +77,7 @@ define_str_enum! {
/// An enumeration of builtin raft spaces
/// An enumeration of builtin raft spaces
pub
enum
StateKey
{
pub
enum
StateKey
{
ReplicationFactor
=
"replication_factor"
,
ReplicationFactor
=
"replication_factor"
,
VshardBootstrapped
=
"vshard_bootstrapped"
,
}
}
FromStr
::
Err
=
UnknownStateKey
;
FromStr
::
Err
=
UnknownStateKey
;
...
...
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