auto move dat/map files we can't regen map for

to trash subdir. later: try to repair them better.
This commit is contained in:
Matt Wells 2015-06-17 06:55:49 -07:00
parent b8f1cf9298
commit 68d04b239f
2 changed files with 19 additions and 0 deletions

View File

@ -839,6 +839,22 @@ int32_t RdbBase::addFile ( int32_t id , bool isNew , int32_t mergeNum , int32_t
// this returns false and sets g_errno on error
if ( ! m->generateMap ( f ) ) {
log("db: Map generation failed.");
log("db: Moving .dat and .map file to trash dir");
SafeBuf tmp;
tmp.safePrintf("%s",f->getFilename());
// take off .dat and make it * so we can move map file
int32_t len = tmp.getLength();
char *str = tmp.getBufStart();
str[len-3] = '*';
str[len-2] = '\0';
SafeBuf cmd;
cmd.safePrintf("mv %s/%s %s/trash/",
m_dir.getDir(),
str,
g_hostdb.m_dir);
log("db: %s",cmd.getBufStart() );
gbsystem ( cmd.getBufStart() );
exit(0);
mdelete ( f , sizeof(BigFile),"RdbBase");
delete (f);
mdelete ( m , sizeof(RdbMap),"RdbBase");

View File

@ -1372,6 +1372,9 @@ bool RdbMap::chopHead ( int32_t fileHeadSize ) {
bool RdbMap::generateMap ( BigFile *f ) {
reset();
if ( g_conf.m_readOnlyMode ) return false;
log("db: Generating map for %s/%s",f->m_dir,f->getFilename());
// we don't support headless datafiles right now
if ( ! f->doesPartExist(0) ) {
g_errno = EBADENGINEER;