Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/api/internal/sandbox/storage/memory/sync.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package memory

import (
"context"
"time"

"github.com/e2b-dev/infra/packages/api/internal/sandbox"
"github.com/e2b-dev/infra/packages/shared/pkg/logger"
)

// TODO: this should be removed once we have a better way to handle node sync
Expand Down Expand Up @@ -37,6 +39,13 @@ func (s *Storage) Sync(sandboxes []sandbox.Sandbox, nodeID string) []sandbox.San

_, found := sandboxMap[data.SandboxID]
if !found {
logger.L().Debug(
context.Background(),
"sync expiring sandbox missing from node report",
logger.WithSandboxID(data.SandboxID),
logger.WithTeamID(data.TeamID.String()),
logger.WithNodeID(nodeID),
)
item.SetExpired()
}
})
Expand All @@ -48,6 +57,13 @@ func (s *Storage) Sync(sandboxes []sandbox.Sandbox, nodeID string) []sandbox.San
continue
}

logger.L().Debug(
context.Background(),
"sync discovered sandbox missing from cache",
logger.WithSandboxID(sandbox.SandboxID),
logger.WithTeamID(sandbox.TeamID.String()),
logger.WithNodeID(nodeID),
)
toBeAdded = append(toBeAdded, sandbox)
}

Expand Down
7 changes: 7 additions & 0 deletions packages/api/internal/sandbox/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ func (s *Store) WaitForStateChange(ctx context.Context, teamID uuid.UUID, sandbo
func (s *Store) Sync(ctx context.Context, sandboxes []Sandbox, nodeID string) {
sbxs := s.storage.Sync(sandboxes, nodeID)
for _, sbx := range sbxs {
logger.L().Debug(
ctx,
"re-adding sandbox during sync",
logger.WithSandboxID(sbx.SandboxID),
logger.WithTeamID(sbx.TeamID.String()),
logger.WithNodeID(nodeID),
)
err := s.Add(ctx, sbx, false)
if err != nil {
logger.L().Error(ctx, "Failed to re-add sandbox during sync", zap.Error(err), logger.WithSandboxID(sbx.SandboxID))
Expand Down
5 changes: 5 additions & 0 deletions packages/shared/pkg/sandbox-catalog/catalog_memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"time"

"github.com/jellydator/ttlcache/v3"

"github.com/e2b-dev/infra/packages/shared/pkg/logger"
)

type MemorySandboxCatalog struct {
Expand Down Expand Up @@ -45,6 +47,8 @@ func (c *MemorySandboxCatalog) StoreSandbox(ctx context.Context, sandboxID strin
_, span := tracer.Start(ctx, "sandbox-catalog-store")
defer span.End()

logger.L().Debug(ctx, "storing sandbox in memory catalog", logger.WithSandboxID(sandboxID))

c.mtx.Lock()
defer c.mtx.Unlock()

Expand Down Expand Up @@ -75,6 +79,7 @@ func (c *MemorySandboxCatalog) DeleteSandbox(ctx context.Context, sandboxID stri
return nil
}

logger.L().Debug(ctx, "deleting sandbox from memory catalog", logger.WithSandboxID(sandboxID))
c.cache.Delete(sandboxID)

return nil
Expand Down
3 changes: 3 additions & 0 deletions packages/shared/pkg/sandbox-catalog/catalog_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ func (c *RedisSandboxCatalog) StoreSandbox(ctx context.Context, sandboxID string
spanCtx, span := tracer.Start(ctx, "sandbox-catalog-store")
defer span.End()

logger.L().Debug(ctx, "storing sandbox in redis catalog", logger.WithSandboxID(sandboxID))

ctx, ctxCancel := context.WithTimeout(spanCtx, catalogRedisTimeout)
defer ctxCancel()

Expand Down Expand Up @@ -132,6 +134,7 @@ func (c *RedisSandboxCatalog) DeleteSandbox(ctx context.Context, sandboxID strin
return nil
}

logger.L().Debug(ctx, "deleting sandbox from redis catalog", logger.WithSandboxID(sandboxID))
c.redisClient.Del(ctx, c.getCatalogKey(sandboxID))
c.cache.Delete(sandboxID)

Expand Down
Loading