Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
heketi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
Evili del Rio i Silvan
heketi
Commits
6ee7ab4e
Commit
6ee7ab4e
authored
7 years ago
by
Raghavendra Talur
Committed by
John Mulligan
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
use StorageSet in device resync op
Signed-off-by:
Raghavendra Talur
<
rtalur@redhat.com
>
parent
6b01cbdc
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
apps/glusterfs/app_device.go
+17
-22
17 additions, 22 deletions
apps/glusterfs/app_device.go
apps/glusterfs/app_device_test.go
+17
-9
17 additions, 9 deletions
apps/glusterfs/app_device_test.go
executors/mockexec/mock.go
+11
-1
11 additions, 1 deletion
executors/mockexec/mock.go
with
45 additions
and
32 deletions
apps/glusterfs/app_device.go
+
17
−
22
View file @
6ee7ab4e
...
@@ -346,8 +346,9 @@ func (a *App) DeviceResync(w http.ResponseWriter, r *http.Request) {
...
@@ -346,8 +346,9 @@ func (a *App) DeviceResync(w http.ResponseWriter, r *http.Request) {
deviceId
:=
vars
[
"id"
]
deviceId
:=
vars
[
"id"
]
var
(
var
(
device
*
DeviceEntry
device
*
DeviceEntry
node
*
NodeEntry
node
*
NodeEntry
brickSizesSum
uint64
)
)
// Get device info from DB
// Get device info from DB
...
@@ -361,6 +362,13 @@ func (a *App) DeviceResync(w http.ResponseWriter, r *http.Request) {
...
@@ -361,6 +362,13 @@ func (a *App) DeviceResync(w http.ResponseWriter, r *http.Request) {
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
for
_
,
brick
:=
range
device
.
Bricks
{
brickEntry
,
err
:=
NewBrickEntryFromId
(
tx
,
brick
)
if
err
!=
nil
{
return
err
}
brickSizesSum
+=
brickEntry
.
Info
.
Size
}
return
nil
return
nil
})
})
if
err
==
ErrNotFound
{
if
err
==
ErrNotFound
{
...
@@ -383,20 +391,6 @@ func (a *App) DeviceResync(w http.ResponseWriter, r *http.Request) {
...
@@ -383,20 +391,6 @@ func (a *App) DeviceResync(w http.ResponseWriter, r *http.Request) {
return
""
,
err
return
""
,
err
}
}
// Note that method GetDeviceInfo returns the free disk space available for allocation.
// The free disk space is equal to the total disk space only if we haven't already
// allocated space, because every allocation decreases the free disk space returned
// by method GetDeviceInfo. In order to calculate a new total space we need to sum
// the free disk space and the space used by heketi.
if
device
.
Info
.
Storage
.
Total
==
info
.
Size
+
device
.
Info
.
Storage
.
Used
{
logger
.
Info
(
"Device %v is up to date"
,
device
.
Info
.
Id
)
return
""
,
nil
}
logger
.
Debug
(
"Free space of '%v' (%v) has changed %v -> %v"
,
device
.
Info
.
Name
,
device
.
Info
.
Id
,
device
.
Info
.
Storage
.
Free
,
info
.
Size
)
// Update device
err
=
a
.
db
.
Update
(
func
(
tx
*
bolt
.
Tx
)
error
{
err
=
a
.
db
.
Update
(
func
(
tx
*
bolt
.
Tx
)
error
{
// Reload device in current transaction
// Reload device in current transaction
...
@@ -406,14 +400,15 @@ func (a *App) DeviceResync(w http.ResponseWriter, r *http.Request) {
...
@@ -406,14 +400,15 @@ func (a *App) DeviceResync(w http.ResponseWriter, r *http.Request) {
return
err
return
err
}
}
newFreeSize
:=
info
.
Size
if
brickSizesSum
!=
info
.
UsedSize
{
newTotalSize
:=
newFreeSize
+
device
.
Info
.
Storage
.
Used
logger
.
Info
(
"Sum of sizes of all bricks on the device:%v differs from used size from LVM:%v"
,
brickSizesSum
,
info
.
UsedSize
)
logger
.
Info
(
"Database needs cleaning"
)
}
logger
.
Info
(
"Updating device %v, total: %v -> %v, free: %v -> %v"
,
device
.
Info
.
Name
,
logger
.
Info
(
"Updating device %v, total: %v -> %v, free: %v ->
%v, used: %v ->
%v"
,
device
.
Info
.
Name
,
device
.
Info
.
Storage
.
Total
,
new
TotalSize
,
device
.
Info
.
Storage
.
Free
,
newFree
Size
)
device
.
Info
.
Storage
.
Total
,
info
.
TotalSize
,
device
.
Info
.
Storage
.
Free
,
info
.
FreeSize
,
device
.
Info
.
Storage
.
Used
,
info
.
Used
Size
)
device
.
Info
.
Storage
.
Total
=
newTotalSize
device
.
StorageSet
(
info
.
TotalSize
,
info
.
FreeSize
,
info
.
UsedSize
)
device
.
Info
.
Storage
.
Free
=
newFreeSize
// Save updated device
// Save updated device
err
=
device
.
Save
(
tx
)
err
=
device
.
Save
(
tx
)
...
...
This diff is collapsed.
Click to expand it.
apps/glusterfs/app_device_test.go
+
17
−
9
View file @
6ee7ab4e
...
@@ -789,14 +789,13 @@ func TestDeviceSync(t *testing.T) {
...
@@ -789,14 +789,13 @@ func TestDeviceSync(t *testing.T) {
ts
:=
httptest
.
NewServer
(
router
)
ts
:=
httptest
.
NewServer
(
router
)
defer
ts
.
Close
()
defer
ts
.
Close
()
var
total
,
used
,
newFree
uint64
total
=
200
*
1024
*
1024
used
=
100
*
1024
*
1024
newFree
=
500
*
1024
*
1024
// see mockexec
nodeId
:=
utils
.
GenUUID
()
nodeId
:=
utils
.
GenUUID
()
deviceId
:=
utils
.
GenUUID
()
deviceId
:=
utils
.
GenUUID
()
var
total
uint64
=
600
*
1024
*
1024
var
used
uint64
=
250
*
1024
*
1024
var
free
uint64
=
350
*
1024
*
1024
// Init test database
// Init test database
err
:=
app
.
db
.
Update
(
func
(
tx
*
bolt
.
Tx
)
error
{
err
:=
app
.
db
.
Update
(
func
(
tx
*
bolt
.
Tx
)
error
{
cluster
:=
NewClusterEntry
()
cluster
:=
NewClusterEntry
()
...
@@ -809,8 +808,8 @@ func TestDeviceSync(t *testing.T) {
...
@@ -809,8 +808,8 @@ func TestDeviceSync(t *testing.T) {
device
.
Info
.
Id
=
deviceId
device
.
Info
.
Id
=
deviceId
device
.
Info
.
Name
=
"/dev/abc"
device
.
Info
.
Name
=
"/dev/abc"
device
.
NodeId
=
nodeId
device
.
NodeId
=
nodeId
device
.
StorageSet
(
total
)
device
.
StorageSet
(
total
,
total
,
0
)
device
.
StorageAllocate
(
used
)
device
.
StorageAllocate
(
100
)
if
err
:=
device
.
Save
(
tx
);
err
!=
nil
{
if
err
:=
device
.
Save
(
tx
);
err
!=
nil
{
return
err
return
err
...
@@ -833,6 +832,14 @@ func TestDeviceSync(t *testing.T) {
...
@@ -833,6 +832,14 @@ func TestDeviceSync(t *testing.T) {
})
})
tests
.
Assert
(
t
,
err
==
nil
)
tests
.
Assert
(
t
,
err
==
nil
)
app
.
xo
.
MockGetDeviceInfo
=
func
(
host
,
device
,
vgid
string
)
(
*
executors
.
DeviceInfo
,
error
)
{
d
:=
&
executors
.
DeviceInfo
{}
d
.
TotalSize
=
total
d
.
FreeSize
=
free
d
.
UsedSize
=
used
d
.
ExtentSize
=
4096
return
d
,
nil
}
r
,
err
:=
http
.
Get
(
ts
.
URL
+
"/devices/"
+
deviceId
+
"/resync"
)
r
,
err
:=
http
.
Get
(
ts
.
URL
+
"/devices/"
+
deviceId
+
"/resync"
)
tests
.
Assert
(
t
,
err
==
nil
)
tests
.
Assert
(
t
,
err
==
nil
)
tests
.
Assert
(
t
,
r
.
StatusCode
==
http
.
StatusAccepted
)
tests
.
Assert
(
t
,
r
.
StatusCode
==
http
.
StatusAccepted
)
...
@@ -856,12 +863,13 @@ func TestDeviceSync(t *testing.T) {
...
@@ -856,12 +863,13 @@ func TestDeviceSync(t *testing.T) {
err
=
app
.
db
.
View
(
func
(
tx
*
bolt
.
Tx
)
error
{
err
=
app
.
db
.
View
(
func
(
tx
*
bolt
.
Tx
)
error
{
device
,
err
:=
NewDeviceEntryFromId
(
tx
,
deviceId
)
device
,
err
:=
NewDeviceEntryFromId
(
tx
,
deviceId
)
tests
.
Assert
(
t
,
err
==
nil
)
tests
.
Assert
(
t
,
err
==
nil
)
tests
.
Assert
(
t
,
device
.
Info
.
Storage
.
Total
==
newFree
+
used
)
tests
.
Assert
(
t
,
device
.
Info
.
Storage
.
Total
==
total
,
"expected:"
,
total
,
"got:"
,
device
.
Info
.
Storage
.
Total
)
tests
.
Assert
(
t
,
device
.
Info
.
Storage
.
Free
==
newF
ree
)
tests
.
Assert
(
t
,
device
.
Info
.
Storage
.
Free
==
f
ree
)
tests
.
Assert
(
t
,
device
.
Info
.
Storage
.
Used
==
used
)
tests
.
Assert
(
t
,
device
.
Info
.
Storage
.
Used
==
used
)
return
nil
return
nil
})
})
tests
.
Assert
(
t
,
err
==
nil
)
tests
.
Assert
(
t
,
err
==
nil
)
}
}
func
TestDeviceSyncIdNotFound
(
t
*
testing
.
T
)
{
func
TestDeviceSyncIdNotFound
(
t
*
testing
.
T
)
{
...
...
This diff is collapsed.
Click to expand it.
executors/mockexec/mock.go
+
11
−
1
View file @
6ee7ab4e
...
@@ -20,6 +20,7 @@ type MockExecutor struct {
...
@@ -20,6 +20,7 @@ type MockExecutor struct {
MockPeerDetach
func
(
exec_host
,
newnode
string
)
error
MockPeerDetach
func
(
exec_host
,
newnode
string
)
error
MockDeviceSetup
func
(
host
,
device
,
vgid
string
,
destroy
bool
)
(
*
executors
.
DeviceInfo
,
error
)
MockDeviceSetup
func
(
host
,
device
,
vgid
string
,
destroy
bool
)
(
*
executors
.
DeviceInfo
,
error
)
MockDeviceTeardown
func
(
host
,
device
,
vgid
string
)
error
MockDeviceTeardown
func
(
host
,
device
,
vgid
string
)
error
MockGetDeviceInfo
func
(
host
,
device
,
vgid
string
)
(
*
executors
.
DeviceInfo
,
error
)
MockBrickCreate
func
(
host
string
,
brick
*
executors
.
BrickRequest
)
(
*
executors
.
BrickInfo
,
error
)
MockBrickCreate
func
(
host
string
,
brick
*
executors
.
BrickRequest
)
(
*
executors
.
BrickInfo
,
error
)
MockBrickDestroy
func
(
host
string
,
brick
*
executors
.
BrickRequest
)
(
bool
,
error
)
MockBrickDestroy
func
(
host
string
,
brick
*
executors
.
BrickRequest
)
(
bool
,
error
)
MockVolumeCreate
func
(
host
string
,
volume
*
executors
.
VolumeRequest
)
(
*
executors
.
Volume
,
error
)
MockVolumeCreate
func
(
host
string
,
volume
*
executors
.
VolumeRequest
)
(
*
executors
.
Volume
,
error
)
...
@@ -66,6 +67,15 @@ func NewMockExecutor() (*MockExecutor, error) {
...
@@ -66,6 +67,15 @@ func NewMockExecutor() (*MockExecutor, error) {
return
nil
return
nil
}
}
m
.
MockGetDeviceInfo
=
func
(
host
,
device
,
vgid
string
)
(
*
executors
.
DeviceInfo
,
error
)
{
d
:=
&
executors
.
DeviceInfo
{}
d
.
TotalSize
=
500
*
1024
*
1024
d
.
FreeSize
=
500
*
1024
*
1024
d
.
UsedSize
=
0
d
.
ExtentSize
=
4096
return
d
,
nil
}
m
.
MockBrickCreate
=
func
(
host
string
,
brick
*
executors
.
BrickRequest
)
(
*
executors
.
BrickInfo
,
error
)
{
m
.
MockBrickCreate
=
func
(
host
string
,
brick
*
executors
.
BrickRequest
)
(
*
executors
.
BrickInfo
,
error
)
{
b
:=
&
executors
.
BrickInfo
{
b
:=
&
executors
.
BrickInfo
{
Path
:
"/mockpath"
,
Path
:
"/mockpath"
,
...
@@ -204,7 +214,7 @@ func (m *MockExecutor) DeviceSetup(host, device, vgid string, destroy bool) (*ex
...
@@ -204,7 +214,7 @@ func (m *MockExecutor) DeviceSetup(host, device, vgid string, destroy bool) (*ex
}
}
func
(
m
*
MockExecutor
)
GetDeviceInfo
(
host
,
device
,
vgid
string
)
(
*
executors
.
DeviceInfo
,
error
)
{
func
(
m
*
MockExecutor
)
GetDeviceInfo
(
host
,
device
,
vgid
string
)
(
*
executors
.
DeviceInfo
,
error
)
{
return
m
.
MockDevice
Setup
(
host
,
device
,
vgid
,
false
)
return
m
.
Mock
Get
Device
Info
(
host
,
device
,
vgid
)
}
}
func
(
m
*
MockExecutor
)
DeviceTeardown
(
host
,
device
,
vgid
string
)
error
{
func
(
m
*
MockExecutor
)
DeviceTeardown
(
host
,
device
,
vgid
string
)
error
{
...
...
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