@@ -189,10 +189,8 @@ class TableResourceMonitor {
189
189
*/
190
190
template <typename Block_size_policy, typename Block_source_policy>
191
191
struct Allocation_scheme {
192
- static Source block_source (size_t block_size,
193
- TableResourceMonitor *table_resource_monitor) {
194
- return Block_source_policy::block_source (block_size,
195
- table_resource_monitor);
192
+ static Source block_source (size_t block_size) {
193
+ return Block_source_policy::block_source (block_size);
196
194
}
197
195
static size_t block_size (size_t number_of_blocks, size_t n_bytes_requested) {
198
196
return Block_size_policy::block_size (number_of_blocks, n_bytes_requested);
@@ -212,8 +210,7 @@ struct Allocation_scheme {
212
210
* tmp_table_size SYSVAR.
213
211
* */
214
212
struct Prefer_RAM_over_MMAP_policy {
215
- static Source block_source (uint32_t block_size,
216
- TableResourceMonitor * = nullptr ) {
213
+ static Source block_source (uint32_t block_size) {
217
214
if (MemoryMonitor::RAM::consumption () < MemoryMonitor::RAM::threshold ()) {
218
215
if (MemoryMonitor::RAM::increase (block_size) <=
219
216
MemoryMonitor::RAM::threshold ()) {
@@ -234,38 +231,6 @@ struct Prefer_RAM_over_MMAP_policy {
234
231
}
235
232
};
236
233
237
- /* Another concrete implementation of Block_source_policy, a type which controls
238
- * where TempTable allocator is going to be allocating next Block of memory
239
- * from. It acts the same as Prefer_RAM_over_MMAP_policy with the main
240
- * difference being that this policy obeys the per-table limit.
241
- *
242
- * What this means is that each temptable::Table is allowed to fit no more data
243
- * than the given threshold controlled through TableResourceMonitor abstraction.
244
- * TableResourceMonitor is a simple abstraction which is in its part an alias
245
- * for tmp_table_size, a system variable that end MySQL users will be using to
246
- * control this threshold.
247
- *
248
- * Updating the tmp_table_size threshold can only be done through the separate
249
- * SET statement which implies that the tmp_table_size threshold cannot be
250
- * updated during the duration of some query which is running within the same
251
- * session. Separate sessions can still of course change this value to their
252
- * liking.
253
- * */
254
- struct Prefer_RAM_over_MMAP_policy_obeying_per_table_limit {
255
- static Source block_source (uint32_t block_size,
256
- TableResourceMonitor *table_resource_monitor) {
257
- assert (table_resource_monitor);
258
- assert (table_resource_monitor->consumption () <=
259
- table_resource_monitor->threshold ());
260
-
261
- if (table_resource_monitor->consumption () + block_size >
262
- table_resource_monitor->threshold ())
263
- throw Result::RECORD_FILE_FULL;
264
-
265
- return Prefer_RAM_over_MMAP_policy::block_source (block_size);
266
- }
267
- };
268
-
269
234
/* Concrete implementation of Block_size_policy, a type which controls how big
270
235
* next Block of memory is going to be allocated by TempTable allocator.
271
236
*
@@ -314,8 +279,7 @@ struct Exponential_policy {
314
279
* over MMAP allocations.
315
280
*/
316
281
using Exponential_growth_preferring_RAM_over_MMAP =
317
- Allocation_scheme<Exponential_policy,
318
- Prefer_RAM_over_MMAP_policy_obeying_per_table_limit>;
282
+ Allocation_scheme<Exponential_policy, Prefer_RAM_over_MMAP_policy>;
319
283
320
284
/* *
321
285
Shared state between all instances of a given allocator.
@@ -556,9 +520,8 @@ inline T *Allocator<T, AllocationScheme>::allocate(size_t n_elements) {
556
520
if (m_shared_block && m_shared_block->is_empty ()) {
557
521
const size_t block_size =
558
522
AllocationScheme::block_size (0 , n_bytes_requested);
559
- *m_shared_block = Block (
560
- block_size,
561
- AllocationScheme::block_source (block_size, &m_table_resource_monitor));
523
+ *m_shared_block =
524
+ Block (block_size, AllocationScheme::block_source (block_size));
562
525
block = m_shared_block;
563
526
} else if (m_shared_block &&
564
527
m_shared_block->can_accommodate (n_bytes_requested)) {
@@ -567,15 +530,30 @@ inline T *Allocator<T, AllocationScheme>::allocate(size_t n_elements) {
567
530
!m_state->current_block .can_accommodate (n_bytes_requested)) {
568
531
const size_t block_size = AllocationScheme::block_size (
569
532
m_state->number_of_blocks , n_bytes_requested);
570
- m_state->current_block = Block (
571
- block_size,
572
- AllocationScheme::block_source (block_size, &m_table_resource_monitor));
533
+ m_state->current_block =
534
+ Block (block_size, AllocationScheme::block_source (block_size));
573
535
block = &m_state->current_block ;
574
536
++m_state->number_of_blocks ;
575
537
} else {
576
538
block = &m_state->current_block ;
577
539
}
578
540
541
+ /* temptable::Table is allowed to fit no more data than the given threshold
542
+ * controlled through TableResourceMonitor abstraction. TableResourceMonitor
543
+ * is a simple abstraction which is in its part an alias for tmp_table_size, a
544
+ * system variable that end MySQL users will be using to control this
545
+ * threshold.
546
+ *
547
+ * Updating the tmp_table_size threshold can only be done through the separate
548
+ * SET statement which implies that the tmp_table_size threshold cannot be
549
+ * updated during the duration of some query which is running within the same
550
+ * session. Separate sessions can still of course change this value to their
551
+ * liking.
552
+ */
553
+ if (m_table_resource_monitor.consumption () + n_bytes_requested >
554
+ m_table_resource_monitor.threshold ()) {
555
+ throw Result::RECORD_FILE_FULL;
556
+ }
579
557
m_table_resource_monitor.increase (n_bytes_requested);
580
558
581
559
T *chunk_data =
0 commit comments