[MDEV-19439] Allow THD member (or base) class constructor/destructor to allocate/free memory Created: 2019-05-10 Updated: 2021-03-08 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | Server |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major |
| Reporter: | Sergey Vojtovich | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Description |
|
Currently such attempts lead to assertions like this:
The reason is that memory accounting is done in THD constructor (which is called after member/base class constructor). Thus memory allocated by member/base constructor is not accounted. Same problem (but turn it upside down) with destructor. This causes ugly constructor/destructor simulation like:
Original implementation was declined due to convoluted current_thd juggling. This juggling is needed, because in some cases THD objects are created by thread creator, not thread itself. Patches implementing this task are in bb-10.5-svoj-MDEV-19439, but they are incomplete and fail on assertions. Move THD creation from creator to creature and do whatever is needed to make them work. |
| Comments |
| Comment by Michael Widenius [ 2019-09-17 ] |
|
Yes, the destructor is a bit ugly, but it's still simple code and only in one place. As we keep the THD around in the cache for future connections, it's probably good that constructors does not allocate memory as this allows us to reduce the memory for THD's that is in the cache. Another problem with allocating memory in constructors is that it makes end-of-memory checking much harder when allocating THD. I greatly prefer to not have any automatic memory allocation in constructors but instead do that in init functions. |