Skip to content
Snippets Groups Projects
Commit 6ee7ab4e authored by Raghavendra Talur's avatar Raghavendra Talur Committed by John Mulligan
Browse files

use StorageSet in device resync op


Signed-off-by: default avatarRaghavendra Talur <rtalur@redhat.com>
parent 6b01cbdc
No related branches found
No related tags found
No related merge requests found
...@@ -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, newTotalSize, device.Info.Storage.Free, newFreeSize) device.Info.Storage.Total, info.TotalSize, device.Info.Storage.Free, info.FreeSize, device.Info.Storage.Used, info.UsedSize)
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)
......
...@@ -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 == newFree) tests.Assert(t, device.Info.Storage.Free == free)
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) {
......
...@@ -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.MockDeviceSetup(host, device, vgid, false) return m.MockGetDeviceInfo(host, device, vgid)
} }
func (m *MockExecutor) DeviceTeardown(host, device, vgid string) error { func (m *MockExecutor) DeviceTeardown(host, device, vgid string) error {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment