Skip to content

use std::enable_shared_from_this for IStorage#96

Merged
alexey-milovidov merged 5 commits intoClickHouse:masterfrom
yurial:yurial-IStorage-enable_shared_from_this
Aug 30, 2016
Merged

use std::enable_shared_from_this for IStorage#96
alexey-milovidov merged 5 commits intoClickHouse:masterfrom
yurial:yurial-IStorage-enable_shared_from_this

Conversation

@yurial
Copy link
Copy Markdown
Contributor

@yurial yurial commented Aug 26, 2016

No description provided.

@yurial yurial changed the title [WIP] DON'T MERGE!!! use std::enable_shared_from_this from IStorage [WIP] DON'T MERGE!!! use std::enable_shared_from_this for IStorage Aug 26, 2016
@yurial yurial force-pushed the yurial-IStorage-enable_shared_from_this branch 2 times, most recently from a1c29cf to 817aa82 Compare August 27, 2016 19:54
@yurial yurial changed the title [WIP] DON'T MERGE!!! use std::enable_shared_from_this for IStorage use std::enable_shared_from_this for IStorage Aug 27, 2016
@yurial yurial force-pushed the yurial-IStorage-enable_shared_from_this branch from 817aa82 to e5825f7 Compare August 29, 2016 13:28
return make_shared(
name_, columns_, materialized_columns_, alias_columns_, column_defaults_,
context_, num_shards_, min_thresholds_, max_thresholds_, destination_database_, destination_table_})->thisPtr();
context_, num_shards_, min_thresholds_, max_thresholds_, destination_database_, destination_table_);;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Две точки с запятой.

@alexey-milovidov
Copy link
Copy Markdown
Member

В остальном всё понятно. Жаль, что нет очевидных преимуществ: количество строк выросло, а сложность кода примерно такая же или чуть выше, чем была. Впрочем, всё Ок.

@yurial
Copy link
Copy Markdown
Contributor Author

yurial commented Aug 30, 2016

В StorageMergeTree теоретически можно было вставить код между созданием экземпляра класса и созданием std::shared_ptr. Если бы он вызывал исключение - мы бы получили утечку памяти, если вставить создание std::shared_ptr( res ) - получили бы double free после res->thisPtr(). Сейчас же создание класса и создание shared_ptr атомарно, что исключает возможность таких ошибок. Так же можно смело использовать стандартную функцию make_shared_from_this().

Прототипы новых методов make_shared и allocate_shared - полностью идентичны методам std::*. Код ext::make_shared полностью соответствует std::make_shared. Код ext::allocate_shared основан на внутренностях g++-v5.3.0/bits/shared_ptr_base.h и близок по выполняемым действиям. Тем не менее у меня есть сомнения на счет shared_ptr_helper::Deleter - она написан по подобию g++-v5.3.0/bits/shared_ptr_base.h:1107: struct _Deleter который создает временный объект аллокатора внутри себя. Кажется это несколько не верно: и для создания объекта и для его удаления должен использовать единственный объект аллокатора, но тут скорее вопрос к разработчикам STL.

@alexey-milovidov alexey-milovidov merged commit 012f34a into ClickHouse:master Aug 30, 2016
@alexey-milovidov
Copy link
Copy Markdown
Member

Понятно.
Про аллокатор можно не беспокоиться, так как не используем.

@alexey-milovidov
Copy link
Copy Markdown
Member

There was at least two bugs in this code:

  • memory is not deallocated;
  • allocation of memory and construction of object is not exception-safe;

Memory is leaking (though very slowly) when creating temporary tables (for example, when using GLOBAL IN/JOIN). It is easily observed with valgrind or address sanitizer.
(We have automatic tests with valgrind, but that tests was broken due to timeout.)

39f2527

@yurial yurial deleted the yurial-IStorage-enable_shared_from_this branch April 12, 2017 19:23
alexey-milovidov pushed a commit that referenced this pull request May 5, 2020
* CLICKHOUSEDOCS-559: Started to describe GRANT

* CLICKHOUSEDOCS-559: Added headers for some other kinds of quries.

* CLICKHOUSEDOCS-559: Further edits.

* CLICKHOUSEDOCS-559: Updated grant description.

* CLICKHOUSEDOCS-559: The first version for the GRANT statement is finished.

* CLICKHOUSEDOCS-559: Almost finished CREATE USER

* CLICKHOUSEDOCS-559: Finished the first version of CREATE queries.

* CLICKHOUSEDOCS-559: Finished ALTER, DROP and SET.

* CLICKHOUSEDOCS-559: Finished the first version of statements.

* CLICKHOUSEDOCS-559: Update by review.

* CLICKHOUSEDOCS-559: Update by review.

* Update docs/en/query_language/alter.md

* Update docs/en/query_language/create.md

Co-Authored-By: Ilya Yatsishin <[email protected]>

* Update docs/en/query_language/grant.md

Co-Authored-By: Ilya Yatsishin <[email protected]>

* Update by comments. Also RBAC-7 aplied.

* moved new files to new structure

* Adopted added articles to a new structure.

* CLICKHOUSEDOCS-559: Fixed links.

* CLICKHOUSEDOCS-559: Links fix.

* CLICKHOUSEDOCS-559: Updated privileges by RBAC-8 changes

* CLICKHOUSEDOCS-559: Added CREATE, ALTER, DROP, and SHOW queries for QUOTAS and SETTINGS PROFILES.

* CLICKHOUSEDOCS-559: Added ON CLUSTER for CREATE, ALTER, DROP.

* CLICKHOUSEDOCS-559: Fixed code-blocks and the anchor.

* CLICKHOUSEDOCS-559: Edits after the last portion of commentaries.

* CLICKHOUSEDOCS-559: Changed example

Co-authored-by: Sergei Shtykov <[email protected]>
Co-authored-by: Ilya Yatsishin <[email protected]>
liuneng1994 pushed a commit to liuneng1994/ClickHouse that referenced this pull request Aug 31, 2022
fuwhu pushed a commit to fuwhu/ClickHouse that referenced this pull request Feb 12, 2026
…ine table can not succeed due to memory leak of rocksdb object
fuwhu pushed a commit to fuwhu/ClickHouse that referenced this pull request Feb 12, 2026
[ClickHouse#96] bug fix : retries of failed merge task for unique engine table can not succeed due to memory leak of rocksdb object

See merge request datacenter/clickhouse!408
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants