Skip to content

Commit 3a1baab

Browse files
committed
Remove unnecessary RwLock from TableBuffer.schema
Schema is immutable after table creation - no lock needed. Just use SchemaRef (Arc<Schema>) directly for zero contention.
1 parent d86e6ae commit 3a1baab

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

docs/buffered-write-layer.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub struct MemBuffer {
7878

7979
pub struct TableBuffer {
8080
buckets: DashMap<i64, TimeBucket>, // bucket_id → TimeBucket
81-
schema: RwLock<SchemaRef>,
81+
schema: SchemaRef, // Immutable after creation
8282
project_id: Arc<str>,
8383
table_name: Arc<str>,
8484
}
@@ -248,7 +248,7 @@ Since MemBuffer uses `UnknownPartitioning` (time buckets) and Delta uses file-ba
248248
|-----------|-----------|------------|
249249
| `MemBuffer.tables` | DashMap (lock-free reads) | Very low |
250250
| `TableBuffer.buckets` | DashMap (lock-free reads) | Very low |
251-
| `TableBuffer.schema` | RwLock | Very low (rarely changes) |
251+
| `TableBuffer.schema` | None (immutable `Arc<Schema>`) | None |
252252
| `TimeBucket.batches` | RwLock | Low (read-heavy workload) |
253253

254254
**Key insight:** Query path uses read locks only. Write path acquires write lock briefly per bucket. Handle caching (`Arc<TableBuffer>`) further reduces contention by avoiding repeated table lookups.

src/mem_buffer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub struct MemBuffer {
117117

118118
pub struct TableBuffer {
119119
buckets: DashMap<i64, TimeBucket>,
120-
schema: RwLock<SchemaRef>,
120+
schema: SchemaRef, // Immutable after creation - no lock needed
121121
project_id: Arc<str>,
122122
table_name: Arc<str>,
123123
}
@@ -711,14 +711,14 @@ impl TableBuffer {
711711
fn new(schema: SchemaRef, project_id: Arc<str>, table_name: Arc<str>) -> Self {
712712
Self {
713713
buckets: DashMap::new(),
714-
schema: RwLock::new(schema),
714+
schema,
715715
project_id,
716716
table_name,
717717
}
718718
}
719719

720720
pub fn schema(&self) -> SchemaRef {
721-
self.schema.read().unwrap().clone()
721+
self.schema.clone() // Arc clone is cheap
722722
}
723723

724724
/// Insert a batch into this table's appropriate time bucket.

0 commit comments

Comments
 (0)