Skip to content

Commit

Permalink
[management] increase network serial on change of networks (#3077)
Browse files Browse the repository at this point in the history
  • Loading branch information
pascal-fischer authored Dec 18, 2024
1 parent d5e4d0c commit e302ce9
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
5 changes: 5 additions & 0 deletions management/server/networks/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ func (m *managerImpl) DeleteNetwork(ctx context.Context, accountID, userID, netw
return fmt.Errorf("failed to delete network: %w", err)
}

err = transaction.IncrementNetworkSerial(ctx, store.LockingStrengthUpdate, accountID)
if err != nil {
return fmt.Errorf("failed to increment network serial: %w", err)
}

eventsToStore = append(eventsToStore, func() {
m.accountManager.StoreEvent(ctx, userID, networkID, accountID, activity.NetworkDeleted, network.EventMeta())
})
Expand Down
25 changes: 19 additions & 6 deletions management/server/networks/resources/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ func (m *managerImpl) CreateResource(ctx context.Context, userID string, resourc
eventsToStore = append(eventsToStore, event)
}

err = transaction.IncrementNetworkSerial(ctx, store.LockingStrengthUpdate, resource.AccountID)
if err != nil {
return fmt.Errorf("failed to increment network serial: %w", err)
}

return nil
})
if err != nil {
Expand Down Expand Up @@ -232,6 +237,11 @@ func (m *managerImpl) UpdateResource(ctx context.Context, userID string, resourc
m.accountManager.StoreEvent(ctx, userID, resource.ID, resource.AccountID, activity.NetworkResourceUpdated, resource.EventMeta(network.Name))
})

err = transaction.IncrementNetworkSerial(ctx, store.LockingStrengthUpdate, resource.AccountID)
if err != nil {
return fmt.Errorf("failed to increment network serial: %w", err)
}

return nil
})
if err != nil {
Expand Down Expand Up @@ -300,8 +310,16 @@ func (m *managerImpl) DeleteResource(ctx context.Context, accountID, userID, net
var events []func()
err = m.store.ExecuteInTransaction(ctx, func(transaction store.Store) error {
events, err = m.DeleteResourceInTransaction(ctx, transaction, accountID, networkID, resourceID)
return err
if err != nil {
return fmt.Errorf("failed to delete resource: %w", err)
}

err = transaction.IncrementNetworkSerial(ctx, store.LockingStrengthUpdate, accountID)
if err != nil {
return fmt.Errorf("failed to increment network serial: %w", err)
}

return nil
})
if err != nil {
return fmt.Errorf("failed to delete network resource: %w", err)
Expand Down Expand Up @@ -346,11 +364,6 @@ func (m *managerImpl) DeleteResourceInTransaction(ctx context.Context, transacti
eventsToStore = append(eventsToStore, event)
}

err = transaction.IncrementNetworkSerial(ctx, store.LockingStrengthUpdate, accountID)
if err != nil {
return nil, fmt.Errorf("failed to increment network serial: %w", err)
}

err = transaction.DeleteNetworkResource(ctx, store.LockingStrengthUpdate, accountID, resourceID)
if err != nil {
return nil, fmt.Errorf("failed to delete network resource: %w", err)
Expand Down
21 changes: 20 additions & 1 deletion management/server/networks/routers/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ func (m *managerImpl) CreateRouter(ctx context.Context, userID string, router *t
return fmt.Errorf("failed to create network router: %w", err)
}

err = transaction.IncrementNetworkSerial(ctx, store.LockingStrengthUpdate, router.AccountID)
if err != nil {
return fmt.Errorf("failed to increment network serial: %w", err)
}

return nil
})
if err != nil {
Expand Down Expand Up @@ -163,6 +168,11 @@ func (m *managerImpl) UpdateRouter(ctx context.Context, userID string, router *t
return fmt.Errorf("failed to update network router: %w", err)
}

err = transaction.IncrementNetworkSerial(ctx, store.LockingStrengthUpdate, router.AccountID)
if err != nil {
return fmt.Errorf("failed to increment network serial: %w", err)
}

return nil
})
if err != nil {
Expand All @@ -188,7 +198,16 @@ func (m *managerImpl) DeleteRouter(ctx context.Context, accountID, userID, netwo
var event func()
err = m.store.ExecuteInTransaction(ctx, func(transaction store.Store) error {
event, err = m.DeleteRouterInTransaction(ctx, transaction, accountID, networkID, routerID)
return err
if err != nil {
return fmt.Errorf("failed to delete network router: %w", err)
}

err = transaction.IncrementNetworkSerial(ctx, store.LockingStrengthUpdate, accountID)
if err != nil {
return fmt.Errorf("failed to increment network serial: %w", err)
}

return nil
})
if err != nil {
return err
Expand Down

0 comments on commit e302ce9

Please sign in to comment.