-
Notifications
You must be signed in to change notification settings - Fork 111
/
runtime.go
56 lines (48 loc) · 1.28 KB
/
runtime.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package runtime
import (
"context"
"fmt"
"github.com/rilldata/rill/runtime/drivers"
"go.uber.org/zap"
)
type Options struct {
ConnectionCacheSize int
MetastoreDriver string
MetastoreDSN string
QueryCacheSize int
}
type Runtime struct {
opts *Options
metastore drivers.Connection
logger *zap.Logger
connCache *connectionCache
catalogCache *catalogCache
queryCache *queryCache
}
func New(opts *Options, logger *zap.Logger) (*Runtime, error) {
// Open metadata db connection
metastore, err := drivers.Open(opts.MetastoreDriver, opts.MetastoreDSN, logger)
if err != nil {
return nil, fmt.Errorf("could not connect to metadata db: %w", err)
}
err = metastore.Migrate(context.Background())
if err != nil {
return nil, fmt.Errorf("metadata db migration: %w", err)
}
// Check the metastore is a registry
_, ok := metastore.RegistryStore()
if !ok {
return nil, fmt.Errorf("server metastore must be a valid registry")
}
return &Runtime{
opts: opts,
metastore: metastore,
logger: logger,
connCache: newConnectionCache(opts.ConnectionCacheSize, logger),
catalogCache: newCatalogCache(),
queryCache: newQueryCache(opts.QueryCacheSize),
}, nil
}
func (r *Runtime) Close() error {
return r.connCache.Close()
}