Skip to content

Commit 4c0e0ba

Browse files
authored
Forward query logs without control-plane batching (#959)
1 parent 10b0840 commit 4c0e0ba

5 files changed

Lines changed: 331 additions & 171 deletions

File tree

controlplane/session_mgr.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,11 @@ func (sm *SessionManager) createSessionOnWorker(ctx context.Context, username st
585585
"pid", pid, "worker", worker.ID, "user", username, "warning", w)
586586
}
587587

588-
executor := flightclient.NewFlightExecutorFromClient(worker.client, sessionToken)
588+
executor := flightclient.NewFlightExecutorFromClientWithQueryLogLimiter(
589+
worker.client,
590+
sessionToken,
591+
worker.workerQueryLogLimiter(),
592+
)
589593
executor.SetControlMetadata(worker.ID, worker.OwnerCPInstanceID(), worker.OwnerEpoch())
590594

591595
if pid == 0 {

controlplane/session_mgr_drain_test.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"context"
77
"errors"
88
"io"
9-
"runtime"
109
"strings"
1110
"sync"
1211
"sync/atomic"
@@ -718,7 +717,6 @@ func TestDestroyAllSessions_ReleasesAllLeasesAndClearsSessions(t *testing.T) {
718717
}
719718

720719
func TestDestroyAllSessionsRejectsInFlightCreateBeforeRegistration(t *testing.T) {
721-
queryLogForwardersBefore := countFlightExecutorQueryLogForwarders()
722720
flightClient := &blockingCreateSessionFlightClient{
723721
createStarted: make(chan struct{}),
724722
allowCreate: make(chan struct{}),
@@ -792,7 +790,6 @@ func TestDestroyAllSessionsRejectsInFlightCreateBeforeRegistration(t *testing.T)
792790
if got := flightClient.destroyCalls.Load(); got != 1 {
793791
t.Fatalf("expected worker session to be destroyed once, got %d", got)
794792
}
795-
waitForFlightExecutorQueryLogForwardersAtMost(t, queryLogForwardersBefore)
796793
}
797794

798795
func TestDestroyAllSessionsWaitsForCreateBlockedInLimiterAcquire(t *testing.T) {
@@ -979,24 +976,6 @@ func waitForSessionManagerDraining(t *testing.T, sm *SessionManager) {
979976
t.Fatal("timed out waiting for session manager to start draining")
980977
}
981978

982-
func waitForFlightExecutorQueryLogForwardersAtMost(t *testing.T, want int) {
983-
t.Helper()
984-
deadline := time.Now().Add(time.Second)
985-
for time.Now().Before(deadline) {
986-
if got := countFlightExecutorQueryLogForwarders(); got <= want {
987-
return
988-
}
989-
time.Sleep(time.Millisecond)
990-
}
991-
t.Fatalf("flight executor query-log forwarder count = %d, want <= %d", countFlightExecutorQueryLogForwarders(), want)
992-
}
993-
994-
func countFlightExecutorQueryLogForwarders() int {
995-
buf := make([]byte, 1<<20)
996-
n := runtime.Stack(buf, true)
997-
return strings.Count(string(buf[:n]), "(*FlightExecutor).queryLogForwardLoop")
998-
}
999-
1000979
func countEvents(events []string, want string) int {
1001980
count := 0
1002981
for _, event := range events {

controlplane/worker_mgr.go

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,27 @@ import (
2626

2727
// ManagedWorker represents a duckdb-service worker process.
2828
type ManagedWorker struct {
29-
ID int
30-
podName string
31-
nodeName string //nolint:unused // only set in kubernetes remote backend; drives cache-locality-aware scheduling
32-
image string //nolint:unused // only set in kubernetes remote backend; carried through runtime store records
33-
profile WorkerProfile //nolint:unused // only set in kubernetes remote backend; pod-shape this worker was spawned with (zero = default exclusive)
34-
cmd *exec.Cmd
35-
socketPath string
36-
bearerToken string
37-
client *flightsql.Client
38-
parentListener net.Listener // CP-side listener; lifecycle managed by releaseSocket
39-
prebound *preboundSocket // non-nil if using a pre-bound socket slot
40-
releaseOnce sync.Once // ensures releaseWorkerSocket body runs exactly once
41-
done chan struct{} // closed when process exits
42-
exitErr error
43-
activeSessions int // Number of sessions currently assigned to this worker
44-
lastUsed time.Time // Last time a session was destroyed on this worker
45-
sharedState SharedWorkerState
46-
reservedAt time.Time //nolint:unused // only set in kubernetes remote backend reservation path
47-
peakSessions int // High-water mark of concurrent sessions (for retirement metrics)
29+
ID int
30+
podName string
31+
nodeName string //nolint:unused // only set in kubernetes remote backend; drives cache-locality-aware scheduling
32+
image string //nolint:unused // only set in kubernetes remote backend; carried through runtime store records
33+
profile WorkerProfile //nolint:unused // only set in kubernetes remote backend; pod-shape this worker was spawned with (zero = default exclusive)
34+
cmd *exec.Cmd
35+
socketPath string
36+
bearerToken string
37+
client *flightsql.Client
38+
queryLogLimiterOnce sync.Once
39+
queryLogLimiter *flightclient.QueryLogLimiter
40+
parentListener net.Listener // CP-side listener; lifecycle managed by releaseSocket
41+
prebound *preboundSocket // non-nil if using a pre-bound socket slot
42+
releaseOnce sync.Once // ensures releaseWorkerSocket body runs exactly once
43+
done chan struct{} // closed when process exits
44+
exitErr error
45+
activeSessions int // Number of sessions currently assigned to this worker
46+
lastUsed time.Time // Last time a session was destroyed on this worker
47+
sharedState SharedWorkerState
48+
reservedAt time.Time //nolint:unused // only set in kubernetes remote backend reservation path
49+
peakSessions int // High-water mark of concurrent sessions (for retirement metrics)
4850
// ownerEpoch is guarded by epochMu so cred-refresh's
4951
// "RefreshLease then SetOwnerEpoch" sequence appears atomic to
5052
// concurrent readers (notably ShutdownAll's lease minting).
@@ -58,6 +60,13 @@ type ManagedWorker struct {
5860
cachedActivationPayload any //nolint:unused // *TenantActivationPayload, cached in kubernetes activation path
5961
}
6062

63+
func (w *ManagedWorker) workerQueryLogLimiter() *flightclient.QueryLogLimiter {
64+
w.queryLogLimiterOnce.Do(func() {
65+
w.queryLogLimiter = flightclient.NewQueryLogLimiter()
66+
})
67+
return w.queryLogLimiter
68+
}
69+
6170
// Profile returns the pod-shape profile this worker was spawned with (zero =
6271
// default exclusive profile). Exposes the unexported field for the admin API.
6372
func (w *ManagedWorker) Profile() WorkerProfile {

0 commit comments

Comments
 (0)