func makeInternalPlanner( opName string, txn *client.Txn, user string, memMetrics *MemoryMetrics, ) *planner { p := makePlanner(opName) p.setTxn(txn) p.resetContexts() p.session.User = user p.session.mon = mon.MakeUnlimitedMonitor(p.session.context, "internal-root", memMetrics.CurBytesCount, memMetrics.MaxBytesHist, noteworthyInternalMemoryUsageBytes) p.session.sessionMon = mon.MakeMonitor("internal-session", memMetrics.SessionCurBytesCount, memMetrics.SessionMaxBytesHist, -1, noteworthyInternalMemoryUsageBytes/5) p.session.sessionMon.Start(p.session.context, &p.session.mon, mon.BoundAccount{}) p.session.TxnState.mon = mon.MakeMonitor("internal-txn", memMetrics.TxnCurBytesCount, memMetrics.TxnMaxBytesHist, -1, noteworthyInternalMemoryUsageBytes/5) p.session.TxnState.mon.Start(p.session.context, &p.session.mon, mon.BoundAccount{}) return p }
// newAdminServer allocates and returns a new REST server for // administrative APIs. func newAdminServer(s *Server) *adminServer { server := &adminServer{server: s, memMetrics: &s.adminMemMetrics} // TODO(knz): We do not limit memory usage by admin operations // yet. Is this wise? server.memMonitor = mon.MakeUnlimitedMonitor( context.Background(), "admin", nil, nil, noteworthyAdminMemoryUsageBytes, ) return server }
// StartUnlimitedMonitor interfaces between Session and mon.MemoryMonitor func (s *Session) StartUnlimitedMonitor() { s.mon = mon.MakeUnlimitedMonitor(s.context, "root", s.memMetrics.CurBytesCount, s.memMetrics.MaxBytesHist, math.MaxInt64, ) s.deriveAndStartMonitors() }
func makeTestV3Conn(c net.Conn) v3Conn { metrics := makeServerMetrics(nil) mon := mon.MakeUnlimitedMonitor(context.Background(), "test", nil, nil, 1000) return makeV3Conn( context.Background(), c, &metrics, &mon, sql.NewDummyExecutor(), ) }
func makeTestV3Conn(c net.Conn) v3Conn { metrics := makeServerMetrics(nil) mon := mon.MakeUnlimitedMonitor(context.Background(), "test", nil, nil, 1000) exec := sql.NewExecutor( sql.ExecutorConfig{ AmbientCtx: log.AmbientContext{Tracer: tracing.NewTracer()}, MetricsSampleInterval: metric.TestSampleInterval, }, nil, /* stopper */ ) return makeV3Conn(context.Background(), c, &metrics, &mon, exec) }
func TestRowContainer(t *testing.T) { defer leaktest.AfterTest(t)() for _, numCols := range []int{1, 2, 3, 5, 10, 15} { for _, numRows := range []int{5, 10, 100} { for _, numPops := range []int{0, 1, 2, numRows / 3, numRows / 2} { resCol := make(ResultColumns, numCols) for i := range resCol { resCol[i] = ResultColumn{Typ: parser.TypeInt} } m := mon.MakeUnlimitedMonitor(context.Background(), "test", nil, nil, math.MaxInt64) rc := NewRowContainer(m.MakeBoundAccount(context.Background()), resCol, 0) row := make(parser.DTuple, numCols) for i := 0; i < numRows; i++ { for j := range row { row[j] = parser.NewDInt(parser.DInt(i*numCols + j)) } if err := rc.AddRow(row); err != nil { t.Fatal(err) } } for i := 0; i < numPops; i++ { rc.PopFirst() } // Given that we just deleted numPops rows, we have numRows - // numPops rows remaining. if rc.Len() != numRows-numPops { t.Fatalf("invalid length, expected %d got %d", numRows-numPops, rc.Len()) } // what was previously rc.At(i + numPops) is now rc.At(i). for i := 0; i < rc.Len(); i++ { row := rc.At(i) for j := range row { dint, ok := row[j].(*parser.DInt) if !ok || int(*dint) != (i+numPops)*numCols+j { t.Fatalf("invalid value %+v on row %d, col %d", row[j], i+numPops, j) } } } } } } }