Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
34280: util: fix NoCopy on go1.11 and later r=RaduBerinde a=petermattis

Vet now requires that `NoCopy` structure has both `Lock` and `Unlock`
methods.

Fixes cockroachdb#34278

Release note: None

34285: storage: test raft log decision input's MaxLogSize r=petermattis a=tbg

See cockroachdb#34284.

Release note: None

Co-authored-by: Peter Mattis <[email protected]>
Co-authored-by: Tobias Schottdorf <[email protected]>
  • Loading branch information
3 people committed Jan 28, 2019
3 parents 7a6bc0c + 049c100 + 150dc26 commit c005f26
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pkg/base/node_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
// multiple layers. It allows setting and getting the value. Once a value is
// set, the value cannot change.
type NodeIDContainer struct {
noCopy util.NoCopy
_ util.NoCopy

// nodeID is atomically updated under the mutex; it can be read atomically
// without the mutex.
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/conn_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ var noteworthyMemoryUsageBytes = envutil.EnvOrDefaultInt64("COCKROACH_NOTEWORTHY
// Server is the top level singleton for handling SQL connections. It creates
// connExecutors to server every incoming connection.
type Server struct {
noCopy util.NoCopy
_ util.NoCopy

cfg *ExecutorConfig

Expand Down Expand Up @@ -776,7 +776,7 @@ func (ex *connExecutor) close(ctx context.Context, closeType closeType) {
}

type connExecutor struct {
noCopy util.NoCopy
_ util.NoCopy

// The server to which this connExecutor is attached. The reference is used
// for getting access to configuration settings.
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/distsqlrun/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func processExpression(
// exprHelper implements the common logic around evaluating an expression that
// depends on a set of values.
type exprHelper struct {
noCopy util.NoCopy
_ util.NoCopy

expr tree.TypedExpr
// vars is used to generate IndexedVars that are "backed" by the values in
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/join_predicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type joinPredicate struct {
// IndexedVarContainer and the IndexedVar objects in sub-expressions
// will link to it by reference after checkRenderStar / analyzeExpr.
// Enforce this using NoCopy.
noCopy util.NoCopy
_ util.NoCopy
}

// tryAddEqualityFilter attempts to turn the given filter expression into
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/pgwire/write_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
// for writing PGWire results. The buffer preserves any errors it encounters when writing,
// and will turn all subsequent write attempts into no-ops until finishMsg is called.
type writeBuffer struct {
noCopy util.NoCopy
_ util.NoCopy

wrapped bytes.Buffer
err error
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ type renderNode struct {
// IndexedVarContainer and the IndexedVar objects in sub-expressions
// will link to it by reference after checkRenderStar / analyzeExpr.
// Enforce this using NoCopy.
noCopy util.NoCopy
_ util.NoCopy
}

// Select selects rows from a SELECT/UNION/VALUES, ordering and/or limiting them.
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ type scanNode struct {
// IndexedVarContainer and the IndexedVar objects in sub-expressions
// will link to it by reference after checkRenderStar / analyzeExpr.
// Enforce this using NoCopy.
noCopy util.NoCopy
_ util.NoCopy

// Set when the scanNode is created via the exec factory.
createdByOpt bool
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/sqlbase/row_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type RowContainer struct {

// We should not copy this structure around; each copy would have a different
// memAcc (among other things like aliasing chunks).
noCopy util.NoCopy
_ util.NoCopy
}

// ColTypeInfo is a type that allows multiple representations of column type
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/upsert.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ type upsertHelper struct {
// IndexedVarContainer and the IndexedVar objects in sub-expressions
// will link to it by reference after checkRenderStar / analyzeExpr.
// Enforce this using NoCopy.
noCopy util.NoCopy
_ util.NoCopy
}

var _ tableUpsertEvaler = (*upsertHelper)(nil)
Expand Down
29 changes: 29 additions & 0 deletions pkg/storage/raft_log_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/storage/engine"
"github.com/cockroachdb/cockroach/pkg/storage/engine/enginepb"
"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/cockroach/pkg/util/stop"
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
Expand Down Expand Up @@ -376,6 +377,34 @@ func TestUpdateRaftStatusActivity(t *testing.T) {
}
}

func TestNewTruncateDecisionMaxSize(t *testing.T) {
defer leaktest.AfterTest(t)()
stopper := stop.NewStopper()
defer stopper.Stop(context.TODO())

cfg := TestStoreConfig(hlc.NewClock(hlc.NewManualClock(123).UnixNano, time.Nanosecond))
const exp = 1881
cfg.RaftLogTruncationThreshold = exp
store := createTestStoreWithConfig(
t, stopper, testStoreOpts{createSystemRanges: true}, &cfg,
)

repl, err := store.GetReplica(1)
if err != nil {
t.Fatal(err)
}

ctx := context.Background()
td, err := newTruncateDecision(ctx, repl)
if err != nil {
t.Fatal(err)
}

if td.Input.MaxLogSize != exp {
t.Fatalf("MaxLogSize %d is unexpected, wanted %d", td.Input.MaxLogSize, exp)
}
}

// TestNewTruncateDecision verifies that old raft log entries are correctly
// removed.
func TestNewTruncateDecision(t *testing.T) {
Expand Down
6 changes: 6 additions & 0 deletions pkg/util/nocopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,11 @@ package util
// for details.
type NoCopy struct{}

// Silence unused warnings.
var _ = NoCopy{}

// Lock is a no-op used by -copylocks checker from `go vet`.
func (*NoCopy) Lock() {}

// Unlock is a no-op used by -copylocks checker from `go vet`.
func (*NoCopy) Unlock() {}

0 comments on commit c005f26

Please sign in to comment.