Skip to content
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

Remove DB Configuration Locking #791

Merged
merged 7 commits into from Jun 19, 2018
Merged

Remove DB Configuration Locking #791

merged 7 commits into from Jun 19, 2018

Conversation

@Headline
Copy link
Member

@Headline Headline commented Mar 28, 2018

As @KyleSanderson asked, I attempted to remove configuration locking in favor of a refcounted structure. I'm a multi-threading novice, and this should be heavily reviewed before any approval.

The idea behind this is that different threads can ask for a specific config, and that configuration file it returns will be grabbed from the latest parse. Because we now have two lists in DatabaseConfBuilder, any search will always happen on the fully populated list. The other one is just used while parsing happens, and it's ptr is copied over to the other member variable once parsing is done. A new list is created in it's place.

{
return &conf;
current->AddRef();
Copy link
Member Author

@Headline Headline Mar 28, 2018

Choose a reason for hiding this comment

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

Without this line, we'll get heap corruption for when info in the snippet below goes out of scope. While this does solve this crash, it is fundamentally wrong. I'm not sure why this fixes the problem. Help.

https://github.com/Headline/sourcemod/blob/53dde59defa8b6029bc2f716952ee1a43841a2ef/core/logic/Database.cpp#L313-L322

Copy link
Member

@KyleSanderson KyleSanderson Mar 28, 2018

Choose a reason for hiding this comment

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

When you're invoking GetDatabaseConf you're not calling AddRef without this line, but you're calling Release by hand in the caller. Pair this with RAII or match the calls, otherwise you're going to get the assert this is probably generating for you.

#define DBPARSE_LEVEL_DATABASE 2

DatabaseConfBuilder::DatabaseConfBuilder() : m_CurInfoList(new ConfDbInfoList()),
m_InfoList(new ConfDbInfoList())
Copy link
Member

@KyleSanderson KyleSanderson Mar 28, 2018

Choose a reason for hiding this comment

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

what happened here?

Copy link
Member

@KyleSanderson KyleSanderson left a comment

oh, this never actually went out last night.

core/logic/DatabaseConfBuilder.cpp Outdated Show resolved Hide resolved
core/logic/DatabaseConfBuilder.cpp Outdated Show resolved Hide resolved
core/logic/DatabaseConfBuilder.cpp Outdated Show resolved Hide resolved
core/logic/Database.cpp Outdated Show resolved Hide resolved
core/logic/Database.cpp Outdated Show resolved Hide resolved
core/logic/DatabaseConfBuilder.cpp Outdated Show resolved Hide resolved
@Headline
Copy link
Member Author

@Headline Headline commented Mar 31, 2018

@dvander here's your reminder :p

ConfDbInfoList *m_ParseList;
private:
ke::AString m_Filename;
ConfDbInfoList *m_InfoList;
Copy link
Member

@dvander dvander Mar 31, 2018

Choose a reason for hiding this comment

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

This (and m_ParseList) should be in a RefPtr.

Copy link
Member Author

@Headline Headline May 8, 2018

Choose a reason for hiding this comment

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

note for people driving by: This review comment is also outdated

: m_ParseList(nullptr),
m_InfoList(new ConfDbInfoList())
{
m_InfoList->AddRef();
Copy link
Member

@dvander dvander Mar 31, 2018

Choose a reason for hiding this comment

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

Drop this manual AddRef + Release

@dvander
Copy link
Member

@dvander dvander commented May 2, 2018

ACK, this should be much safer now w/ the thread lookup removed.

@Headline
Copy link
Member Author

@Headline Headline commented May 8, 2018

Some simple SQL tests produce expected results. Just another pair of eyes and we should be good to go.

I'd request a review, but tagging is the best I can do. @asherkin can you give this a look

@asherkin asherkin self-requested a review May 8, 2018
@asherkin
Copy link
Member

@asherkin asherkin commented May 11, 2018

Without the refcounting, and with the expected use being something like:

ConfDbInfoList *list = m_Builder.GetConfigList();
ConfDbInfo *pInfo = list->GetDatabaseConf(name);

I do not see how this could be safe.

It would be perfectly legal for the main thread to be reloading the database config, preempt a worker thread between those two lines and trash the returned ConfDbInfoList before the call to GetDatabaseConf.

The cleaner organization and ownership is good, but I think this (in its current iteration) has possibly removed the safety along with the locking, rather than leaving the safety behind.

#changemyview

EDIT: Threaded access to the config list was removed, this is all wrong.

DatabaseInfo info;
};

class ConfDbInfoList : public ke::Vector<ConfDbInfo *>
Copy link
Member

@asherkin asherkin May 11, 2018

Choose a reason for hiding this comment

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

Ok, scratch that last comment - I see that threaded access was removed - but it does look like we leak every ConfDbInfo created?

@KyleSanderson KyleSanderson merged commit b9b6832 into alliedmodders:master Jun 19, 2018
2 checks passed
@Headline Headline deleted the hi-dad branch Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants