-
Notifications
You must be signed in to change notification settings - Fork 37
Conversation
10ed60f
to
e8f2d2d
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.
Instead of selecting over filesystems and using a crossjoin with unrelated tables, and doing a query per incoming mount,
you should select over the lustre client mount table (which will allow for matching inner joins to fs and host tables) and do the whole thing in a single batch upsert query.
How can I query an empty table? |
Possibly empty, and you'd be doing an upsert. example: integrated-manager-for-lustre/iml-orm/src/sfa.rs Lines 260 to 274 in 6374408
|
I need filesystem id and host id, which I can't know without querying other tables first, can I? I only have host name and filesystem name. |
It is still possible in this case to do upsert in a batch, but in raw SQL :) |
I think it's possible within the query builder as well |
Here's a high-level way to do the batch upsert on mounted clients (I checked that this compiles): // This content_type_id query can be done once at startup, doesn't need to be inside the loop.
let content_type_id = djct::table
.select(djct::id)
.filter(djct::model.eq("lustreclientmount"))
.first_async::<i32>(&pool)
.await
.optional()?;
let host_id: Option<i32> = mgthost::table
.select(mgthost::id)
.filter(mgthost::fqdn.eq(host.to_string()))
.first_async::<i32>(&pool)
.await
.optional()?;
let host_id = match host_id {
Some(x) => x,
None => continue,
};
let xs: Vec<_> = lustre_mounts
.into_iter()
.map(|(fs, tg)| {
(
clmnt::host_id.eq(host_id),
clmnt::filesystem_id.eq(1), // hardcoded because this needs to be filesystem_name instead
clmnt::mountpoint.eq(tg),
clmnt::state.eq("mounted"),
clmnt::state_modified_at.eq(chrono::offset::Utc::now()),
clmnt::immutable_state.eq(false),
clmnt::not_deleted.eq(true),
clmnt::content_type_id.eq(content_type_id),
)
})
.collect();
diesel::insert_into(clmnt::table)
.values(xs)
.on_conflict((clmnt::host_id, clmnt::filesystem_id, clmnt::not_deleted))
.do_update()
.set((
clmnt::mountpoint.eq(excluded(clmnt::mountpoint)),
clmnt::state.eq(excluded(clmnt::state)),
clmnt::state_modified_at.eq(state_modified_at),
))
.execute_async(&pool)
.await?; I didn't implement upsert for unmounted clients, but it should be mostly similar to this. |
e8f2d2d
to
d616722
Compare
I needs some refactoring. |
d616722
to
226ddda
Compare
Refactored and made it ready for filesystem foreign key removal. |
226ddda
to
0ddf2f1
Compare
0ddf2f1
to
725934e
Compare
On the clippy warning "redundant closure found" => rust-lang/rust-clippy#3791 |
It makes sense since Workaround is to use
|
725934e
to
d9da778
Compare
Signed-off-by: Igor Pashev <pashev.igor@gmail.com>
d9da778
to
9ca30fe
Compare
This won't pass because the python agent needs updates as well (I'll take care of this). |
Example:
Closes #1800, #1801.
Signed-off-by: Igor Pashev pashev.igor@gmail.com
This change is