-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate sequence numbers #309
Conversation
0046395
to
4d8f7d2
Compare
glean-core/android/src/main/java/mozilla/telemetry/glean/Glean.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall the approach seems like a good one!
glean-core/android/src/main/java/mozilla/telemetry/glean/acmigration/GleanACDataMigrator.kt
Outdated
Show resolved
Hide resolved
4d8f7d2
to
5e31979
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(not approving/rejecting for now, I'll do that on the final PR).
Overall I think this is a good approach. Migration is encapsulated and mostly self-contained.
I'd like it to be properly and clearly documented why the migration code exist and it'd be good to not affect other platforms (e.g. iOS).
cfg, | ||
newSequenceNums.first, | ||
newSequenceNums.second, | ||
if (newSequenceNums.first != null) newSequenceNums.first!!.size().toInt() else 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we pull this out into a (then self-documenting) variable with a good name?
glean-core/ffi/src/lib.rs
Outdated
seq_num_len | ||
); | ||
|
||
let glean = if (&seq_nums).as_ref().ok().is_none() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a mouthful.
Can we swap around the if?
if let Ok(seq_nums) = seq_nums {
Glean::with_sequence_numbers(glean_cfg, seq_nums)
} else {
Glean::new(...)
}
glean-core/src/ac_migration/mod.rs
Outdated
) { | ||
let ping_maker = PingMaker::new(); | ||
|
||
for (store_name_with_suffix, next_seq) in seq_numbers.iter() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We own seq_numbers
, we can iterate and consume it with .into_iter()
and save us the &0
below.
glean-core/src/ac_migration/mod.rs
Outdated
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
//! A module containing glean-core code for supporting data migration | ||
//! from glean-ac. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO we should document what it migrates and also call out that this is definitely temporary while we transition Glean AC and planned to be removed in 2020
glean-core/src/ping/mod.rs
Outdated
seq.add(glean, next_seq); | ||
} | ||
|
||
/// This is pub(super) exclusively for enabling the migration tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO the first line should still document the method.
I'd also change the string to "This is crate-internal exclusively for enabling the migration tests." or something along the lines.
|
||
/** | ||
* A class encapsulating the code used for migrating data from glean-ac | ||
* to glean-core. This class, along all the migration code, should be removed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* to glean-core. This class, along all the migration code, should be removed | |
* to glean-core. This class, along with all the migration code, should be removed |
glean-core/android/src/main/java/mozilla/telemetry/glean/acmigration/GleanACDataMigrator.kt
Show resolved
Hide resolved
@@ -67,7 +67,12 @@ internal interface LibGleanFFI : Library { | |||
|
|||
// Glean top-level API | |||
|
|||
fun glean_initialize(cfg: FfiConfiguration): Long | |||
fun glean_initialize( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will affect iOS. It will need to explicitly pass nil, nil, 0
.
Would it make sense to have a duplicate of this method for use by Kotlin instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we have an FFI with this explicitly for migration (e.g. glean_initialize_migration
), so it would be clear that we can remove it and revert back to the single argument version for Kotlin once we don't need migration code anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mh, Good point. Yes, it does.
@@ -67,7 +67,12 @@ internal interface LibGleanFFI : Library { | |||
|
|||
// Glean top-level API | |||
|
|||
fun glean_initialize(cfg: FfiConfiguration): Long | |||
fun glean_initialize( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we have an FFI with this explicitly for migration (e.g. glean_initialize_migration
), so it would be clear that we can remove it and revert back to the single argument version for Kotlin once we don't need migration code anymore?
values: RawIntArray, | ||
len: i32, | ||
) -> glean_core::Result<Option<HashMap<String, i32>>> { | ||
unsafe { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we put the unsafe
around just the minimal parts that we know require unsafe
? For example, I think the first clause here is actually safe, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we touched this topic with @badboy a while ago and we agreed on wrapping the whole function there (I've copy pasted it, basically).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we opted for wrapping it all.
unsafe
doesn't disable Rust's safety features, it's just us telling the compiler "trust us, there's some things you can't proof, but devs can"- The null check is essential to the safety of what follows.
- The
Result
collection is how we guarantee to catch problems that could lead to unsafety.
glean-core/src/database/mod.rs
Outdated
@@ -298,7 +298,7 @@ mod test { | |||
|
|||
#[test] | |||
fn test_panicks_if_fails_dir_creation() { | |||
assert!(Database::new("").is_err()); | |||
assert!(Database::new("!#\"'@#°ç").is_err()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we know these characters are invalid on all major platforms? I think ext4 on Linux (Android) probably allows all of these. Maybe include a /
? That's sure to fail everywhere, I think.
glean-core/src/lib.rs
Outdated
@@ -142,6 +145,32 @@ impl Glean { | |||
Ok(glean) | |||
} | |||
|
|||
/// Create and initialize a new Glean object. | |||
/// | |||
/// This will create the necessary directories and files in `data_path`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And it clears any existing database, right? That seems potentially surprising and should probably be called out.
5e31979
to
21f9871
Compare
This class holds all the functions to perform data migration from glean-ac to glean-core, on the Kotlin side. The initial implementation reads the ac sequence numbers and allows to mark the client as migrated. Note: before the migration, glean-ac will need to land some code to set 'wasMigrated' to false, always, in case we need to roll back.
rkv currently writes data to `app_dir/glean`. To make it easier to roll back partial migrations, we should make it write to `app_dir/glean/db` so that we can delete that directory before starting a migration again.
21f9871
to
755be5a
Compare
We don't want this function to be used outside of the Kotlin FFI, as it's only useful in the glean-ac to glean-core migration.
Codecov Report
@@ Coverage Diff @@
## master #309 +/- ##
============================================
+ Coverage 70.58% 70.87% +0.29%
- Complexity 229 244 +15
============================================
Files 62 64 +2
Lines 3682 3815 +133
Branches 559 586 +27
============================================
+ Hits 2599 2704 +105
- Misses 667 676 +9
- Partials 416 435 +19
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of nits left, but I think this is now a solid approach to the migration.
glean-core/android/src/main/java/mozilla/telemetry/glean/acmigration/GleanACDataMigrator.kt
Show resolved
Hide resolved
values: RawIntArray, | ||
len: i32, | ||
) -> glean_core::Result<Option<HashMap<String, i32>>> { | ||
unsafe { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we opted for wrapping it all.
unsafe
doesn't disable Rust's safety features, it's just us telling the compiler "trust us, there's some things you can't proof, but devs can"- The null check is essential to the safety of what follows.
- The
Result
collection is how we guarantee to catch problems that could lead to unsafety.
This PR enables the cross-platform Glean SDK to migrate sequence numbers from glean-ac.
This additionally adds initial test coverage for the migration process.