MCPcopy Create free account
hub / github.com/cloudspannerecosystem/spanner-cli / startHeartbeat

Method startHeartbeat

session.go:381–395  ·  view source on GitHub ↗

startHeartbeat starts heartbeat for read-write transaction. If no reads or DMLs happen within 10 seconds, the rw-transaction is considered idle at Cloud Spanner server. This "SELECT 1" query prevents the transaction from being considered idle. cf. https://godoc.org/cloud.google.com/go/spanner#hdr-I

()

Source from the content-addressed store, hash-verified

379// at least one user-initialized SQL query has been executed on the transaction.
380// Background: https://github.com/cloudspannerecosystem/spanner-cli/issues/100
381func (s *Session) startHeartbeat() {
382 interval := time.NewTicker(5 * time.Second)
383 defer interval.Stop()
384
385 for {
386 select {
387 case <-interval.C:
388 s.tcMutex.Lock()
389 if s.tc != nil && s.tc.rwTxn != nil && s.tc.sendHeartbeat {
390 heartbeat(s.tc.rwTxn, s.currentPriority())
391 }
392 s.tcMutex.Unlock()
393 }
394 }
395}
396
397func heartbeat(txn *spanner.ReadWriteStmtBasedTransaction, priority pb.RequestOptions_Priority) error {
398 ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)

Callers 1

NewSessionFunction · 0.95

Calls 2

currentPriorityMethod · 0.95
heartbeatFunction · 0.85

Tested by

no test coverage detected