Make ShardRsm aware of trying to write the same vertex into the skip-list

This commit is contained in:
gvolfing 2022-11-04 08:12:37 +01:00
parent 9f71ce0f78
commit 1cee7ecb8a
3 changed files with 14 additions and 4 deletions

View File

@ -79,7 +79,9 @@ struct VertexValidator {
LabelId primary_label_;
};
struct AlreadyInsertedElement {};
template <typename TValue>
using ResultSchema = utils::BasicResult<std::variant<SchemaViolation, Error>, TValue>;
using ResultSchema = utils::BasicResult<std::variant<SchemaViolation, AlreadyInsertedElement, Error>, TValue>;
} // namespace memgraph::storage::v3

View File

@ -361,7 +361,11 @@ ResultSchema<VertexAccessor> Shard::Accessor::CreateVertexAndValidate(
delta->prev.Set(&it->vertex);
VertexAccessor vertex_acc{&it->vertex, transaction_, &shard_->indices_, config_, shard_->vertex_validator_};
MG_ASSERT(inserted, "The vertex must be inserted here!");
// Vertex is allready inserted, return an error.
if (!inserted) {
return {AlreadyInsertedElement{}};
}
// MG_ASSERT(inserted, "The vertex must be inserted here!");
MG_ASSERT(it != acc.end(), "Invalid Vertex accessor!");
// TODO(jbajic) Improve, maybe delay index update

View File

@ -498,6 +498,8 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::CreateVerticesRequest &&req) {
spdlog::debug("Creating vertex failed with error: SchemaViolation");
} else if constexpr (std::is_same_v<ErrorType, Error>) {
spdlog::debug("Creating vertex failed with error: Error");
} else if constexpr (std::is_same_v<ErrorType, AlreadyInsertedElement>) {
spdlog::debug("Updating vertex failed with error: AlreadyInsertedElement");
} else {
static_assert(kAlwaysFalse<T>, "Missing type from variant visitor");
}
@ -540,17 +542,19 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::UpdateVerticesRequest &&req) {
[&action_successful]<typename T>(T &&) {
using ErrorType = std::remove_cvref_t<T>;
if constexpr (std::is_same_v<ErrorType, SchemaViolation>) {
action_successful = false;
spdlog::debug("Updating vertex failed with error: SchemaViolation");
} else if constexpr (std::is_same_v<ErrorType, Error>) {
action_successful = false;
spdlog::debug("Updating vertex failed with error: Error");
} else if constexpr (std::is_same_v<ErrorType, AlreadyInsertedElement>) {
spdlog::debug("Updating vertex failed with error: AlreadyInsertedElement");
} else {
static_assert(kAlwaysFalse<T>, "Missing type from variant visitor");
}
},
error);
action_successful = false;
break;
}
}