From a14c24e71fb6fa1f848e751470c6b678784736f7 Mon Sep 17 00:00:00 2001 From: Teon Banek Date: Fri, 15 Mar 2019 14:03:51 +0100 Subject: [PATCH] Use const_cast in RecordAccessor Summary: It seems that older clang versions erroneously accept modification of constant pointers, this is a quick hack which resolves the issue on new clang versions. None of the const methods are really const and should not be marked as such. This whole accessor thing is just a steaming pile of crap and should be rewritten from scratch. Reviewers: vkasljevic, msantl Reviewed By: vkasljevic Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1922 --- src/storage/distributed/record_accessor.cpp | 30 ++++++++++++--------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/storage/distributed/record_accessor.cpp b/src/storage/distributed/record_accessor.cpp index c0074c2d7..e715f93eb 100644 --- a/src/storage/distributed/record_accessor.cpp +++ b/src/storage/distributed/record_accessor.cpp @@ -245,13 +245,14 @@ bool RecordAccessor::Reconstruct() const { auto &dba = db_accessor(); if (is_local()) { - address().local()->find_set_old_new(dba.transaction(), &local_.old, - &local_.newr); + auto *local = const_cast(&local_); + address().local()->find_set_old_new(dba.transaction(), &local->old, + &local->newr); current_ = local_.old ? CurrentRecord::OLD : CurrentRecord::NEW; return local_.old != nullptr || local_.newr != nullptr; } else { - auto guard = storage::GetDataLock(*this); + auto guard = storage::GetDataLock(*this); TRecord *old_ = remote_.data->old_record.get(); TRecord *new_ = remote_.data->new_record.get(); current_ = old_ ? CurrentRecord::OLD : CurrentRecord::NEW; @@ -281,15 +282,17 @@ void RecordAccessor::update() const { if (newr) return; if (is_local()) { - local_.newr = address().local()->update(t); + auto *local = const_cast(&local_); + local->newr = address().local()->update(t); DCHECK(local_.newr != nullptr) << "RecordAccessor.new_ is null after update"; } else { - remote_.has_updated = true; + auto *remote = const_cast(&remote_); + remote->has_updated = true; if (remote_.lock_counter > 0) { - remote_.data = db_accessor_->data_manager().Find( + remote->data = db_accessor_->data_manager().Find( dba.transaction_id(), dba.worker_id(), address().worker_id(), address().gid(), remote_.has_updated); } @@ -331,13 +334,14 @@ int64_t RecordAccessor::CypherId() const { template void RecordAccessor::HoldCachedData() const { if (!is_local()) { + auto *remote = const_cast(&remote_); if (remote_.lock_counter == 0) { - remote_.data = db_accessor_->data_manager().template Find( + remote->data = db_accessor_->data_manager().template Find( db_accessor_->transaction().id_, db_accessor_->worker_id(), address().worker_id(), address().gid(), remote_.has_updated); } - ++remote_.lock_counter; + ++remote->lock_counter; DCHECK(remote_.lock_counter <= 10000) << "Something wrong with RemoteDataLock"; } @@ -345,11 +349,12 @@ void RecordAccessor::HoldCachedData() const { template void RecordAccessor::ReleaseCachedData() const { - if (!is_local()) { + if (!is_local()) { + auto *remote = const_cast(&remote_); DCHECK(remote_.lock_counter > 0) << "Lock should exist at this point"; - --remote_.lock_counter; + --remote->lock_counter; if (remote_.lock_counter == 0) { - remote_.data = nullptr; + remote->data = nullptr; } } } @@ -387,7 +392,8 @@ void RecordAccessor::ProcessDelta( // exist. If that record is evicted from cache and fetched again it wont // have new record. Once delta has been sent record will have new so we // don't have to update anymore. - remote_.has_updated = false; + auto *remote = const_cast(&remote_); + remote->has_updated = false; } }