Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor 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
elixxir
client
Commits
0a1e1fa3
Commit
0a1e1fa3
authored
4 years ago
by
Josh Brooks
Browse files
Options
Downloads
Patches
Plain Diff
Finalize uncheckedRoundStore design
parent
1773cc6d
No related branches found
No related tags found
1 merge request
!23
Release
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
storage/rounds/uncheckedRounds.go
+49
-34
49 additions, 34 deletions
storage/rounds/uncheckedRounds.go
storage/rounds/uncheckedRounds_test.go
+46
-0
46 additions, 0 deletions
storage/rounds/uncheckedRounds_test.go
with
95 additions
and
34 deletions
storage/rounds/unchecked.go
→
storage/rounds/unchecked
Rounds
.go
+
49
−
34
View file @
0a1e1fa3
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package
rounds
import
(
...
...
@@ -14,16 +21,23 @@ import (
)
const
(
uncheckRoundVersion
=
0
uncheckRoundPrefix
=
"uncheckedRoundPrefix"
uncheck
ed
RoundVersion
=
0
uncheck
ed
RoundPrefix
=
"uncheckedRoundPrefix"
// Key to store round list
uncheckedRoundListKey
=
"uncheckRounds"
// Key to store individual round
uncheckedRoundKey
=
"uncheckedRound-"
// Housekeeping constant (used for s
torage of
uint64 ie id.Round)
// Housekeeping constant (used for s
erializing
uint64 ie id.Round)
uint64Size
=
8
)
// Round identity information used in message retrieval
// Derived from reception.Identity
type
Identity
struct
{
EpdId
ephemeral
.
Id
Source
*
id
.
ID
}
// Unchecked round structure is rounds which failed on message retrieval
// These rounds are stored for retry of message retrieval
type
UncheckedRound
struct
{
...
...
@@ -36,13 +50,6 @@ type UncheckedRound struct {
NumTries
uint
}
// Round identity information used in message retrieval
// Derived from reception.Identity
type
Identity
struct
{
EpdId
ephemeral
.
Id
Source
*
id
.
ID
}
// Storage object saving rounds to retry for message retrieval
type
UncheckedRoundStore
struct
{
list
map
[
id
.
Round
]
UncheckedRound
...
...
@@ -52,7 +59,7 @@ type UncheckedRoundStore struct {
// Constructor for a UncheckedRoundStore
func
NewUncheckedStore
(
kv
*
versioned
.
KV
)
(
*
UncheckedRoundStore
,
error
)
{
kv
=
kv
.
Prefix
(
uncheckRoundPrefix
)
kv
=
kv
.
Prefix
(
uncheck
ed
RoundPrefix
)
urs
:=
&
UncheckedRoundStore
{
list
:
make
(
map
[
id
.
Round
]
UncheckedRound
,
0
),
...
...
@@ -66,8 +73,8 @@ func NewUncheckedStore(kv *versioned.KV) (*UncheckedRoundStore, error) {
// Loads an deserializes a UncheckedRoundStore from memory
func
LoadUncheckedStore
(
kv
*
versioned
.
KV
)
(
*
UncheckedRoundStore
,
error
)
{
kv
=
kv
.
Prefix
(
uncheckRoundPrefix
)
vo
,
err
:=
kv
.
Get
(
uncheckedRoundListKey
,
uncheckRoundVersion
)
kv
=
kv
.
Prefix
(
uncheck
ed
RoundPrefix
)
vo
,
err
:=
kv
.
Get
(
uncheckedRoundListKey
,
uncheck
ed
RoundVersion
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -102,6 +109,8 @@ func LoadUncheckedStore(kv *versioned.KV) (*UncheckedRoundStore, error) {
func
(
s
*
UncheckedRoundStore
)
AddRound
(
rid
id
.
Round
,
ephID
ephemeral
.
Id
,
source
*
id
.
ID
)
error
{
s
.
mux
.
Lock
()
defer
s
.
mux
.
Unlock
()
if
_
,
exists
:=
s
.
list
[
rid
];
!
exists
{
newUncheckedRound
:=
UncheckedRound
{
Rid
:
rid
,
Identity
:
Identity
{
...
...
@@ -117,6 +126,9 @@ func (s *UncheckedRoundStore) AddRound(rid id.Round, ephID ephemeral.Id, source
return
s
.
save
()
}
return
nil
}
// Retrieves an UncheckedRound from the map, if it exists
func
(
s
*
UncheckedRoundStore
)
GetRound
(
rid
id
.
Round
)
(
UncheckedRound
,
bool
)
{
s
.
mux
.
RLock
()
...
...
@@ -133,15 +145,18 @@ func (s *UncheckedRoundStore) GetList() map[id.Round]UncheckedRound {
}
// Increments the amount of checks performed on this stored round
func
(
s
*
UncheckedRoundStore
)
IncrementCheck
(
rid
id
.
Round
)
{
func
(
s
*
UncheckedRoundStore
)
IncrementCheck
(
rid
id
.
Round
)
error
{
s
.
mux
.
Lock
()
defer
s
.
mux
.
Unlock
()
rnd
,
exists
:=
s
.
list
[
rid
]
if
!
exists
{
return
return
errors
.
Errorf
(
"round %d could not be found in RAM"
,
rid
)
}
rnd
.
NumTries
++
return
rnd
.
store
(
s
.
kv
)
}
// Remove deletes a round from UncheckedRoundStore's list and from storage
...
...
@@ -150,7 +165,7 @@ func (s *UncheckedRoundStore) Remove(rid id.Round) error {
defer
s
.
mux
.
Unlock
()
delete
(
s
.
list
,
rid
)
return
s
.
kv
.
Delete
(
roundStoreKey
(
rid
),
uncheckRoundVersion
)
return
s
.
kv
.
Delete
(
roundStoreKey
(
rid
),
uncheck
ed
RoundVersion
)
}
...
...
@@ -177,13 +192,13 @@ func (s *UncheckedRoundStore) saveRoundList() error {
// Create the versioned object
obj
:=
&
versioned
.
Object
{
Version
:
uncheckRoundVersion
,
Version
:
uncheck
ed
RoundVersion
,
Timestamp
:
netTime
.
Now
(),
Data
:
serializeRoundList
(
s
.
list
),
}
// Save to storage
err
:=
s
.
kv
.
Set
(
uncheckedRoundListKey
,
uncheckRoundVersion
,
obj
)
err
:=
s
.
kv
.
Set
(
uncheckedRoundListKey
,
uncheck
ed
RoundVersion
,
obj
)
if
err
!=
nil
{
return
errors
.
WithMessage
(
err
,
"Failed to store round ID list"
)
}
...
...
@@ -211,12 +226,12 @@ func (r UncheckedRound) store(kv *versioned.KV) error {
}
obj
:=
&
versioned
.
Object
{
Version
:
uncheckRoundVersion
,
Version
:
uncheck
ed
RoundVersion
,
Timestamp
:
netTime
.
Now
(),
Data
:
data
,
}
return
kv
.
Set
(
roundStoreKey
(
r
.
Rid
),
uncheckRoundVersion
,
obj
)
return
kv
.
Set
(
roundStoreKey
(
r
.
Rid
),
uncheck
ed
RoundVersion
,
obj
)
}
...
...
@@ -256,7 +271,7 @@ func (r UncheckedRound) Serialize() ([]byte, error) {
// loadRound pulls an UncheckedRound corresponding to roundId from storage
func
loadRound
(
roundId
id
.
Round
,
kv
*
versioned
.
KV
)
(
UncheckedRound
,
error
)
{
vo
,
err
:=
kv
.
Get
(
roundStoreKey
(
roundId
),
uncheckRoundVersion
)
vo
,
err
:=
kv
.
Get
(
roundStoreKey
(
roundId
),
uncheck
ed
RoundVersion
)
if
err
!=
nil
{
return
UncheckedRound
{},
errors
.
WithMessagef
(
err
,
"Could not find %d in storage"
,
roundId
)
}
...
...
This diff is collapsed.
Click to expand it.
storage/rounds/uncheckedRounds_test.go
0 → 100644
+
46
−
0
View file @
0a1e1fa3
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package
rounds
import
(
"gitlab.com/elixxir/client/storage/versioned"
"gitlab.com/elixxir/ekv"
"gitlab.com/xx_network/primitives/id"
"reflect"
"sync"
"testing"
)
func
TestNewUncheckedStore
(
t
*
testing
.
T
)
{
kv
:=
versioned
.
NewKV
(
make
(
ekv
.
Memstore
))
testStore
:=
&
UncheckedRoundStore
{
list
:
make
(
map
[
id
.
Round
]
UncheckedRound
),
kv
:
kv
.
Prefix
(
uncheckedRoundPrefix
),
}
store
,
err
:=
NewUncheckedStore
(
kv
)
if
err
!=
nil
{
t
.
Fatalf
(
"NewUncheckedStore error: "
+
"Could not create unchecked stor: %v"
,
err
)
}
// Compare manually created object with NewUnknownRoundsStore
if
!
reflect
.
DeepEqual
(
testStore
,
store
)
{
t
.
Fatalf
(
"NewUncheckedStore error: "
+
"Returned incorrect Store."
+
"
\n\t
expected: %+v
\n\t
received: %+v"
,
testStore
,
store
)
}
UnknownRounds
{
rounds
:
nil
,
params
:
UnknownRoundsParams
{},
kv
:
nil
,
mux
:
sync
.
Mutex
{},
}
}
\ No newline at end of file
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