flush flushes changes to the underlying store. Unlike other catalog functions, it is safe to call flush concurrently with calls to get and list (i.e. under a read lock). However, it is not safe to call flush concurrently with other calls to flush.
(ctx context.Context)
| 94 | // Unlike other catalog functions, it is safe to call flush concurrently with calls to get and list (i.e. under a read lock). |
| 95 | // However, it is not safe to call flush concurrently with other calls to flush. |
| 96 | func (c *catalogCache) flush(ctx context.Context) error { |
| 97 | for s, n := range c.dirty { |
| 98 | r, err := c.get(n, true, false) |
| 99 | if err != nil { |
| 100 | if !errors.Is(err, drivers.ErrResourceNotFound) { |
| 101 | return fmt.Errorf("flush: unexpected error from get: %w", err) |
| 102 | } |
| 103 | |
| 104 | // Resource should be deleted from store |
| 105 | err = c.store.DeleteResource(ctx, c.version, n.Kind, n.Name) |
| 106 | if err != nil { |
| 107 | return err |
| 108 | } |
| 109 | delete(c.dirty, s) |
| 110 | delete(c.stored, s) |
| 111 | continue |
| 112 | } |
| 113 | |
| 114 | // Resource should be saved in store |
| 115 | s := nameStr(r.Meta.Name) |
| 116 | if c.stored[s] { |
| 117 | // Updating |
| 118 | err = c.store.UpdateResource(ctx, c.version, resourceToDriver(r)) |
| 119 | if err != nil { |
| 120 | return err |
| 121 | } |
| 122 | } else { |
| 123 | // Creating |
| 124 | err = c.store.CreateResource(ctx, c.version, resourceToDriver(r)) |
| 125 | if err != nil { |
| 126 | return err |
| 127 | } |
| 128 | c.stored[s] = true |
| 129 | } |
| 130 | |
| 131 | delete(c.dirty, s) |
| 132 | } |
| 133 | |
| 134 | return nil |
| 135 | } |
| 136 | |
| 137 | // get returns a resource from the catalog. |
| 138 | // Unlike other catalog functions, it is safe to call get concurrently with calls to list and flush (i.e. under a read lock). |
no test coverage detected