Skip to content

Commit 38390e7

Browse files
gautamg795Convex, Inc.
authored andcommitted
make fallback page size a knob + allow falling back to page size 1 in the worst case (#43374)
GitOrigin-RevId: fdd1f12adc5ee8462053813a101b11f7618a3158
1 parent 1692dd2 commit 38390e7

File tree

2 files changed

+42
-23
lines changed

2 files changed

+42
-23
lines changed

crates/common/src/knobs.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,15 @@ pub static MYSQL_MAX_DYNAMIC_SMART_CHUNK_SIZE: LazyLock<usize> =
868868
pub static MYSQL_MAX_CHUNK_BYTES: LazyLock<usize> =
869869
LazyLock::new(|| env_config("MYSQL_MAX_CHUNK_BYTES", 10 << 20));
870870

871+
/// Page size to fall back to when Vitess rejects large result sets.
872+
/// Vitess limits query results to 64MiB. As documents can be up to 1MiB (plus
873+
/// some overhead) and system documents can be larger still, we may need to fall
874+
/// back to a much smaller page size if we hit the limit while loading
875+
/// documents. If the fallback page size still fails, we'll try page size 1
876+
/// before giving up.
877+
pub static MYSQL_FALLBACK_PAGE_SIZE: LazyLock<u32> =
878+
LazyLock::new(|| env_config("MYSQL_FALLBACK_PAGE_SIZE", 5));
879+
871880
/// Timeout for all operations on MySQL connections, Vitess timeout is 20s so
872881
/// set lower than that
873882
pub static MYSQL_TIMEOUT: LazyLock<u64> = LazyLock::new(|| env_config("MYSQL_TIMEOUT_SECONDS", 19));

crates/mysql/src/lib.rs

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ use common::{
5555
},
5656
interval::Interval,
5757
knobs::{
58+
MYSQL_FALLBACK_PAGE_SIZE,
5859
MYSQL_MAX_QUERY_BATCH_SIZE,
5960
MYSQL_MAX_QUERY_DYNAMIC_BATCH_SIZE,
6061
MYSQL_MIN_QUERY_BATCH_SIZE,
@@ -128,12 +129,6 @@ use crate::{
128129
},
129130
};
130131

131-
// Vitess limits query results to 64MiB.
132-
// As documents can be up to 1MiB (plus some overhead) and system documents can
133-
// be larger still, we may need to fall back to a much smaller page size if we
134-
// hit the limit while loading documents.
135-
const FALLBACK_PAGE_SIZE: u32 = 5;
136-
137132
#[derive(Clone, Debug)]
138133
pub struct MySqlInstanceName {
139134
raw: String,
@@ -764,18 +759,26 @@ impl<RT: Runtime> MySqlReader<RT> {
764759
.message
765760
.contains("trying to send message larger than max") =>
766761
{
767-
if page_size == FALLBACK_PAGE_SIZE {
762+
if page_size == 1 {
768763
anyhow::bail!(
769-
"Failed to load documents with fallback page size \
770-
`{FALLBACK_PAGE_SIZE}`: {}",
764+
"Failed to load documents with minimum page size `1`: {}",
765+
db_err.message,
766+
);
767+
}
768+
if page_size == *MYSQL_FALLBACK_PAGE_SIZE {
769+
tracing::warn!(
770+
"Falling back to page size `1` due to repeated server error: {}",
771771
db_err.message
772772
);
773+
page_size = 1;
774+
} else {
775+
tracing::warn!(
776+
"Falling back to page size `{}` due to server error: {}",
777+
*MYSQL_FALLBACK_PAGE_SIZE,
778+
db_err.message
779+
);
780+
page_size = *MYSQL_FALLBACK_PAGE_SIZE;
773781
}
774-
tracing::warn!(
775-
"Falling back to page size `{FALLBACK_PAGE_SIZE}` due to server error: {}",
776-
db_err.message
777-
);
778-
page_size = FALLBACK_PAGE_SIZE;
779782
continue;
780783
},
781784
Err(e) => Err(e),
@@ -931,19 +934,26 @@ impl<RT: Runtime> MySqlReader<RT> {
931934
.message
932935
.contains("trying to send message larger than max") =>
933936
{
934-
if batch_size == FALLBACK_PAGE_SIZE {
937+
if batch_size == 1 {
935938
anyhow::bail!(
936-
"Failed to load documents with fallback page size \
937-
`{FALLBACK_PAGE_SIZE}`: {}",
939+
"Failed to load index rows with minimum page size `1`: {}",
938940
db_err.message
939941
);
940942
}
941-
tracing::warn!(
942-
"Falling back to page size `{FALLBACK_PAGE_SIZE}` due to server \
943-
error: {}",
944-
db_err.message
945-
);
946-
batch_size = FALLBACK_PAGE_SIZE;
943+
if batch_size == *MYSQL_FALLBACK_PAGE_SIZE {
944+
tracing::warn!(
945+
"Falling back to page size `1` due to repeated server error: {}",
946+
db_err.message
947+
);
948+
batch_size = 1;
949+
} else {
950+
tracing::warn!(
951+
"Falling back to page size `{}` due to server error: {}",
952+
*MYSQL_FALLBACK_PAGE_SIZE,
953+
db_err.message
954+
);
955+
batch_size = *MYSQL_FALLBACK_PAGE_SIZE;
956+
}
947957
fallback = true;
948958
continue;
949959
},

0 commit comments

Comments
 (0)