More for prev commit

Use the latest meta page
vmware
Howard Chu 12 years ago
parent e74d70e88e
commit ed86a086f7
  1. 16
      libraries/liblmdb/mdb.c

@ -2416,11 +2416,13 @@ mdb_env_read_header(MDB_env *env, MDB_meta *meta)
MDB_pagebuf pbuf; MDB_pagebuf pbuf;
MDB_page *p; MDB_page *p;
MDB_meta *m; MDB_meta *m;
int rc, err; int i, rc, err;
/* We don't know the page size yet, so use a minimum value. /* We don't know the page size yet, so use a minimum value.
* Read both meta pages so we can use the latest one.
*/ */
for (i=0; i<2; i++) {
#ifdef _WIN32 #ifdef _WIN32
if (!ReadFile(env->me_fd, &pbuf, MDB_PAGESIZE, (DWORD *)&rc, NULL) || rc == 0) if (!ReadFile(env->me_fd, &pbuf, MDB_PAGESIZE, (DWORD *)&rc, NULL) || rc == 0)
#else #else
@ -2456,7 +2458,19 @@ mdb_env_read_header(MDB_env *env, MDB_meta *meta)
return MDB_VERSION_MISMATCH; return MDB_VERSION_MISMATCH;
} }
if (i) {
if (m->mm_txnid > meta->mm_txnid)
memcpy(meta, m, sizeof(*m)); memcpy(meta, m, sizeof(*m));
} else {
memcpy(meta, m, sizeof(*m));
#ifdef _WIN32
if (SetFilePointer(env->me_fd, meta->mm_psize, NULL, FILE_BEGIN) != meta->mm_psize)
#else
if (lseek(env->me_fd, meta->mm_psize, SEEK_SET) != meta->mm_psize)
#endif
return ErrCode();
}
}
return 0; return 0;
} }

Loading…
Cancel
Save