MCPcopy Create free account
hub / github.com/rilldata/rill / flush

Method flush

runtime/catalog_cache.go:96–135  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
96func (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).

Callers 3

closeMethod · 0.95
RunMethod · 0.45
FlushMethod · 0.45

Calls 7

getMethod · 0.95
nameStrFunction · 0.85
resourceToDriverFunction · 0.85
ErrorfMethod · 0.65
DeleteResourceMethod · 0.65
UpdateResourceMethod · 0.65
CreateResourceMethod · 0.65

Tested by

no test coverage detected