Skip to content

Commit 8f5371d

Browse files
authored
Merge pull request #1656 from ydb-platform/mark-attach-goroutine
Added debug mark for attach sessions
2 parents 2fe7275 + a02e383 commit 8f5371d

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

internal/query/session_core.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package query
22

33
import (
44
"context"
5+
"os"
6+
"runtime/pprof"
7+
"strconv"
58
"sync/atomic"
69
"time"
710

@@ -22,6 +25,9 @@ import (
2225
"github.com/ydb-platform/ydb-go-sdk/v3/trace"
2326
)
2427

28+
// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals
29+
var setGoroutineLabelForAttachStream = os.Getenv("YDB_QUERY_SESSION_ATTACH_STREAM_GOROUTINE_LABEL") == "1"
30+
2531
type (
2632
Core interface {
2733
query.SessionInfo
@@ -110,6 +116,7 @@ func WithTrace(t *trace.Query) Option {
110116
}
111117
}
112118

119+
//nolint:funlen
113120
func Open(
114121
ctx context.Context, client Ydb_Query_V1.QueryServiceClient, opts ...Option,
115122
) (_ *sessionCore, finalErr error) {
@@ -152,7 +159,19 @@ func Open(
152159
core.id = response.GetSessionId()
153160
core.nodeID = uint32(response.GetNodeId())
154161

155-
err = core.attach(ctx)
162+
if setGoroutineLabelForAttachStream {
163+
attachRes := make(chan error)
164+
pprof.Do(ctx, pprof.Labels(
165+
"node_id", strconv.Itoa(int(core.NodeID())),
166+
), func(ctx context.Context) {
167+
go func() {
168+
attachRes <- core.attach(ctx)
169+
}()
170+
})
171+
err = <-attachRes
172+
} else {
173+
err = core.attach(ctx)
174+
}
156175
if err != nil {
157176
_ = core.deleteSession(ctx)
158177

0 commit comments

Comments
 (0)