From e302ce97ace90dd4532c46636034f6274aa0bb7c Mon Sep 17 00:00:00 2001 From: Pascal Fischer <32096965+pascal-fischer@users.noreply.github.com> Date: Wed, 18 Dec 2024 20:37:45 +0100 Subject: [PATCH] [management] increase network serial on change of networks (#3077) --- management/server/networks/manager.go | 5 ++++ .../server/networks/resources/manager.go | 25 ++++++++++++++----- management/server/networks/routers/manager.go | 21 +++++++++++++++- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/management/server/networks/manager.go b/management/server/networks/manager.go index cc7b546a803..29c455794a7 100644 --- a/management/server/networks/manager.go +++ b/management/server/networks/manager.go @@ -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()) }) diff --git a/management/server/networks/resources/manager.go b/management/server/networks/resources/manager.go index 2b33f85cd19..209107a3c58 100644 --- a/management/server/networks/resources/manager.go +++ b/management/server/networks/resources/manager.go @@ -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 { @@ -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 { @@ -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) @@ -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) diff --git a/management/server/networks/routers/manager.go b/management/server/networks/routers/manager.go index dc092d8ec35..cfe9bce4e95 100644 --- a/management/server/networks/routers/manager.go +++ b/management/server/networks/routers/manager.go @@ -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 { @@ -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 { @@ -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