DecodeKeyHead decodes the key's head and gets the tableID, indexID. isRecordKey is true when is a record key.
(key kv.Key)
| 259 | |
| 260 | // DecodeKeyHead decodes the key's head and gets the tableID, indexID. isRecordKey is true when is a record key. |
| 261 | func DecodeKeyHead(key kv.Key) (tableID int64, indexID int64, isRecordKey bool, err error) { |
| 262 | isRecordKey = false |
| 263 | k := key |
| 264 | if !key.HasPrefix(tablePrefix) { |
| 265 | err = errInvalidKey.GenWithStack("invalid key - %q", k) |
| 266 | return |
| 267 | } |
| 268 | |
| 269 | key = key[len(tablePrefix):] |
| 270 | key, tableID, err = codec.DecodeInt(key) |
| 271 | if err != nil { |
| 272 | err = errors.Trace(err) |
| 273 | return |
| 274 | } |
| 275 | |
| 276 | if key.HasPrefix(recordPrefixSep) { |
| 277 | isRecordKey = true |
| 278 | return |
| 279 | } |
| 280 | if !key.HasPrefix(indexPrefixSep) { |
| 281 | err = errInvalidKey.GenWithStack("invalid key - %q", k) |
| 282 | return |
| 283 | } |
| 284 | |
| 285 | key = key[len(indexPrefixSep):] |
| 286 | |
| 287 | key, indexID, err = codec.DecodeInt(key) |
| 288 | if err != nil { |
| 289 | err = errors.Trace(err) |
| 290 | return |
| 291 | } |
| 292 | return |
| 293 | } |
| 294 | |
| 295 | // DecodeIndexID decodes indexID from the key. |
| 296 | // this method simply extract index id part, and no other checking. |