File tree Expand file tree Collapse file tree 2 files changed +5
-5
lines changed
Expand file tree Collapse file tree 2 files changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -78,7 +78,7 @@ pub struct MemBuffer {
7878
7979pub 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.
Original file line number Diff line number Diff line change @@ -117,7 +117,7 @@ pub struct MemBuffer {
117117
118118pub 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.
You can’t perform that action at this time.
0 commit comments