From 0ca1ebba6125984fbb004231713b9893705e8859 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 30 Aug 2017 14:21:18 -0700 Subject: [PATCH] ircd::db: Fix valid condition bugs and minor cleanup. --- include/ircd/db/database.h | 7 ++++--- include/ircd/db/row.h | 3 +++ ircd/db.cc | 7 +++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/ircd/db/database.h b/include/ircd/db/database.h index de7b60e63..e8ba6a887 100644 --- a/include/ircd/db/database.h +++ b/include/ircd/db/database.h @@ -49,7 +49,7 @@ namespace ircd::db } struct ircd::db::database -:std::enable_shared_from_this +:std::enable_shared_from_this { struct descriptor; struct options; @@ -60,7 +60,7 @@ struct ircd::db::database struct snapshot; struct comparator; struct column; - using description = std::initializer_list; + using description = std::initializer_list; // central collection of open databases for iteration (non-owning) static std::map dbs; @@ -113,7 +113,6 @@ namespace ircd::db std::shared_ptr shared_from(const database::column &); std::shared_ptr shared_from(database::column &); const std::string &name(const database::column &); - uint64_t sequence(const database::snapshot &); // Sequence of a snapshot uint32_t id(const database::column &); void drop(database::column &); // Request to erase column from db } @@ -188,4 +187,6 @@ struct ircd::db::database::snapshot explicit snapshot(database &); snapshot() = default; ~snapshot() noexcept; + + friend uint64_t sequence(const snapshot &); // Sequence of a snapshot }; diff --git a/include/ircd/db/row.h b/include/ircd/db/row.h index 14fd02d07..3c2625d3b 100644 --- a/include/ircd/db/row.h +++ b/include/ircd/db/row.h @@ -38,6 +38,9 @@ namespace ircd::db // will all return the same index value across the whole `row`. To get the names // of the columns themselves to build ex. the key name of a JSON key-value pair, // use `cell::col()`, which will be different for each `cell` across the `row`. +// +// The db::row::iterator iterates over the cells in a row; to iterate over +// multiple rows use the db::cursor struct ircd::db::row { struct delta; diff --git a/ircd/db.cc b/ircd/db.cc index 023ab5093..9da91b6d9 100644 --- a/ircd/db.cc +++ b/ircd/db.cc @@ -1397,7 +1397,7 @@ ircd::db::cell::compare_exchange(string_view &expected, ircd::db::cell & ircd::db::cell::operator=(const string_view &s) { - write(c, index, s); + write(c, key(), s); return *this; } @@ -1458,7 +1458,7 @@ bool ircd::db::cell::valid() const { - return it && valid_equal(*it, index); + return it && (index.empty() || valid_equal(*it, index)); } /////////////////////////////////////////////////////////////////////////////// @@ -2935,4 +2935,7 @@ ircd::db::value_required(const op &op) case op::SINGLE_DELETE: return false; } + + assert(0); + return false; }