Skip to content

Operation aborts if any file contains a corrupt key [JIRA: RIAK-2371] #230

@joecaswell

Description

@joecaswell

The bitcask backend wraps the key transformation function KT() in a try/catch each time it is called:

K = try KT(K0) catch TxErr -> {key_tx_error, TxErr} end,

However, the TxErr will only match explicitly thrown exceptions. In the case of riak_kv_bitcask_backend:key_transform_to_1/1, if an invalid key is encountered the exception thrown is:

{error,function_clause,[{riak_kv_bitcask_backend,key_transform_to_1,[<<>>],[{file,"src/riak_kv_bitcask_backend.erl"},{line,99}]}

which is not caught by the above pattern.

Proper fix is to rework every instances where a key transform is called to use the Class:Exception pattern so exceptions are actually caught.

As an interim workaround, adding a catch-all clause to the transform functions that explicitly throws an exception would allow the existing catch pattern to match for many cases:

key_transform_to_1(<<?VERSION_1:7, _:1, _Rest/binary>> = Key) ->
    Key;
key_transform_to_1(<<131:8,_Rest/bits>> = Key0) ->
    {Bucket, Key} = binary_to_term(Key0),
    make_bk(?VERSION_BYTE, Bucket, Key);
key_transform_to_1(BadKey) ->
    throw({invalid_key, BadKey}).`

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions