Relax MDB_MAXKEYSIZE for existing data.

Handle keys stored by a liblmdb with a bigger MDB_MAXKEYSIZE.
mdb_get/mdb_del(absent key bigger than our MDB_MAXKEYSIZE)
now return MDB_NOTFOUND instead of MDB_BAD_VALSIZE.
vmware
Hallvard Furuseth 11 years ago
parent a8de10d148
commit 734bc7e6ad
  1. 4
      libraries/liblmdb/lmdb.h
  2. 28
      libraries/liblmdb/mdb.c

@ -797,12 +797,12 @@ int mdb_env_get_maxreaders(MDB_env *env, unsigned int *readers);
*/ */
int mdb_env_set_maxdbs(MDB_env *env, MDB_dbi dbs); int mdb_env_set_maxdbs(MDB_env *env, MDB_dbi dbs);
/** @brief Get the maximum size of a key for the environment. /** @brief Get the maximum size of keys and #MDB_DUPSORT data we can write.
* *
* This is the compile-time constant #MDB_MAXKEYSIZE, default 511. * This is the compile-time constant #MDB_MAXKEYSIZE, default 511.
* See @ref MDB_val. * See @ref MDB_val.
* @param[in] env An environment handle returned by #mdb_env_create() * @param[in] env An environment handle returned by #mdb_env_create()
* @return The maximum size of a key * @return The maximum size of a key we can write
*/ */
int mdb_env_get_maxkeysize(MDB_env *env); int mdb_env_get_maxkeysize(MDB_env *env);

@ -382,10 +382,7 @@ static txnid_t mdb_debug_start;
/** The version number for a database's lockfile format. */ /** The version number for a database's lockfile format. */
#define MDB_LOCK_VERSION 1 #define MDB_LOCK_VERSION 1
/** @brief The maximum size of a key in the database. /** @brief The maximum size of a key we can write to a database.
*
* The library rejects bigger keys, and cannot deal with records
* with bigger keys stored by a library with bigger max keysize.
* *
* We require that keys all fit onto a regular page. This limit * We require that keys all fit onto a regular page. This limit
* could be raised a bit further if needed; to something just * could be raised a bit further if needed; to something just
@ -4972,10 +4969,6 @@ mdb_get(MDB_txn *txn, MDB_dbi dbi,
if (txn->mt_flags & MDB_TXN_ERROR) if (txn->mt_flags & MDB_TXN_ERROR)
return MDB_BAD_TXN; return MDB_BAD_TXN;
if (key->mv_size > MDB_MAXKEYSIZE) {
return MDB_BAD_VALSIZE;
}
mdb_cursor_init(&mc, txn, dbi, &mx); mdb_cursor_init(&mc, txn, dbi, &mx);
return mdb_cursor_set(&mc, key, data, MDB_SET, &exact); return mdb_cursor_set(&mc, key, data, MDB_SET, &exact);
} }
@ -5531,12 +5524,10 @@ mdb_cursor_get(MDB_cursor *mc, MDB_val *key, MDB_val *data,
case MDB_SET_RANGE: case MDB_SET_RANGE:
if (key == NULL) { if (key == NULL) {
rc = EINVAL; rc = EINVAL;
} else if (key->mv_size > MDB_MAXKEYSIZE) { } else {
rc = MDB_BAD_VALSIZE; rc = mdb_cursor_set(mc, key, data, op,
} else if (op == MDB_SET_RANGE) op == MDB_SET_RANGE ? NULL : &exact);
rc = mdb_cursor_set(mc, key, data, op, NULL); }
else
rc = mdb_cursor_set(mc, key, data, op, &exact);
break; break;
case MDB_GET_MULTIPLE: case MDB_GET_MULTIPLE:
if (data == NULL || !(mc->mc_flags & C_INITIALIZED)) { if (data == NULL || !(mc->mc_flags & C_INITIALIZED)) {
@ -5681,7 +5672,6 @@ mdb_cursor_put(MDB_cursor *mc, MDB_val *key, MDB_val *data,
unsigned int mcount = 0, dcount = 0, nospill; unsigned int mcount = 0, dcount = 0, nospill;
size_t nsize; size_t nsize;
int rc, rc2; int rc, rc2;
char dbuf[MDB_MAXKEYSIZE+1];
unsigned int nflags; unsigned int nflags;
DKBUF; DKBUF;
@ -5846,9 +5836,9 @@ more:
/* Back up original data item */ /* Back up original data item */
dkey.mv_size = olddata.mv_size; dkey.mv_size = olddata.mv_size;
dkey.mv_data = memcpy(dbuf, olddata.mv_data, olddata.mv_size); dkey.mv_data = memcpy(fp+1, olddata.mv_data, olddata.mv_size);
/* create a fake page for the dup items */ /* Make sub-page header for the dup items, with dummy body */
fp->mp_flags = P_LEAF|P_DIRTY|P_SUBP; fp->mp_flags = P_LEAF|P_DIRTY|P_SUBP;
fp->mp_lower = PAGEHDRSZ; fp->mp_lower = PAGEHDRSZ;
xdata.mv_size = PAGEHDRSZ + dkey.mv_size + data->mv_size; xdata.mv_size = PAGEHDRSZ + dkey.mv_size + data->mv_size;
@ -7395,10 +7385,6 @@ mdb_del(MDB_txn *txn, MDB_dbi dbi,
if (txn->mt_flags & (MDB_TXN_RDONLY|MDB_TXN_ERROR)) if (txn->mt_flags & (MDB_TXN_RDONLY|MDB_TXN_ERROR))
return (txn->mt_flags & MDB_TXN_RDONLY) ? EACCES : MDB_BAD_TXN; return (txn->mt_flags & MDB_TXN_RDONLY) ? EACCES : MDB_BAD_TXN;
if (key->mv_size > MDB_MAXKEYSIZE) {
return MDB_BAD_VALSIZE;
}
mdb_cursor_init(&mc, txn, dbi, &mx); mdb_cursor_init(&mc, txn, dbi, &mx);
exact = 0; exact = 0;

Loading…
Cancel
Save