Skip to content

Commit

Permalink
Updated to match new devel branch of mdbx as of 11/1/23
Browse files Browse the repository at this point in the history
  • Loading branch information
castortech committed Dec 12, 2023
1 parent 69231ac commit 7472726
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 84 deletions.
41 changes: 29 additions & 12 deletions mdbxjni/src/main/java/com/castortech/mdbxjni/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ private Entry getEqOrGE(Transaction tx, NativeBuffer keyBuffer) {
if (rc == MDBX_NOTFOUND) {
return null;
}
checkErrorCode(env, rc);
checkErrorCode(env, tx, rc);
return value.toByteArray();
}

Expand All @@ -301,7 +301,7 @@ private Entry getEqOrGE(Transaction tx, NativeBuffer keyBuffer) {
if (rc == MDBX_NOTFOUND) {
return null;
}
checkErrorCode(env, rc);
checkErrorCode(env, tx, rc);
return new EntryCount(key.toByteArray(), value.toByteArray(), valCnt[0]);
}

Expand All @@ -313,7 +313,7 @@ private Entry getEqOrGE(Transaction tx, NativeBuffer keyBuffer) {
if (rc == MDBX_NOTFOUND) {
return null;
}
checkErrorCode(env, rc);
checkErrorCode(env, tx, rc);
return new Entry(key.toByteArray(), value.toByteArray());
}

