@@ -50,6 +50,11 @@ const (
5050// Default fetch size
5151const bolt5FetchSize = 1000
5252
53+ const (
54+ telemetryEnabledHintName = "telemetry.enabled"
55+ ssrEnabledHintName = "ssr.enabled"
56+ )
57+
5358type internalTx5 struct {
5459 mode idb.AccessMode
5560 bookmarks []string
@@ -93,28 +98,30 @@ func (i *internalTx5) toMeta(logger log.Logger, logId string, version db.Protoco
9398}
9499
95100type bolt5 struct {
96- state int
97- txId idb.TxHandle
98- streams openstreams
99- conn io.ReadWriteCloser
100- serverName string
101- queue messageQueue
102- connId string
103- logId string
104- serverVersion string
105- bookmark string // Last bookmark
106- birthDate time.Time
107- log log.Logger
108- databaseName string
109- err error // Last fatal error
110- minor int
111- lastQid int64 // Last seen qid
112- idleDate time.Time
113- auth map [string ]any
114- authManager auth.TokenManager
115- resetAuth bool
116- errorListener ConnectionErrorListener
117- telemetryEnabled bool
101+ state int
102+ txId idb.TxHandle
103+ streams openstreams
104+ conn io.ReadWriteCloser
105+ serverName string
106+ queue messageQueue
107+ connId string
108+ logId string
109+ serverVersion string
110+ bookmark string // Last bookmark
111+ birthDate time.Time
112+ log log.Logger
113+ databaseName string
114+ err error // Last fatal error
115+ minor int
116+ lastQid int64 // Last seen qid
117+ idleDate time.Time
118+ auth map [string ]any
119+ authManager auth.TokenManager
120+ resetAuth bool
121+ errorListener ConnectionErrorListener
122+ telemetryEnabled bool
123+ ssrEnabled bool
124+ pinHomeDatabaseCallback func (context.Context , string )
118125}
119126
120127func NewBolt5 (
@@ -322,7 +329,7 @@ func (b *bolt5) TxBegin(
322329 notificationConfig : txConfig .NotificationConfig ,
323330 }
324331
325- b .queue .appendBegin (tx .toMeta (b .log , b .logId , b .Version ()), b .beginResponseHandler ())
332+ b .queue .appendBegin (tx .toMeta (b .log , b .logId , b .Version ()), b .beginResponseHandler (ctx ))
326333 if syncMessages {
327334 if b .queue .send (ctx ); b .err != nil {
328335 return 0 , b .err
@@ -562,7 +569,7 @@ func (b *bolt5) run(ctx context.Context, cypher string, params map[string]any, r
562569 fetchSize := b .normalizeFetchSize (rawFetchSize )
563570 stream := & stream {fetchSize : fetchSize }
564571 b .Version ()
565- b .queue .appendRun (cypher , params , tx .toMeta (b .log , b .logId , b .Version ()), b .runResponseHandler (stream ))
572+ b .queue .appendRun (cypher , params , tx .toMeta (b .log , b .logId , b .Version ()), b .runResponseHandler (ctx , stream ))
566573 b .queue .appendPullN (fetchSize , b .pullResponseHandler (stream ))
567574 if b .queue .send (ctx ); b .err != nil {
568575 return nil , b .err
@@ -850,6 +857,14 @@ func (b *bolt5) SetBoltLogger(boltLogger log.BoltLogger) {
850857 b .queue .setBoltLogger (boltLogger )
851858}
852859
860+ func (b * bolt5 ) SetPinHomeDatabaseCallback (callback func (context.Context , string )) {
861+ b .pinHomeDatabaseCallback = callback
862+ }
863+
864+ func (b * bolt5 ) IsSsrEnabled () bool {
865+ return b .ssrEnabled
866+ }
867+
853868func (b * bolt5 ) ReAuth (ctx context.Context , auth * idb.ReAuthToken ) error {
854869 if b .minor == 0 {
855870 return b .fallbackReAuth (ctx , auth )
@@ -998,12 +1013,19 @@ func (b *bolt5) routeResponseHandler(table **idb.RoutingTable) responseHandler {
9981013 })
9991014}
10001015
1001- func (b * bolt5 ) beginResponseHandler () responseHandler {
1002- return b .expectedSuccessHandler (onSuccessNoOp )
1016+ func (b * bolt5 ) beginResponseHandler (ctx context.Context ) responseHandler {
1017+ return b .expectedSuccessHandler (func (beginSuccess * success ) {
1018+ if b .pinHomeDatabaseCallback != nil && beginSuccess .db != "" {
1019+ b .pinHomeDatabaseCallback (ctx , beginSuccess .db )
1020+ }
1021+ })
10031022}
10041023
1005- func (b * bolt5 ) runResponseHandler (stream * stream ) responseHandler {
1024+ func (b * bolt5 ) runResponseHandler (ctx context. Context , stream * stream ) responseHandler {
10061025 return b .expectedSuccessHandler (func (runSuccess * success ) {
1026+ if b .pinHomeDatabaseCallback != nil && runSuccess .db != "" {
1027+ b .pinHomeDatabaseCallback (ctx , runSuccess .db )
1028+ }
10071029 stream .attached = true
10081030 stream .keys = runSuccess .fields
10091031 stream .qid = runSuccess .qid
@@ -1124,7 +1146,8 @@ func (b *bolt5) onHelloSuccess(helloSuccess *success) {
11241146 b .logId = connectionLogId
11251147 b .queue .setLogId (connectionLogId )
11261148 b .initializeReadTimeoutHint (helloSuccess .configurationHints )
1127- b .initializeTelemetryHint (helloSuccess .configurationHints )
1149+ b .initializeTelemetryEnabledHint (helloSuccess .configurationHints )
1150+ b .initializeSsrEnabledHint (helloSuccess .configurationHints )
11281151}
11291152
11301153func (b * bolt5 ) onCommitSuccess (commitSuccess * success ) {
@@ -1172,19 +1195,30 @@ func (b *bolt5) initializeReadTimeoutHint(hints map[string]any) {
11721195 b .queue .in .connReadTimeout = time .Duration (readTimeout ) * time .Second
11731196}
11741197
1175- const readTelemetryHintName = "telemetry.enabled"
1198+ func (b * bolt5 ) initializeTelemetryEnabledHint (hints map [string ]any ) {
1199+ telemetryEnabledHint , ok := hints [telemetryEnabledHintName ]
1200+ if ! ok {
1201+ return
1202+ }
1203+ telemetryEnabled , ok := telemetryEnabledHint .(bool )
1204+ if ! ok {
1205+ b .log .Infof (log .Bolt5 , b .logId , `invalid %q value: %v, ignoring hint. Only boolean values are accepted` , telemetryEnabledHintName , telemetryEnabledHint )
1206+ return
1207+ }
1208+ b .telemetryEnabled = telemetryEnabled
1209+ }
11761210
1177- func (b * bolt5 ) initializeTelemetryHint (hints map [string ]any ) {
1178- readTelemetryHint , ok := hints [readTelemetryHintName ]
1211+ func (b * bolt5 ) initializeSsrEnabledHint (hints map [string ]any ) {
1212+ ssrEnabledHint , ok := hints [ssrEnabledHintName ]
11791213 if ! ok {
11801214 return
11811215 }
1182- readTelemetry , ok := readTelemetryHint .(bool )
1216+ ssrEnabled , ok := ssrEnabledHint .(bool )
11831217 if ! ok {
1184- b .log .Infof (log .Bolt5 , b .logId , `invalid %q value: %v, ignoring hint. Only boolean values are accepted` , readTelemetryHintName , readTelemetryHint )
1218+ b .log .Infof (log .Bolt5 , b .logId , `invalid %q value: %v, ignoring hint. Only boolean values are accepted` , ssrEnabledHintName , ssrEnabledHint )
11851219 return
11861220 }
1187- b .telemetryEnabled = readTelemetry
1221+ b .ssrEnabled = ssrEnabled
11881222}
11891223
11901224func (b * bolt5 ) extractSummary (success * success , stream * stream ) * db.Summary {
0 commit comments