You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: datafusion/execution/src/memory_pool/pool.rs
+88-14Lines changed: 88 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -654,10 +654,10 @@ mod tests {
654
654
assert_eq!(pool.reserved(),4000);
655
655
656
656
let err = r2.try_grow(1).unwrap_err().strip_backtrace();
657
-
assert_snapshot!(err, @"Resources exhausted: Failed to allocate additional 1.0 B for r2 with 2000.0 B already allocated for this reservation - 0.0 B remain available for the total memory pool:");
657
+
assert_snapshot!(err, @"Resources exhausted: Failed to allocate additional 1.0 B for r2 with 2000.0 B already allocated for this reservation - 0.0 B remain available for the total memory pool: fair(pool_size: 100.0 B)");
658
658
659
659
let err = r2.try_grow(1).unwrap_err().strip_backtrace();
660
-
assert_snapshot!(err, @"Resources exhausted: Failed to allocate additional 1.0 B for r2 with 2000.0 B already allocated for this reservation - 0.0 B remain available for the total memory pool:");
660
+
assert_snapshot!(err, @"Resources exhausted: Failed to allocate additional 1.0 B for r2 with 2000.0 B already allocated for this reservation - 0.0 B remain available for the total memory pool: fair(pool_size: 100.0 B)");
661
661
662
662
r1.shrink(1990);
663
663
r2.shrink(2000);
@@ -682,12 +682,12 @@ mod tests {
682
682
.register(&pool);
683
683
684
684
let err = r3.try_grow(70).unwrap_err().strip_backtrace();
685
-
assert_snapshot!(err, @"Resources exhausted: Failed to allocate additional 70.0 B for r3 with 0.0 B already allocated for this reservation - 40.0 B remain available for the total memory pool:");
685
+
assert_snapshot!(err, @"Resources exhausted: Failed to allocate additional 70.0 B for r3 with 0.0 B already allocated for this reservation - 40.0 B remain available for the total memory pool: fair(pool_size: 100.0 B)");
686
686
687
687
//Shrinking r2 to zero doesn't allow a3 to allocate more than 45
688
688
r2.free();
689
689
let err = r3.try_grow(70).unwrap_err().strip_backtrace();
690
-
assert_snapshot!(err, @"Resources exhausted: Failed to allocate additional 70.0 B for r3 with 0.0 B already allocated for this reservation - 40.0 B remain available for the total memory pool:");
690
+
assert_snapshot!(err, @"Resources exhausted: Failed to allocate additional 70.0 B for r3 with 0.0 B already allocated for this reservation - 40.0 B remain available for the total memory pool: fair(pool_size: 100.0 B)");
691
691
692
692
// But dropping r2 does
693
693
drop(r2);
@@ -700,7 +700,7 @@ mod tests {
700
700
701
701
let r4 = MemoryConsumer::new("s4").register(&pool);
702
702
let err = r4.try_grow(30).unwrap_err().strip_backtrace();
703
-
assert_snapshot!(err, @"Resources exhausted: Failed to allocate additional 30.0 B for s4 with 0.0 B already allocated for this reservation - 20.0 B remain available for the total memory pool:");
703
+
assert_snapshot!(err, @"Resources exhausted: Failed to allocate additional 30.0 B for s4 with 0.0 B already allocated for this reservation - 20.0 B remain available for the total memory pool: fair(pool_size: 100.0 B)");
r2#[ID](can spill: false) consumed 15.0 B, peak 15.0 B.
751
-
Error: Failed to allocate additional 150.0 B for r5 with 0.0 B already allocated for this reservation - 5.0 B remain available for the total memory pool:
751
+
Error: Failed to allocate additional 150.0 B for r5 with 0.0 B already allocated for this reservation - 5.0 B remain available for the total memory pool: greedy(used: 95.0 B, pool_size: 100.0 B)
752
752
");
753
753
}
754
754
@@ -771,7 +771,7 @@ mod tests {
771
771
assert_snapshot!(error, @r"
772
772
Resources exhausted: Additional allocation failed for foo with top memory consumers (across reservations) as:
773
773
foo#[ID](can spill: false) consumed 0.0 B, peak 0.0 B.
774
-
Error: Failed to allocate additional 150.0 B for foo with 0.0 B already allocated for this reservation - 100.0 B remain available for the total memory pool:
774
+
Error: Failed to allocate additional 150.0 B for foo with 0.0 B already allocated for this reservation - 100.0 B remain available for the total memory pool: greedy(used: 0.0 B, pool_size: 100.0 B)
775
775
");
776
776
777
777
// API: multiple registrations using the same hashed consumer,
@@ -789,7 +789,7 @@ mod tests {
789
789
Resources exhausted: Additional allocation failed for foo with top memory consumers (across reservations) as:
foo#[ID](can spill: false) consumed 0.0 B, peak 0.0 B.
792
-
Error: Failed to allocate additional 150.0 B for foo with 0.0 B already allocated for this reservation - 90.0 B remain available for the total memory pool:
792
+
Error: Failed to allocate additional 150.0 B for foo with 0.0 B already allocated for this reservation - 90.0 B remain available for the total memory pool: greedy(used: 10.0 B, pool_size: 100.0 B)
793
793
");
794
794
795
795
// Test: will accumulate size changes per consumer, not per reservation
@@ -802,7 +802,7 @@ mod tests {
802
802
Resources exhausted: Additional allocation failed for foo with top memory consumers (across reservations) as:
foo#[ID](can spill: false) consumed 10.0 B, peak 10.0 B.
805
-
Error: Failed to allocate additional 150.0 B for foo with 20.0 B already allocated for this reservation - 70.0 B remain available for the total memory pool:
805
+
Error: Failed to allocate additional 150.0 B for foo with 20.0 B already allocated for this reservation - 70.0 B remain available for the total memory pool: greedy(used: 30.0 B, pool_size: 100.0 B)
806
806
");
807
807
808
808
// Test: different hashed consumer, (even with the same name),
foo#[ID](can spill: true) consumed 0.0 B, peak 0.0 B.
821
-
Error: Failed to allocate additional 150.0 B for foo with 0.0 B already allocated for this reservation - 70.0 B remain available for the total memory pool:
821
+
Error: Failed to allocate additional 150.0 B for foo with 0.0 B already allocated for this reservation - 70.0 B remain available for the total memory pool: greedy(used: 30.0 B, pool_size: 100.0 B)
822
822
");
823
823
}
824
824
@@ -841,7 +841,7 @@ mod tests {
841
841
Resources exhausted: Additional allocation failed for r0 with top memory consumers (across reservations) as:
r0#[ID](can spill: false) consumed 10.0 B, peak 10.0 B.
844
-
Error: Failed to allocate additional 150.0 B for r0 with 10.0 B already allocated for this reservation - 70.0 B remain available for the total memory pool:
844
+
Error: Failed to allocate additional 150.0 B for r0 with 10.0 B already allocated for this reservation - 70.0 B remain available for the total memory pool: greedy(used: 30.0 B, pool_size: 100.0 B)
845
845
"));
846
846
847
847
// Test: unregister one
@@ -853,7 +853,7 @@ mod tests {
853
853
allow_duplicates!(assert_snapshot!(error, @r"
854
854
Resources exhausted: Additional allocation failed for r0 with top memory consumers (across reservations) as:
855
855
r0#[ID](can spill: false) consumed 10.0 B, peak 10.0 B.
856
-
Error: Failed to allocate additional 150.0 B for r0 with 10.0 B already allocated for this reservation - 90.0 B remain available for the total memory pool:
856
+
Error: Failed to allocate additional 150.0 B for r0 with 10.0 B already allocated for this reservation - 90.0 B remain available for the total memory pool: fair(pool_size: 100.0 B)
857
857
"));
858
858
859
859
// Test: actual message we see is the `available is 70`. When it should be `available is 90`.
@@ -864,7 +864,7 @@ mod tests {
864
864
allow_duplicates!(assert_snapshot!(error, @r"
865
865
Resources exhausted: Additional allocation failed for r0 with top memory consumers (across reservations) as:
866
866
r0#[ID](can spill: false) consumed 10.0 B, peak 10.0 B.
867
-
Error: Failed to allocate additional 150.0 B for r0 with 10.0 B already allocated for this reservation - 90.0 B remain available for the total memory pool:
867
+
Error: Failed to allocate additional 150.0 B for r0 with 10.0 B already allocated for this reservation - 90.0 B remain available for the total memory pool: fair(pool_size: 100.0 B)
868
868
"));
869
869
870
870
// Test: the registration needs to free itself (or be dropped),
@@ -875,7 +875,7 @@ mod tests {
875
875
allow_duplicates!(assert_snapshot!(error, @r"
876
876
Resources exhausted: Additional allocation failed for r0 with top memory consumers (across reservations) as:
877
877
r0#[ID](can spill: false) consumed 10.0 B, peak 10.0 B.
878
-
Error: Failed to allocate additional 150.0 B for r0 with 10.0 B already allocated for this reservation - 90.0 B remain available for the total memory pool:
878
+
Error: Failed to allocate additional 150.0 B for r0 with 10.0 B already allocated for this reservation - 90.0 B remain available for the total memory pool: fair(pool_size: 100.0 B)
879
879
"));
880
880
}
881
881
@@ -973,4 +973,78 @@ mod tests {
973
973
r1#[ID](can spill: false) consumed 20.0 B, peak 20.0 B.
974
974
");
975
975
}
976
+
977
+
#[test]
978
+
fntest_memory_pool_display_fmt(){
979
+
let top = NonZeroUsize::new(5).unwrap();
980
+
981
+
// UnboundedMemoryPool Display with default allocation: 0.0B
982
+
let unbounded = UnboundedMemoryPool::default();
983
+
assert_eq!(
984
+
unbounded.to_string(),
985
+
"unbounded(used: 0.0 B)",
986
+
"UnboundedMemoryPool Display"
987
+
);
988
+
989
+
// UnboundedMemoryPool Display with reservations
990
+
let unbounded_arc:Arc<dynMemoryPool> = Arc::new(UnboundedMemoryPool::default());
991
+
let r = MemoryConsumer::new("u").register(&unbounded_arc);
992
+
r.grow(2048);
993
+
assert_eq!(
994
+
unbounded_arc.as_ref().to_string(),
995
+
"unbounded(used: 2.0 KB)",
996
+
"UnboundedMemoryPool Display with reservations"
997
+
);
998
+
999
+
// GreedyMemoryPool Display with default allocation: 100.0B
1000
+
let greedy = GreedyMemoryPool::new(100);
1001
+
assert_eq!(
1002
+
greedy.to_string(),
1003
+
"greedy(used: 0.0 B, pool_size: 100.0 B)",
1004
+
"GreedyMemoryPool Display"
1005
+
);
1006
+
1007
+
// GreedyMemoryPool Display with reservations
1008
+
let greedy_arc:Arc<dynMemoryPool> = Arc::new(GreedyMemoryPool::new(100));
1009
+
let r = MemoryConsumer::new("g").register(&greedy_arc);
1010
+
r.grow(50);
1011
+
assert_eq!(
1012
+
greedy_arc.as_ref().to_string(),
1013
+
"greedy(used: 50.0 B, pool_size: 100.0 B)",
1014
+
"GreedyMemoryPool Display with reservations"
1015
+
);
1016
+
1017
+
// FairSpillPool Display with default allocation: 4.0KB and without reservations
1018
+
let fair = FairSpillPool::new(4096);
1019
+
assert_eq!(
1020
+
fair.to_string(),
1021
+
"fair(pool_size: 4.0 KB)",
1022
+
"FairSpillPool Display"
1023
+
);
1024
+
1025
+
// TrackConsumersPool<GreedyMemoryPool> Display with default allocation: 128.0B and without reservations
1026
+
let tracked_greedy = TrackConsumersPool::new(GreedyMemoryPool::new(128), top);
0 commit comments