From f8c7cad2b88d870c31a504d9670c7a1a3d9fb717 Mon Sep 17 00:00:00 2001 From: zwang28 <70626450+zwang28@users.noreply.github.com> Date: Mon, 13 Jan 2025 13:34:23 +0800 Subject: [PATCH] refactor(meta): use insert_many to reduce latency (#20120) --- src/meta/src/hummock/manager/time_travel.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/meta/src/hummock/manager/time_travel.rs b/src/meta/src/hummock/manager/time_travel.rs index 38a2339241ae3..af5a3d2d7dc44 100644 --- a/src/meta/src/hummock/manager/time_travel.rs +++ b/src/meta/src/hummock/manager/time_travel.rs @@ -444,6 +444,7 @@ impl HummockManager { Ok(count) } + let mut batch = vec![]; for (table_id, cg_id, committed_epoch) in tables_to_commit { if !select_groups.contains(cg_id) { continue; @@ -454,8 +455,20 @@ impl HummockManager { table_id: Set(table_id.table_id.into()), version_id: Set(version_id.try_into().unwrap()), }; + batch.push(m); + // Use the same batch size as hummock_time_travel_sst_info_insert_batch_size. + if batch.len() >= self.env.opts.hummock_time_travel_sst_info_insert_batch_size { + // There should be no conflict rows. + hummock_epoch_to_version::Entity::insert_many(std::mem::take(&mut batch)) + .do_nothing() + .exec(txn) + .await?; + } + } + if !batch.is_empty() { // There should be no conflict rows. - hummock_epoch_to_version::Entity::insert(m) + hummock_epoch_to_version::Entity::insert_many(batch) + .do_nothing() .exec(txn) .await?; }