Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Prepare for more DefaultFileSource changes #12072

Merged
merged 9 commits into from
Jun 12, 2018
Merged

Prepare for more DefaultFileSource changes #12072

merged 9 commits into from
Jun 12, 2018

Conversation

kkaefer
Copy link
Contributor

@kkaefer kkaefer commented Jun 6, 2018

No description provided.

@kkaefer kkaefer requested a review from jfirebaugh June 6, 2018 15:54
@friedbunny friedbunny added refactor Core The cross-platform C++ core, aka mbgl labels Jun 6, 2018
}

} // namespace

TEST(OfflineDatabase, TEST_REQUIRES_WRITE(Create)) {
using namespace mbgl;
class OfflineDatabaseTest : public ::testing::Test {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dislike the "fixture" style of testing -- it makes it non-obvious what tests do, because they have hidden behavior without even an obvious function call you can trace through. Can we stick to the existing style?

@@ -43,8 +43,7 @@ void Log::record(EventSeverity severity, Event event, int64_t code) {
}

void Log::record(EventSeverity severity, Event event, int64_t code, const std::string &msg) {
if (currentObserver && severity != EventSeverity::Debug &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there a reason this was skipping Debug severity before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really; we aren't using Debug much. I changed the logging of one expected message from Debug to Info since it was a better fit anyway.

@@ -190,25 +187,46 @@ Database &Database::operator=(Database &&other) {

Database::~Database() = default;


DatabaseImpl::~DatabaseImpl() {
// Mark all transactions as invalid by removing the pointer to the database
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When does this situation arise? Do we not want it to be considered a logic error, and require the database to outlive any transactions?

@kkaefer kkaefer requested a review from jfirebaugh June 7, 2018 13:11
@kkaefer kkaefer force-pushed the refactor-sqlite branch 2 times, most recently from 137a039 to 792dea4 Compare June 8, 2018 08:01
@kkaefer
Copy link
Contributor Author

kkaefer commented Jun 8, 2018

Please re-review; I split up all of the commits to make them easier to review. I removed the common base class for tests, and they now explicitly perform all preparatory actions in each test body.

Copy link
Contributor

@jfirebaugh jfirebaugh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch on the Transaction/Database move interaction.

switch (userVersion()) {
case 0:
case 1:
// cache-only database; remove old table
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Newly created database, or old cache-only database; remove old table if it exists.

Before this change, we've tried to open the database in read/write, but not create mode. In situations where the database didn't exist yet, this logged an error to the console, and we proceeded to opening it again in read/write/create mode, which actually created the file. The reason we did this is so that we could detect really old caching databases from January 2016 in case a developer upgraded from an older SDK (iOS v3.1 and earlier, Android v3.2 and earlier) that didn't have #3715 yet.

However, these error messages, while innocent, look scary in the console and some users suspect that it's a bug. This change opens the file directly in read/write/create mode, omitting the first failed attempt. To handle old cache databases, we're now deleting the `http_cache` table, which was the only table in those old databases, and create the new schema, rather than deleting the entire file and recreating the Database object. In most scenarios, this will lead to one fewer opening attempt, while the database migration will continue to work for the few users who upgrade all the way from a January 2016 SDK.

Additionally, this fixes a mismatch between the Qt and non-Qt implementation: Qt doesn't support opening a file in read/write mode without the create flag. This means that we've seen a different control flow on Qt compared to the non-Qt implementation when opening a database.
@kkaefer kkaefer merged commit 0ecdbeb into master Jun 12, 2018
@kkaefer kkaefer deleted the refactor-sqlite branch June 12, 2018 15:41
@lilykaiser
Copy link

🎉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Core The cross-platform C++ core, aka mbgl refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants