Created
September 1, 2011 14:46
-
-
Save magicaltrevor/1186318 to your computer and use it in GitHub Desktop.
patch for mysqlse/ha_sphinx.cc put it in the same directory as source and run patch --dry-run -p0 -i ha_sphinx.cc.patch then patch -p0 -i ha_sphinx.cc.patch if no errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*** ha_sphinx.cc 2011-09-01 10:33:06.000000000 -0400 | |
--- ha_sphinx.cc.new 2011-09-01 10:32:49.000000000 -0400 | |
*************** | |
*** 1,5 **** | |
// | |
! // $Id: ha_sphinx.cc 2752 2011-03-29 08:21:05Z tomat $ | |
// | |
// | |
--- 1,5 ---- | |
// | |
! // $Id: ha_sphinx.cc 2921 2011-08-21 21:35:02Z tomat $ | |
// | |
// | |
*************** | |
*** 24,30 **** | |
#include <mysql_version.h> | |
! #if MYSQL_VERSION_ID>50100 | |
#include "mysql_priv.h" | |
#include <mysql/plugin.h> | |
#else | |
--- 24,33 ---- | |
#include <mysql_version.h> | |
! #if MYSQL_VERSION_ID>=50515 | |
! #include "sql_class.h" | |
! #include "sql_array.h" | |
! #elif MYSQL_VERSION_ID>50100 | |
#include "mysql_priv.h" | |
#include <mysql/plugin.h> | |
#else | |
*************** | |
*** 119,124 **** | |
--- 122,143 ---- | |
#endif | |
+ #if MYSQL_VERSION_ID>=50515 | |
+ | |
+ #define sphinx_hash_init my_hash_init | |
+ #define sphinx_hash_free my_hash_free | |
+ #define sphinx_hash_search my_hash_search | |
+ #define sphinx_hash_delete my_hash_delete | |
+ | |
+ #else | |
+ | |
+ #define sphinx_hash_init hash_init | |
+ #define sphinx_hash_free hash_free | |
+ #define sphinx_hash_search hash_search | |
+ #define sphinx_hash_delete hash_delete | |
+ | |
+ #endif | |
+ | |
///////////////////////////////////////////////////////////////////////////// | |
// FIXME! make this all dynamic | |
*************** | |
*** 135,141 **** | |
#define SPHINXSE_MAX_ALLOC (16*1024*1024) | |
#define SPHINXSE_MAX_KEYWORDSTATS 4096 | |
! #define SPHINXSE_VERSION "0.9.9 ($Revision: 2752 $)" | |
// FIXME? the following is cut-n-paste from sphinx.h and searchd.cpp | |
// cut-n-paste is somewhat simpler that adding dependencies however.. | |
--- 154,160 ---- | |
#define SPHINXSE_MAX_ALLOC (16*1024*1024) | |
#define SPHINXSE_MAX_KEYWORDSTATS 4096 | |
! #define SPHINXSE_VERSION "2.0.2-dev ($Revision: 2917)" | |
// FIXME? the following is cut-n-paste from sphinx.h and searchd.cpp | |
// cut-n-paste is somewhat simpler that adding dependencies however.. | |
*************** | |
*** 144,150 **** | |
{ | |
SPHINX_SEARCHD_PROTO = 1, | |
SEARCHD_COMMAND_SEARCH = 0, | |
! VER_COMMAND_SEARCH = 0x116, | |
}; | |
/// search query sorting orders | |
--- 163,169 ---- | |
{ | |
SPHINX_SEARCHD_PROTO = 1, | |
SEARCHD_COMMAND_SEARCH = 0, | |
! VER_COMMAND_SEARCH = 0x119, | |
}; | |
/// search query sorting orders | |
*************** | |
*** 210,217 **** | |
SPH_ATTR_BOOL = 4, ///< this attr is a boolean bit field | |
SPH_ATTR_FLOAT = 5, | |
SPH_ATTR_BIGINT = 6, | |
! SPH_ATTR_MULTI = 0x40000000UL ///< this attr has multiple values (0 or more) | |
}; | |
/// known answers | |
--- 229,238 ---- | |
SPH_ATTR_BOOL = 4, ///< this attr is a boolean bit field | |
SPH_ATTR_FLOAT = 5, | |
SPH_ATTR_BIGINT = 6, | |
+ SPH_ATTR_STRING = 7, ///< string (binary; in-memory) | |
! SPH_ATTR_UINT32SET = 0x40000001UL, ///< this attr is multiple int32 values (0 or more) | |
! SPH_ATTR_UINT64SET = 0x40000002UL ///< this attr is multiple int64 values (0 or more) | |
}; | |
/// known answers | |
*************** | |
*** 673,680 **** | |
if ( !sphinx_init ) | |
{ | |
sphinx_init = 1; | |
! VOID ( pthread_mutex_init ( &sphinx_mutex, MY_MUTEX_INIT_FAST ) ); | |
! hash_init ( &sphinx_open_tables, system_charset_info, 32, 0, 0, | |
sphinx_get_key, 0, 0 ); | |
#if MYSQL_VERSION_ID > 50100 | |
--- 694,701 ---- | |
if ( !sphinx_init ) | |
{ | |
sphinx_init = 1; | |
! void ( pthread_mutex_init ( &sphinx_mutex, MY_MUTEX_INIT_FAST ) ); | |
! sphinx_hash_init ( &sphinx_open_tables, system_charset_info, 32, 0, 0, | |
sphinx_get_key, 0, 0 ); | |
#if MYSQL_VERSION_ID > 50100 | |
*************** | |
*** 724,730 **** | |
sphinx_init = 0; | |
if ( sphinx_open_tables.records ) | |
error = 1; | |
! hash_free ( &sphinx_open_tables ); | |
pthread_mutex_destroy ( &sphinx_mutex ); | |
} | |
--- 745,751 ---- | |
sphinx_init = 0; | |
if ( sphinx_open_tables.records ) | |
error = 1; | |
! sphinx_hash_free ( &sphinx_open_tables ); | |
pthread_mutex_destroy ( &sphinx_mutex ); | |
} | |
*************** | |
*** 1129,1140 **** | |
{ | |
// check if we already have this share | |
#if MYSQL_VERSION_ID>=50120 | |
! pShare = (CSphSEShare*) hash_search ( &sphinx_open_tables, (const uchar *) table_name, strlen(table_name) ); | |
#else | |
#ifdef __WIN__ | |
! pShare = (CSphSEShare*) hash_search ( &sphinx_open_tables, (const byte *) table_name, strlen(table_name) ); | |
#else | |
! pShare = (CSphSEShare*) hash_search ( &sphinx_open_tables, table_name, strlen(table_name) ); | |
#endif // win | |
#endif // pre-5.1.20 | |
--- 1150,1161 ---- | |
{ | |
// check if we already have this share | |
#if MYSQL_VERSION_ID>=50120 | |
! pShare = (CSphSEShare*) sphinx_hash_search ( &sphinx_open_tables, (const uchar *) table_name, strlen(table_name) ); | |
#else | |
#ifdef __WIN__ | |
! pShare = (CSphSEShare*) sphinx_hash_search ( &sphinx_open_tables, (const byte *) table_name, strlen(table_name) ); | |
#else | |
! pShare = (CSphSEShare*) sphinx_hash_search ( &sphinx_open_tables, table_name, strlen(table_name) ); | |
#endif // win | |
#endif // pre-5.1.20 | |
*************** | |
*** 1186,1192 **** | |
if ( !--pShare->m_iUseCount ) | |
{ | |
! hash_delete ( &sphinx_open_tables, (byte *)pShare ); | |
SafeDelete ( pShare ); | |
} | |
--- 1207,1213 ---- | |
if ( !--pShare->m_iUseCount ) | |
{ | |
! sphinx_hash_delete ( &sphinx_open_tables, (byte *)pShare ); | |
SafeDelete ( pShare ); | |
} | |
*************** | |
*** 1807,1813 **** | |
SPH_ENTER_METHOD(); | |
// calc request length | |
! int iReqSize = 124 + 4*m_iWeights | |
+ strlen ( m_sSortBy ) | |
+ strlen ( m_sQuery ) | |
+ strlen ( m_sIndex ) | |
--- 1828,1834 ---- | |
SPH_ENTER_METHOD(); | |
// calc request length | |
! int iReqSize = 128 + 4*m_iWeights | |
+ strlen ( m_sSortBy ) | |
+ strlen ( m_sQuery ) | |
+ strlen ( m_sIndex ) | |
*************** | |
*** 1860,1865 **** | |
--- 1881,1887 ---- | |
SendWord ( SEARCHD_COMMAND_SEARCH ); // command id | |
SendWord ( VER_COMMAND_SEARCH ); // command version | |
SendInt ( iReqSize-8 ); // packet body length | |
+ SendInt ( 0 ); // its a client | |
SendInt ( 1 ); // number of queries | |
SendInt ( m_iOffset ); | |
*************** | |
*** 2070,2084 **** | |
} else | |
{ | |
int tmp_errno; | |
struct hostent tmp_hostent, *hp; | |
char buff2 [ GETHOSTBYNAME_BUFF_SIZE ]; | |
! | |
! hp = my_gethostbyname_r ( sHost, &tmp_hostent, | |
! buff2, sizeof(buff2), &tmp_errno ); | |
if ( !hp ) | |
{ | |
my_gethostbyname_r_free(); | |
char sError[256]; | |
my_snprintf ( sError, sizeof(sError), "failed to resolve searchd host (name=%s)", sHost ); | |
--- 2092,2120 ---- | |
} else | |
{ | |
int tmp_errno; | |
+ bool bError = false; | |
+ | |
+ #if MYSQL_VERSION_ID>=50515 | |
+ struct addrinfo tmp_hostent, *hp; | |
+ tmp_errno = getaddrinfo ( sHost, NULL, &tmp_hostent, &hp ); | |
+ if ( !tmp_errno ) | |
+ { | |
+ freeaddrinfo ( hp ); | |
+ bError = true; | |
+ } | |
+ #else | |
struct hostent tmp_hostent, *hp; | |
char buff2 [ GETHOSTBYNAME_BUFF_SIZE ]; | |
! hp = my_gethostbyname_r ( sHost, &tmp_hostent, buff2, sizeof(buff2), &tmp_errno ); | |
if ( !hp ) | |
{ | |
my_gethostbyname_r_free(); | |
+ bError = true; | |
+ } | |
+ #endif | |
+ if ( bError ) | |
+ { | |
char sError[256]; | |
my_snprintf ( sError, sizeof(sError), "failed to resolve searchd host (name=%s)", sHost ); | |
*************** | |
*** 2086,2094 **** | |
SPH_RET(-1); | |
} | |
! memcpy ( &sin.sin_addr, hp->h_addr, | |
! Min ( sizeof(sin.sin_addr), (size_t)hp->h_length ) ); | |
my_gethostbyname_r_free(); | |
} | |
} else | |
{ | |
--- 2122,2134 ---- | |
SPH_RET(-1); | |
} | |
! #if MYSQL_VERSION_ID>=50515 | |
! memcpy ( &sin.sin_addr, hp->ai_addr, Min ( sizeof(sin.sin_addr), (size_t)hp->ai_addrlen ) ); | |
! freeaddrinfo ( hp ); | |
! #else | |
! memcpy ( &sin.sin_addr, hp->h_addr, Min ( sizeof(sin.sin_addr), (size_t)hp->h_length ) ); | |
my_gethostbyname_r_free(); | |
+ #endif | |
} | |
} else | |
{ | |
*************** | |
*** 2380,2391 **** | |
} | |
! uint32 ha_sphinx::UnpackDword () | |
{ | |
! if ( m_pCur+sizeof(uint32)>m_pResponseEnd ) // NOLINT | |
{ | |
m_pCur = m_pResponseEnd; | |
m_bUnpackError = true; | |
return 0; | |
} | |
--- 2420,2442 ---- | |
} | |
! bool ha_sphinx::CheckResponcePtr ( int iLen ) | |
{ | |
! if ( m_pCur+iLen>m_pResponseEnd ) | |
{ | |
m_pCur = m_pResponseEnd; | |
m_bUnpackError = true; | |
+ return false; | |
+ } | |
+ | |
+ return true; | |
+ } | |
+ | |
+ | |
+ uint32 ha_sphinx::UnpackDword () | |
+ { | |
+ if ( !CheckResponcePtr ( sizeof(uint32) ) ) // NOLINT | |
+ { | |
return 0; | |
} | |
*************** | |
*** 2401,2410 **** | |
if ( !iLen ) | |
return NULL; | |
! if ( m_pCur+iLen>m_pResponseEnd ) | |
{ | |
- m_pCur = m_pResponseEnd; | |
- m_bUnpackError = true; | |
return NULL; | |
} | |
--- 2452,2459 ---- | |
if ( !iLen ) | |
return NULL; | |
! if ( !CheckResponcePtr ( iLen ) ) | |
{ | |
return NULL; | |
} | |
*************** | |
*** 2557,2567 **** | |
m_pCur += m_bId64 ? 12 : 8; // skip id+weight | |
for ( uint32 i=0; i<m_iAttrs && m_pCur<m_pResponseEnd-sizeof(uint32); i++ ) // NOLINT | |
{ | |
! if ( m_dAttrs[i].m_uType & SPH_ATTR_MULTI ) | |
{ | |
// skip MVA list | |
uint32 uCount = UnpackDword (); | |
m_pCur += uCount*4; | |
} else // skip normal value | |
m_pCur += m_dAttrs[i].m_uType==SPH_ATTR_BIGINT ? 8 : 4; | |
} | |
--- 2606,2620 ---- | |
m_pCur += m_bId64 ? 12 : 8; // skip id+weight | |
for ( uint32 i=0; i<m_iAttrs && m_pCur<m_pResponseEnd-sizeof(uint32); i++ ) // NOLINT | |
{ | |
! if ( m_dAttrs[i].m_uType==SPH_ATTR_UINT32SET || m_dAttrs[i].m_uType==SPH_ATTR_UINT64SET ) | |
{ | |
// skip MVA list | |
uint32 uCount = UnpackDword (); | |
m_pCur += uCount*4; | |
+ } else if ( m_dAttrs[i].m_uType==SPH_ATTR_STRING ) | |
+ { | |
+ uint32 iLen = UnpackDword(); | |
+ m_pCur += iLen; | |
} else // skip normal value | |
m_pCur += m_dAttrs[i].m_uType==SPH_ATTR_BIGINT ? 8 : 4; | |
} | |
*************** | |
*** 2916,2929 **** | |
for ( uint32 i=0; i<m_iAttrs; i++ ) | |
{ | |
! longlong iValue64; | |
uint32 uValue = UnpackDword (); | |
if ( m_dAttrs[i].m_uType==SPH_ATTR_BIGINT ) | |
iValue64 = ( (longlong)uValue<<32 ) | UnpackDword(); | |
if ( m_dAttrs[i].m_iField<0 ) | |
{ | |
// skip MVA | |
! if ( m_dAttrs[i].m_uType & SPH_ATTR_MULTI ) | |
for ( ; uValue>0 && !m_bUnpackError; uValue-- ) | |
UnpackDword(); | |
continue; | |
--- 2969,2982 ---- | |
for ( uint32 i=0; i<m_iAttrs; i++ ) | |
{ | |
! longlong iValue64 = 0; | |
uint32 uValue = UnpackDword (); | |
if ( m_dAttrs[i].m_uType==SPH_ATTR_BIGINT ) | |
iValue64 = ( (longlong)uValue<<32 ) | UnpackDword(); | |
if ( m_dAttrs[i].m_iField<0 ) | |
{ | |
// skip MVA | |
! if ( m_dAttrs[i].m_uType==SPH_ATTR_UINT32SET || m_dAttrs[i].m_uType==SPH_ATTR_UINT64SET ) | |
for ( ; uValue>0 && !m_bUnpackError; uValue-- ) | |
UnpackDword(); | |
continue; | |
*************** | |
*** 2953,2959 **** | |
af->store ( iValue64, 0 ); | |
break; | |
! case ( SPH_ATTR_MULTI | SPH_ATTR_INTEGER ): | |
if ( uValue<=0 ) | |
{ | |
// shortcut, empty MVA set | |
--- 3006,3023 ---- | |
af->store ( iValue64, 0 ); | |
break; | |
! case SPH_ATTR_STRING: | |
! if ( !uValue ) | |
! af->store ( "", 0, &my_charset_bin ); | |
! else if ( CheckResponcePtr ( uValue ) ) | |
! { | |
! af->store ( m_pCur, uValue, &my_charset_bin ); | |
! m_pCur += uValue; | |
! } | |
! break; | |
! | |
! case SPH_ATTR_UINT64SET: | |
! case SPH_ATTR_UINT32SET : | |
if ( uValue<=0 ) | |
{ | |
// shortcut, empty MVA set | |
*************** | |
*** 2965,2979 **** | |
char sBuf[1024]; // FIXME! magic size | |
char * pCur = sBuf; | |
! for ( ; uValue>0 && !m_bUnpackError; uValue-- ) | |
{ | |
! uint32 uEntry = UnpackDword (); | |
! if ( pCur < sBuf+sizeof(sBuf)-16 ) // 10 chars per 32bit value plus some safety bytes | |
{ | |
! snprintf ( pCur, sBuf+sizeof(sBuf)-pCur, "%u", uEntry ); | |
! while ( *pCur ) *pCur++; | |
! if ( uValue>1 ) | |
! *pCur++ = ','; // non-trailing commas | |
} | |
} | |
--- 3029,3060 ---- | |
char sBuf[1024]; // FIXME! magic size | |
char * pCur = sBuf; | |
! if ( m_dAttrs[i].m_uType==SPH_ATTR_UINT32SET ) | |
! { | |
! for ( ; uValue>0 && !m_bUnpackError; uValue-- ) | |
! { | |
! uint32 uEntry = UnpackDword (); | |
! if ( pCur < sBuf+sizeof(sBuf)-16 ) // 10 chars per 32bit value plus some safety bytes | |
! { | |
! snprintf ( pCur, sBuf+sizeof(sBuf)-pCur, "%u", uEntry ); | |
! while ( *pCur ) *pCur++; | |
! if ( uValue>1 ) | |
! *pCur++ = ','; // non-trailing commas | |
! } | |
! } | |
! } else | |
{ | |
! for ( ; uValue>0 && !m_bUnpackError; uValue-=2 ) | |
{ | |
! uint64 uEntry = UnpackDword (); | |
! uEntry = ( uEntry<<32 ) | UnpackDword(); | |
! if ( pCur < sBuf+sizeof(sBuf)-24 ) // 20 chars per 64bit value plus some safety bytes | |
! { | |
! snprintf ( pCur, sBuf+sizeof(sBuf)-pCur, "%llu", uEntry ); | |
! while ( *pCur ) *pCur++; | |
! if ( uValue>2 ) | |
! *pCur++ = ','; // non-trailing commas | |
! } | |
} | |
} | |
*************** | |
*** 3506,3510 **** | |
#endif // >50100 | |
// | |
! // $Id: ha_sphinx.cc 2752 2011-03-29 08:21:05Z tomat $ | |
// | |
--- 3587,3591 ---- | |
#endif // >50100 | |
// | |
! // $Id: ha_sphinx.cc 2921 2011-08-21 21:35:02Z tomat $ | |
// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment