New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql: region leaks on select #3199
Comments
I have a test case: tarantool> box.sql.execute('SELECT a, b, a + b FROM test ORDER BY b')
---
- - [1, 1, 2]
- [2, 2, 4]
...
tarantool> fiber.info()[fiber.self().id()].memory
---
- total: 61744
used: 82
...
tarantool> box.sql.execute('SELECT a, b, a + b FROM test ORDER BY b')
---
- - [1, 1, 2]
- [2, 2, 4]
...
tarantool> fiber.info()[fiber.self().id()].memory
---
- total: 61744
used: 164
...
tarantool> box.sql.execute('SELECT a, b, a + b FROM test ORDER BY b')
---
- - [1, 1, 2]
- [2, 2, 4]
...
tarantool> fiber.info()[fiber.self().id()].memory
---
- total: 61744
used: 246
...
tarantool> box.sql.execute('SELECT a, b, a + b FROM test ORDER BY b')
---
- - [1, 1, 2]
- [2, 2, 4]
...
tarantool> fiber.info()[fiber.self().id()].memory
---
- total: 61744
used: 328
... As it seen, fiber uses more and more memory. |
The same is actual for iproto - it uses the same SQL API as Lua. |
It turns out that bug was introduced by this commit: a706e97 The idea to allocate memory on region while making record firstly seemed to be reasonable (moreover, it has passed through review and got to trunk). However, ephemeral spaces have nothing in common with txn routine. Thus, txn_commit() won't release memory which is allocated on region to hold tuples to be inserted into ephemeral spaces. So, for ephemeral spaces we MUST (and it is not kind of optimisation as we thought before) allocate memory for records using ordinary malloc. I can suggest following solutions:
|
I like 3, because it allows to move more memory allocations to a region. For example, column metadata. Halt must in such a case do fiber_gc(), if there is no active transaction. But this does not work, when SQL iterators will be introduced. In any case, I very do not like, that now VDBE has many members on runtime memory. And there is a second problem with region: even when it is for |
Well, p.3 really works (at least now, even if it is unlikely to be the most elegant solution). Also, I can't reproduce/notice memory leaks, if
It seems that we do call:
And all inserts/deletes/updates start execution from |
When ticket #3021 was implemented, alongside with it leak of region memory was introduced. It occured due to allocation memory for tuples at region at once (previously, it was allocated using malloc and before insertion to space it was copied to the region). However, if space is ephemeral, it has nothing in common with txn routine. As a result, region memory for tuples to be inserted in ephemeral spaces isn't pinned to any txn and isn't freed by txn_commit() or txn_rollback(). To avoid this leak, now all used region memory is released in vdbe's halt routine. Closes #3199
Is it really true, that it is hard to guess whether you are inserting to ephemeral space or not at compile time? |
I would say yes. Anyway, you are able to investigate it yourself. |
"Zabey, vse ravno ne peresporish"
… 1 марта 2018 г., в 2:43, Nikita Pettik ***@***.***> написал(а):
Is it really true, that it is hard to guess whether you are inserting to ephemeral space or not at compile time?
I would say yes. Anyway, you are able to investigate it yourself.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub <#3199 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AE_WK7WiqhDZLAKJPI4BV4aTQNeElZWiks5tZeSbgaJpZM4SUzSo>.
|
This probleam appeared because region was cleaned twice: once in sqlite3VdbeHalt() and once in sqlite3VdbeDelete() which was executed during sqlite3_finalize(). Autogenerated ids that were saved there, were fetched after sqlite3VdbeHalt() and before sqlite3_finalize(). In this patch region cleaning in sqlite3VdbeHalt() were removed. Needed for #3505 Follow up #2618 Follow up #3199
This probleam appeared because region was cleaned twice: once in sqlite3VdbeHalt() and once in sqlite3VdbeDelete() which was executed during sqlite3_finalize(). Autogenerated ids that were saved there, were fetched after sqlite3VdbeHalt() and before sqlite3_finalize(). In this patch region cleaning in sqlite3VdbeHalt() were removed. Follow up #2618 Follow up #3199
This probleam appeared because region was cleaned twice: once in sqlite3VdbeHalt() and once in sqlite3VdbeDelete() which was executed during sqlite3_finalize(). Autogenerated ids that were saved there, were fetched after sqlite3VdbeHalt() and before sqlite3_finalize(). In this patch region cleaning in sqlite3VdbeHalt() were removed. Follow up #2618 Follow up #3199
This probleam appeared because region was cleaned twice: once in sqlite3VdbeHalt() and once in sqlite3VdbeDelete() which was executed during sqlite3_finalize(). Autogenerated ids that were saved there, were fetched after sqlite3VdbeHalt() and before sqlite3_finalize(). In this patch region cleaning in sqlite3VdbeHalt() were removed. Follow up #2618 Follow up #3199
Too many autogenerated ids leads to SEGFAULT. This problem appeared because region was cleaned twice: once in sqlite3VdbeHalt() and once in sqlite3VdbeDelete() which was executed during sqlite3_finalize(). Autogenerated ids that were saved there, were fetched after sqlite3VdbeHalt() and before sqlite3_finalize(). In this patch region cleaning in sqlite3VdbeHalt() has been removed. Follow up #2618 Follow up #3199
Too many autogenerated ids leads to SEGFAULT. This problem appeared because region was cleaned twice: once in sqlite3VdbeHalt() and once in sqlite3VdbeDelete() which was executed during sqlite3_finalize(). Autogenerated ids that were saved there, were fetched after sqlite3VdbeHalt() and before sqlite3_finalize(). In this patch region cleaning in sqlite3VdbeHalt() has been removed. Follow up #2618 Follow up #3199
Before SELECT set a breakpoint to
region_alloc
and in it seeregion_used
. Run SELECT multiple times -region_used
increases. It is region leak.The text was updated successfully, but these errors were encountered: