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
16f928e6
Commit
16f928e6
authored
2 years ago
by
Georgy Moshkin
Committed by
Yaroslav Dynnikov
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
refactor(storage): use UnsafeCell for space_peers in Peers
parent
9ffbbbdb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!279
Refactor/remove old storage
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/traft/storage.rs
+45
-8
45 additions, 8 deletions
src/traft/storage.rs
with
45 additions
and
8 deletions
src/traft/storage.rs
+
45
−
8
View file @
16f928e6
...
...
@@ -11,7 +11,7 @@ use crate::traft::error::Error as TraftError;
use
crate
::
traft
::
RaftId
;
use
crate
::
traft
::
RaftIndex
;
use
std
::
cell
::
{
RefCell
,
UnsafeCell
}
;
use
std
::
cell
::
UnsafeCell
;
use
super
::
RaftSpaceAccess
;
...
...
@@ -276,9 +276,9 @@ impl Clone for State {
/// A struct for accessing storage of all the cluster peers
/// (currently raft_group).
#[derive(
Clone,
Debug)]
#[derive(Debug)]
pub
struct
Peers
{
space_peers
:
Ref
Cell
<
Space
>
,
space_peers
:
Unsafe
Cell
<
Space
>
,
index_instance_id
:
Index
,
index_raft_id
:
Index
,
index_replicaset_id
:
Index
,
...
...
@@ -321,23 +321,36 @@ impl Peers {
.create
()
?
;
Ok
(
Self
{
space_peers
:
Ref
Cell
::
new
(
space_peers
),
space_peers
:
Unsafe
Cell
::
new
(
space_peers
),
index_instance_id
,
index_raft_id
,
index_replicaset_id
,
})
}
#[inline(always)]
fn
space
(
&
self
)
->
&
Space
{
// This is safe, because data inside Space struct itself never changes.
unsafe
{
&*
self
.space_peers
.get
()
}
}
#[allow(clippy::mut_from_ref)]
#[inline(always)]
fn
space_mut
(
&
self
)
->
&
mut
Space
{
// This is safe, because data inside Space struct itself never changes.
unsafe
{
&
mut
*
self
.space_peers
.get
()
}
}
#[inline]
pub
fn
persist_peer
(
&
self
,
peer
:
&
traft
::
Peer
)
->
tarantool
::
Result
<
()
>
{
self
.space_
peers
.borrow_
mut
()
.replace
(
peer
)
?
;
self
.space_mut
()
.replace
(
peer
)
?
;
Ok
(())
}
#[allow(dead_code)]
#[inline]
pub
fn
delete_peer
(
&
self
,
instance_id
:
&
str
)
->
tarantool
::
Result
<
()
>
{
self
.space_
peers
.borrow_
mut
()
.delete
(
&
[
instance_id
])
?
;
self
.space_mut
()
.delete
(
&
[
instance_id
])
?
;
Ok
(())
}
...
...
@@ -375,6 +388,20 @@ impl Peers {
Ok
(
res
)
}
<<<<<<<
HEAD
=======
/// Return an iterator over all peers. Items of the iterator are
/// specified by `F` (see `PeerFieldDef` & `peer_field` module).
#[inline(always)]
pub
fn
peers_fields
<
F
>
(
&
self
)
->
Result
<
PeersFields
<
F
>
,
TraftError
>
where
F
:
PeerFieldDef
,
{
let
iter
=
self
.space
()
.select
(
IteratorType
::
All
,
&
())
?
;
Ok
(
PeersFields
::
new
(
iter
))
}
>>>>>>>
refactor
(
storage
):
use
UnsafeCell
for
space_peers
in
Peers
#[inline]
pub
fn
peer_by_instance_id
(
&
self
,
instance_id
:
&
str
)
->
tarantool
::
Result
<
Option
<
traft
::
Peer
>>
{
let
tuple
=
self
.index_instance_id
.get
(
&
(
instance_id
,))
?
;
...
...
@@ -386,8 +413,7 @@ impl Peers {
#[inline]
pub
fn
all_peers
(
&
self
)
->
tarantool
::
Result
<
Vec
<
traft
::
Peer
>>
{
self
.space_peers
.borrow
()
self
.space
()
.select
(
IteratorType
::
All
,
&
())
?
.map
(|
tuple
|
tuple
.decode
())
.collect
()
...
...
@@ -432,6 +458,17 @@ impl Peers {
}
}
impl
Clone
for
Peers
{
fn
clone
(
&
self
)
->
Self
{
Self
{
space_peers
:
UnsafeCell
::
new
(
self
.space
()
.clone
()),
index_instance_id
:
self
.index_instance_id
.clone
(),
index_raft_id
:
self
.index_raft_id
.clone
(),
index_replicaset_id
:
self
.index_replicaset_id
.clone
(),
}
}
}
////////////////////////////////////////////////////////////////////////////////
// PeerField
////////////////////////////////////////////////////////////////////////////////
...
...
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