forked from talent-plan/tinykv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement latching for MVCC transactions (talent-plan#70)
* Implement latching for MVCC transactions Signed-off-by: Nick Cameron <[email protected]> * Refactor commands Signed-off-by: Nick Cameron <[email protected]> * Refactoring: make executing commands more succinct Signed-off-by: Nick Cameron <[email protected]> * Test latching Signed-off-by: Nick Cameron <[email protected]> * Address review comments and do some refactoring Signed-off-by: Nick Cameron <[email protected]>
- Loading branch information
Showing
26 changed files
with
583 additions
and
774 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package commands | ||
|
||
import ( | ||
"github.com/pingcap-incubator/tinykv/kv/tikv/inner_server" | ||
"github.com/pingcap-incubator/tinykv/kv/tikv/storage/kvstore" | ||
"github.com/pingcap-incubator/tinykv/proto/pkg/kvrpcpb" | ||
"reflect" | ||
) | ||
|
||
// This file contains some base types for commands to reduce boilerplate. | ||
|
||
type CommandBase struct { | ||
context *kvrpcpb.Context | ||
} | ||
|
||
func (base CommandBase) Context() *kvrpcpb.Context { | ||
return base.context | ||
} | ||
|
||
func (base CommandBase) Read(txn *kvstore.RoTxn) (interface{}, [][]byte, error) { | ||
return nil, nil, nil | ||
} | ||
|
||
type ReadOnly struct{} | ||
|
||
func (ro ReadOnly) WillWrite() [][]byte { | ||
return nil | ||
} | ||
|
||
func (ro ReadOnly) PrepareWrites(txn *kvstore.MvccTxn) (interface{}, error) { | ||
return nil, nil | ||
} | ||
|
||
func regionError(err error, resp interface{}) (interface{}, error) { | ||
if regionErr, ok := err.(*inner_server.RegionError); ok { | ||
respValue := reflect.ValueOf(resp) | ||
respValue.FieldByName("RegionError").Set(reflect.ValueOf(regionErr.RequestErr)) | ||
return resp, nil | ||
} | ||
|
||
return nil, err | ||
} | ||
|
||
// regionErrorRo is a convenience version of regionError to match the return type of Read. | ||
func regionErrorRo(err error, resp interface{}) (interface{}, [][]byte, error) { | ||
resp, err = regionError(err, resp) | ||
return resp, nil, err | ||
} |
Oops, something went wrong.