Skip to content

Commit

Permalink
Update response message when adding schema historically existed (#5227)
Browse files Browse the repository at this point in the history
* update the error code and message for checking history schemas

* update tck

* update comment

* change to log error

* fix ddl tck

* increase wait time in schema.feature

Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com>
  • Loading branch information
wenhaocs and Sophie-Xie committed Jan 28, 2023
1 parent 9c9fb93 commit b0b84df
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/clients/meta/MetaClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,8 @@ Status MetaClient::handleResponse(const RESP& resp) {
return Status::Error("No hosts!");
case nebula::cpp2::ErrorCode::E_EXISTED:
return Status::Error("Existed!");
case nebula::cpp2::ErrorCode::E_HISTORY_CONFLICT:
return Status::Error("Schema exisited before!");
case nebula::cpp2::ErrorCode::E_SPACE_NOT_FOUND:
return Status::SpaceNotFound("Space not existed!");
case nebula::cpp2::ErrorCode::E_TAG_NOT_FOUND:
Expand Down
1 change: 1 addition & 0 deletions src/common/graph/Response.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
X(E_WRONGCLUSTER, -2010) \
X(E_ZONE_NOT_ENOUGH, -2011) \
X(E_ZONE_IS_EMPTY, -2012) \
X(E_HISTORY_CONFLICT, -2018) \
\
X(E_STORE_FAILURE, -2021) \
X(E_STORE_SEGMENT_ILLEGAL, -2022) \
Expand Down
1 change: 1 addition & 0 deletions src/interface/common.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ enum ErrorCode {
E_RELATED_INDEX_EXISTS = -2015, // There are still indexes related to tag or edge, cannot drop it
E_RELATED_SPACE_EXISTS = -2016, // There are still some space on the host, cannot drop it
E_RELATED_FULLTEXT_INDEX_EXISTS = -2017, // There are still fulltext index on tag/edge
E_HISTORY_CONFLICT = -2018, // Existed before (e.g., schema)

E_STORE_FAILURE = -2021, // Failed to store data
E_STORE_SEGMENT_ILLEGAL = -2022, // Illegal storage segment
Expand Down
13 changes: 11 additions & 2 deletions src/meta/MetaServiceUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,20 @@ nebula::cpp2::ErrorCode MetaServiceUtils::alterColumnDefs(
bool isEdge) {
switch (op) {
case cpp2::AlterSchemaOp::ADD:
// Check the current schema first. Then check all schemas.
for (auto it = cols.begin(); it != cols.end(); ++it) {
if (it->get_name() == col.get_name()) {
LOG(ERROR) << "Column existing: " << col.get_name();
return nebula::cpp2::ErrorCode::E_EXISTED;
}
}
// There won't any two columns having the same name across all schemas. If there is a column
// having the same name with the intended change, it must be from history schemas.
for (auto& versionedCols : allVersionedCols) {
for (auto it = versionedCols.begin(); it != versionedCols.end(); ++it) {
if (it->get_name() == col.get_name()) {
LOG(ERROR) << "Column currently or previously existing: " << col.get_name();
return nebula::cpp2::ErrorCode::E_EXISTED;
LOG(ERROR) << "Column previously existing: " << col.get_name();
return nebula::cpp2::ErrorCode::E_HISTORY_CONFLICT;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/tck/features/ddl/Ddl.feature
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Feature: DDL test
ALTER TAG B ADD (name string)
"""
# IMHO, this is really confusing. https://github.com/vesoft-inc/nebula/issues/2671
Then a ExecutionError should be raised at runtime: Existed!
Then a ExecutionError should be raised at runtime: Schema exisited before!
When executing query:
"""
ALTER TAG B ADD (namex string)
Expand Down Expand Up @@ -225,7 +225,7 @@ Feature: DDL test
"""
ALTER EDGE E2 ADD (name string)
"""
Then a ExecutionError should be raised at runtime: Existed!
Then a ExecutionError should be raised at runtime: Schema exisited before!
When executing query:
"""
ALTER EDGE E2 ADD (namex string)
Expand Down
6 changes: 3 additions & 3 deletions tests/tck/features/schema/Schema.feature
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ Feature: Insert string vid of vertex and edge
CREATE TAG person(name string, age int);
"""
Then the execution should be successful
And wait 3 seconds
And wait 10 seconds
When executing query:
"""
INSERT VERTEX person values "1":("Tom", 23);
Expand All @@ -974,7 +974,7 @@ Feature: Insert string vid of vertex and edge
ALTER TAG person DROP (age);
"""
Then the execution should be successful
And wait 3 seconds
And wait 10 seconds
When executing query:
"""
FETCH PROP ON person "1" yield properties(vertex) AS props;
Expand All @@ -986,4 +986,4 @@ Feature: Insert string vid of vertex and edge
"""
ALTER TAG person ADD (age int);
"""
Then a ExecutionError should be raised at runtime: Existed
Then a ExecutionError should be raised at runtime: Schema exisited before!

0 comments on commit b0b84df

Please sign in to comment.