change collnum of reset collection

so any adds in progress will fail.
This commit is contained in:
Matt Wells
2013-10-18 15:46:00 -07:00
parent b589b17e63
commit ecab57ff0f
4 changed files with 53 additions and 10 deletions

@ -724,9 +724,44 @@ bool Collectiondb::resetColl ( char *coll , bool resetTurkdb ) {
cr->m_globalCrawlInfo.reset();
cr->m_localCrawlInfo.reset();
// . save it again after copy
// . no, i think addRec above saves it, so don't double save
// . ah just double save since we copied "tmp" back to it above
// make a new collnum so records in transit will not be added
// to any rdb...
cr->m_collnum = m_numRecs;
m_recs[collnum] = NULL;
m_recs[m_numRecs] = cr;
m_numRecs++;
// readd it to the hashtable that maps name to collnum too
long long h64 = hash64n(cr->m_coll);
g_collTable.removeKey ( &h64 );
g_collTable.addKey ( &h64 , &cr->m_collnum );
// a new directory then since we changed the collnum
char dname[512];
sprintf(dname, "%scoll.%s.%li/",
g_hostdb.m_dir,
cr->m_coll,
(long)cr->m_collnum);
if ( opendir ( dname ) ) {
//g_errno = EEXIST;
log("admin: Trying to create collection %s but "
"directory %s already exists on disk.",coll,dname);
}
if ( ::mkdir ( dname ,
S_IRUSR | S_IWUSR | S_IXUSR |
S_IRGRP | S_IWGRP | S_IXGRP |
S_IROTH | S_IXOTH ) ) {
// valgrind?
//if ( errno == EINTR ) goto retry22;
//g_errno = errno;
log("admin: Creating directory %s had error: "
"%s.", dname,mstrerror(g_errno));
}
// save coll.conf to new directory
cr->save();

@ -1217,6 +1217,10 @@ bool addMetaList ( char *p , UdpSlot *slot ) {
g_repairMode > 0 )
//g_repair.m_fullRebuild )
g_errno = ETRYAGAIN;
// ignore enocollrec errors since collection can be reset while
// spiders are on now.
if ( g_errno == ENOCOLLREC )
g_errno = 0;
// are we done
if ( g_errno ) return false;
// success

@ -3025,13 +3025,15 @@ void RdbTree::cleanTree ( ) { // char **bases ) {
long RdbTree::getNumNegativeKeys ( collnum_t collnum ) {
if ( ! m_isRealTree ) { char *xx=NULL;*xx=0; }
return g_collectiondb.m_recs[collnum]->
m_numNegKeysInTree[(unsigned char)m_rdbId];
CollectionRec *cr = g_collectiondb.m_recs[collnum];
if ( ! cr ) return 0;
return cr->m_numNegKeysInTree[(unsigned char)m_rdbId];
}
long RdbTree::getNumPositiveKeys ( collnum_t collnum ) {
if ( ! m_isRealTree ) { char *xx=NULL;*xx=0; }
return g_collectiondb.m_recs[collnum]->
m_numPosKeysInTree[(unsigned char)m_rdbId];
CollectionRec *cr = g_collectiondb.m_recs[collnum];
if ( ! cr ) return 0;
return cr->m_numPosKeysInTree[(unsigned char)m_rdbId];
}

@ -940,6 +940,8 @@ SpiderColl *SpiderCache::getSpiderColl ( collnum_t collnum ) {
//if ( ! g_conf.m_spideringEnabled ) return NULL;
// shortcut
CollectionRec *cr = g_collectiondb.m_recs[collnum];
// collection might have been reset in which case collnum changes
if ( ! cr ) return NULL;
// return it if non-NULL
SpiderColl *sc = cr->m_spiderColl;
if ( sc ) return sc;
@ -5025,13 +5027,13 @@ bool SpiderLoop::indexedDoc ( XmlDoc *xd ) {
// get coll
collnum_t collnum = xd->m_collnum;//tiondb.getCollnum ( xd->m_coll );
// get it
// if coll was deleted while spidering, sc will be NULL
SpiderColl *sc = g_spiderCache.getSpiderColl(collnum);
// decrement this
sc->m_spidersOut--;
if ( sc ) sc->m_spidersOut--;
// get the original request from xmldoc
SpiderRequest *sreq = &xd->m_oldsr;
// update this. if coll was deleted while spidering, sc will be NULL
// update this.
if ( sc ) sc->m_outstandingSpiders[(unsigned char)sreq->m_priority]--;
// debug log