DecodeTableID decodes the table ID of the key, if the key is not table key, returns 0.
(key kv.Key)
| 307 | |
| 308 | // DecodeTableID decodes the table ID of the key, if the key is not table key, returns 0. |
| 309 | func DecodeTableID(key kv.Key) int64 { |
| 310 | if !key.HasPrefix(tablePrefix) { |
| 311 | // If the key is in API V2, then ignore the prefix |
| 312 | _, k, err := tikv.DecodeKey(key, kvrpcpb.APIVersion_V2) |
| 313 | if err != nil { |
| 314 | terror.Log(errors.Trace(err)) |
| 315 | return 0 |
| 316 | } |
| 317 | key = k |
| 318 | if !key.HasPrefix(tablePrefix) { |
| 319 | return 0 |
| 320 | } |
| 321 | } |
| 322 | key = key[len(tablePrefix):] |
| 323 | _, tableID, err := codec.DecodeInt(key) |
| 324 | // TODO: return error. |
| 325 | terror.Log(errors.Trace(err)) |
| 326 | return tableID |
| 327 | } |
| 328 | |
| 329 | // DecodeRowKey decodes the key and gets the handle. |
| 330 | func DecodeRowKey(key kv.Key) (kv.Handle, error) { |