Skip to content

Commit

Permalink
add thread_stack variable
Browse files Browse the repository at this point in the history
`set [global] thread_stack = intval` - overrides value given in config.
Global requires VIP conn, non-global affects only current connection.
Fool-protections requires that stack should be >=1M.

`show variables` displays the value.

CHANGELOG: `thread_stack` now can be changed in runtime by mysql 'set'
statement. Both, session-local and daemon-wide variants available.
Current values available in 'show variables' output.
  • Loading branch information
klirichek committed May 24, 2023
1 parent 9df056b commit d70b0d5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/client_task_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ ClientTaskInfo_t * HazardGetClient ()
return (ClientTaskInfo_t *) myinfo::GetHazardTypedNode ( ClientTaskInfo_t::Task() );
}

ClientTaskInfo_t & ClientTaskInfo_t::Info ( bool bStrict )
ClientTaskInfo_t & ClientTaskInfo_t::Info ( bool bStrict ) noexcept
{
auto * pInfo = HazardGetClient();
if ( !pInfo )
Expand Down
6 changes: 5 additions & 1 deletion src/client_task_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ struct ClientTaskInfo_t : public MiniTaskInfo_t
int m_iDesiredStack = -1;
int m_iTimeoutS = -1;
int m_iWTimeoutS = -1;
int64_t m_iMaxStackSize = Threads::GetMaxCoroStackSize();
bool m_bSqlQuoteShowCreate = false;

ESphCollation m_eCollation { GlobalCollation () };
Expand Down Expand Up @@ -140,7 +141,7 @@ struct ClientTaskInfo_t : public MiniTaskInfo_t
ClientSession_c* GetClientSession();

public:
static ClientTaskInfo_t& Info ( bool bStrict = false );
static ClientTaskInfo_t& Info ( bool bStrict = false ) noexcept;
};

inline bool operator== ( const ClientTaskInfo_t& lhs, const ClientTaskInfo_t& rhs )
Expand Down Expand Up @@ -207,6 +208,9 @@ namespace session {
inline void SetPersistent ( bool bPersistent ) { ClientTaskInfo_t::Info().SetPersistent(bPersistent); }
inline bool GetPersistent () { return ClientTaskInfo_t::Info().GetPersistent(); }

inline void SetMaxStackSize ( int64_t iStackSize ) { ClientTaskInfo_t::Info().m_iMaxStackSize = iStackSize; }
inline int64_t GetMaxStackSize() noexcept { return ClientTaskInfo_t::Info().m_iMaxStackSize; }

} // namespace session

namespace myinfo {
Expand Down
17 changes: 17 additions & 0 deletions src/searchd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13863,6 +13863,12 @@ static bool HandleSetLocal ( CSphString& sError, const CSphString& sName, int64_
return true;
}

if ( sName == "thread_stack" )
{
session::SetMaxStackSize ( Max ( iSetValue, 1024 * 1024 ) );
return true;
}

if ( sName == "optimize_by_id" )
{
session::SetOptimizeById ( !!iSetValue );
Expand Down Expand Up @@ -14072,6 +14078,15 @@ static bool HandleSetGlobal ( CSphString& sError, const CSphString& sName, int64
return true;
}

if ( sName == "thread_stack" )
{
if ( tSess.GetVip() )
Threads::SetMaxCoroStackSize ( Max ( iSetValue, 1024 * 1024 ) );
else
sError = "Only VIP connections can change global thread_stack value";
return true;
}

if ( sName == "wait_timeout" )
{
if ( tSess.GetVip() )
Expand Down Expand Up @@ -15289,6 +15304,7 @@ void HandleMysqlShowVariables ( RowBuffer_i & dRows, const SqlStmt_t & tStmt )

if ( tStmt.m_iIntParam>=0 ) // that is SHOW GLOBAL VARIABLES
{
dTable.MatchTupletf ( "thread_stack", "%d", Threads::GetMaxCoroStackSize() );
dTable.MatchTupletFn ( "threads_ex", [] {
StringBuilder_c tBuf;
auto x = Dispatcher::GetGlobalBaseDispatcherTemplate();
Expand All @@ -15302,6 +15318,7 @@ void HandleMysqlShowVariables ( RowBuffer_i & dRows, const SqlStmt_t & tStmt )
dTable.MatchTupletf ( dVar.first.cstr(), "%d", dVar.second.m_pVal ? dVar.second.m_pVal->GetLength() : 0 );
});
} else { // that is local (session) variables
dTable.MatchTupletf ( "thread_stack", "%d", session::GetMaxStackSize() );
dTable.MatchTupletFn ( "threads_ex", [] {
StringBuilder_c tBuf;
auto x = ClientTaskInfo_t::Info().GetBaseDispatcherTemplate();
Expand Down
2 changes: 1 addition & 1 deletion src/sphinx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10033,7 +10033,7 @@ int ConsiderStack ( const struct XQNode_t * pRoot, CSphString & sError )
// align as stack of tree + 8K
// (being run in new coro, most probably you'll start near the top of stack, so 32k should be enough)
iQueryStack = iStackNeed + 8*1024;
if ( Threads::GetMaxCoroStackSize()>=iQueryStack )
if ( session::GetMaxStackSize()>=iQueryStack )
return (int)iQueryStack;

sError.SetSprintf ( "query too complex, not enough stack (thread_stack=%dK or higher required)", (int) (( iQueryStack+1024-( iQueryStack % 1024 )) / 1024 ));
Expand Down

0 comments on commit d70b0d5

Please sign in to comment.