From 3c0de0f1f5490b5d97d56f6949316c1c9d0a5091 Mon Sep 17 00:00:00 2001 From: Nathan VanBenschoten Date: Mon, 18 May 2020 18:13:13 -0400 Subject: [PATCH 1/2] kv: include lease epoch in RangeInfo.CTEntry Should help with debugging. --- pkg/kv/kvserver/replica.go | 3 +- pkg/kv/kvserver/storagepb/state.pb.go | 165 +++++++++++++++----------- pkg/kv/kvserver/storagepb/state.proto | 1 + 3 files changed, 101 insertions(+), 68 deletions(-) diff --git a/pkg/kv/kvserver/replica.go b/pkg/kv/kvserver/replica.go index 939f7b05dcd7..4654906888aa 100644 --- a/pkg/kv/kvserver/replica.go +++ b/pkg/kv/kvserver/replica.go @@ -1025,8 +1025,9 @@ func (r *Replica) State() storagepb.RangeInfo { } if ri.NewestClosedTimestamp.ClosedTimestamp.Less(e.ClosedTimestamp) { ri.NewestClosedTimestamp.NodeID = replDesc.NodeID - ri.NewestClosedTimestamp.MLAI = int64(mlai) ri.NewestClosedTimestamp.ClosedTimestamp = e.ClosedTimestamp + ri.NewestClosedTimestamp.MLAI = int64(mlai) + ri.NewestClosedTimestamp.Epoch = int64(e.Epoch) } return true // done }) diff --git a/pkg/kv/kvserver/storagepb/state.pb.go b/pkg/kv/kvserver/storagepb/state.pb.go index ca733faa0614..af38fb201d70 100644 --- a/pkg/kv/kvserver/storagepb/state.pb.go +++ b/pkg/kv/kvserver/storagepb/state.pb.go @@ -77,7 +77,7 @@ func (m *ReplicaState) Reset() { *m = ReplicaState{} } func (m *ReplicaState) String() string { return proto.CompactTextString(m) } func (*ReplicaState) ProtoMessage() {} func (*ReplicaState) Descriptor() ([]byte, []int) { - return fileDescriptor_state_a986c1c7fbef0ea5, []int{0} + return fileDescriptor_state_00e68aa34820cec1, []int{0} } func (m *ReplicaState) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -144,7 +144,7 @@ func (m *RangeInfo) Reset() { *m = RangeInfo{} } func (m *RangeInfo) String() string { return proto.CompactTextString(m) } func (*RangeInfo) ProtoMessage() {} func (*RangeInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_state_a986c1c7fbef0ea5, []int{1} + return fileDescriptor_state_00e68aa34820cec1, []int{1} } func (m *RangeInfo) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -173,13 +173,14 @@ type RangeInfo_CTEntry struct { NodeID github_com_cockroachdb_cockroach_pkg_roachpb.NodeID `protobuf:"varint,1,opt,name=node_id,json=nodeId,proto3,casttype=github.com/cockroachdb/cockroach/pkg/roachpb.NodeID" json:"node_id,omitempty"` ClosedTimestamp hlc.Timestamp `protobuf:"bytes,2,opt,name=closed_timestamp,json=closedTimestamp,proto3" json:"closed_timestamp"` MLAI int64 `protobuf:"varint,3,opt,name=mlai,proto3" json:"mlai,omitempty"` + Epoch int64 `protobuf:"varint,4,opt,name=epoch,proto3" json:"epoch,omitempty"` } func (m *RangeInfo_CTEntry) Reset() { *m = RangeInfo_CTEntry{} } func (m *RangeInfo_CTEntry) String() string { return proto.CompactTextString(m) } func (*RangeInfo_CTEntry) ProtoMessage() {} func (*RangeInfo_CTEntry) Descriptor() ([]byte, []int) { - return fileDescriptor_state_a986c1c7fbef0ea5, []int{1, 0} + return fileDescriptor_state_00e68aa34820cec1, []int{1, 0} } func (m *RangeInfo_CTEntry) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -215,7 +216,7 @@ func (m *LatchManagerInfo) Reset() { *m = LatchManagerInfo{} } func (m *LatchManagerInfo) String() string { return proto.CompactTextString(m) } func (*LatchManagerInfo) ProtoMessage() {} func (*LatchManagerInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_state_a986c1c7fbef0ea5, []int{2} + return fileDescriptor_state_00e68aa34820cec1, []int{2} } func (m *LatchManagerInfo) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -384,6 +385,9 @@ func (this *RangeInfo_CTEntry) Equal(that interface{}) bool { if this.MLAI != that1.MLAI { return false } + if this.Epoch != that1.Epoch { + return false + } return true } func (m *ReplicaState) Marshal() (dAtA []byte, err error) { @@ -617,6 +621,11 @@ func (m *RangeInfo_CTEntry) MarshalTo(dAtA []byte) (int, error) { i++ i = encodeVarintState(dAtA, i, uint64(m.MLAI)) } + if m.Epoch != 0 { + dAtA[i] = 0x20 + i++ + i = encodeVarintState(dAtA, i, uint64(m.Epoch)) + } return i, nil } @@ -758,6 +767,9 @@ func (m *RangeInfo_CTEntry) Size() (n int) { if m.MLAI != 0 { n += 1 + sovState(uint64(m.MLAI)) } + if m.Epoch != 0 { + n += 1 + sovState(uint64(m.Epoch)) + } return n } @@ -1544,6 +1556,25 @@ func (m *RangeInfo_CTEntry) Unmarshal(dAtA []byte) error { break } } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Epoch", wireType) + } + m.Epoch = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowState + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Epoch |= (int64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipState(dAtA[iNdEx:]) @@ -1759,71 +1790,71 @@ var ( ) func init() { - proto.RegisterFile("kv/kvserver/storagepb/state.proto", fileDescriptor_state_a986c1c7fbef0ea5) + proto.RegisterFile("kv/kvserver/storagepb/state.proto", fileDescriptor_state_00e68aa34820cec1) } -var fileDescriptor_state_a986c1c7fbef0ea5 = []byte{ - // 978 bytes of a gzipped FileDescriptorProto +var fileDescriptor_state_00e68aa34820cec1 = []byte{ + // 991 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x55, 0x4d, 0x6f, 0xdb, 0x46, - 0x10, 0x35, 0x23, 0xda, 0x96, 0x56, 0x76, 0xac, 0x6e, 0x93, 0x98, 0x71, 0x62, 0xc9, 0x35, 0xd0, + 0x10, 0x35, 0x2d, 0xca, 0x96, 0x56, 0x76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x73, 0x72, 0x19, 0x27, 0x5e, 0x2f, 0x09, 0x3c, 0x19, + 0x0f, 0x40, 0x48, 0x3a, 0xc8, 0x8a, 0xc8, 0x7a, 0xc4, 0x22, 0xa6, 0x8f, 0x9e, 0x3a, 0x19, 0x74, + 0xe7, 0x77, 0x1b, 0xad, 0x10, 0xc8, 0x92, 0x38, 0xa0, 0xcf, 0xd4, 0x6d, 0xf0, 0x67, 0x08, 0xab, + 0x57, 0xfb, 0x34, 0xcb, 0x92, 0x18, 0x42, 0x3f, 0x4e, 0x43, 0xb8, 0x70, 0xac, 0x6d, 0x6b, 0xd7, + 0x26, 0x75, 0x15, 0xd9, 0x37, 0x81, 0x43, 0x85, 0x63, 0x17, 0x7d, 0x98, 0x00, 0x15, 0x70, 0x8b, + 0xbe, 0xa8, 0xe9, 0x1f, 0xe8, 0xd0, 0x1c, 0xff, 0x2b, 0x64, 0x87, 0x20, 0x02, 0xa7, 0xb4, 0x6d, + 0xed, 0xd6, 0xf6, 0x76, 0xdc, 0x37, 0xa2, 0x15, 0x77, 0x71, 0x09, 0x4d, 0x23, 0x38, 0x00, 0x11, + 0xf0, 0x38, 0x93, 0x8c, 0x13, 0xcd, 0xc7, 0x2e, 0x2a, 0xeb, 0x62, 0x8e, 0xad, 0x13, 0x9d, 0xb7, + 0x24, 0x1e, 0xab, 0x38, 0x31, 0x34, 0x7c, 0x8a, 0xd6, 0x24, 0xcf, 0xd3, 0x80, 0x4a, 0x08, 0x7d, + 0x3d, 0x26, 0xa7, 0xac, 0x33, 0x3f, 0x7e, 0xeb, 0x2b, 0xcf, 0x65, 0x67, 0xc2, 0xd6, 0x2a, 0x90, + 0x7b, 0x72, 0xee, 0x19, 0x9f, 0xa1, 0x95, 0x28, 0xf0, 0x65, 0x8f, 0x83, 0xe8, 0xb1, 0x24, 0x74, + 0x96, 0x74, 0xb1, 0xad, 0x99, 0x62, 0x4a, 0x77, 0xb7, 0x97, 0x04, 0x6e, 0x67, 0xa2, 0x7b, 0x6b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0xa7, + 0x52, 0xcb, 0x51, 0x22, 0x55, 0x85, 0xb4, 0x15, 0xa0, 0x3e, 0xcc, 0x97, 0x3c, 0x96, 0x50, 0xc4, + 0x17, 0x75, 0x1c, 0x69, 0x48, 0x13, 0x5a, 0x9f, 0x5e, 0xfd, 0xdd, 0x58, 0xb8, 0x1a, 0x37, 0xac, + 0xeb, 0x71, 0xc3, 0x7a, 0x3d, 0x6e, 0x58, 0x7f, 0x8d, 0x1b, 0xd6, 0x1f, 0x37, 0x8d, 0x85, 0xeb, + 0x9b, 0xc6, 0xc2, 0xeb, 0x9b, 0xc6, 0xc2, 0xf3, 0xea, 0xd4, 0xc5, 0xdd, 0x25, 0xfd, 0x43, 0x7a, + 0xf2, 0x7f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x85, 0x42, 0xe7, 0xd0, 0x6c, 0x07, 0x00, 0x00, } diff --git a/pkg/kv/kvserver/storagepb/state.proto b/pkg/kv/kvserver/storagepb/state.proto index baff822412f8..2e96f56db803 100644 --- a/pkg/kv/kvserver/storagepb/state.proto +++ b/pkg/kv/kvserver/storagepb/state.proto @@ -103,6 +103,7 @@ message RangeInfo { (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/roachpb.NodeID"]; util.hlc.Timestamp closed_timestamp = 2 [(gogoproto.nullable) = false]; int64 mlai = 3 [(gogoproto.customname) = "MLAI"]; + int64 epoch = 4; } // The highest closed timestamp known to have data for this replica, taken // across the data received from all nodes. This does not reflect whether From 1d421daf91f77706490b77ad3f891ee97a5291b8 Mon Sep 17 00:00:00 2001 From: Andrew Werner Date: Mon, 18 May 2020 17:48:24 -0400 Subject: [PATCH 2/2] sql: deal with retriable errors in `DROP INDEX` Prior to this commit we would assume any error while retrieving a descriptor during the execution of `DROP INDEX` was an assertion failure. This was overly paranoid. Plenty of retriable errors are possible (and furthermore so are errors due to shutdown). The only error we should freak out about is if we discover the relation is not defined. Fixes #48474. Release note (bug fix): Fix bug where contended `DROP INDEX` queries return an assertion failure error rather than a retriable error. --- pkg/sql/drop_index.go | 5 +- pkg/sql/drop_test.go | 138 ++++++++++++++++++++++++++ pkg/sql/helpers_test.go | 3 + pkg/sql/pgwire/testdata/pgtest/notice | 2 +- 4 files changed, 146 insertions(+), 2 deletions(-) diff --git a/pkg/sql/drop_index.go b/pkg/sql/drop_index.go index 5fcd8d5291c1..025de97a34cc 100644 --- a/pkg/sql/drop_index.go +++ b/pkg/sql/drop_index.go @@ -86,13 +86,16 @@ func (n *dropIndexNode) startExec(params runParams) error { // drop need to be visible to the second drop. tableDesc, err := params.p.ResolveMutableTableDescriptor( ctx, index.tn, true /*required*/, ResolveRequireTableDesc) - if err != nil { + if sqlbase.IsUndefinedRelationError(err) { // Somehow the descriptor we had during planning is not there // any more. return errors.NewAssertionErrorWithWrappedErrf(err, "table descriptor for %q became unavailable within same txn", tree.ErrString(index.tn)) } + if err != nil { + return err + } // If we couldn't find the index by name, this is either a legitimate error or // this statement contains an 'IF EXISTS' qualifier. Both of these cases are diff --git a/pkg/sql/drop_test.go b/pkg/sql/drop_test.go index 9495c2e54a5a..45e9e5d5b590 100644 --- a/pkg/sql/drop_test.go +++ b/pkg/sql/drop_test.go @@ -15,6 +15,7 @@ import ( gosql "database/sql" "fmt" "math/rand" + "regexp" "testing" "github.com/cockroachdb/cockroach/pkg/base" @@ -23,6 +24,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/jobs/jobspb" "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/kv" + "github.com/cockroachdb/cockroach/pkg/kv/kvserver" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/security" "github.com/cockroachdb/cockroach/pkg/server" @@ -36,9 +38,14 @@ import ( "github.com/cockroachdb/cockroach/pkg/testutils/jobutils" "github.com/cockroachdb/cockroach/pkg/testutils/serverutils" "github.com/cockroachdb/cockroach/pkg/testutils/sqlutils" + "github.com/cockroachdb/cockroach/pkg/testutils/testcluster" "github.com/cockroachdb/cockroach/pkg/util/leaktest" "github.com/cockroachdb/cockroach/pkg/util/protoutil" + "github.com/cockroachdb/cockroach/pkg/util/syncutil" + "github.com/cockroachdb/cockroach/pkg/util/tracing" + "github.com/cockroachdb/cockroach/pkg/util/uuid" "github.com/cockroachdb/errors" + "github.com/opentracing/opentracing-go" "github.com/stretchr/testify/require" ) @@ -1290,3 +1297,134 @@ CREATE VIEW test.acol(a) AS SELECT a FROM test.t; return err }) } + +// TestDropIndexHandlesRetriableErrors is a regression test against #48474. +// The bug was that retriable errors, which are generally possible, were being +// treated as assertion failures. +func TestDropIndexHandlesRetriableErrors(t *testing.T) { + defer leaktest.AfterTest(t)() + + ctx := context.Background() + rf := newDynamicRequestFilter() + tc := testcluster.StartTestCluster(t, 1, base.TestClusterArgs{ + ServerArgs: base.TestServerArgs{ + Knobs: base.TestingKnobs{ + Store: &kvserver.StoreTestingKnobs{ + TestingRequestFilter: rf.filter, + }, + }, + }, + }) + defer tc.Stopper().Stop(ctx) + + // What we want to do is have a transaction which does the planning work to + // drop an index. Then we want to expose the execution of the DROP INDEX to + // an error when retrieving the mutable table descriptor. We'll do this by + // injecting a ReadWithinUncertainty error underneath the DROP INDEX + // after planning has concluded. + + tdb := sqlutils.MakeSQLRunner(tc.ServerConn(0)) + tdb.Exec(t, "CREATE TABLE foo (i INT PRIMARY KEY, j INT, INDEX j_idx (j))") + + var tableID uint32 + tdb.QueryRow(t, ` +SELECT + table_id +FROM + crdb_internal.tables +WHERE + name = $1 AND database_name = current_database();`, + "foo").Scan(&tableID) + + // Start the user transaction and enable tracing as we'll use the trace + // to determine when planning has concluded. + txn, err := tc.ServerConn(0).Begin() + require.NoError(t, err) + _, err = txn.Exec("SET TRACING = on") + require.NoError(t, err) + // Let's find out our transaction ID for our transaction by running a query. + // We'll also use this query to install a refresh span over the table data. + // Inject a request filter to snag the transaction ID. + tablePrefix := keys.SystemSQLCodec.TablePrefix(tableID) + tableSpan := roachpb.Span{ + Key: tablePrefix, + EndKey: tablePrefix.PrefixEnd(), + } + var filterState struct { + syncutil.Mutex + txnID uuid.UUID + } + getTxnID := func() uuid.UUID { + filterState.Lock() + defer filterState.Unlock() + return filterState.txnID + } + rf.setFilter(func(ctx context.Context, request roachpb.BatchRequest) *roachpb.Error { + if request.Txn == nil || request.Txn.Name != sql.SQLTxnName { + return nil + } + filterState.Lock() + defer filterState.Unlock() + if filterState.txnID != (uuid.UUID{}) { + return nil + } + if scanRequest, ok := request.GetArg(roachpb.Scan); ok { + scan := scanRequest.(*roachpb.ScanRequest) + if scan.Span().Overlaps(tableSpan) { + filterState.txnID = request.Txn.ID + } + } + return nil + }) + + // Run the scan of the table to activate the filter as well as add the + // refresh span over the table data. + var trash int + require.Equal(t, gosql.ErrNoRows, + txn.QueryRow("SELECT * FROM foo").Scan(&trash)) + rf.setFilter(nil) + require.NotEqual(t, uuid.UUID{}, getTxnID()) + + // Perform a write after the above read so that a refresh will fail and + // observe its timestamp. + tdb.Exec(t, "INSERT INTO foo VALUES (1)") + var afterInsertStr string + tdb.QueryRow(t, "SELECT cluster_logical_timestamp()").Scan(&afterInsertStr) + afterInsert, err := sql.ParseHLC(afterInsertStr) + require.NoError(t, err) + + // Now set up a filter to detect when the DROP INDEX execution will begin + // and inject an error forcing a refresh above the conflicting write which + // will fail. We'll want to ensure that we get a retriable error. + // Use the below pattern to detect when the user transaction has finished + // planning and is now executing. + dropIndexPlanningEndsRE := regexp.MustCompile("(?s)planning starts: DROP INDEX.*planning ends") + rf.setFilter(func(ctx context.Context, request roachpb.BatchRequest) *roachpb.Error { + if request.Txn == nil { + return nil + } + filterState.Lock() + defer filterState.Unlock() + if filterState.txnID != request.Txn.ID { + return nil + } + sp := opentracing.SpanFromContext(ctx) + rec := tracing.GetRecording(sp) + if !dropIndexPlanningEndsRE.MatchString(rec.String()) { + return nil + } + if getRequest, ok := request.GetArg(roachpb.Get); ok { + put := getRequest.(*roachpb.GetRequest) + if put.Key.Equal(sqlbase.MakeDescMetadataKey(keys.SystemSQLCodec, sqlbase.ID(tableID))) { + filterState.txnID = uuid.UUID{} + return roachpb.NewError(roachpb.NewReadWithinUncertaintyIntervalError( + request.Txn.ReadTimestamp, afterInsert, request.Txn)) + } + } + return nil + }) + + _, err = txn.Exec("DROP INDEX foo@j_idx") + require.Truef(t, isRetryableErr(err), "drop index error: %v", err) + require.NoError(t, txn.Rollback()) +} diff --git a/pkg/sql/helpers_test.go b/pkg/sql/helpers_test.go index b7f07ef83030..1f1c6b7c21b6 100644 --- a/pkg/sql/helpers_test.go +++ b/pkg/sql/helpers_test.go @@ -25,6 +25,9 @@ type tableVersionID struct { version sqlbase.DescriptorVersion } +// SQLTxnName is the transaction name used by sql transactions. +const SQLTxnName = sqlTxnName + // LeaseRemovalTracker can be used to wait for leases to be removed from the // store (leases are removed from the store async w.r.t. LeaseManager // operations). diff --git a/pkg/sql/pgwire/testdata/pgtest/notice b/pkg/sql/pgwire/testdata/pgtest/notice index bc5f6754f4a8..1e3ea5aa5386 100644 --- a/pkg/sql/pgwire/testdata/pgtest/notice +++ b/pkg/sql/pgwire/testdata/pgtest/notice @@ -29,7 +29,7 @@ ReadyForQuery ---- {"Type":"ParseComplete"} {"Type":"BindComplete"} -{"Severity":"NOTICE","Code":"00000","Message":"the data for dropped indexes is reclaimed asynchronously","Detail":"","Hint":"The reclamation delay can be customized in the zone configuration for the table.","Position":0,"InternalPosition":0,"InternalQuery":"","Where":"","SchemaName":"","TableName":"","ColumnName":"","DataTypeName":"","ConstraintName":"","File":"drop_index.go","Line":496,"Routine":"dropIndexByName","UnknownFields":null} +{"Severity":"NOTICE","Code":"00000","Message":"the data for dropped indexes is reclaimed asynchronously","Detail":"","Hint":"The reclamation delay can be customized in the zone configuration for the table.","Position":0,"InternalPosition":0,"InternalQuery":"","Where":"","SchemaName":"","TableName":"","ColumnName":"","DataTypeName":"","ConstraintName":"","File":"drop_index.go","Line":499,"Routine":"dropIndexByName","UnknownFields":null} {"Type":"CommandComplete","CommandTag":"DROP INDEX"} {"Type":"ReadyForQuery","TxStatus":"I"}