Remove redundant code

This commit is contained in:
jbajic 2022-11-09 15:52:08 +01:00
parent 23f1536eac
commit 691f6af36d

View File

@ -318,6 +318,40 @@ bool FillEdges(const std::vector<EdgeAccessor> &edges, msgs::ExpandOneResultRow
return true;
}
void LogError(const ResultErrorType &error, const std::string_view action) {
std::visit(
[action]<typename T>(T &&error) {
using ErrorType = std::remove_cvref_t<T>;
if constexpr (std::is_same_v<ErrorType, SchemaViolation>) {
spdlog::debug("{} failed with error: SchemaViolation", action);
} else if constexpr (std::is_same_v<ErrorType, Error>) {
switch (error) {
case Error::DELETED_OBJECT:
spdlog::debug("{} failed with error: DELETED_OBJECT", action);
break;
case Error::NONEXISTENT_OBJECT:
spdlog::debug("{} failed with error: NONEXISTENT_OBJECT", action);
break;
case Error::SERIALIZATION_ERROR:
spdlog::debug("{} failed with error: SERIALIZATION_ERROR", action);
break;
case Error::PROPERTIES_DISABLED:
spdlog::debug("{} failed with error: PROPERTIES_DISABLED", action);
break;
case Error::VERTEX_HAS_EDGES:
spdlog::debug("{} failed with error: VERTEX_HAS_EDGES", action);
break;
case Error::VERTEX_ALREADY_INSERTED:
spdlog::debug("{} failed with error: VERTEX_ALREADY_INSERTED", action);
break;
}
} else {
static_assert(kAlwaysFalse<T>, "Missing type from variant visitor");
}
},
error);
}
std::optional<msgs::ExpandOneResultRow> GetExpandOneResult(
Shard::Accessor &acc, msgs::VertexId src_vertex, const msgs::ExpandOneRequest &req,
const EdgeUniqunessFunction &maybe_filter_based_on_edge_uniquness, const EdgeFiller &edge_filler,
@ -490,42 +524,10 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::CreateVerticesRequest &&req) {
PrimaryKey transformed_pk;
std::transform(new_vertex.primary_key.begin(), new_vertex.primary_key.end(), std::back_inserter(transformed_pk),
[](msgs::Value &val) { return ToPropertyValue(std::move(val)); });
auto result_schema = acc.CreateVertexAndValidate(converted_label_ids, transformed_pk, converted_property_map);
if (result_schema.HasError()) {
auto &error = result_schema.GetError();
std::visit(
[]<typename T>(T &&error) {
using ErrorType = std::remove_cvref_t<T>;
if constexpr (std::is_same_v<ErrorType, SchemaViolation>) {
spdlog::debug("Creating vertex failed with error: SchemaViolation");
} else if constexpr (std::is_same_v<ErrorType, Error>) {
switch (error) {
case Error::DELETED_OBJECT:
spdlog::debug("Creating vertex failed with error: DELETED_OBJECT");
break;
case Error::NONEXISTENT_OBJECT:
spdlog::debug("Creating vertex failed with error: NONEXISTENT_OBJECT");
break;
case Error::SERIALIZATION_ERROR:
spdlog::debug("Creating vertex failed with error: SERIALIZATION_ERROR");
break;
case Error::PROPERTIES_DISABLED:
spdlog::debug("Creating vertex failed with error: PROPERTIES_DISABLED");
break;
case Error::VERTEX_HAS_EDGES:
spdlog::debug("Creating vertex failed with error: VERTEX_HAS_EDGES");
break;
case Error::VERTEX_ALREADY_INSERTED:
spdlog::debug("Creating vertex failed with error: VERTEX_ALREADY_INSERTED");
break;
}
} else {
static_assert(kAlwaysFalse<T>, "Missing type from variant visitor");
}
},
error);
if (auto result_schema = acc.CreateVertexAndValidate(converted_label_ids, transformed_pk, converted_property_map);
result_schema.HasError()) {
LogError(result_schema.GetError(), "Creating Vertex");
action_successful = false;
break;
@ -535,40 +537,6 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::CreateVerticesRequest &&req) {
return msgs::CreateVerticesResponse{.success = action_successful};
}
void HandleError(const ResultErrorType &error, const std::string_view action) {
std::visit(
[action]<typename T>(T &&error) {
using ErrorType = std::remove_cvref_t<T>;
if constexpr (std::is_same_v<ErrorType, SchemaViolation>) {
spdlog::debug("{} failed with error: SchemaViolation", action);
} else if constexpr (std::is_same_v<ErrorType, Error>) {
switch (error) {
case Error::DELETED_OBJECT:
spdlog::debug("{} failed with error: DELETED_OBJECT", action);
break;
case Error::NONEXISTENT_OBJECT:
spdlog::debug("{} failed with error: NONEXISTENT_OBJECT", action);
break;
case Error::SERIALIZATION_ERROR:
spdlog::debug("{} failed with error: SERIALIZATION_ERROR", action);
break;
case Error::PROPERTIES_DISABLED:
spdlog::debug("{} failed with error: PROPERTIES_DISABLED", action);
break;
case Error::VERTEX_HAS_EDGES:
spdlog::debug("{} failed with error: VERTEX_HAS_EDGES", action);
break;
case Error::VERTEX_ALREADY_INSERTED:
spdlog::debug("{} failed with error: VERTEX_ALREADY_INSERTED", action);
break;
}
} else {
static_assert(kAlwaysFalse<T>, "Missing type from variant visitor");
}
},
error);
}
msgs::WriteResponses ShardRsm::ApplyWrite(msgs::UpdateVerticesRequest &&req) {
auto acc = shard_->Access(req.transaction_id);
@ -589,14 +557,14 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::UpdateVerticesRequest &&req) {
for (const auto label : vertex.add_labels) {
if (const auto maybe_error = vertex_to_update->AddLabelAndValidate(label); maybe_error.HasError()) {
HandleError(maybe_error.GetError(), "Update Vertex");
LogError(maybe_error.GetError(), "Update Vertex");
action_successful = false;
break;
}
}
for (const auto label : vertex.remove_labels) {
if (const auto maybe_error = vertex_to_update->RemoveLabelAndValidate(label); maybe_error.HasError()) {
HandleError(maybe_error.GetError(), "Update Vertex");
LogError(maybe_error.GetError(), "Update Vertex");
}
}
@ -604,7 +572,7 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::UpdateVerticesRequest &&req) {
if (const auto result_schema = vertex_to_update->SetPropertyAndValidate(
update_prop.first, ToPropertyValue(std::move(update_prop.second)));
result_schema.HasError()) {
HandleError(result_schema.GetError(), "Update Vertex");
LogError(result_schema.GetError(), "Update Vertex");
action_successful = false;
break;
}