-
Notifications
You must be signed in to change notification settings - Fork 117
/
runtime.go
65 lines (58 loc) · 1.6 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
57
58
59
60
61
62
63
64
65
package runtime
import (
"context"
"errors"
"fmt"
"math"
runtimev1 "github.com/rilldata/rill/proto/gen/rill/runtime/v1"
"github.com/rilldata/rill/runtime/drivers"
"github.com/rilldata/rill/runtime/pkg/activity"
"go.uber.org/zap"
)
type Options struct {
ConnectionCacheSize int
MetastoreConnector string
QueryCacheSizeBytes int64
AllowHostAccess bool
SafeSourceRefresh bool
// SystemConnectors are drivers whose handles are shared with all instances
SystemConnectors []*runtimev1.Connector
}
type Runtime struct {
opts *Options
metastore drivers.Handle
logger *zap.Logger
connCache *connectionCache
migrationMetaCache *migrationMetaCache
queryCache *queryCache
}
func New(opts *Options, logger *zap.Logger, client activity.Client) (*Runtime, error) {
rt := &Runtime{
opts: opts,
logger: logger,
connCache: newConnectionCache(opts.ConnectionCacheSize, logger, client),
migrationMetaCache: newMigrationMetaCache(math.MaxInt),
queryCache: newQueryCache(opts.QueryCacheSizeBytes),
}
store, _, err := rt.AcquireSystemHandle(context.Background(), opts.MetastoreConnector)
if err != nil {
return nil, err
}
// Check the metastore is a registry
_, ok := store.AsRegistry()
if !ok {
return nil, fmt.Errorf("server metastore must be a valid registry")
}
rt.metastore = store
return rt, nil
}
func (r *Runtime) AllowHostAccess() bool {
return r.opts.AllowHostAccess
}
func (r *Runtime) Close() error {
return errors.Join(
r.metastore.Close(),
r.connCache.Close(),
r.queryCache.close(),
)
}