Skip to content
This repository was archived by the owner on Feb 20, 2023. It is now read-only.

Commit 3ebdd86

Browse files
authored
Additional AbstractAction Information (#1445)
1 parent c20fc94 commit 3ebdd86

File tree

7 files changed

+57
-14
lines changed

7 files changed

+57
-14
lines changed

src/include/self_driving/pilot/action/abstract_action.h

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <string>
44
#include <vector>
55

6+
#include "catalog/catalog_defs.h"
67
#include "common/resource_tracker.h"
78
#include "self_driving/pilot/action/action_defs.h"
89

@@ -16,8 +17,10 @@ class AbstractAction {
1617
/**
1718
* Constructor for the base AbstractAction.
1819
* @param family The family that this action belongs to
20+
* @param db_oid The ID of the database that this action belongs to
1921
*/
20-
explicit AbstractAction(ActionType family) : action_family_(family), id_(action_id_counter++) {}
22+
explicit AbstractAction(ActionType family, catalog::db_oid_t db_oid)
23+
: action_family_(family), db_oid_(db_oid), id_(action_id_counter++) {}
2124

2225
virtual ~AbstractAction() = default;
2326

@@ -30,25 +33,40 @@ class AbstractAction {
3033
}
3134

3235
/** @return The estimated runtime metrics for this action */
33-
const common::ResourceTracker::Metrics &GetActualMetrics() { return estimated_metrics_; }
36+
const common::ResourceTracker::Metrics &GetEstimatedMetrics() { return estimated_metrics_; }
3437

3538
/** @return This action's ID */
3639
action_id_t GetActionID() const { return id_; }
3740

3841
/** @return This action's family */
3942
ActionType GetActionFamily() const { return action_family_; }
4043

44+
/** @return This action's database oid */
45+
catalog::db_oid_t GetDatabaseOid() const { return db_oid_; }
46+
47+
/**
48+
* Add an invalidated action
49+
* @param id Action ID
50+
*/
51+
void AddInvalidatedAction(action_id_t id) { invalidated_action_ids_.emplace_back(id); }
52+
4153
/**
42-
* Add an equivalent action
54+
* Get the invalidated action ids if this action is applied
55+
* @return Action ID vector
56+
*/
57+
const std::vector<action_id_t> &GetInvalidatedActions() const { return invalidated_action_ids_; }
58+
59+
/**
60+
* Add an invalidated action
4361
* @param id Action ID
4462
*/
45-
void AddEquivalentAction(action_id_t id) { equivalent_action_ids_.emplace_back(id); }
63+
void AddEnabledAction(action_id_t id) { enabled_action_ids_.emplace_back(id); }
4664

4765
/**
48-
* Get the equivalent action ids
66+
* Get the enabled action ids if this action is applied
4967
* @return Action ID vector
5068
*/
51-
const std::vector<action_id_t> &GetEquivalentActions() const { return equivalent_action_ids_; }
69+
const std::vector<action_id_t> &GetEnabledActions() const { return enabled_action_ids_; }
5270

5371
/**
5472
* Add a reverse action
@@ -87,10 +105,13 @@ class AbstractAction {
87105

88106
ActionType action_family_;
89107

108+
catalog::db_oid_t db_oid_;
109+
90110
/** ID is unique for an action among on planning process (one MCTS) */
91111
action_id_t id_;
92112

93-
std::vector<action_id_t> equivalent_action_ids_;
113+
std::vector<action_id_t> invalidated_action_ids_;
114+
std::vector<action_id_t> enabled_action_ids_;
94115
std::vector<action_id_t> reverse_action_ids_;
95116
};
96117

src/include/self_driving/pilot/action/create_index_action.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ class CreateIndexAction : public AbstractAction {
2222
public:
2323
/**
2424
* Construct CreateIndexAction
25+
* @param db_oid Database id of the index
2526
* @param index_name Name of the index
2627
* @param table_name The table to create index on
2728
* @param columns The columns to build index on
2829
*/
29-
CreateIndexAction(std::string index_name, std::string table_name, std::vector<IndexColumn> columns)
30-
: AbstractAction(ActionType::CREATE_INDEX),
30+
CreateIndexAction(catalog::db_oid_t db_oid, std::string index_name, std::string table_name,
31+
std::vector<IndexColumn> columns)
32+
: AbstractAction(ActionType::CREATE_INDEX, db_oid),
3133
index_name_(std::move(index_name)),
3234
table_name_(std::move(table_name)),
3335
columns_(std::move(columns)) {

src/include/self_driving/pilot/action/drop_index_action.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ class DropIndexAction : public AbstractAction {
1616
public:
1717
/**
1818
* Construct DropIndexAction
19+
* @param db_oid Database id of the index
1920
* @param index_name The name of the index
2021
* @param table_name The table to create index on
2122
* @param columns The columns to build index on
2223
*/
23-
DropIndexAction(std::string index_name, std::string table_name, std::vector<IndexColumn> columns)
24-
: AbstractAction(ActionType::DROP_INDEX),
24+
DropIndexAction(catalog::db_oid_t db_oid, std::string index_name, std::string table_name,
25+
std::vector<IndexColumn> columns)
26+
: AbstractAction(ActionType::DROP_INDEX, db_oid),
2527
index_name_(std::move(index_name)),
2628
table_name_(std::move(table_name)),
2729
columns_(std::move(columns)) {

src/self_driving/pilot/action/change_knob_action.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ namespace noisepage::selfdriving::pilot {
88
template <class T>
99
ChangeKnobAction<T>::ChangeKnobAction(settings::Param param, std::string param_name, T change_value,
1010
common::ManagedPointer<settings::SettingsManager> settings_manager)
11-
: AbstractAction(ActionType::CHANGE_KNOB),
11+
// ChangeKnobAction should not need a database oid so put the invalid oid here
12+
: AbstractAction(ActionType::CHANGE_KNOB, catalog::INVALID_DATABASE_OID),
1213
param_(param),
1314
param_name_(std::move(param_name)),
1415
change_value_(change_value),

src/self_driving/pilot/action/generators/change_knob_action_generator.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ void ChangeKnobActionGenerator::GenerateActionForType(
6161

6262
// Populate the reverse actions
6363
action_map->at(first_action_id)->AddReverseAction(second_action_id);
64+
65+
// Note: change knob actions do not have any enabled/invalidated actions since they're based on deltas and
66+
// always valid (unless exceeds the knob setting limit, which is handled by `ChangeKnobAction::IsValid()`).
6467
}
6568
}
6669
}

src/self_driving/pilot/action/generators/index_action_generator.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ void IndexActionGenerator::FindMissingIndex(const planner::AbstractPlanNode *pla
4343
reinterpret_cast<const planner::IndexScanPlanNode *>(plan)->GetCoverAllColumns())
4444
return;
4545

46+
// Get database oid
47+
catalog::db_oid_t db_oid = scan_plan->GetDatabaseOid();
48+
4649
// Get table oid
4750
catalog::table_oid_t table_oid;
4851
if (plan_type == planner::PlanNodeType::INDEXSCAN)
@@ -85,20 +88,27 @@ void IndexActionGenerator::FindMissingIndex(const planner::AbstractPlanNode *pla
8588
// TODO(Lin): Don't insert potentially duplicated actions
8689
// Generate the create index action
8790
std::string new_index_name = IndexActionUtil::GenerateIndexName(table_name, index_columns);
88-
auto create_index_action = std::make_unique<CreateIndexAction>(new_index_name, table_name, index_columns);
91+
auto create_index_action = std::make_unique<CreateIndexAction>(db_oid, new_index_name, table_name, index_columns);
8992
action_id_t create_index_action_id = create_index_action->GetActionID();
93+
// Create index would invalidate itself
94+
create_index_action->AddInvalidatedAction(create_index_action_id);
9095
action_map->emplace(create_index_action_id, std::move(create_index_action));
9196
// Only the create index action is valid
9297
candidate_actions->emplace_back(create_index_action_id);
9398

9499
// Generate the drop index action
95-
auto drop_index_action = std::make_unique<DropIndexAction>(new_index_name, table_name, index_columns);
100+
auto drop_index_action = std::make_unique<DropIndexAction>(db_oid, new_index_name, table_name, index_columns);
96101
action_id_t drop_index_action_id = drop_index_action->GetActionID();
102+
// Drop index would invalidate itself
103+
drop_index_action->AddInvalidatedAction(drop_index_action_id);
97104
action_map->emplace(drop_index_action_id, std::move(drop_index_action));
98105

99106
// Populate the reverse actions
100107
action_map->at(create_index_action_id)->AddReverseAction(drop_index_action_id);
101108
action_map->at(drop_index_action_id)->AddReverseAction(create_index_action_id);
109+
// Populate the enabled actions
110+
action_map->at(create_index_action_id)->AddEnabledAction(drop_index_action_id);
111+
action_map->at(drop_index_action_id)->AddEnabledAction(create_index_action_id);
102112
}
103113
}
104114
}

test/self_driving/generate_index_action_test.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ TEST_F(GenerateIndexAction, GenerateSingleColumnIndexAction) {
8282
action_id_t second_action_id = action_ids[1];
8383
EXPECT_EQ(action_map[first_action_id]->GetReverseActions()[0], second_action_id);
8484
EXPECT_EQ(action_map[second_action_id]->GetReverseActions()[0], first_action_id);
85+
EXPECT_EQ(action_map[first_action_id]->GetEnabledActions()[0], second_action_id);
86+
EXPECT_EQ(action_map[second_action_id]->GetEnabledActions()[0], first_action_id);
87+
EXPECT_EQ(action_map[first_action_id]->GetInvalidatedActions()[0], first_action_id);
88+
EXPECT_EQ(action_map[second_action_id]->GetInvalidatedActions()[0], second_action_id);
8589
}
8690

8791
// NOLINTNEXTLINE

0 commit comments

Comments
 (0)