Fix some overwrite quirks

Was skipping the overwrite in some cases, if the cmp function
said the new and old already matched. We should always perform
the overwrite anyway, since the cmp function may only be doing
a prefix compare and the data may actually be different.
incre
Howard Chu 11 years ago
parent dc7f2530dd
commit b4ecbd78d9
  1. 14
      libraries/liblmdb/mdb.c

@ -5457,8 +5457,10 @@ set1:
mc->mc_flags &= ~C_EOF; mc->mc_flags &= ~C_EOF;
if (IS_LEAF2(mp)) { if (IS_LEAF2(mp)) {
if (op == MDB_SET_RANGE || op == MDB_SET_KEY) {
key->mv_size = mc->mc_db->md_pad; key->mv_size = mc->mc_db->md_pad;
key->mv_data = LEAF2KEY(mp, mc->mc_ki[mc->mc_top], key->mv_size); key->mv_data = LEAF2KEY(mp, mc->mc_ki[mc->mc_top], key->mv_size);
}
return MDB_SUCCESS; return MDB_SUCCESS;
} }
@ -5942,13 +5944,12 @@ mdb_cursor_put(MDB_cursor *mc, MDB_val *key, MDB_val *data,
} else { } else {
/* there's only a key anyway, so this is a no-op */ /* there's only a key anyway, so this is a no-op */
if (IS_LEAF2(mc->mc_pg[mc->mc_top])) { if (IS_LEAF2(mc->mc_pg[mc->mc_top])) {
char *ptr;
unsigned int ksize = mc->mc_db->md_pad; unsigned int ksize = mc->mc_db->md_pad;
if (key->mv_size != ksize) if (key->mv_size != ksize)
return MDB_BAD_VALSIZE; return MDB_BAD_VALSIZE;
if (flags == MDB_CURRENT) { ptr = LEAF2KEY(mc->mc_pg[mc->mc_top], mc->mc_ki[mc->mc_top], ksize);
char *ptr = LEAF2KEY(mc->mc_pg[mc->mc_top], mc->mc_ki[mc->mc_top], ksize);
memcpy(ptr, key->mv_data, ksize); memcpy(ptr, key->mv_data, ksize);
}
return MDB_SUCCESS; return MDB_SUCCESS;
} }
@ -5978,12 +5979,12 @@ more:
if (mc->mc_dbx->md_dcmp == mdb_cmp_int && olddata.mv_size == sizeof(size_t)) if (mc->mc_dbx->md_dcmp == mdb_cmp_int && olddata.mv_size == sizeof(size_t))
mc->mc_dbx->md_dcmp = mdb_cmp_clong; mc->mc_dbx->md_dcmp = mdb_cmp_clong;
#endif #endif
/* if data matches, skip it */ /* does data match? */
if (!mc->mc_dbx->md_dcmp(data, &olddata)) { if (!mc->mc_dbx->md_dcmp(data, &olddata)) {
if (flags & MDB_NODUPDATA) if (flags & MDB_NODUPDATA)
return MDB_KEYEXIST; return MDB_KEYEXIST;
rc = MDB_SUCCESS; /* overwrite it */
goto next_sub; goto current;
} }
/* Back up original data item */ /* Back up original data item */
@ -6259,7 +6260,6 @@ put_sub:
*/ */
mc->mc_flags |= C_INITIALIZED; mc->mc_flags |= C_INITIALIZED;
} }
next_sub:
if (flags & MDB_MULTIPLE) { if (flags & MDB_MULTIPLE) {
if (!rc) { if (!rc) {
mcount++; mcount++;

Loading…
Cancel
Save