Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
empiredan committed Dec 5, 2024
1 parent 45089d2 commit 3768b89
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions idl/duplication.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ struct duplication_entry
11:optional map<i32, duplication_partition_state> partition_states;
}

// States for the duplications of a table.
struct duplication_app_state
{
1:i32 appid;
Expand Down Expand Up @@ -248,6 +249,7 @@ struct duplication_sync_response
// per-duplication info and progress of each partition for one or multiple tables.
struct duplication_list_request
{
// The pattern used to match an app name, whose type is specified by `match_type`.
1:string app_name_pattern;
2:utils.pattern_match_type match_type;
}
Expand Down
1 change: 1 addition & 0 deletions src/meta/duplication/meta_duplication_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ void meta_duplication_service::list_duplication_info(const duplication_list_requ

for (const auto &[app_name, app] : _state->_exist_apps) {
if (app->status != app_status::AS_AVAILABLE) {
// Unavailable tables would not be listed for duplications.
continue;
}

Expand Down
2 changes: 2 additions & 0 deletions src/meta/duplication/meta_duplication_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ class meta_duplication_service

/// See replication.thrift for possible errors for each rpc.

// Query duplications for one table.
void query_duplication_info(const duplication_query_request &, duplication_query_response &);

// List duplications for one or multiple tables.
void list_duplication_info(const duplication_list_request &, duplication_list_response &);

void add_duplication(duplication_add_rpc rpc);
Expand Down
20 changes: 20 additions & 0 deletions src/meta/test/meta_duplication_service_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,12 +536,19 @@ class meta_duplication_service_test : public meta_test_base
void test_list_dup_app_state(const std::string &app_name, const duplication_app_state &state)
{
const auto &app = find_app(app_name);

// Each app id should be matched.
ASSERT_EQ(app->app_id, state.appid);

// The number of returned duplications for each table should be as expected.
ASSERT_EQ(app->duplications.size(), state.duplications.size());

for (const auto &[dup_id, dup] : app->duplications) {
// Each dup id should be matched.
ASSERT_TRUE(gutil::ContainsKey(state.duplications, dup_id));
ASSERT_EQ(dup_id, gutil::FindOrDie(state.duplications, dup_id).dupid);

// The number of returned partitions should be as expected.
ASSERT_EQ(app->partition_count,
gutil::FindOrDie(state.duplications, dup_id).partition_states.size());
}
Expand All @@ -553,11 +560,17 @@ class meta_duplication_service_test : public meta_test_base
{
const auto &resp = list_dup_info(app_name_pattern, match_type);

// Request for listing duplications should be successful.
ASSERT_EQ(ERR_OK, resp.err);

// The number of returned tables should be as expected.
ASSERT_EQ(app_names.size(), resp.app_states.size());

for (const auto &app_name : app_names) {
// Each table name should be in the returned list.
ASSERT_TRUE(gutil::ContainsKey(resp.app_states, app_name));

// Test the states of each table.
test_list_dup_app_state(app_name, gutil::FindOrDie(resp.app_states, app_name));
}
}
Expand Down Expand Up @@ -852,8 +865,10 @@ TEST_F(meta_duplication_service_test, query_duplication_info)

TEST_F(meta_duplication_service_test, list_duplication_info)
{
// Remove all tables from memory to prevent later tests from interference.
clear_apps();

// Create some tables with some partitions and duplications randomly.
create_app(kTestAppName, 8);
create_dup(kTestAppName);
create_dup(kTestAppName);
Expand All @@ -871,19 +886,24 @@ TEST_F(meta_duplication_service_test, list_duplication_info)
create_dup(app_name_3);
create_dup(app_name_3);

// Test for returning all of the existing tables.
test_list_dup_info({kTestAppName, app_name_1, app_name_2, app_name_3},
{},
utils::pattern_match_type::PMT_MATCH_ALL);

// Test for returning the tables whose name are matched exactly.
test_list_dup_info({app_name_2}, app_name_2, utils::pattern_match_type::PMT_MATCH_EXACT);

// Test for returning the tables whose name are matched with pattern anywhere.
test_list_dup_info(
{kTestAppName, app_name_2}, "app", utils::pattern_match_type::PMT_MATCH_ANYWHERE);

// Test for returning the tables whose name are matched with pattern as prefix.
test_list_dup_info({kTestAppName, app_name_1, app_name_3},
"test",
utils::pattern_match_type::PMT_MATCH_PREFIX);

// Test for returning the tables whose name are matched with pattern as postfix.
test_list_dup_info({app_name_2}, "test", utils::pattern_match_type::PMT_MATCH_POSTFIX);
}

Expand Down

0 comments on commit 3768b89

Please sign in to comment.