Skip to content

Commit

Permalink
server: support getting the MVCC of the temporary index (#40830)
Browse files Browse the repository at this point in the history
close #40826
  • Loading branch information
wjhuang2016 authored Jan 30, 2023
1 parent 97e1563 commit 28d0325
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
15 changes: 13 additions & 2 deletions server/http_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (t *tikvHandlerTool) getHandle(tb table.PhysicalTable, params map[string]st
return handle, nil
}

func (t *tikvHandlerTool) getMvccByIdxValue(idx table.Index, values url.Values, idxCols []*model.ColumnInfo, handle kv.Handle) (*helper.MvccKV, error) {
func (t *tikvHandlerTool) getMvccByIdxValue(idx table.Index, values url.Values, idxCols []*model.ColumnInfo, handle kv.Handle) ([]*helper.MvccKV, error) {
sc := new(stmtctx.StatementContext)
// HTTP request is not a database session, set timezone to UTC directly here.
// See https://github.com/pingcap/tidb/blob/master/docs/tidb_http_api.md for more details.
Expand All @@ -227,7 +227,18 @@ func (t *tikvHandlerTool) getMvccByIdxValue(idx table.Index, values url.Values,
if err != nil {
return nil, err
}
return &helper.MvccKV{Key: strings.ToUpper(hex.EncodeToString(encodedKey)), RegionID: regionID, Value: data}, err
idxData := &helper.MvccKV{Key: strings.ToUpper(hex.EncodeToString(encodedKey)), RegionID: regionID, Value: data}
tablecodec.IndexKey2TempIndexKey(idx.Meta().ID, encodedKey)
data, err = t.GetMvccByEncodedKey(encodedKey)
if err != nil {
return nil, err
}
regionID, err = t.getRegionIDByKey(encodedKey)
if err != nil {
return nil, err
}
tempIdxData := &helper.MvccKV{Key: strings.ToUpper(hex.EncodeToString(encodedKey)), RegionID: regionID, Value: data}
return append([]*helper.MvccKV{}, idxData, tempIdxData), err
}

// formValue2DatumRow converts URL query string to a Datum Row.
Expand Down
12 changes: 6 additions & 6 deletions server/http_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,16 +539,16 @@ partition by range (a)

func decodeKeyMvcc(closer io.ReadCloser, t *testing.T, valid bool) {
decoder := json.NewDecoder(closer)
var data helper.MvccKV
var data []helper.MvccKV
err := decoder.Decode(&data)
require.NoError(t, err)
if valid {
require.NotNil(t, data.Value.Info)
require.Greater(t, len(data.Value.Info.Writes), 0)
require.NotNil(t, data[0].Value.Info)
require.Greater(t, len(data[0].Value.Info.Writes), 0)
} else {
require.Nil(t, data.Value.Info.Lock)
require.Nil(t, data.Value.Info.Writes)
require.Nil(t, data.Value.Info.Values)
require.Nil(t, data[0].Value.Info.Lock)
require.Nil(t, data[0].Value.Info.Writes)
require.Nil(t, data[0].Value.Info.Values)
}
}

Expand Down

0 comments on commit 28d0325

Please sign in to comment.