Skip to content

Commit

Permalink
Merge #40993 #41654
Browse files Browse the repository at this point in the history
40993: util/log: refactor and bug fixes r=knz a=knz

Fixes #40983.
Fixes #40973.
Fixes #40974.
Fixes #41231.

I might also want to add code to clean up #40972, #40982 and #40990 provided I receive some guidance from @tbg or someone familiar with the log package.


41654: parser: fix telemetry link for materialized views r=jordanlewis a=jordanlewis

This commit fixes the error message that you get if you try to create a
materialized view to point at the right GitHub issue.

Release note: None

Co-authored-by: Raphael 'kena' Poss <[email protected]>
Co-authored-by: Jordan Lewis <[email protected]>
  • Loading branch information
3 people committed Oct 17, 2019
3 parents 68b0b32 + f2bae17 + ae9ecc9 commit 0e655a3
Show file tree
Hide file tree
Showing 29 changed files with 1,763 additions and 1,417 deletions.
2 changes: 1 addition & 1 deletion pkg/sql/parser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2992,7 +2992,7 @@ func TestUnimplementedSyntax(t *testing.T) {
{`CREATE FUNCTION a`, 17511, `create`},
{`CREATE OR REPLACE FUNCTION a`, 17511, `create`},
{`CREATE LANGUAGE a`, 17511, `create language a`},
{`CREATE MATERIALIZED VIEW a`, 24747, ``},
{`CREATE MATERIALIZED VIEW a`, 41649, ``},
{`CREATE OPERATOR a`, 0, `create operator`},
{`CREATE PUBLICATION a`, 0, `create publication`},
{`CREATE RULE a`, 0, `create rule`},
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -2218,7 +2218,7 @@ create_unsupported:
| CREATE FUNCTION error { return unimplementedWithIssueDetail(sqllex, 17511, "create function") }
| CREATE OR REPLACE FUNCTION error { return unimplementedWithIssueDetail(sqllex, 17511, "create function") }
| CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name error { return unimplementedWithIssueDetail(sqllex, 17511, "create language " + $6) }
| CREATE MATERIALIZED VIEW error { return unimplementedWithIssue(sqllex, 24747) }
| CREATE MATERIALIZED VIEW error { return unimplementedWithIssue(sqllex, 41649) }
| CREATE OPERATOR error { return unimplemented(sqllex, "create operator") }
| CREATE PUBLICATION error { return unimplemented(sqllex, "create publication") }
| CREATE opt_or_replace RULE error { return unimplemented(sqllex, "create rule") }
Expand Down
2 changes: 1 addition & 1 deletion pkg/testutils/lint/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func TestLint(t *testing.T) {
":!nightly",
":!testutils/lint",
":!util/envutil/env.go",
":!util/log/clog.go",
":!util/log/tracebacks.go",
":!util/sdnotify/sdnotify_unix.go",
},
},
Expand Down
91 changes: 91 additions & 0 deletions pkg/util/log/backtrace_trigger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright 2019 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package log

import (
"fmt"
"strconv"
"strings"

"github.com/cockroachdb/errors"
)

// traceLocation represents the setting of the -log_backtrace_at flag.
// When a log entry is written that was produced at that location,
// a backtrace is also emitted to the log.
//
// TODO(knz): this seems to be dead code.
// See: https://github.com/cockroachdb/cockroach/issues/40990
type traceLocation struct {
file string
line int
}

// isSet reports whether the trace location has been specified.
// mainLog.mu is held.
func (t *traceLocation) isSet() bool {
return t.line > 0
}

// match reports whether the specified file and line matches the trace location.
// The argument file name is the full path, not the basename specified in the flag.
// mainLog.mu is held.
func (t *traceLocation) match(file string, line int) bool {
if t.line != line {
return false
}
if i := strings.LastIndexByte(file, '/'); i >= 0 {
file = file[i+1:]
}
return t.file == file
}

func (t *traceLocation) String() string {
// Lock because the type is not atomic. TODO: clean this up.
logging.mu.Lock()
defer logging.mu.Unlock()
return fmt.Sprintf("%s:%d", t.file, t.line)
}

var errTraceSyntax = errors.New("syntax error: expect file.go:234")

// Syntax: -log_backtrace_at=gopherflakes.go:234
// Note that unlike vmodule the file extension is included here.
func (t *traceLocation) Set(value string) error {
if value == "" {
// Unset.
logging.mu.Lock()
defer logging.mu.Unlock()
t.line = 0
t.file = ""
return nil
}
fields := strings.Split(value, ":")
if len(fields) != 2 {
return errTraceSyntax
}
file, line := fields[0], fields[1]
if !strings.Contains(file, ".") {
return errTraceSyntax
}
v, err := strconv.Atoi(line)
if err != nil {
return errTraceSyntax
}
if v <= 0 {
return errors.New("negative or zero value for level")
}
logging.mu.Lock()
defer logging.mu.Unlock()
t.line = v
t.file = file
return nil
}
Loading

0 comments on commit 0e655a3

Please sign in to comment.