Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

Commit

Permalink
Fix log deletion (#2168)
Browse files Browse the repository at this point in the history
So query returns correct number of rows deleted.

Signed-off-by: Joe Grund <jgrund@whamcloud.io>
  • Loading branch information
jgrund authored Aug 19, 2020
1 parent 5a7bf45 commit a97e435
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
19 changes: 8 additions & 11 deletions iml-services/iml-journal/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use iml_journal::{execute_handlers, get_message_class, ImlJournalError};
use iml_manager_env::get_pool_limit;
use iml_postgres::{
get_db_pool,
sqlx::{self, PgPool},
sqlx::{self, Done, PgPool},
};
use iml_service_queue::service_queue::consume_data;
use iml_tracing::tracing;
Expand All @@ -31,25 +31,22 @@ async fn purge_excess(pool: &PgPool, num_rows: i64) -> Result<i64, ImlJournalErr
let mut num_remove: i64 = num_rows - *DBLOG_LW;

while num_remove > 0 {
let xs = sqlx::query!(
let x = sqlx::query!(
r#"
DELETE FROM chroma_core_logmessage
WHERE id in (
SELECT id FROM chroma_core_logmessage ORDER BY id LIMIT $1
)
RETURNING id"#,
"#,
std::cmp::min(10_000, num_remove)
)
.fetch_all(pool)
.await?;
.execute(pool)
.await?
.rows_affected();

num_remove -= xs.len() as i64;
num_remove -= x as i64;

tracing::info!(
"Purged {} rows, {} remain for purging",
xs.len(),
num_remove
);
tracing::info!("Purged {} rows, {} remain for purging", x, num_remove);
}

Ok(num_rows)
Expand Down
16 changes: 4 additions & 12 deletions sqlx-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -743,24 +743,16 @@
]
}
},
"9e69b2d4692f2bcd76349322b1bbdbb71ada4d3144fc543bff0417ccc576a62a": {
"query": "\n DELETE FROM chroma_core_logmessage\n WHERE id in ( \n SELECT id FROM chroma_core_logmessage ORDER BY id LIMIT $1\n )\n RETURNING id",
"922e7457db1e165807273def66a5ecc6b22be1a849f5e4b06d5149ec00b5e8aa": {
"query": "\n DELETE FROM chroma_core_logmessage\n WHERE id in ( \n SELECT id FROM chroma_core_logmessage ORDER BY id LIMIT $1\n )\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int4"
}
],
"columns": [],
"parameters": {
"Left": [
"Int8"
]
},
"nullable": [
false
]
"nullable": []
}
},
"9edb0846023aa1a9250204fb686d5b95a95962ce20aab75cec2e906edad8eec7": {
Expand Down

0 comments on commit a97e435

Please sign in to comment.