Skip to content

Commit 404d576

Browse files
authored
Merge branch 'main' into replace-bitset-with-roaring
2 parents 0205899 + 10e4f50 commit 404d576

2 files changed

Lines changed: 57 additions & 4 deletions

File tree

packages/db/scripts/seed/postgres/seed-db.go

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,46 @@ func main() {
7777
}
7878
defer authDb.Close()
7979

80-
// Open .e2b/config.json
81-
// Delete existing user and recreate (simpler for seeding)
80+
// Clean up existing data for idempotent re-seeding.
81+
// Delete child rows that have ON DELETE NO ACTION constraints
82+
// before deleting the team and user.
83+
err = authDb.TestsRawSQL(ctx, `
84+
DELETE FROM envs WHERE team_id IN (SELECT id FROM teams WHERE email = $1)
85+
`, email)
86+
if err != nil {
87+
panic(err)
88+
}
89+
90+
err = authDb.TestsRawSQL(ctx, `
91+
DELETE FROM snapshots WHERE team_id IN (SELECT id FROM teams WHERE email = $1)
92+
`, email)
93+
if err != nil {
94+
panic(err)
95+
}
96+
97+
err = authDb.TestsRawSQL(ctx, `
98+
DELETE FROM volumes WHERE team_id IN (SELECT id FROM teams WHERE email = $1)
99+
`, email)
100+
if err != nil {
101+
panic(err)
102+
}
103+
104+
err = authDb.TestsRawSQL(ctx, `
105+
DELETE FROM addons WHERE added_by IN (SELECT id FROM auth.users WHERE email = $1)
106+
`, email)
107+
if err != nil {
108+
panic(err)
109+
}
110+
111+
// Now safe to delete team (team_api_keys, users_teams cascade automatically)
112+
err = authDb.TestsRawSQL(ctx, `
113+
DELETE FROM teams WHERE email = $1
114+
`, email)
115+
if err != nil {
116+
panic(err)
117+
}
118+
119+
// Now safe to delete user (access_tokens cascade automatically)
82120
err = authDb.TestsRawSQL(ctx, `
83121
DELETE FROM auth.users WHERE email = $1
84122
`, email)
@@ -87,6 +125,10 @@ DELETE FROM auth.users WHERE email = $1
87125
}
88126

89127
// Create the user
128+
// NOTE: Inserting into auth.users fires the sync_inserts_to_public_users trigger,
129+
// which inserts into public.users, which fires the post_user_signup trigger,
130+
// which auto-creates a default team + users_teams row. We delete that
131+
// trigger-created team below so we can create our own with a known ID/name.
90132
userID := uuid.New()
91133
err = authDb.TestsRawSQL(ctx, `
92134
INSERT INTO auth.users (id, email)
@@ -96,7 +138,8 @@ VALUES ($1, $2)
96138
panic(err)
97139
}
98140

99-
// Delete team
141+
// Remove the team auto-created by the post_user_signup trigger so we can
142+
// create our own seed team with a deterministic ID and custom name/slug.
100143
err = authDb.TestsRawSQL(ctx, `
101144
DELETE FROM teams WHERE email = $1
102145
`, email)

packages/orchestrator/pkg/sandbox/nbd/dispatch.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ var (
3434

3535
var ErrShuttingDown = errors.New("shutting down. Cannot serve any new requests")
3636

37+
var dispatchBufPool = sync.Pool{
38+
New: func() any {
39+
b := make([]byte, dispatchBufferSize)
40+
41+
return &b
42+
},
43+
}
44+
3745
type Provider interface {
3846
storage.SeekableReader
3947
io.WriterAt
@@ -141,7 +149,9 @@ func (d *Dispatch) writeResponse(respError uint32, respHandle uint64, chunk []by
141149
*
142150
*/
143151
func (d *Dispatch) Handle(ctx context.Context) error {
144-
buffer := make([]byte, dispatchBufferSize)
152+
poolBuf := dispatchBufPool.Get().(*[]byte)
153+
defer dispatchBufPool.Put(poolBuf)
154+
buffer := *poolBuf
145155
wp := 0
146156

147157
request := Request{}

0 commit comments

Comments
 (0)