本文整理汇总了Golang中github.com/cockroachdb/cockroach/roachpb.UserPriority函数的典型用法代码示例。如果您正苦于以下问题:Golang UserPriority函数的具体用法?Golang UserPriority怎么用?Golang UserPriority使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了UserPriority函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Open
// Open creates a new database handle to the cockroach cluster specified by
// addr. The cluster is identified by a URL with the format:
//
// [<sender>:]//[<user>@]<host>:<port>[?certs=<dir>,priority=<val>]
//
// The URL scheme (<sender>) specifies which transport to use for talking to
// the cockroach cluster. Currently allowable values are: http, https, rpc,
// rpcs. The rpc and rpcs senders use a variant of Go's builtin rpc library for
// communication with the cluster. This protocol is lower overhead and more
// efficient than http. The decision between the encrypted (https, rpcs) and
// unencrypted senders (http, rpc) depends on the settings of the cluster. A
// given cluster supports either encrypted or unencrypted traffic, but not
// both.
//
// If not specified, the <user> field defaults to "root".
//
// The certs parameter can be used to override the default directory to use for
// client certificates. In tests, the directory "test_certs" uses the embedded
// test certificates.
//
// The priority parameter can be used to override the default priority for
// operations.
func Open(stopper *stop.Stopper, addr string) (*DB, error) {
u, err := url.Parse(addr)
if err != nil {
return nil, err
}
ctx := &base.Context{}
ctx.InitDefaults()
if u.User != nil {
ctx.User = u.User.Username()
}
q := u.Query()
if dir := q["certs"]; len(dir) > 0 {
ctx.Certs = dir[0]
}
sender, err := newSender(u, ctx, stopper)
if err != nil {
return nil, err
}
if sender == nil {
return nil, fmt.Errorf("\"%s\" no sender specified", addr)
}
db := &DB{
sender: sender,
userPriority: roachpb.NormalUserPriority,
txnRetryOptions: DefaultTxnRetryOptions,
}
if priority := q["priority"]; len(priority) > 0 {
p, err := strconv.ParseFloat(priority[0], 64)
if err != nil {
return nil, err
}
db.userPriority = roachpb.UserPriority(p)
}
return db, nil
}
开发者ID:danieldeb,项目名称:cockroach,代码行数:62,代码来源:db.go
示例2: TestSetPriority
// TestSetPriority verifies that the batch UserPriority is correctly set
// depending on the transaction priority.
func TestSetPriority(t *testing.T) {
defer leaktest.AfterTest(t)()
var expected roachpb.UserPriority
db := NewDB(newTestSender(
func(ba roachpb.BatchRequest) (*roachpb.BatchResponse, *roachpb.Error) {
if ba.UserPriority != expected {
pErr := roachpb.NewErrorf("Priority not set correctly in the batch! "+
"(expected: %s, value: %s)", expected, ba.UserPriority)
return nil, pErr
}
br := &roachpb.BatchResponse{}
br.Txn = &roachpb.Transaction{}
br.Txn.Update(ba.Txn) // copy
return br, nil
}, nil))
// Verify the normal priority setting path.
expected = roachpb.HighUserPriority
txn := NewTxn(context.Background(), *db)
if err := txn.SetUserPriority(expected); err != nil {
t.Fatal(err)
}
if _, pErr := txn.db.sender.Send(context.Background(), roachpb.BatchRequest{}); pErr != nil {
t.Fatal(pErr)
}
// Verify the internal (fixed value) priority setting path.
expected = roachpb.UserPriority(-13)
txn = NewTxn(context.Background(), *db)
txn.InternalSetPriority(13)
if _, pErr := txn.db.sender.Send(context.Background(), roachpb.BatchRequest{}); pErr != nil {
t.Fatal(pErr)
}
}
开发者ID:petermattis,项目名称:cockroach,代码行数:39,代码来源:txn_test.go
示例3: TestTxnPutOutOfOrder
//.........这里部分代码省略.........
err := store.DB().Put(key, initVal)
if err != nil {
t.Fatalf("failed to put: %s", err)
}
waitPut := make(chan struct{})
waitFirstGet := make(chan struct{})
waitTxnRestart := make(chan struct{})
waitSecondGet := make(chan struct{})
waitTxnComplete := make(chan struct{})
// Start the Writer.
go func() {
epoch := -1
// Start a txn that does read-after-write.
// The txn will be restarted twice, and the out-of-order put
// will happen in the second epoch.
if err := store.DB().Txn(func(txn *client.Txn) error {
epoch++
if epoch == 1 {
// Wait until the second get operation is issued.
close(waitTxnRestart)
<-waitSecondGet
}
updatedVal := []byte("updatedVal")
if err := txn.Put(key, updatedVal); err != nil {
return err
}
// Make sure a get will return the value that was just written.
actual, err := txn.Get(key)
if err != nil {
return err
}
if !bytes.Equal(actual.ValueBytes(), updatedVal) {
t.Fatalf("unexpected get result: %s", actual)
}
if epoch == 0 {
// Wait until the first get operation will push the txn timestamp.
close(waitPut)
<-waitFirstGet
}
b := txn.NewBatch()
return txn.CommitInBatch(b)
}); err != nil {
t.Fatal(err)
}
if epoch != 2 {
t.Fatalf("unexpected number of txn retries: %d", epoch)
}
close(waitTxnComplete)
}()
<-waitPut
// Start the Reader.
// Advance the clock and send a get operation with higher
// priority to trigger the txn restart.
manualClock.Increment(100)
priority := roachpb.UserPriority(-math.MaxInt32)
requestHeader := roachpb.Span{
Key: roachpb.Key(key),
}
ts := clock.Now()
if _, err := client.SendWrappedWith(rg1(store), nil, roachpb.Header{
Timestamp: ts,
UserPriority: priority,
}, &roachpb.GetRequest{Span: requestHeader}); err != nil {
t.Fatalf("failed to get: %s", err)
}
// Wait until the writer restarts the txn.
close(waitFirstGet)
<-waitTxnRestart
// Advance the clock and send a get operation again. This time
// we use TestingCommandFilter so that a get operation is not
// processed after the write intent is resolved (to prevent the
// timestamp cache from being updated).
manualClock.Increment(100)
ts = clock.Now()
if _, err := client.SendWrappedWith(rg1(store), nil, roachpb.Header{
Timestamp: ts,
UserPriority: priority,
}, &roachpb.GetRequest{Span: requestHeader}); err == nil {
t.Fatal("unexpected success of get")
}
close(waitSecondGet)
<-waitTxnComplete
}
开发者ID:yangxuanjia,项目名称:cockroach,代码行数:101,代码来源:client_replica_test.go
示例4: InternalSetPriority
// InternalSetPriority sets the transaction priority. It is intended for
// internal (testing) use only.
func (txn *Txn) InternalSetPriority(priority int32) {
// The negative user priority is translated on the server into a positive,
// non-randomized, priority for the transaction.
txn.db.userPriority = roachpb.UserPriority(-priority)
}
开发者ID:soniabhishek,项目名称:cockroach,代码行数:7,代码来源:txn.go
示例5: Unmarshal
func (m *Session_Transaction) Unmarshal(data []byte) error {
l := len(data)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowSession
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := data[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: Transaction: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: Transaction: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Txn", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowSession
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := data[iNdEx]
iNdEx++
msglen |= (int(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthSession
}
postIndex := iNdEx + msglen
if postIndex > l {
return io.ErrUnexpectedEOF
}
if err := m.Txn.Unmarshal(data[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Timestamp", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowSession
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := data[iNdEx]
iNdEx++
msglen |= (int(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthSession
}
postIndex := iNdEx + msglen
if postIndex > l {
return io.ErrUnexpectedEOF
}
if err := m.Timestamp.Unmarshal(data[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
case 3:
if wireType != 1 {
return fmt.Errorf("proto: wrong wireType = %d for field UserPriority", wireType)
}
var v uint64
if (iNdEx + 8) > l {
return io.ErrUnexpectedEOF
}
iNdEx += 8
v = uint64(data[iNdEx-8])
v |= uint64(data[iNdEx-7]) << 8
//.........这里部分代码省略.........
开发者ID:alaypatel07,项目名称:cockroach,代码行数:101,代码来源:session.pb.go
注:本文中的github.com/cockroachdb/cockroach/roachpb.UserPriority函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论