Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
9421746c
Unverified
Commit
9421746c
authored
Dec 23, 2019
by
Erik Wilson
Committed by
GitHub
Dec 23, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1235 from ibuildthecloud/master
Fix uint64 truncation issue in dqlite
parents
12c3d74a
9bda58c8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
7 deletions
+21
-7
join.go
pkg/dqlite/join.go
+16
-6
server.go
pkg/dqlite/server.go
+5
-1
No files found.
pkg/dqlite/join.go
View file @
9421746c
...
...
@@ -33,6 +33,13 @@ func (d *DQLite) Test(ctx context.Context) error {
return
nil
}
func
nodeIDsEqual
(
testID
,
currentID
uint64
)
bool
{
// this is a test for a bug in v1.0.0. In future versions we don't
// generate node ID higher than 1<<20 so this doesn't matter. But
// basically just ignore the first 32 bits.
return
uint32
(
testID
)
==
uint32
(
currentID
)
}
func
(
d
*
DQLite
)
Join
(
ctx
context
.
Context
,
nodes
[]
client
.
NodeInfo
)
error
{
if
len
(
nodes
)
>
0
{
if
err
:=
d
.
NodeStore
.
Set
(
ctx
,
nodes
);
err
!=
nil
{
...
...
@@ -51,22 +58,25 @@ func (d *DQLite) Join(ctx context.Context, nodes []client.NodeInfo) error {
return
err
}
nodeID
,
err
:=
getClusterID
(
false
,
d
.
DataDir
)
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"get cluster ID"
)
}
for
_
,
testNode
:=
range
current
{
if
testNode
.
Address
==
d
.
NodeInfo
.
Address
{
nodeID
,
err
:=
getClusterID
(
false
,
d
.
DataDir
)
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"get cluster ID"
)
}
if
testNode
.
ID
!=
nodeID
{
if
!
nodeIDsEqual
(
testNode
.
ID
,
nodeID
)
{
if
err
:=
d
.
node
.
Close
();
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"node close for id reset"
)
}
if
err
:=
writeClusterID
(
testNode
.
ID
,
d
.
DataDir
);
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"restart node to reset ID"
)
}
return
fmt
.
Errorf
(
"rese
ting node ID from %d to %d, please restart"
,
nodeID
,
testNode
.
ID
)
logrus
.
Fatalf
(
"reset
ting node ID from %d to %d, please restart"
,
nodeID
,
testNode
.
ID
)
}
return
nil
}
else
if
nodeIDsEqual
(
testNode
.
ID
,
nodeID
)
{
deleteClusterID
(
d
.
DataDir
)
logrus
.
Fatalf
(
"node ID %d is in use, please restart"
,
nodeID
)
}
}
...
...
pkg/dqlite/server.go
View file @
9421746c
...
...
@@ -214,6 +214,10 @@ func writeClusterID(id uint64, dataDir string) error {
return
ioutil
.
WriteFile
(
idFile
,
[]
byte
(
strconv
.
FormatUint
(
id
,
10
)),
0644
)
}
func
deleteClusterID
(
dataDir
string
)
{
os
.
Remove
(
filepath
.
Join
(
GetDBDir
(
dataDir
),
NodeIDFile
))
}
func
getClusterID
(
initCluster
bool
,
dataDir
string
)
(
uint64
,
error
)
{
idFile
:=
filepath
.
Join
(
GetDBDir
(
dataDir
),
NodeIDFile
)
content
,
err
:=
ioutil
.
ReadFile
(
idFile
)
...
...
@@ -225,7 +229,7 @@ func getClusterID(initCluster bool, dataDir string) (uint64, error) {
idStr
:=
strings
.
TrimSpace
(
string
(
content
))
if
idStr
==
""
{
id
:=
rand
.
Uint64
(
)
id
:=
uint64
(
rand
.
Intn
(
1
<<
20
)
)
if
initCluster
{
id
=
1
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment