Skip to content

Commit

Permalink
fixed allocation of the max_packet_size buffer for the initial socket…
Browse files Browse the repository at this point in the history
… probe, use mini buffer constant; fixed #2418
  • Loading branch information
tomatolog committed Jul 18, 2024
1 parent 66b4475 commit a37a03d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/net_action_accept.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void MultiServe ( std::unique_ptr<AsyncNetBuffer_c> pBuf, NetConnection_t tConn,
case Proto_e::MYSQL41: return SqlServe ( std::move ( pBuf ) );
case Proto_e::SPHINXSE: eMultiProto = Proto_e::SPHINXSE; break; // force sphinx SE
default:
eMultiProto = pBuf->Probe ( false );
eMultiProto = pBuf->Probe();
}

switch ( eMultiProto )
Expand Down
12 changes: 5 additions & 7 deletions src/networking_daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -937,14 +937,14 @@ AsyncNetInputBuffer_c::AsyncNetInputBuffer_c ()
m_iLen = 0;
}

Proto_e AsyncNetInputBuffer_c::Probe ( bool bLight )
Proto_e AsyncNetInputBuffer_c::Probe()
{
Proto_e eResult = Proto_e::UNKNOWN;
m_bIntr = false;
int iRest = 0;
if ( !HasBytes() )
{
iRest = GetRoomForTail();
iRest = Min ( NET_MINIBUFFER_SIZE, GetRoomForTail() );
if ( !iRest )
return eResult; // hard limit reached
AppendData ( 0, iRest, true );
Expand All @@ -953,11 +953,6 @@ Proto_e AsyncNetInputBuffer_c::Probe ( bool bLight )
auto iHas = HasBytes();
if (!iHas)
{
if ( bLight )
{
sphLogDebugv ( "+++++ Light probing revealed nothing, bail" );
return eResult;
}
sphLogDebugv ( "+++++ Light probing revealed nothing, try blocking" );
AppendData ( 1, iRest, true );
iHas = HasBytes ();
Expand Down Expand Up @@ -1061,6 +1056,9 @@ int AsyncNetInputBuffer_c::ReadAny ()
auto iRest = GetRoomForTail();
if ( !iRest )
return 0;
// ReadAny used only for HTTP header read (NET_MINIBUFFER_SIZE is enough for header) and for initial HTTP fetch with the empty buffer - no need to allocate up to g_iMaxPacketSize
if ( !HasBytes() )
iRest = Min ( NET_MINIBUFFER_SIZE, iRest );

return AppendData ( 1, iRest, true );
}
Expand Down
3 changes: 1 addition & 2 deletions src/networking_daemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ class AsyncNetInputBuffer_c : protected LazyVector_T<BYTE>, public InputBuffer_c
int ReadAny ();

/// try to peek first bytes from socket and imagine proto from this
/// @param bLight determines whether just look to existing (buffered) data, or also query socket, if no such data.
Proto_e Probe ( bool bLight );
Proto_e Probe ();

/// Ensure we have iLen bytes available in buffer. If not - read new chunk from backend.
/// return true on success
Expand Down
6 changes: 3 additions & 3 deletions src/searchdhttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3310,18 +3310,18 @@ bool HttpHandlerEsBulk_c::Process()
return bOk;
}

static const JsonObj_c g_tShards ( "{ \"total\": 1, \"successful\": 1, \"failed\": 0 }" );

static void AddEsReply ( const BulkDoc_t & tDoc, JsonObj_c & tRoot )
{
const JsonObj_c tRefShards ( "{ \"total\": 1, \"successful\": 1, \"failed\": 0 }" );

char sBuf[70];
snprintf ( sBuf, sizeof(sBuf), UINT64_FMT, (uint64_t)tDoc.m_tDocid );
const char * sActionRes = "created";
if ( tDoc.m_sAction=="delete" )
sActionRes = "deleted";
else if ( tDoc.m_sAction=="update" )
sActionRes = "updated";
JsonObj_c tShard ( g_tShards.Clone() );
JsonObj_c tShard ( tRefShards.Clone() );

JsonObj_c tRes;
tRes.AddStr ( "_index", tDoc.m_sIndex.cstr() );
Expand Down

0 comments on commit a37a03d

Please sign in to comment.