Skip to content

Commit

Permalink
update the pg serial after all insertions (#460)
Browse files Browse the repository at this point in the history
  • Loading branch information
philsippl authored Sep 26, 2024
1 parent ced3161 commit 408722d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
11 changes: 11 additions & 0 deletions iris-mpc-store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ DO UPDATE SET right_code = EXCLUDED.right_code, right_mask = EXCLUDED.right_mask

Ok(())
}

pub async fn insert_results(
&self,
tx: &mut Transaction<'_, Postgres>,
Expand All @@ -321,6 +322,16 @@ DO UPDATE SET right_code = EXCLUDED.right_code, right_mask = EXCLUDED.right_mask
Ok(())
}

pub async fn update_iris_id_sequence(&self) -> Result<()> {
sqlx::query(
"SELECT setval(pg_get_serial_sequence('irises', 'id'), COALESCE(MAX(id), 0), false) \
FROM irises",
)
.execute(&self.pool)
.await?;
Ok(())
}

pub async fn last_results(&self, count: usize) -> Result<Vec<String>> {
let mut result_events: Vec<String> =
sqlx::query_scalar("SELECT result_event FROM results ORDER BY id DESC LIMIT $1")
Expand Down
9 changes: 8 additions & 1 deletion iris-mpc-upgrade/src/bin/tcp_upgrade_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async fn main() -> eyre::Result<()> {
background_tasks.check_tasks();
tracing::info!("Healthcheck server running on port 3000.");

let upgrader = IrisCodeUpgrader::new(args.party_id, sink);
let upgrader = IrisCodeUpgrader::new(args.party_id, sink.clone());

// listen for incoming connections from clients
let client_listener = tokio::net::TcpListener::bind(args.bind_addr).await?;
Expand Down Expand Up @@ -191,6 +191,9 @@ async fn main() -> eyre::Result<()> {
}
client_stream2.write_u8(FINAL_BATCH_SUCCESSFUL_ACK).await?;
client_stream1.write_u8(FINAL_BATCH_SUCCESSFUL_ACK).await?;

sink.update_iris_id_sequence().await?;

Ok(())
}

Expand Down Expand Up @@ -227,4 +230,8 @@ impl NewIrisShareSink for IrisShareDbSink {
}
}
}

async fn update_iris_id_sequence(&self) -> eyre::Result<()> {
self.store.update_iris_id_sequence().await
}
}
6 changes: 6 additions & 0 deletions iris-mpc-upgrade/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pub trait NewIrisShareSink {
code_share: &[u16; IRIS_CODE_LENGTH],
mask_share: &[u16; MASK_CODE_LENGTH],
) -> eyre::Result<()>;

async fn update_iris_id_sequence(&self) -> eyre::Result<()>;
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -80,6 +82,10 @@ impl NewIrisShareSink for IrisShareTestFileSink {
file.flush()?;
Ok(())
}

async fn update_iris_id_sequence(&self) -> eyre::Result<()> {
Ok(())
}
}

#[derive(Clone)]
Expand Down

0 comments on commit 408722d

Please sign in to comment.