fix facet mem leak from QueryTerm::m_facetHashTable and safebuf

when doing federated queries over a token.
This commit is contained in:
Matt Wells 2015-03-15 07:18:32 -07:00
parent 427fae7135
commit 3b39b1d37a
5 changed files with 54 additions and 4 deletions

@ -25,6 +25,7 @@ void Msg3a::constructor ( ) {
m_numDocIds = 0;
m_collnums = NULL;
m_inUse = false;
m_q = NULL;
// need to call all safebuf constructors now to set m_label
m_rbuf2.constructor();
@ -1063,13 +1064,21 @@ bool Msg3a::mergeLists ( ) {
// and Msg40.cpp ultimately.
HashTableX *ht = &qt->m_facetHashTable;
// we have to manually call this because Query::constructor()
// might have been called explicitly
ht->constructor();
// might have been called explicitly. not now because
// i added a call the Query::constructor() to call
// QueryTerm::constructor() for each QueryTerm in
// Query::m_qterms[]. this was causing a mem leak of
// 'fhtqt' too beacause we were re-using the query for each
// coll in the federated loop search.
//ht->constructor();
// 4 byte key, 4 byte score for counting facet values
if ( ! ht->set(4,sizeof(FacetEntry),
128,NULL,0,false,
m_r->m_niceness,"fhtqt"))
return true;
// debug note
// log("results: alloc fhtqt of %"PTRFMT" for st0=%"PTRFMT,
// (PTRTYPE)ht->m_buf,(PTRTYPE)m_q->m_st0Ptr);
// sanity
if ( ! ht->m_isWritable ) {char *xx=NULL;*xx=0;}
}
@ -1186,7 +1195,6 @@ bool Msg3a::mergeLists ( ) {
if ( ! sortFacetEntries() )
return true;
//if ( m_r->m_getSectionStats ) return true;
//
// HACK: END section stats merge

@ -140,6 +140,13 @@ void Msg40::resetBuf2 ( ) {
}
Msg40::~Msg40() {
// free tmp msg3as now
for ( int32_t i = 0 ; i < m_numCollsToSearch ; i++ ) {
if ( ! m_msg3aPtrs[i] ) continue;
mdelete ( m_msg3aPtrs[i] , sizeof(Msg3a), "tmsg3a");
delete ( m_msg3aPtrs[i] );
m_msg3aPtrs[i] = NULL;
}
if ( m_buf ) mfree ( m_buf , m_bufMaxSize , "Msg40" );
m_buf = NULL;
resetBuf2();

@ -128,6 +128,8 @@ bool sendReply ( State0 *st , char *reply ) {
g_stats.logAvgQueryTime(st->m_startTime);
//log("results: debug: in sendReply deleting st=%"PTRFMT,(PTRTYPE)st);
if ( ! savedErr ) { // g_errno ) {
g_stats.m_numSuccess++;
// . one hour cache time... no 1000 hours, basically infinite
@ -563,6 +565,9 @@ bool sendPageResults ( TcpSocket *s , HttpRequest *hr ) {
return sendReply ( st, NULL );
}
// for debug
si->m_q.m_st0Ptr = (char *)st;
int32_t codeLen = 0;
char *code = hr->getString("code", &codeLen, NULL);
// allow up to 1000 results per query for paying clients
@ -635,7 +640,13 @@ bool sendPageResults ( TcpSocket *s , HttpRequest *hr ) {
return sendReply(st,NULL);
}
// filter that one query causing the memleak for now
// if ( strstr(si->m_q.m_orig,
// "type:json AND ((((query=humanLanguage:en") ) {
// g_errno = EQUERYINGDISABLED;
// return sendReply(st,NULL);
// }
// LAUNCH ADS
// . now get the ad space for this query
// . don't get ads if we're not on the first page of results
@ -692,6 +703,8 @@ bool sendPageResults ( TcpSocket *s , HttpRequest *hr ) {
// save error
st->m_errno = g_errno;
//log("results: debug: new state=%"PTRFMT,(PTRTYPE)st);
// wait for ads and spellcheck and results?
if ( !st->m_gotAds || !st->m_gotSpell || !st->m_gotResults )
return false;
@ -1128,6 +1141,7 @@ bool gotResults ( void *state ) {
// record that
st->m_took = took;
//log("results: debug: in gotResults state=%"PTRFMT,(PTRTYPE)st);
// grab the query
Msg40 *msg40 = &(st->m_msg40);

@ -32,6 +32,11 @@ void Query::constructor ( ) {
m_qwords = NULL;
m_numTerms = 0;
m_containingParent = NULL;
m_st0Ptr = NULL;
// we have to manually call this because Query::constructor()
// might have been called explicitly
for ( int32_t i = 0 ; i < MAX_QUERY_TERMS ; i++ )
m_qterms[i].constructor();
//m_expressions = NULL;
reset ( );
}
@ -48,10 +53,15 @@ void Query::reset ( ) {
// if Query::constructor() was called explicitly then we have to
// call destructors explicitly as well...
// essentially call QueryTerm::reset() on each query term
for ( long i = 0 ; i < m_numTerms ; i++ ) {
// get it
QueryTerm *qt = &m_qterms[i];
HashTableX *ht = &qt->m_facetHashTable;
// debug note
// log("results: free fhtqt of %"PTRFMT" for q=%"PTRFMT
// " st0=%"PTRFMT,
// (PTRTYPE)ht->m_buf,(PTRTYPE)this,(PTRTYPE)m_st0Ptr);
ht->reset();
qt->m_facetIndexBuf.purge();
}
@ -5043,6 +5053,11 @@ bool Query::isSplit() {
return false;
}
void QueryTerm::constructor ( ) {
m_facetHashTable.constructor(); // hashtablex
m_facetIndexBuf.constructor(); // safebuf
}
bool QueryTerm::isSplit() {
if(!m_fieldCode) return true;
if(m_fieldCode == FIELD_QUOTA) return false;

@ -397,6 +397,9 @@ class QueryWord {
class QueryTerm {
public:
void constructor ( ) ;
// the query word we were derived from
QueryWord *m_qword;
// . are we a phrase termid or single word termid from that QueryWord?
@ -871,6 +874,9 @@ class Query {
return NULL;
};
// for debugging fhtqt mem leak
char *m_st0Ptr;
// silly little functions that support the BIG HACK
//int32_t getNumNonFieldedSingletonTerms() { return m_numTermsSpecial; };
//int32_t getTermsFound ( Query *q , char *foundTermVector ) ;