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
61306ea3
Commit
61306ea3
authored
8 months ago
by
Georgy Moshkin
Committed by
Yaroslav Dynnikov
8 months ago
Browse files
Options
Downloads
Patches
Plain Diff
refactor: support passing additional Dml entries to update_instance_request
parent
d8ffec81
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1156
fix: store just the vshard config version
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/rpc/update_instance.rs
+34
-2
34 additions, 2 deletions
src/rpc/update_instance.rs
src/traft/op.rs
+9
-0
9 additions, 0 deletions
src/traft/op.rs
with
43 additions
and
2 deletions
src/rpc/update_instance.rs
+
34
−
2
View file @
61306ea3
...
...
@@ -96,8 +96,26 @@ impl Request {
/// Returns `Ok(())` when the entry is committed.
///
/// **This function yields**
// TODO: for this function to be async and have an outer timeout wait_* fns need to be async
#[inline(always)]
pub
fn
handle_update_instance_request_and_wait
(
req
:
Request
,
timeout
:
Duration
)
->
Result
<
()
>
{
handle_update_instance_request_in_governor_and_also_wait_too
(
req
,
None
,
timeout
)
}
/// Processes the [`crate::rpc::update_instance::Request`] and appends
/// the corresponding operation along with the provided `additional_dml` entry
/// to the raft log within a single [`Op::BatchDml`] (if successful).
///
/// **This function should be used directly only from governor** everywhere else
/// should use [`handle_update_instance_request_and_wait`] instead.
///
/// Returns `Ok(())` when the entry is committed.
///
/// **This function yields**
pub
fn
handle_update_instance_request_in_governor_and_also_wait_too
(
req
:
Request
,
additional_dml
:
Option
<&
Dml
>
,
timeout
:
Duration
,
)
->
Result
<
()
>
{
let
node
=
node
::
global
()
?
;
let
cluster_id
=
node
.raft_storage
.cluster_id
()
?
;
let
storage
=
&
node
.storage
;
...
...
@@ -111,9 +129,15 @@ pub fn handle_update_instance_request_and_wait(req: Request, timeout: Duration)
});
}
#[cfg(debug_assertions)]
if
let
Some
(
op
)
=
additional_dml
{
debug_assert_eq!
(
op
.table_id
(),
ClusterwideTable
::
Property
.id
(),
"for CaS safety reasons currently we only allow updating _pico_property simultaneously with instance"
);
}
let
deadline
=
fiber
::
clock
()
.saturating_add
(
timeout
);
loop
{
let
old_instance
=
storage
.instances
.get
(
&
req
.instance_id
)
?
;
// TODO: this should instead be a Dml::Update operation with just the fields which are changed
let
mut
new_instance
=
old_instance
.clone
();
update_instance
(
&
mut
new_instance
,
&
req
,
storage
)
.map_err
(
raft
::
Error
::
ConfChangeError
)
?
;
if
old_instance
==
new_instance
{
...
...
@@ -127,6 +151,14 @@ pub fn handle_update_instance_request_and_wait(req: Request, timeout: Duration)
let
dml
=
Dml
::
replace
(
ClusterwideTable
::
Instance
,
&
new_instance
,
ADMIN_ID
)
.expect
(
"encoding should not fail"
);
let
op
=
match
additional_dml
{
// TODO: to eliminate redundant copies here we should refactor `BatchDml` and/or `Dml`
Some
(
additional_dml
)
=>
Op
::
BatchDml
{
ops
:
vec!
[
dml
,
additional_dml
.clone
()],
},
// No need to wrap it in a BatchDml and confuse the users
None
=>
Op
::
Dml
(
dml
),
};
let
ranges
=
vec!
[
cas
::
Range
::
new
(
ClusterwideTable
::
Instance
),
...
...
@@ -135,7 +167,7 @@ pub fn handle_update_instance_request_and_wait(req: Request, timeout: Duration)
];
let
cas_req
=
crate
::
cas
::
Request
::
new
(
Op
::
Dml
(
dml
)
,
op
,
cas
::
Predicate
{
index
:
raft_storage
.applied
()
?
,
term
:
raft_storage
.term
()
?
,
...
...
This diff is collapsed.
Click to expand it.
src/traft/op.rs
+
9
−
0
View file @
61306ea3
...
...
@@ -426,6 +426,15 @@ pub enum Dml {
}
impl
Dml
{
pub
fn
table_id
(
&
self
)
->
SpaceId
{
match
*
self
{
Dml
::
Insert
{
table
,
..
}
=>
table
,
Dml
::
Replace
{
table
,
..
}
=>
table
,
Dml
::
Update
{
table
,
..
}
=>
table
,
Dml
::
Delete
{
table
,
..
}
=>
table
,
}
}
pub
fn
initiator
(
&
self
)
->
UserId
{
match
self
{
Dml
::
Insert
{
initiator
,
..
}
=>
*
initiator
,
...
...
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