Help: Error Listing Keys with a Certain Prefix - tikv aborts txn: Error(Txn(Error(Codec(KeyPadding)))

This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 求助:列出某前缀的 keys 时报错 tikv aborts txn: Error(Txn(Error(Codec(KeyPadding))))

| username: TiDBer_QBsB7GOW

Bug Report
Clearly and accurately describe the issue you found. Providing any steps to reproduce the issue can help the development team address it promptly.
[TiKV Version]
TiKV 7.4.0 (not using TiDB)
[Impact of the Bug]
Unable to list keys with the specified prefix
[Possible Steps to Reproduce]
Uncertain how to reproduce
(If possible, could someone explain what this error means? I’ve searched for a long time but couldn’t find relevant information)
[Observed Unexpected Behavior]
Listing failed with the following error:
[errorVerbose=“tikv aborts txn: Error(Txn(Error(Codec(KeyPadding))))\\n\t/Users/apap/go/pkg/mod/\\n\t/Users/apap/go/pkg/mod/\*Scanner).getData\n\t/Users/apap/go/pkg/mod/\*Scanner).Next\n\t/Users/apap/go/pkg/mod/\\n\t/Users/apap/go/pkg/mod/\*KVSnapshot).Iter\n\t/Users/apap/go/pkg/mod/\*KVUnionStore).Iter\n\t/Users/apap/go/pkg/mod/\*KVTxn).Iter\n\t/Users/apap/go/pkg/mod/\*TikvStore).ListPrefixedObjects.func1\n\t/Users/apap/starstor/uttc/core/tikv/tikv_store.go:433\*TxnWrapper).RunInTxn\n\t/Users/apap/starstor/uttc/core/tikv/tikv_store.go:548\*TikvStore).ListPrefixedObjects\n\t/Users/apap/starstor/uttc/core/tikv/tikv_store.go:432\*CoreStoreWrapper).ListPrefixedObjects\n\t/Users/apap/starstor/uttc/core/corestore_wrapper.go:377\*Core).runListDirectoryObjects\n\t/Users/apap/starstor/uttc/core/core.go:327\*Core).runListValidObjects\n\t/Users/apap/starstor/uttc/core/core_search.go:101\*Core).runListPatternMatchedObjects\n\t/Users/apap/starstor/uttc/core/core_search.go:70\*Core).StreamListDirectoryObjects\n\t/Users/apap/starstor/uttc/core/core_search.go:58\*CoreServer).ListObjects\n\t/Users/apap/starstor/uttc/server/core_grpc_server.go:60\\n\t/Users/apap/starstor/uttc/pb/core_pb/core_grpc.pb.go:454\*Server).processStreamingRPC\n\t/Users/apap/go/pkg/mod/\*Server).handleStream\n\t/Users/apap/go/pkg/mod/\*Server).serveStreams.func1.1\n\t/Users/apap/go/pkg/mod/\nruntime.goexit\n\t/usr/local/go/src/runtime/asm_amd64.s:1650”]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x2d90d77]

[Expected Behavior]
List normally
[Related Components and Specific Versions]
go sdk
[Other Background Information or Screenshots]
Rocky Linux 9.2 5.14.0-284.30.1.el9_2.x86_64
wx: nicoljiang

| username: Billmay表妹 | Original post link

Raw KV? Not using TiDB?

| username: TiDBer_QBsB7GOW | Original post link

Yes, Raw Kv

| username: xfworld | Original post link

Can you describe how it was operated?
From the logs, it looks like the transaction request was abandoned. It would be best if you could provide a scenario description.

| username: xfworld | Original post link

The raw kv mode does not initiate txn requests. Maybe you are using the wrong method…

| username: Fly-bird | Original post link

The region may have undergone changes.

| username: ti-tiger | Original post link

Check the versions of TiKV and client-go to ensure they are compatible.

| username: TiDBer_QBsB7GOW | Original post link

Thanks a lot. After troubleshooting last night, it should be caused by txn.Iter(lastKey, nil). I’ll keep looking into it.

| username: TiDBer_QBsB7GOW | Original post link

@xfworld @Fly-bird @ti-tiger Can TiKV’s key allow bytes like ESC and \n to exist?

The [bytes] lastKey we generated contains an ESC and a newline.


| username: xfworld | Original post link

Not quite sure, I suggest using escaping to avoid unrecognizable characters :slightly_smiling_face:

| username: TiDBer_QBsB7GOW | Original post link

After investigation, it seems that when the endkey is empty, the client is querying the wrong endkey (it is possible that an incorrect region is returned).

| username: TiDBer_QBsB7GOW | Original post link

There is no region returning an error.
The error is triggered when the client calculates the end key given a start key and the end key is nil.
@xfworld @ti-tiger @Fly-bird Do you have any tips or suggestions?

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.