github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/pgwire/helpers_test.go (about) 1 // Copyright 2017 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package pgwire 12 13 import ( 14 "context" 15 "time" 16 ) 17 18 func (s *Server) DrainImpl(drainWait time.Duration, cancelWait time.Duration) error { 19 return s.drainImpl(drainWait, cancelWait, nil /* reporter */) 20 } 21 22 // OverwriteCancelMap overwrites all active connections' context.CancelFuncs so 23 // that the cancellation of any context.CancelFunc in s.mu.connCancelMap does 24 // not trigger a response by the associated connection. A slice of the original 25 // context.CancelFuncs is returned. 26 func (s *Server) OverwriteCancelMap() []context.CancelFunc { 27 s.mu.Lock() 28 defer s.mu.Unlock() 29 cancel := func() {} 30 originalCancels := make([]context.CancelFunc, 0, len(s.mu.connCancelMap)) 31 for done, originalCancel := range s.mu.connCancelMap { 32 s.mu.connCancelMap[done] = cancel 33 originalCancels = append(originalCancels, originalCancel) 34 } 35 return originalCancels 36 }