本文整理汇总了Golang中github.com/youtube/vitess/go/vt/key.KeyRange.Contains方法的典型用法代码示例。如果您正苦于以下问题:Golang KeyRange.Contains方法的具体用法?Golang KeyRange.Contains怎么用?Golang KeyRange.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/youtube/vitess/go/vt/key.KeyRange
的用法示例。
在下文中一共展示了KeyRange.Contains方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: KeyRangeFilterFunc
// KeyRangeFilterFunc returns a function that calls sendReply only if statements
// in the transaction match the specified keyrange. The resulting function can be
// passed into the BinlogStreamer: bls.Stream(file, pos, sendTransaction) ->
// bls.Stream(file, pos, KeyRangeFilterFunc(sendTransaction))
func KeyRangeFilterFunc(keyrange key.KeyRange, sendReply sendTransactionFunc) sendTransactionFunc {
return func(reply *proto.BinlogTransaction) error {
matched := false
filtered := make([]proto.Statement, 0, len(reply.Statements))
for _, statement := range reply.Statements {
switch statement.Category {
case proto.BL_SET:
filtered = append(filtered, statement)
case proto.BL_DDL:
filtered = append(filtered, statement)
matched = true
case proto.BL_DML:
keyspaceIndex := bytes.LastIndex(statement.Sql, KEYSPACE_ID_COMMENT)
if keyspaceIndex == -1 {
updateStreamErrors.Add("KeyRangeStream", 1)
log.Errorf("Error parsing keyspace id: %s", string(statement.Sql))
continue
}
idstart := keyspaceIndex + len(KEYSPACE_ID_COMMENT)
idend := bytes.Index(statement.Sql[idstart:], SPACE)
if idend == -1 {
updateStreamErrors.Add("KeyRangeStream", 1)
log.Errorf("Error parsing keyspace id: %s", string(statement.Sql))
continue
}
id, err := strconv.ParseUint(string(statement.Sql[idstart:idstart+idend]), 10, 64)
if err != nil {
updateStreamErrors.Add("KeyRangeStream", 1)
log.Errorf("Error parsing keyspace id: %s", string(statement.Sql))
continue
}
if !keyrange.Contains(key.Uint64Key(id).KeyspaceId()) {
continue
}
filtered = append(filtered, statement)
matched = true
}
}
if matched {
reply.Statements = filtered
} else {
reply.Statements = nil
}
return sendReply(reply)
}
}
示例2: KeyRangeFilterFunc
// KeyRangeFilterFunc returns a function that calls sendReply only if statements
// in the transaction match the specified keyrange. The resulting function can be
// passed into the BinlogStreamer: bls.Stream(file, pos, sendTransaction) ->
// bls.Stream(file, pos, KeyRangeFilterFunc(sendTransaction))
func KeyRangeFilterFunc(kit key.KeyspaceIdType, keyrange key.KeyRange, sendReply sendTransactionFunc) sendTransactionFunc {
isInteger := true
if kit == key.KIT_BYTES {
isInteger = false
}
return func(reply *proto.BinlogTransaction) error {
matched := false
filtered := make([]proto.Statement, 0, len(reply.Statements))
for _, statement := range reply.Statements {
switch statement.Category {
case proto.BL_SET:
filtered = append(filtered, statement)
case proto.BL_DDL:
log.Warningf("Not forwarding DDL: %s", string(statement.Sql))
continue
case proto.BL_DML:
keyspaceIndex := bytes.LastIndex(statement.Sql, KEYSPACE_ID_COMMENT)
if keyspaceIndex == -1 {
updateStreamErrors.Add("KeyRangeStream", 1)
log.Errorf("Error parsing keyspace id: %s", string(statement.Sql))
continue
}
idstart := keyspaceIndex + len(KEYSPACE_ID_COMMENT)
idend := bytes.Index(statement.Sql[idstart:], SPACE)
if idend == -1 {
updateStreamErrors.Add("KeyRangeStream", 1)
log.Errorf("Error parsing keyspace id: %s", string(statement.Sql))
continue
}
textId := string(statement.Sql[idstart : idstart+idend])
if isInteger {
id, err := strconv.ParseUint(textId, 10, 64)
if err != nil {
updateStreamErrors.Add("KeyRangeStream", 1)
log.Errorf("Error parsing keyspace id: %s", string(statement.Sql))
continue
}
if !keyrange.Contains(key.Uint64Key(id).KeyspaceId()) {
continue
}
} else {
data, err := base64.StdEncoding.DecodeString(textId)
if err != nil {
updateStreamErrors.Add("KeyRangeStream", 1)
log.Errorf("Error parsing keyspace id: %s", string(statement.Sql))
continue
}
if !keyrange.Contains(key.KeyspaceId(data)) {
continue
}
}
filtered = append(filtered, statement)
matched = true
case proto.BL_UNRECOGNIZED:
updateStreamErrors.Add("KeyRangeStream", 1)
log.Errorf("Error parsing keyspace id: %s", string(statement.Sql))
continue
}
}
if matched {
reply.Statements = filtered
} else {
reply.Statements = nil
}
return sendReply(reply)
}
}