DecodeRecordKey decodes the key and gets the tableID, handle.
(key kv.Key)
| 141 | |
| 142 | // DecodeRecordKey decodes the key and gets the tableID, handle. |
| 143 | func DecodeRecordKey(key kv.Key) (tableID int64, handle kv.Handle, err error) { |
| 144 | if len(key) <= prefixLen { |
| 145 | return 0, nil, errInvalidRecordKey.GenWithStack("invalid record key - %q", key) |
| 146 | } |
| 147 | |
| 148 | k := key |
| 149 | if !hasTablePrefix(key) { |
| 150 | return 0, nil, errInvalidRecordKey.GenWithStack("invalid record key - %q", k) |
| 151 | } |
| 152 | |
| 153 | key = key[tablePrefixLength:] |
| 154 | key, tableID, err = codec.DecodeInt(key) |
| 155 | if err != nil { |
| 156 | return 0, nil, errors.Trace(err) |
| 157 | } |
| 158 | |
| 159 | if !hasRecordPrefixSep(key) { |
| 160 | return 0, nil, errInvalidRecordKey.GenWithStack("invalid record key - %q", k) |
| 161 | } |
| 162 | |
| 163 | key = key[recordPrefixSepLength:] |
| 164 | if len(key) == 8 { |
| 165 | var intHandle int64 |
| 166 | key, intHandle, err = codec.DecodeInt(key) |
| 167 | if err != nil { |
| 168 | return 0, nil, errors.Trace(err) |
| 169 | } |
| 170 | return tableID, kv.IntHandle(intHandle), nil |
| 171 | } |
| 172 | h, err := kv.NewCommonHandle(key) |
| 173 | if err != nil { |
| 174 | return 0, nil, errInvalidRecordKey.GenWithStack("invalid record key - %q %v", k, err) |
| 175 | } |
| 176 | return tableID, h, nil |
| 177 | } |
| 178 | |
| 179 | // DecodeIndexKey decodes the key and gets the tableID, indexID, indexValues. |
| 180 | func DecodeIndexKey(key kv.Key) (tableID int64, indexID int64, indexValues []string, err error) { |