cql3: avoid using shared_ptr's in unrecognized_entity_exception

Using shared_ptr's in `unrecognized_entity_exception` can lead
to cross-cpu deletion of a pointer which will trigger an assert
`_cpu == std::this_thread::get_id()' when shared_ptr is disposed.

Copy `column_identifier` to the exception object and avoid using
an instance of `cql3::relation`: just get a string representation
from it since nothing more is used in associated exception
handling code.

Fixes: #6287
Tests: unit(dev, debug), dtest(lwt_destructive_ddl_test.py:LwtDestructiveDDLTest.test_rename_column)

Signed-off-by: Pavel Solodovnikov <pa.solodovnikov@scylladb.com>
Message-Id: <20200506155714.150497-1-pa.solodovnikov@scylladb.com>
This commit is contained in:
Pavel Solodovnikov
2020-05-06 18:57:14 +03:00
committed by Avi Kivity
parent f48e414eab
commit 1d3f9174c5
3 changed files with 11 additions and 11 deletions

View File

@@ -49,7 +49,7 @@ relation::to_column_definition(const schema& schema, const column_identifier::ra
auto id = entity.prepare_column_identifier(schema);
auto def = get_column_definition(schema, *id);
if (!def || def->is_hidden_from_cql()) {
throw exceptions::unrecognized_entity_exception(id, shared_from_this());
throw exceptions::unrecognized_entity_exception(*id, to_string());
}
return *def;
}

View File

@@ -1385,8 +1385,8 @@ select_statement::prepare_restrictions(database& db,
return ::make_shared<restrictions::statement_restrictions>(db, schema, statement_type::SELECT, std::move(_where_clause), bound_names,
selection->contains_only_static_columns(), selection->contains_a_collection(), for_view, allow_filtering);
} catch (const exceptions::unrecognized_entity_exception& e) {
if (contains_alias(*e.entity)) {
throw exceptions::invalid_request_exception(format("Aliases aren't allowed in the where clause ('{}')", e.relation->to_string()));
if (contains_alias(e.entity)) {
throw exceptions::invalid_request_exception(format("Aliases aren't allowed in the where clause ('{}')", e.relation_str));
}
throw;
}

View File

@@ -56,22 +56,22 @@ public:
/**
* The unrecognized entity.
*/
::shared_ptr<cql3::column_identifier> entity;
cql3::column_identifier entity;
/**
* The entity relation.
* The entity relation in a stringified form.
*/
cql3::relation_ptr relation;
sstring relation_str;
/**
* Creates a new <code>UnrecognizedEntityException</code>.
* @param entity the unrecognized entity
* @param relation the entity relation
* @param relation_str the entity relation string
*/
unrecognized_entity_exception(::shared_ptr<cql3::column_identifier> entity, cql3::relation_ptr relation)
: invalid_request_exception(format("Undefined name {} in where clause ('{}')", *entity, relation->to_string()))
, entity(entity)
, relation(relation)
unrecognized_entity_exception(cql3::column_identifier entity, sstring relation_str)
: invalid_request_exception(format("Undefined name {} in where clause ('{}')", entity, relation_str))
, entity(std::move(entity))
, relation_str(std::move(relation_str))
{ }
};