Skip to content

Commit 59ca911

Browse files
chore: remove unused cache from sandbox catalog (#2315)
* chore: remove unused cache from sandbox catalog * chore: auto-commit generated changes * fix: remove unused file --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent edd7b2b commit 59ca911

6 files changed

Lines changed: 3 additions & 220 deletions

File tree

packages/api/internal/orchestrator/orchestrator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func New(
112112

113113
var routingCatalog e2bcatalog.SandboxesCatalog
114114
if redisClient != nil {
115-
routingCatalog = e2bcatalog.NewRedisSandboxCatalog(redisClient, e2bcatalog.NewReadThroughSandboxCache())
115+
routingCatalog = e2bcatalog.NewRedisSandboxCatalog(redisClient)
116116
} else {
117117
routingCatalog = e2bcatalog.NewMemorySandboxesCatalog()
118118
}

packages/client-proxy/go.sum

Lines changed: 0 additions & 80 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/client-proxy/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func run() int {
122122
l.Error(ctx, "Failed to close redis client", zap.Error(err))
123123
}
124124
}()
125-
catalog = e2bcatalog.NewRedisSandboxCatalog(redisClient, e2bcatalog.NewNoopSandboxCache())
125+
catalog = e2bcatalog.NewRedisSandboxCatalog(redisClient)
126126
} else {
127127
if !errors.Is(err, factories.ErrRedisDisabled) {
128128
l.Error(ctx, "Failed to create redis client", zap.Error(err))

packages/shared/pkg/sandbox-catalog/cache_noop.go

Lines changed: 0 additions & 27 deletions
This file was deleted.

packages/shared/pkg/sandbox-catalog/catalog_redis.go

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"fmt"
88
"time"
99

10-
"github.com/jellydator/ttlcache/v3"
1110
"github.com/redis/go-redis/v9"
1211
"go.uber.org/zap"
1312

@@ -16,52 +15,24 @@ import (
1615

1716
const (
1817
catalogRedisTimeout = time.Second * 1
19-
20-
// this is just how long we are keeping sandbox in local cache so we don't have to query redis every time
21-
// we don't want to go too high because then sbx can be run on different orchestrator, and we will not be able to find it
22-
catalogRedisLocalCacheTtl = time.Millisecond * 500
2318
)
2419

25-
type SandboxCache interface {
26-
Get(key string, opts ...ttlcache.Option[string, *SandboxInfo]) *ttlcache.Item[string, *SandboxInfo]
27-
Set(key string, value *SandboxInfo, ttl time.Duration) *ttlcache.Item[string, *SandboxInfo]
28-
Delete(key string)
29-
Stop()
30-
}
31-
3220
type RedisSandboxCatalog struct {
3321
redisClient redis.UniversalClient
34-
cache SandboxCache
3522
}
3623

3724
var _ SandboxesCatalog = (*RedisSandboxCatalog)(nil)
3825

39-
func NewReadThroughSandboxCache() *ttlcache.Cache[string, *SandboxInfo] {
40-
cache := ttlcache.New(
41-
ttlcache.WithTTL[string, *SandboxInfo](catalogRedisLocalCacheTtl),
42-
ttlcache.WithDisableTouchOnHit[string, *SandboxInfo](),
43-
)
44-
go cache.Start()
45-
46-
return cache
47-
}
48-
49-
func NewRedisSandboxCatalog(redisClient redis.UniversalClient, cache SandboxCache) *RedisSandboxCatalog {
26+
func NewRedisSandboxCatalog(redisClient redis.UniversalClient) *RedisSandboxCatalog {
5027
return &RedisSandboxCatalog{
5128
redisClient: redisClient,
52-
cache: cache,
5329
}
5430
}
5531

5632
func (c *RedisSandboxCatalog) GetSandbox(ctx context.Context, sandboxID string) (*SandboxInfo, error) {
5733
spanCtx, span := tracer.Start(ctx, "sandbox-catalog-get")
5834
defer span.End()
5935

60-
sandboxInfo := c.cache.Get(sandboxID)
61-
if sandboxInfo != nil {
62-
return sandboxInfo.Value(), nil
63-
}
64-
6536
ctx, ctxCancel := context.WithTimeout(spanCtx, catalogRedisTimeout)
6637
defer ctxCancel()
6738

@@ -80,8 +51,6 @@ func (c *RedisSandboxCatalog) GetSandbox(ctx context.Context, sandboxID string)
8051
return nil, fmt.Errorf("failed to unmarshal sandbox info: %w", err)
8152
}
8253

83-
c.cache.Set(sandboxID, info, catalogRedisLocalCacheTtl)
84-
8554
return info, nil
8655
}
8756

@@ -104,8 +73,6 @@ func (c *RedisSandboxCatalog) StoreSandbox(ctx context.Context, sandboxID string
10473
return fmt.Errorf("failed to store sandbox info in redis: %w", status.Err())
10574
}
10675

107-
c.cache.Set(sandboxID, sandboxInfo, catalogRedisLocalCacheTtl)
108-
10976
return nil
11077
}
11178

@@ -134,7 +101,6 @@ func (c *RedisSandboxCatalog) DeleteSandbox(ctx context.Context, sandboxID strin
134101
}
135102

136103
c.redisClient.Del(ctx, c.getCatalogKey(sandboxID))
137-
c.cache.Delete(sandboxID)
138104

139105
return nil
140106
}
@@ -144,7 +110,5 @@ func (c *RedisSandboxCatalog) getCatalogKey(sandboxID string) string {
144110
}
145111

146112
func (c *RedisSandboxCatalog) Close(_ context.Context) error {
147-
c.cache.Stop()
148-
149113
return nil
150114
}

0 commit comments

Comments
 (0)