diff --git a/GLOCKFILE b/GLOCKFILE index efbf921c701e..6ee40cbec32f 100644 --- a/GLOCKFILE +++ b/GLOCKFILE @@ -1,7 +1,7 @@ cmd github.com/client9/misspell/cmd/misspell cmd github.com/cockroachdb/c-protobuf/cmd/protoc -cmd github.com/cockroachdb/crlfmt cmd github.com/cockroachdb/cockroach/cmd/protoc-gen-gogoroach +cmd github.com/cockroachdb/crlfmt cmd github.com/cockroachdb/stress cmd github.com/cockroachdb/yacc cmd github.com/golang/lint/golint @@ -47,11 +47,11 @@ github.com/cockroachdb/pq 44a6473ebbc26e3af09fe57bbdf761475c2c9f7c github.com/cockroachdb/stress 029c9348806514969d1109a6ae36e521af411ca7 github.com/cockroachdb/yacc 7c99dfd2164a5d23c3f495ffc2e0b72b6379d066 github.com/codahale/hdrhistogram f8ad88b59a584afeee9d334eff879b104439117b -github.com/coreos/etcd 02912fe8c43da66d263baffdd88d18400c1b3ef8 +github.com/coreos/etcd 33e4f2ea283c187cac459462994d084f44d7c9de github.com/cpuguy83/go-md2man a65d4d2de4d5f7c74868dfa9b202a3c8be315aaa github.com/davecgh/go-spew 6d212800a42e8ab5c146b8ace3490ee17e5225f9 github.com/docker/distribution 99cb7c0946d2f5a38015443e515dc916295064d7 -github.com/docker/docker 7e29b33546098816d5dbc1fc429e868f02b69e44 +github.com/docker/docker bd57e6d25c2c9d41a6cf2c9931606f58bb66a07d github.com/docker/go-connections 988efe982fdecb46f01d53465878ff1f2ff411ce github.com/docker/go-units f2145db703495b2e525c59662db69a7344b00bb8 github.com/dustin/go-humanize bd88f87ad3a420f7bcf05e90566fd1ceb351fa7f @@ -62,10 +62,10 @@ github.com/go-ole/go-ole 7dfdcf409020452e29b4babcbb22f984d2aa308a github.com/go-sql-driver/mysql 0b58b37b664c21f3010e836f1b931e1d0b0b0685 github.com/gogo/protobuf fdc14ac22689d09f8639e603614593811bc1d81c github.com/golang/glog 23def4e6c14b4da8ac2ed8007337bc5eb5007998 -github.com/golang/lint c6242afa6ced3be489e1184eb80bc2d85f1f5e7b +github.com/golang/lint 64229b89515c2a585c623c79a7ccdea71e8589ff github.com/golang/protobuf df1d3ca07d2d07bba352d5b73c4313b4e2a6203e github.com/google/btree 7364763242911ab6d418d2722e237194938ebad0 -github.com/gordonklaus/ineffassign cb7fbaf18166b1f12a02c381e89ab5ce538a02ec +github.com/gordonklaus/ineffassign 99762ed65232b1477364c8c53778f8b6503e868c github.com/grpc-ecosystem/grpc-gateway acebe0f9ff5993e130b141ee60e83e592839ca22 github.com/inconshreveable/mousetrap 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75 github.com/jteeuwen/go-bindata a0ff2567cfb70903282db057e799fd826784d41d @@ -84,7 +84,7 @@ github.com/mdempsky/unconvert beb68d938016d2dec1d1b078054f4d3db25f97be github.com/mibk/dupl d8ac57fa998861b7aeaa149bba1cb7fceeace18f github.com/montanaflynn/stats 60dcacf48f43d6dd654d0ed94120ff5806c5ca5c github.com/olekukonko/tablewriter bdcc175572fd7abece6c831e643891b9331bc9e7 -github.com/opencontainers/runc 7b1bcb3762feb762eb53b7cf167372320c2bcf9e +github.com/opencontainers/runc 02f8fa7863dd3f82909a73e2061897828460d52f github.com/opennota/check 5b00aacd5639507d2b039245a278ec9f5505509f github.com/opentracing/basictracer-go 1b32af207119a14b1b231d451df3ed04a72efebf github.com/opentracing/opentracing-go 30dda9350627161ff15581c0bdc504e32ec9a536 @@ -105,13 +105,13 @@ github.com/stretchr/testify 976c720a22c8eb4eb6a0b4348ad85ad12491a506 github.com/tebeka/go2xunit cb8eb3dedfac9cf4cb1f2d8988f3390f2d0cf2e7 github.com/termie/go-shutil bcacb06fecaeec8dc42af03c87c6949f4a05c74c github.com/wadey/gocovmerge b5bfa59ec0adc420475f97f89b58045c721d761c -golang.org/x/crypto 84e98f45760e87786b7f24603b8166a6fa09811d +golang.org/x/crypto 484eb34681af59703e639b971bc307019182c41f golang.org/x/net 0f2be02c5ddfa7c7936000ad519b04c6c795eab3 golang.org/x/oauth2 3c3a985cb79f52a3190fbc056984415ca6763d01 golang.org/x/sys 8f0908ab3b2457e2e15403d3697c9ef5cb4b57a9 golang.org/x/text 098f51fb687dbaba1f6efabeafbb6461203f9e21 golang.org/x/tools fc2b74b64ef08c618146ebc92062f6499db5314c -google.golang.org/appengine 150dc57a1b433e64154302bdc40b6bb8aefa313a +google.golang.org/appengine 926995697fa8241be2dc73eb318666e24f44ed51 google.golang.org/grpc 79b7c349179cdd6efd8bac4a1ce7f01b98c16e9b gopkg.in/check.v1 4f90aeace3a26ad7021961c297b22c42160c7b25 gopkg.in/inf.v0 3887ee99ecf07df5b447e9b00d9c0b2adaa9f3e4 diff --git a/build/check-style.sh b/build/check-style.sh index 80a020ecfe10..2c074b668d33 100755 --- a/build/check-style.sh +++ b/build/check-style.sh @@ -95,7 +95,7 @@ TestImportNames() { } TestIneffassign() { - ! ineffassign . | grep -vF '.pb.go' # https://github.com/gogo/protobuf/issues/149 + ! ineffassign . | grep -vF 'ineffectual assignment to sqlDollar' | grep -vF '.pb.go' # https://github.com/gogo/protobuf/issues/149 } TestErrcheck() { diff --git a/server/admin.go b/server/admin.go index 18cc99ba982a..35f4f90f97cb 100644 --- a/server/admin.go +++ b/server/admin.go @@ -969,10 +969,10 @@ func (s *adminServer) waitForStoreFrozen( delete(mu.oks, storeID) } mu.Unlock() - err = stream.Send(&serverpb.ClusterFreezeResponse{ - Message: message, - }) } + err = stream.Send(&serverpb.ClusterFreezeResponse{ + Message: message, + }) }() conn, err := s.server.rpcContext.GRPCDial(addr) if err != nil { diff --git a/server/server_test.go b/server/server_test.go index 8b367de5f990..bc7126ec5dc9 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -226,12 +226,11 @@ func TestMultiRangeScanDeleteRange(t *testing.T) { var delTS hlc.Timestamp for i, k := range writes { put := roachpb.NewPut(k, roachpb.MakeValueFromBytes(k)) - reply, err := client.SendWrapped(tds, nil, put) - if err != nil { + if _, err := client.SendWrapped(tds, nil, put); err != nil { t.Fatal(err) } scan := roachpb.NewScan(writes[0], writes[len(writes)-1].Next()) - reply, err = client.SendWrapped(tds, nil, scan) + reply, err := client.SendWrapped(tds, nil, scan) if err != nil { t.Fatal(err) } diff --git a/sql/backfill.go b/sql/backfill.go index 0170406a4a57..d6714e41b148 100644 --- a/sql/backfill.go +++ b/sql/backfill.go @@ -335,6 +335,9 @@ func (sc *SchemaChanger) truncateAndBackfillColumnsChunk( curIndexKey, _, err = sqlbase.EncodeIndexKey( tableDesc, &tableDesc.PrimaryIndex, colIDtoRowIndex, row, indexKeyPrefix) + if err != nil { + return err + } for j, col := range added { if defaultExprs == nil || defaultExprs[j] == nil { diff --git a/sql/check.go b/sql/check.go index 4c9171daa8b6..b578ecf34be9 100644 --- a/sql/check.go +++ b/sql/check.go @@ -111,6 +111,9 @@ func (p *planner) validateCheckExpr( // would be marginal compared to the work of the actual query, so the added // complexity seems unjustified. rows, err := p.SelectClause(sel, nil, lim, nil, publicColumns) + if err != nil { + return err + } if err := rows.expandPlan(); err != nil { return err } diff --git a/sql/config_test.go b/sql/config_test.go index 48e673f6b1dd..2f43dc231fd8 100644 --- a/sql/config_test.go +++ b/sql/config_test.go @@ -92,7 +92,7 @@ func TestGetZoneConfig(t *testing.T) { defer srv.Stopper().Stop() s := srv.(*server.TestServer) - expectedCounter := uint32(keys.MaxReservedDescID + 1) + expectedCounter := uint32(keys.MaxReservedDescID) defaultZoneConfig := config.DefaultZoneConfig() defaultZoneConfig.RangeMinBytes = 1 << 20 @@ -114,41 +114,41 @@ func TestGetZoneConfig(t *testing.T) { // db1 has tables tb11 and tb12 // db2 has tables tb21 and tb22 + expectedCounter++ db1 := expectedCounter if _, err := sqlDB.Exec(`CREATE DATABASE db1`); err != nil { t.Fatal(err) } - expectedCounter++ + expectedCounter++ db2 := expectedCounter if _, err := sqlDB.Exec(`CREATE DATABASE db2`); err != nil { t.Fatal(err) } - expectedCounter++ + expectedCounter++ tb11 := expectedCounter if _, err := sqlDB.Exec(`CREATE TABLE db1.tb1 (k INT PRIMARY KEY, v INT)`); err != nil { t.Fatal(err) } - expectedCounter++ + expectedCounter++ tb12 := expectedCounter if _, err := sqlDB.Exec(`CREATE TABLE db1.tb2 (k INT PRIMARY KEY, v INT)`); err != nil { t.Fatal(err) } - expectedCounter++ + expectedCounter++ tb21 := expectedCounter if _, err := sqlDB.Exec(`CREATE TABLE db2.tb1 (k INT PRIMARY KEY, v INT)`); err != nil { t.Fatal(err) } - expectedCounter++ + expectedCounter++ tb22 := expectedCounter if _, err := sqlDB.Exec(`CREATE TABLE db2.tb2 (k INT PRIMARY KEY, v INT)`); err != nil { t.Fatal(err) } - expectedCounter++ { cfg := forceNewConfig(t, s) diff --git a/sql/index_selection.go b/sql/index_selection.go index 457d228f0e3a..f5fd4f5f0021 100644 --- a/sql/index_selection.go +++ b/sql/index_selection.go @@ -380,8 +380,14 @@ func (v *indexInfo) analyzeOrdering( // Analyze the ordering provided by the index (either forward or reverse). fwdIndexOrdering := scan.computeOrdering(v.index, v.exactPrefix, false) revIndexOrdering := scan.computeOrdering(v.index, v.exactPrefix, true) - fwdMatch, orderCols := analyzeOrdering(fwdIndexOrdering) - revMatch, orderCols := analyzeOrdering(revIndexOrdering) + fwdMatch, fwdOrderCols := analyzeOrdering(fwdIndexOrdering) + revMatch, revOrderCols := analyzeOrdering(revIndexOrdering) + + if fwdOrderCols != revOrderCols { + panic(fmt.Sprintf("fwdOrderCols(%d) != revOrderCols(%d)", fwdOrderCols, revOrderCols)) + } + + orderCols := fwdOrderCols // Weigh the cost by how much of the ordering matched. // diff --git a/sql/pgwire/types.go b/sql/pgwire/types.go index 340bca036211..1f7146361cae 100644 --- a/sql/pgwire/types.go +++ b/sql/pgwire/types.go @@ -692,14 +692,15 @@ func decodeOidDatum(id oid.Oid, code formatCode, b []byte) (parser.Datum, error) case formatText: ts, err := parseTs(string(b)) if err != nil { - if res, err := parser.ParseDDate(string(b), time.UTC); err == nil { - d = res - } else { + res, err := parser.ParseDDate(string(b), time.UTC) + if err != nil { return d, errors.Errorf("could not parse string %q as date", b) } + d = res + } else { + daysSinceEpoch := ts.Unix() / secondsInDay + d = parser.NewDDate(parser.DDate(daysSinceEpoch)) } - daysSinceEpoch := ts.Unix() / secondsInDay - d = parser.NewDDate(parser.DDate(daysSinceEpoch)) case formatBinary: if len(b) < 4 { return d, errors.Errorf("date requires 4 bytes for binary format") diff --git a/sql/rename_test.go b/sql/rename_test.go index 35035de72513..6de0dabd2cc9 100644 --- a/sql/rename_test.go +++ b/sql/rename_test.go @@ -39,26 +39,24 @@ func TestRenameTable(t *testing.T) { s, db, kvDB := serverutils.StartServer(t, base.TestServerArgs{}) defer s.Stopper().Stop() - counter := int64(keys.MaxReservedDescID + 1) + counter := int64(keys.MaxReservedDescID) - // Table creation should fail, and nothing should have been written. + counter++ oldDBID := sqlbase.ID(counter) if _, err := db.Exec(`CREATE DATABASE test`); err != nil { t.Fatal(err) } - counter++ // Create table in 'test'. - tableCounter := counter + counter++ oldName := "foo" if _, err := db.Exec(`CREATE TABLE test.foo (k INT PRIMARY KEY, v int)`); err != nil { t.Fatal(err) } - counter++ // Check the table descriptor. desc := &sqlbase.Descriptor{} - tableDescKey := sqlbase.MakeDescMetadataKey(sqlbase.ID(tableCounter)) + tableDescKey := sqlbase.MakeDescMetadataKey(sqlbase.ID(counter)) if err := kvDB.GetProto(context.TODO(), tableDescKey, desc); err != nil { t.Fatal(err) } @@ -71,11 +69,11 @@ func TestRenameTable(t *testing.T) { } // Create database test2. + counter++ newDBID := sqlbase.ID(counter) if _, err := db.Exec(`CREATE DATABASE test2`); err != nil { t.Fatal(err) } - counter++ // Move table to test2 and change its name as well. newName := "bar" diff --git a/sql/sqlbase/table.go b/sql/sqlbase/table.go index 328e503e910e..c3afe30c3c47 100644 --- a/sql/sqlbase/table.go +++ b/sql/sqlbase/table.go @@ -498,7 +498,6 @@ func DecodeIndexKeyPrefix( if tableID == desc.ID { // Once desc's table id has been decoded, there can be no more // interleaves. - remaining = key break } @@ -569,6 +568,9 @@ func DecodeIndexKey( length := int(ancestor.SharedPrefixLen) key, err = DecodeKeyVals(a, valTypes[:length], vals[:length], colDirs[:length], key) + if err != nil { + return nil, false, err + } valTypes, vals, colDirs = valTypes[length:], vals[length:], colDirs[length:] // We reuse NotNullDescending as the interleave sentinel, consume it. diff --git a/storage/engine/mvcc_test.go b/storage/engine/mvcc_test.go index fa200c03bc0e..faf8a28f8312 100644 --- a/storage/engine/mvcc_test.go +++ b/storage/engine/mvcc_test.go @@ -376,8 +376,7 @@ func TestMVCCPutOutOfOrder(t *testing.T) { // Another put operation with earlier logical time. Will NOT be ignored. txn.Sequence++ - err = MVCCPut(context.Background(), engine, nil, testKey1, makeTS(2, 0), value2, &txn) - if err != nil { + if err := MVCCPut(context.Background(), engine, nil, testKey1, makeTS(2, 0), value2, &txn); err != nil { t.Fatal(err) } @@ -462,8 +461,7 @@ func TestMVCCIncrementOldTimestamp(t *testing.T) { // Override value. val.SetInt(2) - err = MVCCPut(context.Background(), engine, nil, testKey1, makeTS(3, 0), val, nil) - if err != nil { + if err := MVCCPut(context.Background(), engine, nil, testKey1, makeTS(3, 0), val, nil); err != nil { t.Fatal(err) } @@ -501,8 +499,7 @@ func TestMVCCUpdateExistingKey(t *testing.T) { value1.RawBytes, value.RawBytes) } - err = MVCCPut(context.Background(), engine, nil, testKey1, makeTS(2, 0), value2, nil) - if err != nil { + if err := MVCCPut(context.Background(), engine, nil, testKey1, makeTS(2, 0), value2, nil); err != nil { t.Fatal(err) } @@ -533,18 +530,15 @@ func TestMVCCUpdateExistingKeyOldVersion(t *testing.T) { defer stopper.Stop() engine := createTestEngine(stopper) - err := MVCCPut(context.Background(), engine, nil, testKey1, makeTS(1, 1), value1, nil) - if err != nil { + if err := MVCCPut(context.Background(), engine, nil, testKey1, makeTS(1, 1), value1, nil); err != nil { t.Fatal(err) } // Earlier wall time. - err = MVCCPut(context.Background(), engine, nil, testKey1, makeTS(0, 1), value2, nil) - if err == nil { + if err := MVCCPut(context.Background(), engine, nil, testKey1, makeTS(0, 1), value2, nil); err == nil { t.Fatal("expected error on old version") } // Earlier logical time. - err = MVCCPut(context.Background(), engine, nil, testKey1, makeTS(1, 0), value2, nil) - if err == nil { + if err := MVCCPut(context.Background(), engine, nil, testKey1, makeTS(1, 0), value2, nil); err == nil { t.Fatal("expected error on old version") } } @@ -599,8 +593,12 @@ func TestMVCCGetNoMoreOldVersion(t *testing.T) { defer stopper.Stop() engine := createTestEngine(stopper) - err := MVCCPut(context.Background(), engine, nil, testKey1, makeTS(3, 0), value1, nil) - err = MVCCPut(context.Background(), engine, nil, testKey2, makeTS(1, 0), value2, nil) + if err := MVCCPut(context.Background(), engine, nil, testKey1, makeTS(3, 0), value1, nil); err != nil { + t.Fatal(err) + } + if err := MVCCPut(context.Background(), engine, nil, testKey2, makeTS(1, 0), value2, nil); err != nil { + t.Fatal(err) + } value, _, err := MVCCGet(context.Background(), engine, testKey1, makeTS(2, 0), true, nil) if err != nil { @@ -686,7 +684,9 @@ func TestMVCCGetAndDelete(t *testing.T) { defer stopper.Stop() engine := createTestEngine(stopper) - err := MVCCPut(context.Background(), engine, nil, testKey1, makeTS(1, 0), value1, nil) + if err := MVCCPut(context.Background(), engine, nil, testKey1, makeTS(1, 0), value1, nil); err != nil { + t.Fatal(err) + } value, _, err := MVCCGet(context.Background(), engine, testKey1, makeTS(2, 0), true, nil) if err != nil { t.Fatal(err) @@ -1146,14 +1146,30 @@ func TestMVCCScan(t *testing.T) { defer stopper.Stop() engine := createTestEngine(stopper) - err := MVCCPut(context.Background(), engine, nil, testKey1, makeTS(1, 0), value1, nil) - err = MVCCPut(context.Background(), engine, nil, testKey1, makeTS(2, 0), value4, nil) - err = MVCCPut(context.Background(), engine, nil, testKey2, makeTS(1, 0), value2, nil) - err = MVCCPut(context.Background(), engine, nil, testKey2, makeTS(3, 0), value3, nil) - err = MVCCPut(context.Background(), engine, nil, testKey3, makeTS(1, 0), value3, nil) - err = MVCCPut(context.Background(), engine, nil, testKey3, makeTS(4, 0), value2, nil) - err = MVCCPut(context.Background(), engine, nil, testKey4, makeTS(1, 0), value4, nil) - err = MVCCPut(context.Background(), engine, nil, testKey4, makeTS(5, 0), value1, nil) + if err := MVCCPut(context.Background(), engine, nil, testKey1, makeTS(1, 0), value1, nil); err != nil { + t.Fatal(err) + } + if err := MVCCPut(context.Background(), engine, nil, testKey1, makeTS(2, 0), value4, nil); err != nil { + t.Fatal(err) + } + if err := MVCCPut(context.Background(), engine, nil, testKey2, makeTS(1, 0), value2, nil); err != nil { + t.Fatal(err) + } + if err := MVCCPut(context.Background(), engine, nil, testKey2, makeTS(3, 0), value3, nil); err != nil { + t.Fatal(err) + } + if err := MVCCPut(context.Background(), engine, nil, testKey3, makeTS(1, 0), value3, nil); err != nil { + t.Fatal(err) + } + if err := MVCCPut(context.Background(), engine, nil, testKey3, makeTS(4, 0), value2, nil); err != nil { + t.Fatal(err) + } + if err := MVCCPut(context.Background(), engine, nil, testKey4, makeTS(1, 0), value4, nil); err != nil { + t.Fatal(err) + } + if err := MVCCPut(context.Background(), engine, nil, testKey4, makeTS(5, 0), value1, nil); err != nil { + t.Fatal(err) + } kvs, resumeSpan, _, err := MVCCScan(context.Background(), engine, testKey2, testKey4, math.MaxInt64, makeTS(1, 0), true, nil) if err != nil { @@ -1198,7 +1214,9 @@ func TestMVCCScan(t *testing.T) { t.Fatalf("resumeSpan = %+v", resumeSpan) } - _, _, err = MVCCGet(context.Background(), engine, testKey1, makeTS(1, 0), true, txn2) + if _, _, err := MVCCGet(context.Background(), engine, testKey1, makeTS(1, 0), true, txn2); err != nil { + t.Fatal(err) + } kvs, _, _, err = MVCCScan(context.Background(), engine, keyMin, testKey2, math.MaxInt64, makeTS(1, 0), true, nil) if err != nil { t.Fatal(err) @@ -1216,10 +1234,18 @@ func TestMVCCScanMaxNum(t *testing.T) { defer stopper.Stop() engine := createTestEngine(stopper) - err := MVCCPut(context.Background(), engine, nil, testKey1, makeTS(1, 0), value1, nil) - err = MVCCPut(context.Background(), engine, nil, testKey2, makeTS(1, 0), value2, nil) - err = MVCCPut(context.Background(), engine, nil, testKey3, makeTS(1, 0), value3, nil) - err = MVCCPut(context.Background(), engine, nil, testKey4, makeTS(1, 0), value4, nil) + if err := MVCCPut(context.Background(), engine, nil, testKey1, makeTS(1, 0), value1, nil); err != nil { + t.Fatal(err) + } + if err := MVCCPut(context.Background(), engine, nil, testKey2, makeTS(1, 0), value2, nil); err != nil { + t.Fatal(err) + } + if err := MVCCPut(context.Background(), engine, nil, testKey3, makeTS(1, 0), value3, nil); err != nil { + t.Fatal(err) + } + if err := MVCCPut(context.Background(), engine, nil, testKey4, makeTS(1, 0), value4, nil); err != nil { + t.Fatal(err) + } kvs, resumeSpan, _, err := MVCCScan(context.Background(), engine, testKey2, testKey4, 1, makeTS(1, 0), true, nil) if err != nil { @@ -1263,11 +1289,21 @@ func TestMVCCScanWithKeyPrefix(t *testing.T) { // b // In this case, if we scan from "a"-"b", we wish to skip // a and a and find "aa'. - err := MVCCPut(context.Background(), engine, nil, roachpb.Key("/a"), makeTS(1, 0), value1, nil) - err = MVCCPut(context.Background(), engine, nil, roachpb.Key("/a"), makeTS(2, 0), value2, nil) - err = MVCCPut(context.Background(), engine, nil, roachpb.Key("/aa"), makeTS(2, 0), value2, nil) - err = MVCCPut(context.Background(), engine, nil, roachpb.Key("/aa"), makeTS(3, 0), value3, nil) - err = MVCCPut(context.Background(), engine, nil, roachpb.Key("/b"), makeTS(1, 0), value3, nil) + if err := MVCCPut(context.Background(), engine, nil, roachpb.Key("/a"), makeTS(1, 0), value1, nil); err != nil { + t.Fatal(err) + } + if err := MVCCPut(context.Background(), engine, nil, roachpb.Key("/a"), makeTS(2, 0), value2, nil); err != nil { + t.Fatal(err) + } + if err := MVCCPut(context.Background(), engine, nil, roachpb.Key("/aa"), makeTS(2, 0), value2, nil); err != nil { + t.Fatal(err) + } + if err := MVCCPut(context.Background(), engine, nil, roachpb.Key("/aa"), makeTS(3, 0), value3, nil); err != nil { + t.Fatal(err) + } + if err := MVCCPut(context.Background(), engine, nil, roachpb.Key("/b"), makeTS(1, 0), value3, nil); err != nil { + t.Fatal(err) + } kvs, _, _, err := MVCCScan(context.Background(), engine, roachpb.Key("/a"), roachpb.Key("/b"), math.MaxInt64, makeTS(2, 0), true, nil) if err != nil { @@ -1400,12 +1436,24 @@ func TestMVCCDeleteRange(t *testing.T) { defer stopper.Stop() engine := createTestEngine(stopper) - err := MVCCPut(context.Background(), engine, nil, testKey1, makeTS(1, 0), value1, nil) - err = MVCCPut(context.Background(), engine, nil, testKey2, makeTS(1, 0), value2, nil) - err = MVCCPut(context.Background(), engine, nil, testKey3, makeTS(1, 0), value3, nil) - err = MVCCPut(context.Background(), engine, nil, testKey4, makeTS(1, 0), value4, nil) - err = MVCCPut(context.Background(), engine, nil, testKey5, makeTS(1, 0), value5, nil) - err = MVCCPut(context.Background(), engine, nil, testKey6, makeTS(1, 0), value6, nil) + if err := MVCCPut(context.Background(), engine, nil, testKey1, makeTS(1, 0), value1, nil); err != nil { + t.Fatal(err) + } + if err := MVCCPut(context.Background(), engine, nil, testKey2, makeTS(1, 0), value2, nil); err != nil { + t.Fatal(err) + } + if err := MVCCPut(context.Background(), engine, nil, testKey3, makeTS(1, 0), value3, nil); err != nil { + t.Fatal(err) + } + if err := MVCCPut(context.Background(), engine, nil, testKey4, makeTS(1, 0), value4, nil); err != nil { + t.Fatal(err) + } + if err := MVCCPut(context.Background(), engine, nil, testKey5, makeTS(1, 0), value5, nil); err != nil { + t.Fatal(err) + } + if err := MVCCPut(context.Background(), engine, nil, testKey6, makeTS(1, 0), value6, nil); err != nil { + t.Fatal(err) + } // Attempt to delete two keys. deleted, resumeSpan, num, err := MVCCDeleteRange( @@ -1514,12 +1562,24 @@ func TestMVCCDeleteRangeReturnKeys(t *testing.T) { defer stopper.Stop() engine := createTestEngine(stopper) - err := MVCCPut(context.Background(), engine, nil, testKey1, makeTS(1, 0), value1, nil) - err = MVCCPut(context.Background(), engine, nil, testKey2, makeTS(1, 0), value2, nil) - err = MVCCPut(context.Background(), engine, nil, testKey3, makeTS(1, 0), value3, nil) - err = MVCCPut(context.Background(), engine, nil, testKey4, makeTS(1, 0), value4, nil) - err = MVCCPut(context.Background(), engine, nil, testKey5, makeTS(1, 0), value5, nil) - err = MVCCPut(context.Background(), engine, nil, testKey6, makeTS(1, 0), value6, nil) + if err := MVCCPut(context.Background(), engine, nil, testKey1, makeTS(1, 0), value1, nil); err != nil { + t.Fatal(err) + } + if err := MVCCPut(context.Background(), engine, nil, testKey2, makeTS(1, 0), value2, nil); err != nil { + t.Fatal(err) + } + if err := MVCCPut(context.Background(), engine, nil, testKey3, makeTS(1, 0), value3, nil); err != nil { + t.Fatal(err) + } + if err := MVCCPut(context.Background(), engine, nil, testKey4, makeTS(1, 0), value4, nil); err != nil { + t.Fatal(err) + } + if err := MVCCPut(context.Background(), engine, nil, testKey5, makeTS(1, 0), value5, nil); err != nil { + t.Fatal(err) + } + if err := MVCCPut(context.Background(), engine, nil, testKey6, makeTS(1, 0), value6, nil); err != nil { + t.Fatal(err) + } // Attempt to delete two keys. deleted, resumeSpan, num, err := MVCCDeleteRange( @@ -1647,21 +1707,27 @@ func TestMVCCDeleteRangeFailed(t *testing.T) { engine := createTestEngine(stopper) txn := *txn1 - err := MVCCPut(context.Background(), engine, nil, testKey1, makeTS(1, 0), value1, nil) + if err := MVCCPut(context.Background(), engine, nil, testKey1, makeTS(1, 0), value1, nil); err != nil { + t.Fatal(err) + } txn.Sequence++ - err = MVCCPut(context.Background(), engine, nil, testKey2, makeTS(1, 0), value2, &txn) + if err := MVCCPut(context.Background(), engine, nil, testKey2, makeTS(1, 0), value2, &txn); err != nil { + t.Fatal(err) + } txn.Sequence++ - err = MVCCPut(context.Background(), engine, nil, testKey3, makeTS(1, 0), value3, &txn) - err = MVCCPut(context.Background(), engine, nil, testKey4, makeTS(1, 0), value4, nil) + if err := MVCCPut(context.Background(), engine, nil, testKey3, makeTS(1, 0), value3, &txn); err != nil { + t.Fatal(err) + } + if err := MVCCPut(context.Background(), engine, nil, testKey4, makeTS(1, 0), value4, nil); err != nil { + t.Fatal(err) + } - _, _, _, err = MVCCDeleteRange(context.Background(), engine, nil, testKey2, testKey4, math.MaxInt64, makeTS(1, 0), nil, false) - if err == nil { + if _, _, _, err := MVCCDeleteRange(context.Background(), engine, nil, testKey2, testKey4, math.MaxInt64, makeTS(1, 0), nil, false); err == nil { t.Fatal("expected error on uncommitted write intent") } txn.Sequence++ - _, _, _, err = MVCCDeleteRange(context.Background(), engine, nil, testKey2, testKey4, math.MaxInt64, makeTS(1, 0), &txn, false) - if err != nil { + if _, _, _, err := MVCCDeleteRange(context.Background(), engine, nil, testKey2, testKey4, math.MaxInt64, makeTS(1, 0), &txn, false); err != nil { t.Fatal(err) } } @@ -1672,13 +1738,20 @@ func TestMVCCDeleteRangeConcurrentTxn(t *testing.T) { defer stopper.Stop() engine := createTestEngine(stopper) - err := MVCCPut(context.Background(), engine, nil, testKey1, makeTS(1, 0), value1, nil) - err = MVCCPut(context.Background(), engine, nil, testKey2, makeTS(1, 0), value2, txn1) - err = MVCCPut(context.Background(), engine, nil, testKey3, makeTS(2, 0), value3, txn2) - err = MVCCPut(context.Background(), engine, nil, testKey4, makeTS(1, 0), value4, nil) + if err := MVCCPut(context.Background(), engine, nil, testKey1, makeTS(1, 0), value1, nil); err != nil { + t.Fatal(err) + } + if err := MVCCPut(context.Background(), engine, nil, testKey2, makeTS(1, 0), value2, txn1); err != nil { + t.Fatal(err) + } + if err := MVCCPut(context.Background(), engine, nil, testKey3, makeTS(2, 0), value3, txn2); err != nil { + t.Fatal(err) + } + if err := MVCCPut(context.Background(), engine, nil, testKey4, makeTS(1, 0), value4, nil); err != nil { + t.Fatal(err) + } - _, _, _, err = MVCCDeleteRange(context.Background(), engine, nil, testKey2, testKey4, math.MaxInt64, makeTS(1, 0), txn1, false) - if err == nil { + if _, _, _, err := MVCCDeleteRange(context.Background(), engine, nil, testKey2, testKey4, math.MaxInt64, makeTS(1, 0), txn1, false); err == nil { t.Fatal("expected error on uncommitted write intent") } } diff --git a/storage/entry_cache_test.go b/storage/entry_cache_test.go index 1ac5884485ef..ac7d4d59d678 100644 --- a/storage/entry_cache_test.go +++ b/storage/entry_cache_test.go @@ -115,8 +115,8 @@ func TestEntryCacheEviction(t *testing.T) { rec := newRaftEntryCache(100) rec.addEntries(rangeID, []raftpb.Entry{newEntry(1, 40), newEntry(2, 40)}) ents, _, hi := rec.getEntries(rangeID, 1, 3, 0) - if len(ents) != 2 { - t.Errorf("expected both entries; got %+v", ents) + if len(ents) != 2 || hi != 3 { + t.Errorf("expected both entries; got %+v, %d", ents, hi) } // Add another entry to evict first. rec.addEntries(rangeID, []raftpb.Entry{newEntry(3, 40)}) diff --git a/storage/replica_state.go b/storage/replica_state.go index 2b212c89ef7c..2c0218ba3155 100644 --- a/storage/replica_state.go +++ b/storage/replica_state.go @@ -323,7 +323,7 @@ func loadFrozenStatus( func loadLastIndex( ctx context.Context, reader engine.Reader, rangeID roachpb.RangeID, ) (uint64, error) { - lastIndex := uint64(0) + var lastIndex uint64 v, _, err := engine.MVCCGet(ctx, reader, keys.RaftLastIndexKey(rangeID), hlc.ZeroTimestamp, true /* consistent */, nil) diff --git a/storage/store.go b/storage/store.go index a91670d066ff..e47f43d4ce92 100644 --- a/storage/store.go +++ b/storage/store.go @@ -2632,6 +2632,9 @@ func sendSnapshot( } // Wait until we get a response from the server. resp, err := stream.Recv() + if err != nil { + return err + } switch resp.Status { case SnapshotResponse_DECLINED: if header.CanDecline { diff --git a/util/encoding/decimal.go b/util/encoding/decimal.go index 09da465c645b..e61f43c7e310 100644 --- a/util/encoding/decimal.go +++ b/util/encoding/decimal.go @@ -614,7 +614,7 @@ func encodeNonsortingDecimalValueWithoutExp(digits []big.Word, buf []byte) []byt // It will only modify the provided big.Int if copyOnWrite is not set, and // it will use the formatted representation of the big.Int if it is provided. func normalizeBigInt(bi *big.Int, copyOnWrite bool, formatted, tmp []byte) *big.Int { - tens := 0 + var tens int if formatted != nil { tens = trailingZerosFromBytes(formatted) } else {