Skip to content

Commit

Permalink
Revert renamings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominic Frei committed May 11, 2021
1 parent a29e13e commit 37b2345
Show file tree
Hide file tree
Showing 40 changed files with 1,106 additions and 1,110 deletions.
48 changes: 24 additions & 24 deletions src/realm/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1604,18 +1604,18 @@ void DB::close_internal(std::unique_lock<InterprocessMutex> lock, bool allow_ope

bool DB::has_changed(TransactionRef tr)
{
bool changed = tr->m_read_lock_info.m_version != get_version_of_latest_snapshot();
bool changed = tr->m_read_lock.m_version != get_version_of_latest_snapshot();
return changed;
}

bool DB::wait_for_change(TransactionRef tr)
{
SharedInfo* info = m_file_map.get_addr();
std::lock_guard<InterprocessMutex> lock(m_controlmutex);
while (tr->m_read_lock_info.m_version == info->latest_version_number && m_wait_for_change_enabled) {
while (tr->m_read_lock.m_version == info->latest_version_number && m_wait_for_change_enabled) {
m_new_commit_available.wait(m_controlmutex, 0);
}
return tr->m_read_lock_info.m_version != info->latest_version_number;
return tr->m_read_lock.m_version != info->latest_version_number;
}


Expand Down Expand Up @@ -1681,7 +1681,7 @@ void DB::do_async_commits()
// overwritten by commits being made to memory by others.
{
VersionID version_id = VersionID(); // Latest available snapshot
grab_read_lock(m_read_lock_info, version_id); // Throws
grab_read_lock(m_read_lock, version_id); // Throws
}
// we must treat version and version_index the same way:
{
Expand All @@ -1701,7 +1701,7 @@ void DB::do_async_commits()
}

bool is_same;
Group::ReadLockInfo next_read_lock = m_read_lock_info;
Group::ReadLockInfo next_read_lock = m_read_lock;
{
// detect if we're the last "client", and if so, shutdown (must be under lock):
std::lock_guard<InterprocessMutex> lock2(m_writemutex);
Expand All @@ -1715,7 +1715,7 @@ void DB::do_async_commits()
std::cerr << "Daemon exiting nicely" << std::endl << std::endl;
#endif
release_read_lock(next_read_lock);
release_read_lock(m_read_lock_info);
release_read_lock(m_read_lock);
info->daemon_started = 0;
info->daemon_ready = 0;
return;
Expand All @@ -1725,7 +1725,7 @@ void DB::do_async_commits()
if (!is_same) {

#ifdef REALM_ENABLE_LOGFILE
std::cerr << "Syncing from version " << m_read_lock_info.m_version << " to " << next_read_lock.m_version
std::cerr << "Syncing from version " << m_read_lock.m_version << " to " << next_read_lock.m_version
<< std::endl;
#endif
/* FIXME
Expand All @@ -1739,8 +1739,8 @@ void DB::do_async_commits()

// Now we can release the version that was previously commited
// to disk and just keep the lock on the latest version.
release_read_lock(m_read_lock_info);
m_read_lock_info = next_read_lock;
release_read_lock(m_read_lock);
m_read_lock = next_read_lock;

m_balancemutex.lock();

Expand Down Expand Up @@ -2119,13 +2119,13 @@ VersionID Transaction::commit_and_continue_as_read()
// Grabbing the new lock before releasing the old one prevents m_transaction_count
// from going shortly to zero
db->grab_read_lock(new_read_lock, version_id); // Throws
db->release_read_lock(m_read_lock_info);
m_read_lock_info = new_read_lock;
db->release_read_lock(m_read_lock);
m_read_lock = new_read_lock;

db->do_end_write();

// Remap file if it has grown, and update refs in underlying node structure
remap_and_update_refs(m_read_lock_info.m_top_ref, m_read_lock_info.m_file_size, false); // Throws
remap_and_update_refs(m_read_lock.m_top_ref, m_read_lock.m_file_size, false); // Throws

m_history = nullptr;
set_transact_stage(DB::transact_Reading);
Expand Down Expand Up @@ -2386,7 +2386,7 @@ Transaction::Transaction(DBRef _db, SlabAlloc* alloc, Group::ReadLockInfo& rli,
set_metrics(db->m_metrics);
set_transact_stage(stage);
m_alloc.note_reader_start(this);
attach_shared(m_read_lock_info.m_top_ref, m_read_lock_info.m_file_size, writable);
attach_shared(m_read_lock.m_top_ref, m_read_lock.m_file_size, writable);
}

void Transaction::close()
Expand All @@ -2411,7 +2411,7 @@ void Transaction::end_read()
void Transaction::do_end_read() noexcept
{
detach();
db->release_read_lock(m_read_lock_info);
db->release_read_lock(m_read_lock);
m_alloc.note_reader_end(this);
set_transact_stage(DB::transact_Ready);
// reset the std::shared_ptr to allow the DB object to release resources
Expand All @@ -2423,13 +2423,13 @@ TransactionRef Transaction::freeze()
{
if (m_transact_stage != DB::transact_Reading)
throw LogicError(LogicError::wrong_transact_state);
auto version = VersionID(m_read_lock_info.m_version, m_read_lock_info.m_reader_idx);
auto version = VersionID(m_read_lock.m_version, m_read_lock.m_reader_idx);
return db->start_frozen(version);
}

TransactionRef Transaction::duplicate()
{
auto version = VersionID(m_read_lock_info.m_version, m_read_lock_info.m_reader_idx);
auto version = VersionID(m_read_lock.m_version, m_read_lock.m_reader_idx);
if (m_transact_stage == DB::transact_Reading)
return db->start_read(version);
if (m_transact_stage == DB::transact_Frozen)
Expand Down Expand Up @@ -2505,7 +2505,7 @@ DB::version_type Transaction::commit()

DB::version_type new_version = db->do_commit(*this); // Throws

// We need to set m_read_lock_info in order for wait_for_change to work.
// We need to set m_read_lock in order for wait_for_change to work.
// To set it, we grab a readlock on the latest available snapshot
// and release it again.
VersionID version_id = VersionID(); // Latest available snapshot
Expand All @@ -2516,7 +2516,7 @@ DB::version_type Transaction::commit()
db->do_end_write();

do_end_read();
m_read_lock_info = lock_after_commit;
m_read_lock = lock_after_commit;

return new_version;
}
Expand All @@ -2535,24 +2535,24 @@ void Transaction::commit_and_continue_writing()

db->do_commit(*this); // Throws

// We need to set m_read_lock_info in order for wait_for_change to work.
// We need to set m_read_lock in order for wait_for_change to work.
// To set it, we grab a readlock on the latest available snapshot
// and release it again.
VersionID version_id = VersionID(); // Latest available snapshot
Group::ReadLockInfo lock_after_commit;
db->grab_read_lock(lock_after_commit, version_id);
db->release_read_lock(m_read_lock_info);
m_read_lock_info = lock_after_commit;
db->release_read_lock(m_read_lock);
m_read_lock = lock_after_commit;

bool writable = true;
remap_and_update_refs(m_read_lock_info.m_top_ref, m_read_lock_info.m_file_size, writable); // Throws
remap_and_update_refs(m_read_lock.m_top_ref, m_read_lock.m_file_size, writable); // Throws
}

void Transaction::initialize_replication()
{
if (m_transact_stage == DB::transact_Writing) {
if (Replication* repl = get_replication()) {
auto current_version = m_read_lock_info.m_version;
auto current_version = m_read_lock.m_version;
bool history_updated = false;
repl->initiate_transact(*this, current_version, history_updated); // Throws
}
Expand All @@ -2568,7 +2568,7 @@ Transaction::~Transaction()

DB::VersionID Transaction::get_version_of_current_transaction()
{
return VersionID(m_read_lock_info.m_version, m_read_lock_info.m_reader_idx);
return VersionID(m_read_lock.m_version, m_read_lock.m_reader_idx);
}


Expand Down
30 changes: 15 additions & 15 deletions src/realm/db.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ class Transaction : public Group {

DB::version_type get_version() const noexcept
{
return m_read_lock_info.m_version;
return m_read_lock.m_version;
}
DB::version_type get_version_of_latest_snapshot()
{
Expand Down Expand Up @@ -814,22 +814,22 @@ class DB::ReadLockGuard {
public:
ReadLockGuard(DB& shared_group, Group::ReadLockInfo& read_lock) noexcept
: m_shared_group(shared_group)
, m_read_lock_info(&read_lock)
, m_read_lock(&read_lock)
{
}
~ReadLockGuard() noexcept
{
if (m_read_lock_info)
m_shared_group.release_read_lock(*m_read_lock_info);
if (m_read_lock)
m_shared_group.release_read_lock(*m_read_lock);
}
void release() noexcept
{
m_read_lock_info = 0;
m_read_lock = 0;
}

private:
DB& m_shared_group;
Group::ReadLockInfo* m_read_lock_info;
Group::ReadLockInfo* m_read_lock;
};

template <class O>
Expand All @@ -839,7 +839,7 @@ inline void Transaction::advance_read(O* observer, VersionID version_id)
throw LogicError(LogicError::wrong_transact_state);

// It is an error if the new version precedes the currently bound one.
if (version_id.version < m_read_lock_info.m_version)
if (version_id.version < m_read_lock.m_version)
throw LogicError(LogicError::bad_version);

auto hist = get_history(); // Throws
Expand Down Expand Up @@ -874,7 +874,7 @@ inline bool Transaction::promote_to_write(O* observer, bool nonblocking)
bool history_updated = internal_advance_read(observer, version, *m_history, true); // Throws

REALM_ASSERT(repl); // Presence of `repl` follows from the presence of `hist`
DB::version_type current_version = m_read_lock_info.m_version;
DB::version_type current_version = m_read_lock.m_version;
m_alloc.init_mapping_management(current_version);
repl->initiate_transact(*this, current_version, history_updated); // Throws

Expand Down Expand Up @@ -923,8 +923,8 @@ inline void Transaction::rollback_and_continue_as_read(O* observer)
// Mark all managed space (beyond the attached file) as free.
db->reset_free_space_tracking(); // Throws

ref_type top_ref = m_read_lock_info.m_top_ref;
size_t file_size = m_read_lock_info.m_file_size;
ref_type top_ref = m_read_lock.m_top_ref;
size_t file_size = m_read_lock.m_file_size;
_impl::ReversedNoCopyInputStream reversed_in(reverser);
m_alloc.update_reader_view(file_size); // Throws
update_allocator_wrappers(false);
Expand All @@ -943,16 +943,16 @@ inline bool Transaction::internal_advance_read(O* observer, VersionID version_id
{
Group::ReadLockInfo new_read_lock;
db->grab_read_lock(new_read_lock, version_id); // Throws
REALM_ASSERT(new_read_lock.m_version >= m_read_lock_info.m_version);
if (new_read_lock.m_version == m_read_lock_info.m_version) {
REALM_ASSERT(new_read_lock.m_version >= m_read_lock.m_version);
if (new_read_lock.m_version == m_read_lock.m_version) {
db->release_read_lock(new_read_lock);
// _impl::History::update_early_from_top_ref() was not called
// update allocator wrappers merely to update write protection
update_allocator_wrappers(writable);
return false;
}

DB::version_type old_version = m_read_lock_info.m_version;
DB::version_type old_version = m_read_lock.m_version;
DB::ReadLockGuard g(*db, new_read_lock);
DB::version_type new_version = new_read_lock.m_version;
size_t new_file_size = new_read_lock.m_file_size;
Expand Down Expand Up @@ -987,8 +987,8 @@ inline bool Transaction::internal_advance_read(O* observer, VersionID version_id
_impl::ChangesetInputStream in(hist, old_version, new_version);
advance_transact(new_top_ref, in, writable); // Throws
g.release();
db->release_read_lock(m_read_lock_info);
m_read_lock_info = new_read_lock;
db->release_read_lock(m_read_lock);
m_read_lock = new_read_lock;

return true; // _impl::History::update_early_from_top_ref() was called
}
Expand Down
2 changes: 1 addition & 1 deletion src/realm/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Group::Group(SlabAlloc* alloc) noexcept
}

Group::Group(SlabAlloc* alloc, ReadLockInfo read_lock_info) noexcept
: m_read_lock_info(read_lock_info)
: m_read_lock(read_lock_info)
, m_alloc(*alloc) // Throws
, m_top(m_alloc)
, m_tables(m_alloc)
Expand Down
6 changes: 3 additions & 3 deletions src/realm/group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class Group : public ArrayParent {
/// Returns the keys for all tables in this group.
TableKeys get_table_keys() const;

// Returns a new `VersionID` using the `m_read_lock_info`.
// Returns a new `VersionID` using the `m_read_lock`.
VersionID get_current_version() const;

/// \defgroup group_table_access Table Accessors
Expand Down Expand Up @@ -571,7 +571,7 @@ class Group : public ArrayParent {
ref_type m_top_ref = 0;
size_t m_file_size = 0;
};
ReadLockInfo m_read_lock_info;
ReadLockInfo m_read_lock;

protected:
virtual Replication* const* get_repl() const
Expand Down Expand Up @@ -955,7 +955,7 @@ inline TableKeys Group::get_table_keys() const

inline VersionID Group::get_current_version() const
{
return VersionID(m_read_lock_info.m_version, m_read_lock_info.m_reader_idx);
return VersionID(m_read_lock.m_version, m_read_lock.m_reader_idx);
}

inline bool Group::is_attached() const noexcept
Expand Down
12 changes: 6 additions & 6 deletions src/realm/object-store/c_api/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RLM_API bool realm_get_num_objects(const realm_t* realm, realm_class_key_t key,
{
return wrap_err([&]() {
auto& rlm = **realm;
auto table = rlm.get_group().get_table(TableKey(key));
auto table = rlm.read_group().get_table(TableKey(key));
if (out_count)
*out_count = table->size();
return true;
Expand All @@ -21,7 +21,7 @@ RLM_API realm_object_t* realm_get_object(const realm_t* realm, realm_class_key_t
return wrap_err([&]() {
auto& shared_realm = *realm;
auto table_key = TableKey(tbl_key);
auto table = shared_realm->get_group().get_table(table_key);
auto table = shared_realm->read_group().get_table(table_key);
auto obj = table->get_object(ObjKey(obj_key));
auto object = Object{shared_realm, std::move(obj)};
return new realm_object_t{std::move(object)};
Expand All @@ -34,7 +34,7 @@ RLM_API realm_object_t* realm_object_find_with_primary_key(const realm_t* realm,
return wrap_err([&]() -> realm_object_t* {
auto& shared_realm = *realm;
auto table_key = TableKey(class_key);
auto table = shared_realm->get_group().get_table(table_key);
auto table = shared_realm->read_group().get_table(table_key);
auto pk_val = from_capi(pk);

auto pk_col = table->get_primary_key_column();
Expand Down Expand Up @@ -69,7 +69,7 @@ RLM_API realm_results_t* realm_object_find_all(const realm_t* realm, realm_class
{
return wrap_err([&]() {
auto& shared_realm = *realm;
auto table = shared_realm->get_group().get_table(TableKey(key));
auto table = shared_realm->read_group().get_table(TableKey(key));
return new realm_results{Results{shared_realm, table}};
});
}
Expand All @@ -79,7 +79,7 @@ RLM_API realm_object_t* realm_object_create(realm_t* realm, realm_class_key_t ta
return wrap_err([&]() {
auto& shared_realm = *realm;
auto tblkey = TableKey(table_key);
auto table = shared_realm->get_group().get_table(tblkey);
auto table = shared_realm->read_group().get_table(tblkey);

if (table->get_primary_key_column()) {
auto& object_schema = schema_for_table(*realm, tblkey);
Expand All @@ -98,7 +98,7 @@ RLM_API realm_object_t* realm_object_create_with_primary_key(realm_t* realm, rea
return wrap_err([&]() {
auto& shared_realm = *realm;
auto tblkey = TableKey(table_key);
auto table = shared_realm->get_group().get_table(tblkey);
auto table = shared_realm->read_group().get_table(tblkey);
// FIXME: Provide did_create?
auto pkval = from_capi(pk);

Expand Down
2 changes: 1 addition & 1 deletion src/realm/object-store/c_api/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ RLM_API realm_query_t* realm_query_parse(const realm_t* realm, realm_class_key_t
const char* query_string, size_t num_args, const realm_value_t* args)
{
return wrap_err([&]() {
auto table = (*realm)->get_group().get_table(TableKey(target_table_key));
auto table = (*realm)->read_group().get_table(TableKey(target_table_key));
DescriptorOrdering ordering;
Query query = parse_and_apply_query(*realm, table, ordering, query_string, num_args, args);
return new realm_query_t{std::move(query), std::move(ordering), *realm};
Expand Down
4 changes: 2 additions & 2 deletions src/realm/object-store/c_api/realm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ RLM_API bool realm_is_closed(realm_t* realm)

RLM_API bool realm_is_writable(const realm_t* realm)
{
return (*realm)->is_in_write_transaction();
return (*realm)->is_in_transaction();
}

RLM_API bool realm_close(realm_t* realm)
Expand All @@ -58,7 +58,7 @@ RLM_API bool realm_close(realm_t* realm)
RLM_API bool realm_begin_write(realm_t* realm)
{
return wrap_err([&]() {
(*realm)->begin_write_transaction();
(*realm)->begin_transaction();
return true;
});
}
Expand Down
Loading

0 comments on commit 37b2345

Please sign in to comment.