Skip to content
This repository was archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #9743 from EOSIO/fix_get_kv_table_518
Browse files Browse the repository at this point in the history
fixed get_kv_table_rows issues
  • Loading branch information
kimjh2005 authored Dec 7, 2020
2 parents a2358ae + 10bb5ba commit 64ff4ef
Show file tree
Hide file tree
Showing 6 changed files with 423 additions and 21 deletions.
19 changes: 11 additions & 8 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2170,6 +2170,7 @@ read_only::get_table_rows_result read_only::get_kv_table_rows( const read_only::

read_only::get_table_rows_result read_only::get_kv_table_rows_context( const read_only::get_kv_table_rows_params& pp, kv_context &kv_context, const abi_def &abi )const {
read_only::get_kv_table_rows_params p(pp);
EOS_ASSERT(p.limit > 0, chain::contract_table_query_exception, "invalid limit : ${n}", ("n", p.limit));
string tbl_name = p.table.to_string();

// Check valid table name
Expand Down Expand Up @@ -2213,6 +2214,7 @@ read_only::get_table_rows_result read_only::get_kv_table_rows_context( const rea
const string &index_value = *p.index_value;
p.lower_bound = p.index_value;
unbounded = true;
p.reverse = false;
}

///////////////////////////////////////////////////////////
Expand Down Expand Up @@ -2284,8 +2286,8 @@ read_only::get_table_rows_result read_only::get_kv_table_rows_context( const rea
if( has_upper_bound ) {
auto exact_match = kv_context.kv_get(p.code.to_uint64_t(), ub_key.data(), ub_key.size(), value_size);
status_ub = ub_itr->kv_it_lower_bound(ub_key.data(), ub_key.size(), &ub_key_size, &ub_value_size);
if( p.reverse && !point_query && !exact_match ) {
status_ub = ub_itr->kv_it_prev(&ub_key_size, &ub_value_size);
if( !point_query && !exact_match ) {
status_ub = ub_itr->kv_it_prev(&ub_key_size, &ub_value_size);
}

EOS_ASSERT(status_ub != chain::kv_it_stat::iterator_erased, chain::contract_table_query_exception, "Invalid upper bound iterator in ${t} ${i}", ("t", p.table)("i", p.index_name));
Expand Down Expand Up @@ -2320,7 +2322,7 @@ read_only::get_table_rows_result read_only::get_kv_table_rows_context( const rea
}

unsigned int count = 0;
for( count = 0; cur_time <= end_time && count < p.limit && cmp < 0; cur_time = fc::time_point::now() ) {
for( count = 0; cur_time <= end_time && count < p.limit && cmp <= 0; cur_time = fc::time_point::now() ) {
row_key.resize(key_size);
status = itr->kv_it_key(0, row_key.data(), key_size, actual_size);
EOS_ASSERT(key_size == actual_size, chain::contract_table_query_exception, "Invalid iterator in ${t} ${i}", ("t", p.table)("i", p.index_name));
Expand Down Expand Up @@ -2354,9 +2356,7 @@ read_only::get_table_rows_result read_only::get_kv_table_rows_context( const rea
auto time_left = end_time - cur_time;
try {
row_var = abis.binary_to_variant( p.table.to_string(), row_value, abi_serializer::create_yield_function( time_left ), shorten_abi_errors );
}
catch ( fc::exception &e )
{
} catch ( fc::exception &e ) {
row_var = fc::variant( row_value );
}
} else {
Expand All @@ -2371,7 +2371,10 @@ read_only::get_table_rows_result read_only::get_kv_table_rows_context( const rea
} else {
status = itr->kv_it_next(&key_size, &value_size);
}
EOS_ASSERT(status != chain::kv_it_stat::iterator_erased, chain::contract_table_query_exception, "Invalid lower bound iterator in ${t} ${i}", ("t", p.table)("i", p.index_name));
if( status == chain::kv_it_stat::iterator_end ) {
break;
}
EOS_ASSERT(status == chain::kv_it_stat::iterator_ok, chain::contract_table_query_exception, "Invalid iterator in ${t} ${i}", ("t", p.table)("i", p.index_name));

if (unbounded) {
cur_status = itr->kv_it_status();
Expand All @@ -2386,7 +2389,7 @@ read_only::get_table_rows_result read_only::get_kv_table_rows_context( const rea
}
}

if (count == p.limit && cmp < 0)
if (count == p.limit && cmp <= 0)
{
result.more = true;
row_key.resize(key_size);
Expand Down
4 changes: 2 additions & 2 deletions tests/get_kv_table_addr_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ BOOST_FIXTURE_TEST_CASE( get_kv_table_addr_test, TESTER ) try {
p.upper_bound = "lois";
p.reverse = false;
result = plugin.read_only::get_kv_table_rows(p);
BOOST_REQUIRE_EQUAL(1u, result.rows.size());
BOOST_REQUIRE_EQUAL(2u, result.rows.size());
chk_result(0, 2);

p.index_name = "accname"_n;
Expand All @@ -174,7 +174,7 @@ BOOST_FIXTURE_TEST_CASE( get_kv_table_addr_test, TESTER ) try {
p.upper_bound = "steve";
p.reverse = true;
result = plugin.read_only::get_kv_table_rows(p);
BOOST_REQUIRE_EQUAL(2u, result.rows.size());
BOOST_REQUIRE_EQUAL(3u, result.rows.size());
chk_result(0, 4);
chk_result(1, 3);

Expand Down
Loading

0 comments on commit 64ff4ef

Please sign in to comment.