Skip to content

Commit

Permalink
move 2nd occurence of same collnum_t collection id
Browse files Browse the repository at this point in the history
on the same shard to the trash/ subdir.
put call to syncParmsWithHost0 in a sleep loop in case
host #0 has error, although the timeout is really high.
  • Loading branch information
Matt Wells committed Aug 19, 2015
1 parent 9642947 commit 6c14d65
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 9 deletions.
20 changes: 20 additions & 0 deletions Collectiondb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,26 @@ bool Collectiondb::addExistingColl ( char *coll, collnum_t collnum ) {
char *xx=NULL;*xx=0;
}

// also try by #, i've seen this happen too
CollectionRec *ocr = getRec ( i );
if ( ocr ) {
g_errno = EEXIST;
log("admin: Collection id %i is in use already by "
"%s, so we can not add %s. moving %s to trash."
,(int)i,ocr->m_coll,coll,coll);
SafeBuf cmd;
int64_t now = gettimeofdayInMilliseconds();
cmd.safePrintf ( "mv coll.%s.%i trash/coll.%s.%i.%"UINT64
, coll
,(int)i
, coll
,(int)i
, now );
//log("admin: %s",cmd.getBufStart());
gbsystem ( cmd.getBufStart() );
return true;
}

// create the record in memory
CollectionRec *cr = new (CollectionRec);
if ( ! cr )
Expand Down
26 changes: 23 additions & 3 deletions Parms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@ class Checksum {
Parms::Parms ( ) {
m_isDefaultLoaded = false;
m_inSyncWithHost0 = false;
m_triedToSync = false;
}

void Parms::detachSafeBufs ( CollectionRec *cr ) {
Expand Down Expand Up @@ -21736,20 +21737,37 @@ void handleRequest3f ( UdpSlot *slot , int32_t niceness ) {
// have with ETRYAGAIN in Msg4.cpp


void tryToSyncWrapper ( int fd , void *state ) {
g_parms.syncParmsWithHost0();
}

// host #0 just sends back an empty reply, but it will hit us with
// 0x3f parmlist requests. that way it uses the same mechanism and can
// guarantee ordering of the parm update requests
void gotReplyFromHost0Wrapper ( void *state , UdpSlot *slot ) {
// ignore his reply unless error?
if ( g_errno )
log("parms: got error syncing with host 0: %s",
if ( g_errno ) {
log("parms: got error syncing with host 0: %s. Retrying.",
mstrerror(g_errno));
// re-try it!
g_parms.m_triedToSync = false;
}
else {
log("parms: synced with host #0");
// do not re-call
g_loop.unregisterSleepCallback(NULL,tryToSyncWrapper);
}

g_errno = 0;
}

// returns false and sets g_errno on error, true otherwise
bool Parms::syncParmsWithHost0 ( ) {

if ( m_triedToSync ) return true;

m_triedToSync = true;

m_inSyncWithHost0 = false;

// dont sync with ourselves
Expand Down Expand Up @@ -21782,6 +21800,8 @@ bool Parms::syncParmsWithHost0 ( ) {

Host *h = g_hostdb.getHost(0);

log("parms: trying to sync with host #0");

// . send it off. use 3e i guess
// . host #0 will reply using msg4 really
// . msg4 guarantees ordering of requests
Expand Down
1 change: 1 addition & 0 deletions Parms.h
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ class Parms {
//

bool m_inSyncWithHost0;
bool m_triedToSync;

bool m_isDefaultLoaded;

Expand Down
15 changes: 9 additions & 6 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ extern void resetQuery ( );
extern void resetStopWords ( );
extern void resetUnicode ( );

extern void tryToSyncWrapper ( int fd , void *state ) ;

#if 0
void stack_test();
Expand Down Expand Up @@ -3855,7 +3856,9 @@ int main2 ( int argc , char *argv[] ) {
! g_loop.registerSleepCallback(2000,(void *)1,runSEOQueryLoop))
log("db: Failed to register seo query loop");


// try to sync parms (and collection recs) with host 0
if ( ! g_loop.registerSleepCallback(1000,NULL,tryToSyncWrapper,0))
return false;

//if( !g_loop.registerSleepCallback(2000,(void *)1,controlDumpTopDocs) )
// log("db: Failed to init dump TopDocs sleep callback.");
Expand All @@ -3873,11 +3876,11 @@ int main2 ( int argc , char *argv[] ) {
//msg3e.checkForNewParms();

// this stuff is similar to alden's msg3e but will sync collections
// that were added/deleted
if ( ! g_parms.syncParmsWithHost0() ) {
log("parms: error syncing parms: %s",mstrerror(g_errno));
return 0;
}
// that were added/deletede
//if ( ! g_parms.syncParmsWithHost0() ) {
// log("parms: error syncing parms: %s",mstrerror(g_errno));
// return 0;
//}


if(g_recoveryMode) {
Expand Down

0 comments on commit 6c14d65

Please sign in to comment.