Merge remote-tracking branch 'origin/mdb.master'

This commit is contained in:
Howard Chu 2013-07-28 17:13:04 -07:00
commit 4f4590f110

View File

@ -3535,20 +3535,37 @@ mdb_hash_val(MDB_val *val, mdb_hash_t hval)
return hval;
}
/** Hash the string and output the hash in hex.
/** Hash the string and output the encoded hash.
* This uses modified RFC1924 Ascii85 encoding to accommodate systems with
* very short name limits. We don't care about the encoding being reversible,
* we just want to preserve as many bits of the input as possible in a
* small printable string.
* @param[in] str string to hash
* @param[out] hexbuf an array of 17 chars to hold the hash
* @param[out] encbuf an array of 11 chars to hold the hash
*/
const static char mdb_a85[]= "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~";
static void
mdb_hash_hex(MDB_val *val, char *hexbuf)
mdb_pack85(unsigned long l, char *out)
{
int i;
mdb_hash_t h = mdb_hash_val(val, MDB_HASH_INIT);
for (i=0; i<8; i++) {
hexbuf += sprintf(hexbuf, "%02x", (unsigned int)h & 0xff);
h >>= 8;
for (i=0; i<5; i++) {
*out++ = mdb_a85[l % 85];
l /= 85;
}
}
static void
mdb_hash_enc(MDB_val *val, char *encbuf)
{
mdb_hash_t h = mdb_hash_val(val, MDB_HASH_INIT);
unsigned long *l = (unsigned long *)&h;
mdb_pack85(l[0], encbuf);
mdb_pack85(l[1], encbuf+5);
encbuf[10] = '\0';
}
#endif
/** Open and/or initialize the lock region for the environment.
@ -3661,7 +3678,7 @@ mdb_env_setup_locks(MDB_env *env, char *lpath, int mode, int *excl)
DWORD nlow;
} idbuf;
MDB_val val;
char hexbuf[17];
char encbuf[11];
if (!mdb_sec_inited) {
InitializeSecurityDescriptor(&mdb_null_sd,
@ -3678,9 +3695,9 @@ mdb_env_setup_locks(MDB_env *env, char *lpath, int mode, int *excl)
idbuf.nlow = stbuf.nFileIndexLow;
val.mv_data = &idbuf;
val.mv_size = sizeof(idbuf);
mdb_hash_hex(&val, hexbuf);
sprintf(env->me_txns->mti_rmname, "Global\\MDBr%s", hexbuf);
sprintf(env->me_txns->mti_wmname, "Global\\MDBw%s", hexbuf);
mdb_hash_enc(&val, encbuf);
sprintf(env->me_txns->mti_rmname, "Global\\MDBr%s", encbuf);
sprintf(env->me_txns->mti_wmname, "Global\\MDBw%s", encbuf);
env->me_rmutex = CreateMutex(&mdb_all_sa, FALSE, env->me_txns->mti_rmname);
if (!env->me_rmutex) goto fail_errno;
env->me_wmutex = CreateMutex(&mdb_all_sa, FALSE, env->me_txns->mti_wmname);
@ -3692,16 +3709,22 @@ mdb_env_setup_locks(MDB_env *env, char *lpath, int mode, int *excl)
ino_t ino;
} idbuf;
MDB_val val;
char hexbuf[17];
char encbuf[11];
#if defined(__NetBSD__)
#define MDB_SHORT_SEMNAMES 1 /* limited to 14 chars */
#endif
if (fstat(env->me_lfd, &stbuf)) goto fail_errno;
idbuf.dev = stbuf.st_dev;
idbuf.ino = stbuf.st_ino;
val.mv_data = &idbuf;
val.mv_size = sizeof(idbuf);
mdb_hash_hex(&val, hexbuf);
sprintf(env->me_txns->mti_rmname, "/MDBr%s", hexbuf);
sprintf(env->me_txns->mti_wmname, "/MDBw%s", hexbuf);
mdb_hash_enc(&val, encbuf);
#ifdef MDB_SHORT_SEMNAMES
encbuf[9] = '\0'; /* drop name from 15 chars to 14 chars */
#endif
sprintf(env->me_txns->mti_rmname, "/MDBr%s", encbuf);
sprintf(env->me_txns->mti_wmname, "/MDBw%s", encbuf);
/* Clean up after a previous run, if needed: Try to
* remove both semaphores before doing anything else.
*/
@ -7659,7 +7682,12 @@ mdb_env_info(MDB_env *env, MDB_envinfo *arg)
arg->me_mapaddr = (env->me_flags & MDB_FIXEDMAP) ? env->me_map : 0;
arg->me_mapsize = env->me_mapsize;
arg->me_maxreaders = env->me_maxreaders;
arg->me_numreaders = env->me_numreaders;
/* me_numreaders may be zero if this process never used any readers. Use
* the shared numreader count if it exists.
*/
arg->me_numreaders = env->me_txns ? env->me_txns->mti_numreaders : env->me_numreaders;
arg->me_last_pgno = env->me_metas[toggle]->mm_last_pg;
arg->me_last_txnid = env->me_metas[toggle]->mm_txnid;
return MDB_SUCCESS;