Skip to content
This repository was archived by the owner on Oct 18, 2018. It is now read-only.

Bug 900289 - Add foreign key pragma to FHR database and associated tests#342

Merged
mcomella merged 19 commits intomozilla-services:developfrom
mcomella:mcomella/bug-900289-foreign_key_pragma
Aug 9, 2013
Merged

Bug 900289 - Add foreign key pragma to FHR database and associated tests#342
mcomella merged 19 commits intomozilla-services:developfrom
mcomella:mcomella/bug-900289-foreign_key_pragma

Conversation

@mcomella
Copy link
Contributor

@mcomella mcomella commented Aug 2, 2013

No description provided.

@mcomella
Copy link
Contributor Author

mcomella commented Aug 2, 2013

Additional concern: What assumptions are we making about null values? HealthReportDatabaseStorage.ensureMeasurementInitialized never checks for a null string which I imagine would put null into the database. This test (and subsequent fix) can be added to this series of commits.

@mcomella
Copy link
Contributor Author

mcomella commented Aug 2, 2013

Additional concern 2: Do we want to verify that old databases don't violate constraints? We can dbVersion++ and remove any nulls from violations there.

@mcomella
Copy link
Contributor Author

mcomella commented Aug 2, 2013

Additional concern 3: Performance implications of foreign keys. I imagine it's negligible, but it might be worth investigating.

@rnewman
Copy link
Contributor

rnewman commented Aug 5, 2013

You could skip the PRAGMA for read-only DB connections. That would help with any perf issue. Write load is low-frequency enough that it's not a concern to me.

@rnewman
Copy link
Contributor

rnewman commented Aug 5, 2013

And yeah, we should probably discard any inconsistent data in a migration.

Copy link
Contributor

Choose a reason for hiding this comment

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

Heh, I guess you already did what I suggested :P

@rnewman
Copy link
Contributor

rnewman commented Aug 5, 2013

This looks good to me. Take a look at migration/cleanup next, 'cos we'll want to land those together.

@mcomella
Copy link
Contributor Author

mcomella commented Aug 6, 2013

Also, before I forget, please comment on #342 (comment). I feel like assertions would be useful here but I don't believe they're enabled by our build system. :(

@rnewman
Copy link
Contributor

rnewman commented Aug 7, 2013

I'm not sure what you mean by assertions in this context; what can we check at build time?

@mcomella
Copy link
Contributor Author

mcomella commented Aug 7, 2013

Like

assert measurementNames != null;

But I do not believe assertions are enabled in our build system. Alternatively,

if (measurementNames == null) {
    throw new IllegalStateException("measurementNames should not be null.");
}

Or better yet,

public void ensureMeasurementsInitialized(String[] measurementNames, ...) {
    ensureNonNull(measurementNames);
    // ...
}

private void ensureNonNull(Object obj) {
    if (obj == null) {
        throw new IllegalStateException("obj was null!");
    }
}

It'd probably be good to check for these things rather than assuming they'll never be null, though at the cost of some code complexity so I wanted to know if such checks are worthwhile.

@rnewman
Copy link
Contributor

rnewman commented Aug 7, 2013

Yeah, the typical approach is to use exceptions during validation. E.g., https://github.com/mozilla-services/android-sync/blob/develop/src/main/java/org/mozilla/gecko/sync/Utils.java#L209

If doing something will break things, the only three options are:

  • Throw (validate)
  • Ignore/log (leads to problems later, and relies on a web of contracts: what happens when I later try to retrieve my measurement by name?)
  • Specify preconditions — e.g., in Javadoc,
@param measurementNames an array of non-null <code>String</code> instances.
@throw IllegalArgumentException if a <code>null</code> measurement name is provided.

In richer languages we wouldn't have this problem.

@mcomella
Copy link
Contributor Author

mcomella commented Aug 8, 2013

In response to argument validation, without being overzealous, nothing I touched here seems to be a prime candidate for such validation but I'll keep an eye open in the future for places where it's applicable. Thanks for the edification.

@mcomella
Copy link
Contributor Author

mcomella commented Aug 8, 2013

@rnewman: Ready for review if you didn't get the BZ notification.

@mcomella
Copy link
Contributor Author

mcomella commented Aug 8, 2013

@rnewman: Ready for followup review.

@rnewman
Copy link
Contributor

rnewman commented Aug 9, 2013

LGTM.

@mcomella mcomella merged commit 4c617a1 into mozilla-services:develop Aug 9, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants