Skip to content

Commit

Permalink
lmdb: Sync to upstream.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco van Wieringen committed Feb 5, 2016
1 parent 7e7f95c commit 240a876
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 41 deletions.
4 changes: 2 additions & 2 deletions src/lmdb/lmdb.h
Expand Up @@ -135,7 +135,7 @@
*
* @author Howard Chu, Symas Corporation.
*
* @copyright Copyright 2011-2015 Howard Chu, Symas Corp. All rights reserved.
* @copyright Copyright 2011-2016 Howard Chu, Symas Corp. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
Expand Down Expand Up @@ -1544,7 +1544,7 @@ int mdb_cursor_del(MDB_cursor *cursor, unsigned int flags);
* <li>EINVAL - cursor is not initialized, or an invalid parameter was specified.
* </ul>
*/
int mdb_cursor_count(MDB_cursor *cursor, size_t *countp);
int mdb_cursor_count(MDB_cursor *cursor, mdb_size_t *countp);

/** @brief Compare two data items according to a particular database.
*
Expand Down
53 changes: 16 additions & 37 deletions src/lmdb/mdb.c
Expand Up @@ -5,7 +5,7 @@
* BerkeleyDB API, but much simplified.
*/
/*
* Copyright 2011-2015 Howard Chu, Symas Corp.
* Copyright 2011-2016 Howard Chu, Symas Corp.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -1079,7 +1079,7 @@ typedef struct MDB_db {
pgno_t md_branch_pages; /**< number of internal pages */
pgno_t md_leaf_pages; /**< number of leaf pages */
pgno_t md_overflow_pages; /**< number of overflow pages */
pgno_t md_entries; /**< number of data items */
mdb_size_t md_entries; /**< number of data items */
pgno_t md_root; /**< the root page of this tree */
} MDB_db;

Expand Down Expand Up @@ -4036,7 +4036,7 @@ mdb_env_write_meta(MDB_txn *txn)
mp->mm_dbs[MAIN_DBI] = txn->mt_dbs[MAIN_DBI];
mp->mm_last_pg = txn->mt_next_pgno - 1;
#if defined(__SUNPRO_C)
__machine_rw_barrier();
__machine_rw_barrier();
#elif defined(__GNUC__)
#if (__GNUC__ * 100 + __GNUC_MINOR__ >= 404) && /* TODO: portability */ \
!(defined(__i386__) || defined(__x86_64__))
Expand Down Expand Up @@ -5838,7 +5838,7 @@ mdb_rpage_get(MDB_txn *txn, pgno_t pg0, MDB_page **ret)
if (rc)
goto fail;
if (!el[x].mref) {
munmap(el[x].mptr, el[x].mcnt);
munmap(el[x].mptr, env->me_psize * el[x].mcnt);
el[x].mptr = id3.mptr;
el[x].mcnt = id3.mcnt;
} else {
Expand Down Expand Up @@ -5890,36 +5890,15 @@ mdb_rpage_get(MDB_txn *txn, pgno_t pg0, MDB_page **ret)
pthread_mutex_unlock(&env->me_rpmutex);
return rc;
}
/* If this page is far enough from the end of the env, scan for
* any overflow pages that would spill onto another block.
* Note we must compare against mt_last_pgno, the last written
* page in the environment. Not mt_next_pgno, which increases
* for every newly allocated (but not yet written) page. If
* we scanned beyond the last written page we'd get a bus error.
*/
if (pgno + MDB_RPAGE_CHUNK <= txn->mt_last_pgno) {
int i;
char *cp = (char *)id3.mptr + rem * env->me_psize;
for (i=rem; i<MDB_RPAGE_CHUNK;) {
p = (MDB_page *)cp;
if (IS_OVERFLOW(p)) {
int nop = p->mp_pages;
if (nop + i > MDB_RPAGE_CHUNK) {
munmap(id3.mptr, len);
id3.mcnt = nop + i;
len = id3.mcnt * env->me_psize;
MAP(rc, env, id3.mptr, len, off);
if (rc)
goto fail;
break;
}
i += nop;
cp += nop * env->me_psize;
} else {
i++;
cp += env->me_psize;
}
}
/* check for overflow size */
p = (MDB_page *)((char *)id3.mptr + rem * env->me_psize);
if (IS_OVERFLOW(p) && p->mp_pages + rem > id3.mcnt) {
id3.mcnt = p->mp_pages + rem;
munmap(id3.mptr, len);
len = id3.mcnt * env->me_psize;
MAP(rc, env, id3.mptr, len, off);
if (rc)
goto fail;
}
mdb_mid3l_insert(el, &id3);
pthread_mutex_unlock(&env->me_rpmutex);
Expand Down Expand Up @@ -7574,7 +7553,7 @@ mdb_cursor_put(MDB_cursor *mc, MDB_val *key, MDB_val *data,
*/
if (do_sub) {
int xflags, new_dupdata;
size_t ecount;
mdb_size_t ecount;
put_sub:
xdata.mv_size = 0;
xdata.mv_data = "";
Expand Down Expand Up @@ -8289,7 +8268,7 @@ mdb_cursor_renew(MDB_txn *txn, MDB_cursor *mc)

/* Return the count of duplicate data items for the current key */
int
mdb_cursor_count(MDB_cursor *mc, size_t *countp)
mdb_cursor_count(MDB_cursor *mc, mdb_size_t *countp)
{
MDB_node *leaf;

Expand Down Expand Up @@ -10149,7 +10128,7 @@ mdb_env_copy2(MDB_env *env, const char *path, unsigned int flags)
#ifdef _WIN32
rc = utf8_to_utf16(lpath, -1, &wpath, NULL);
if (rc)
return rc;
goto leave;
newfd = CreateFileW(wpath, GENERIC_WRITE, 0, NULL, CREATE_NEW,
FILE_FLAG_NO_BUFFERING|FILE_FLAG_WRITE_THROUGH, NULL);
free(wpath);
Expand Down
2 changes: 1 addition & 1 deletion src/lmdb/midl.c
Expand Up @@ -3,7 +3,7 @@
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
* Copyright 2000-2015 The OpenLDAP Foundation.
* Copyright 2000-2016 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 1 addition & 1 deletion src/lmdb/midl.h
Expand Up @@ -11,7 +11,7 @@
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
* Copyright 2000-2015 The OpenLDAP Foundation.
* Copyright 2000-2016 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down

0 comments on commit 240a876

Please sign in to comment.