Skip to content

Commit d328110

Browse files
author
Allen Reese
committed
Add MdbmLocker courtesy of Bhopesh Bassi (@bbhopesh)
Fix a bug in the iteration that came up courtesy of Bhopesh Bassi (@bbhopesh)
1 parent 6ad93be commit d328110

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

AUTHORS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,8 @@ Based on:
6161
Bhagyashri Mahule, Yahoo!, Inc.
6262
Lakshmanan Suryanarayanan, Yahoo!, Inc.
6363

64+
Modifications for:
65+
. Java JNI wrappers
66+
By
67+
Allen Reese, Yahoo!, Inc.
68+
Manu Bassi, Yahoo!, Inc. (MdbmLocker code, bug fixes around iteration)

src/java/com_yahoo_db_mdbm_internal_NativeMdbmAccess.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ class ScopedKvPair {
340340

341341
GET_CACHED_CLASS(jenv, mdbmKvPairClass);
342342
GET_CACHED_METHOD_ID(jenv, mdbmKvPairDatumCtorId);
343-
if (NULL == mdbmDatumClass || NULL == mdbmKvPairDatumCtorId) {
343+
if (NULL == mdbmKvPairClass || NULL == mdbmKvPairDatumCtorId) {
344344
// valid is set to false so bail.
345345
return;
346346
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* Copyright 2017 Yahoo! Inc. */
2+
/* Licensed under the terms of the 3-Clause BSD license. See LICENSE file in the project root for details. */
3+
4+
package com.yahoo.db.mdbm;
5+
6+
import com.yahoo.db.mdbm.exceptions.MdbmException;
7+
8+
/**
9+
* This class takes an MdbmInterface as it's constructor, and locks the mdbm. The use case is for locking during
10+
* iteration via try-with resources.
11+
*
12+
* Credit to bbhopesh for noticing this was missing.
13+
*
14+
*/
15+
public class MdbmLocker implements AutoCloseable {
16+
private MdbmInterface m;
17+
18+
public MdbmLocker(MdbmInterface m) throws MdbmException {
19+
this.m = m;
20+
m.lock();
21+
}
22+
23+
@Override
24+
public void close() throws MdbmException {
25+
if (null != m) {
26+
m.unlock();
27+
m = null;
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)