Expand Down Expand Up @@ -458,8 +458,8 @@ public byte[] put(Transaction tx, byte[] key, byte[] value, int flags, long valu
try {
long now = System.currentTimeMillis();
byte[] rc = put(tx, new Value(keyBuffer), value1, value2, flags);
if (log.isDebugEnabled())
log.debug("Db put:{}, ms:{}", key, System.currentTimeMillis() - now);
// if (log.isDebugEnabled())
// log.debug("Db put:{}, ms:{}", key, System.currentTimeMillis() - now);
return rc;
}
finally {
Expand Down Expand Up @@ -791,7 +791,7 @@ private boolean delete(Transaction tx, Value keySlice, Value valueSlice) {
if (rc == MDBX_NOTFOUND) {
return false;
}
checkErrorCode(env, rc);
checkErrorCode(env, tx, rc);
deleteSecondaries(tx, keySlice, valueSlices);

return true;
Expand Down Expand Up @@ -834,7 +834,7 @@ public Cursor openCursor(Transaction tx) {
long[] cursor = new long[1];
if (log.isTraceEnabled())
log.trace("Calling cursor open for {}", this); //$NON-NLS-1$
checkErrorCode(env, mdbx_cursor_open(tx.pointer(), pointer(), cursor));
checkErrorCode(env, tx, mdbx_cursor_open(tx.pointer(), pointer(), cursor));
return new Cursor(env, cursor[0], tx, this);
}
catch (Exception e) {
Expand All @@ -854,7 +854,7 @@ public SecondaryCursor openSecondaryCursor(Transaction tx) {
long[] cursor = new long[1];
if (log.isTraceEnabled())
log.trace("Calling sec cursor open for {}", this); //$NON-NLS-1$
checkErrorCode(env, mdbx_cursor_open(tx.pointer(), pointer(), cursor));
checkErrorCode(env, tx, mdbx_cursor_open(tx.pointer(), pointer(), cursor));
return new SecondaryCursor(env, cursor[0], tx, this);
}
catch (Exception e) {
Expand All @@ -877,7 +877,7 @@ public int getFlags(Transaction tx) {
long[] flags = new long[1];
if (log.isTraceEnabled())
log.trace("Calling db flags for {}", this); //$NON-NLS-1$
checkErrorCode(env, mdbx_dbi_flags(tx.pointer(), pointer(), flags));
checkErrorCode(env, tx, mdbx_dbi_flags(tx.pointer(), pointer(), flags));
return (int)flags[0];
}

Expand All @@ -886,23 +886,40 @@ public FlagState getFlagsState(Transaction tx) {
long[] state = new long[1];
if (log.isTraceEnabled())
log.trace("Calling db flags ex for {}", this); //$NON-NLS-1$
checkErrorCode(env, mdbx_dbi_flags_ex(tx.pointer(), pointer(), flags, state));
checkErrorCode(env, tx, mdbx_dbi_flags_ex(tx.pointer(), pointer(), flags, state));
return new FlagState((int)flags[0], (int)state[0]);
}

public int getDupsortDepthMask(Transaction tx) {
long[] mask = new long[1];
if (log.isTraceEnabled())
log.trace("Calling db dupsort for {}", this); //$NON-NLS-1$
checkErrorCode(env, mdbx_dbi_dupsort_depthmask(tx.pointer(), pointer(), mask));
checkErrorCode(env, tx, mdbx_dbi_dupsort_depthmask(tx.pointer(), pointer(), mask));
return (int)mask[0];
}

public int getSequence(Transaction tx, long increment) {
long[] res = new long[1];
if (log.isTraceEnabled())
log.trace("Calling db sequence for {}", this); //$NON-NLS-1$
checkErrorCode(env, mdbx_dbi_sequence(tx.pointer(), pointer(), res, increment));
checkErrorCode(env, tx, mdbx_dbi_sequence(tx.pointer(), pointer(), res, increment));
return (int)res[0];
}

public int rename(Transaction tx, String name) {
long[] res = new long[1];
checkErrorCode(env, tx, mdbx_dbi_rename(tx.pointer(), pointer(), name));
return (int)res[0];
}

@SuppressWarnings("nls")
public int rename2(Transaction tx, byte[] name) {
checkArgNotNull(tx, "tx");
checkArgNotNull(name, "name");

NativeBuffer nameBuffer = NativeBuffer.create(name);
long[] res = new long[1];
checkErrorCode(env, tx, mdbx_dbi_rename2(tx.pointer(), pointer(), new Value(nameBuffer)));
return (int)res[0];
}

Expand Down
24 changes: 12 additions & 12 deletions mdbxjni/src/main/java/com/castortech/mdbxjni/Env.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ public static String version() {
return "" + JNI.MDBX_VERSION_MAJOR + '.' + JNI.MDBX_VERSION_MINOR; //$NON-NLS-1$
}

// public static BuildInfo buildInfo() {
// MDBX_build_info rc = new MDBX_build_info();
//
// NativeBuffer buffer = NativeBuffer.create(JNI.SIZEOF_BUILDINFO);
// get_mdbx_build_info(buffer.pointer(), JNI.SIZEOF_BUILDINFO);
// return new BuildInfo(rc);
// }
public static BuildInfo buildInfo() {
MDBX_build_info rc = new MDBX_build_info();

NativeBuffer buffer = NativeBuffer.create(JNI.SIZEOF_BUILDINFO);
// mdbx_build();
return new BuildInfo(rc);
}


// printf("mdbx_copy version %d.%d.%d.%d\n"
Expand Down Expand Up @@ -345,8 +345,8 @@ public void open(String path, EnvConfig config) {
mainDb = new Database(this, 1L, MAIN_DB);
}

if (config.isUsePooledCursors()) {
CursorPoolConfig poolConfig = new CursorPoolConfig();
if (config.isUsePooledCursors()) {
poolConfig.setTimeBetweenEvictionRuns(config.getPooledCursorTimeBetweenEvictionRuns());
poolConfig.setMaxIdlePerKey(config.getPooledCursorMaxIdle());
poolConfig.setSoftMinEvictableIdleTime(config.getPooledCursorMinEvictableIdleTime());
Expand Down Expand Up @@ -856,7 +856,7 @@ public Database openDatabase(Transaction tx, String name, int flags) {
checkArgNotNull(tx, "tx"); //$NON-NLS-1$
// checkArgNotNull(name, "name");
long[] dbi = new long[1];
checkErrorCode(this, mdbx_dbi_open(tx.pointer(), name, flags, dbi));
checkErrorCode(this, tx, mdbx_dbi_open(tx.pointer(), name, flags, dbi));
return new Database(this, dbi[0], name);
}

Expand Down Expand Up @@ -960,7 +960,7 @@ public Database openDatabase(Transaction tx, String name, int flags, Comparator<
dataComparator = dataComp;
}

checkErrorCode(this, mdbx_dbi_open_ex(tx.pointer(), name, flags, dbi, keyCmpAddr, dataCmpAddr));
checkErrorCode(this, tx, mdbx_dbi_open_ex(tx.pointer(), name, flags, dbi, keyCmpAddr, dataCmpAddr));
return new Database(this, dbi[0], name);
}

Expand Down Expand Up @@ -1016,7 +1016,7 @@ public SecondaryDatabase openSecondaryDatabase(Transaction tx, Database primary,
checkArgNotNull(primary, "primary"); //$NON-NLS-1$
// checkArgNotNull(name, "name");
long[] dbi = new long[1];
checkErrorCode(this, mdbx_dbi_open(tx.pointer(), name, flags, dbi));
checkErrorCode(this, tx, mdbx_dbi_open(tx.pointer(), name, flags, dbi));
SecondaryDbConfig config = new SecondaryDbConfig();
SecondaryDatabase secDb = new SecondaryDatabase(this, primary, dbi[0], name, config);

Expand Down Expand Up @@ -1050,7 +1050,7 @@ public SecondaryDatabase openSecondaryDatabase(Transaction tx, Database primary,

int flags = setFlags(config);
long[] dbi = new long[1];
checkErrorCode(this, mdbx_dbi_open(tx.pointer(), name, flags, dbi));
checkErrorCode(this, tx, mdbx_dbi_open(tx.pointer(), name, flags, dbi));
SecondaryDatabase secDb = new SecondaryDatabase(this, primary, dbi[0], name, config);

if (associateDbs(tx, primary, secDb)) {
Expand Down
Loading

0 comments on commit 7472726

Please sign in to comment.