Skip to content

Commit b450591

Browse files
authored
Merge pull request #34 from tidesdb/0.7.0
iss #32 #33 retire unused objecttargetfilesize cf config field and ad…
2 parents 3fc5671 + d443b1a commit b450591

8 files changed

Lines changed: 131 additions & 30 deletions

File tree

README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,3 @@ Multiple licenses apply:
3131
## Contributing
3232

3333
Contributions are welcome! Please feel free to submit a Pull Request.
34-
35-
## Support
36-
37-
- [Discord](https://discord.gg/tWEmjR66cy)
38-
- [GitHub Issues](https://github.com/tidesdb/tidesdb-java/issues)

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.tidesdb</groupId>
88
<artifactId>tidesdb-java</artifactId>
9-
<version>0.6.8</version>
9+
<version>0.7.0</version>
1010
<packaging>jar</packaging>
1111

1212
<name>TidesDB Java</name>

src/main/c/com_tidesdb_TidesDB.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ JNIEXPORT void JNICALL Java_com_tidesdb_TidesDB_nativeCreateColumnFamily(
189189
jboolean enableBlockIndexes, jint indexSampleRatio, jint blockIndexPrefixLen, jint syncMode,
190190
jlong syncIntervalUs, jstring comparatorName, jint skipListMaxLevel, jfloat skipListProbability,
191191
jint defaultIsolationLevel, jlong minDiskSpace, jint l1FileCountTrigger,
192-
jint l0QueueStallThreshold, jboolean useBtree, jlong objectTargetFileSize,
192+
jint l0QueueStallThreshold, jboolean useBtree,
193193
jboolean objectLazyCompaction, jboolean objectPrefetchCompaction)
194194
{
195195
tidesdb_t *db = (tidesdb_t *)(uintptr_t)handle;
@@ -227,7 +227,6 @@ JNIEXPORT void JNICALL Java_com_tidesdb_TidesDB_nativeCreateColumnFamily(
227227
.l1_file_count_trigger = l1FileCountTrigger,
228228
.l0_queue_stall_threshold = l0QueueStallThreshold,
229229
.use_btree = useBtree ? 1 : 0,
230-
.object_target_file_size = (size_t)objectTargetFileSize,
231230
.object_lazy_compaction = objectLazyCompaction ? 1 : 0,
232231
.object_prefetch_compaction = objectPrefetchCompaction ? 1 : 0};
233232

@@ -724,6 +723,27 @@ JNIEXPORT void JNICALL Java_com_tidesdb_Transaction_nativeDelete(JNIEnv *env, jc
724723
}
725724
}
726725

726+
JNIEXPORT void JNICALL Java_com_tidesdb_Transaction_nativeSingleDelete(JNIEnv *env, jclass cls,
727+
jlong handle,
728+
jlong cfHandle,
729+
jbyteArray key)
730+
{
731+
tidesdb_txn_t *txn = (tidesdb_txn_t *)(uintptr_t)handle;
732+
tidesdb_column_family_t *cf = (tidesdb_column_family_t *)(uintptr_t)cfHandle;
733+
734+
jsize keyLen = (*env)->GetArrayLength(env, key);
735+
jbyte *keyBytes = (*env)->GetByteArrayElements(env, key, NULL);
736+
737+
int result = tidesdb_txn_single_delete(txn, cf, (uint8_t *)keyBytes, keyLen);
738+
739+
(*env)->ReleaseByteArrayElements(env, key, keyBytes, JNI_ABORT);
740+
741+
if (result != TDB_SUCCESS)
742+
{
743+
throwTidesDBException(env, result, getErrorMessage(result));
744+
}
745+
}
746+
727747
JNIEXPORT void JNICALL Java_com_tidesdb_Transaction_nativeCommit(JNIEnv *env, jclass cls,
728748
jlong handle)
729749
{

src/main/java/com/tidesdb/ColumnFamily.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ public void syncWal() throws TidesDBException {
149149

150150
/**
151151
* Estimates the computational cost of iterating between two keys in this column family.
152-
* The returned value is an opaque double meaningful only for comparison with other
152+
* The returned value is an opaque double - meaningful only for comparison with other
153153
* values from the same method. Uses only in-memory metadata and performs no disk I/O.
154-
* Key order does not matter the method normalizes the range internally.
154+
* Key order does not matter - the method normalizes the range internally.
155155
*
156156
* @param keyA first key (bound of range)
157157
* @param keyB second key (bound of range)

src/main/java/com/tidesdb/ColumnFamilyConfig.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public class ColumnFamilyConfig {
4444
private int l1FileCountTrigger;
4545
private int l0QueueStallThreshold;
4646
private boolean useBtree;
47-
private long objectTargetFileSize;
4847
private boolean objectLazyCompaction;
4948
private boolean objectPrefetchCompaction;
5049

@@ -70,7 +69,6 @@ private ColumnFamilyConfig(Builder builder) {
7069
this.l1FileCountTrigger = builder.l1FileCountTrigger;
7170
this.l0QueueStallThreshold = builder.l0QueueStallThreshold;
7271
this.useBtree = builder.useBtree;
73-
this.objectTargetFileSize = builder.objectTargetFileSize;
7472
this.objectLazyCompaction = builder.objectLazyCompaction;
7573
this.objectPrefetchCompaction = builder.objectPrefetchCompaction;
7674
}
@@ -103,7 +101,6 @@ public static ColumnFamilyConfig defaultConfig() {
103101
.l1FileCountTrigger(4)
104102
.l0QueueStallThreshold(20)
105103
.useBtree(false)
106-
.objectTargetFileSize(0)
107104
.objectLazyCompaction(false)
108105
.objectPrefetchCompaction(true)
109106
.build();
@@ -139,7 +136,6 @@ public static Builder builder() {
139136
public int getL1FileCountTrigger() { return l1FileCountTrigger; }
140137
public int getL0QueueStallThreshold() { return l0QueueStallThreshold; }
141138
public boolean isUseBtree() { return useBtree; }
142-
public long getObjectTargetFileSize() { return objectTargetFileSize; }
143139
public boolean isObjectLazyCompaction() { return objectLazyCompaction; }
144140
public boolean isObjectPrefetchCompaction() { return objectPrefetchCompaction; }
145141

@@ -168,7 +164,6 @@ public static class Builder {
168164
private int l1FileCountTrigger = 4;
169165
private int l0QueueStallThreshold = 20;
170166
private boolean useBtree = false;
171-
private long objectTargetFileSize = 0;
172167
private boolean objectLazyCompaction = false;
173168
private boolean objectPrefetchCompaction = true;
174169

@@ -277,11 +272,6 @@ public Builder useBtree(boolean useBtree) {
277272
return this;
278273
}
279274

280-
public Builder objectTargetFileSize(long objectTargetFileSize) {
281-
this.objectTargetFileSize = objectTargetFileSize;
282-
return this;
283-
}
284-
285275
public Builder objectLazyCompaction(boolean objectLazyCompaction) {
286276
this.objectLazyCompaction = objectLazyCompaction;
287277
return this;

src/main/java/com/tidesdb/TidesDB.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ public void createColumnFamily(String name, ColumnFamilyConfig config) throws Ti
142142
config.getL1FileCountTrigger(),
143143
config.getL0QueueStallThreshold(),
144144
config.isUseBtree(),
145-
config.getObjectTargetFileSize(),
146145
config.isObjectLazyCompaction(),
147146
config.isObjectPrefetchCompaction()
148147
);
@@ -399,7 +398,7 @@ private static native void nativeCreateColumnFamily(long handle, String name,
399398
int syncMode, long syncIntervalUs, String comparatorName, int skipListMaxLevel,
400399
float skipListProbability, int defaultIsolationLevel, long minDiskSpace,
401400
int l1FileCountTrigger, int l0QueueStallThreshold, boolean useBtree,
402-
long objectTargetFileSize, boolean objectLazyCompaction,
401+
boolean objectLazyCompaction,
403402
boolean objectPrefetchCompaction) throws TidesDBException;
404403

405404
private static native void nativeDropColumnFamily(long handle, String name) throws TidesDBException;

src/main/java/com/tidesdb/Transaction.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,33 @@ public void delete(ColumnFamily cf, byte[] key) throws TidesDBException {
108108
}
109109
nativeDelete(nativeHandle, cf.getNativeHandle(), key);
110110
}
111-
111+
112+
/**
113+
* Writes a single-delete tombstone for a key. Has the same read semantics as
114+
* {@link #delete}, but lets compaction drop the put and tombstone together as
115+
* soon as both appear in the same merge input.
116+
*
117+
* Caller contract: between any two single-deletes on the same key (and from
118+
* the start of the key's history to its first single-delete) the key has been
119+
* put at most once. The engine cannot verify this; violating it can leave
120+
* older puts visible after the single-delete. Use only for workloads that
121+
* insert each key once and delete it once. When in doubt, prefer {@link #delete}.
122+
*
123+
* @param cf the column family
124+
* @param key the key
125+
* @throws TidesDBException if the single-delete fails
126+
*/
127+
public void singleDelete(ColumnFamily cf, byte[] key) throws TidesDBException {
128+
checkNotFreed();
129+
if (cf == null) {
130+
throw new IllegalArgumentException("Column family cannot be null");
131+
}
132+
if (key == null || key.length == 0) {
133+
throw new IllegalArgumentException("Key cannot be null");
134+
}
135+
nativeSingleDelete(nativeHandle, cf.getNativeHandle(), key);
136+
}
137+
112138
/**
113139
* Commits the transaction.
114140
*
@@ -234,6 +260,7 @@ long getNativeHandle() {
234260
private static native void nativePut(long handle, long cfHandle, byte[] key, byte[] value, long ttl) throws TidesDBException;
235261
private static native byte[] nativeGet(long handle, long cfHandle, byte[] key) throws TidesDBException;
236262
private static native void nativeDelete(long handle, long cfHandle, byte[] key) throws TidesDBException;
263+
private static native void nativeSingleDelete(long handle, long cfHandle, byte[] key) throws TidesDBException;
237264
private static native void nativeCommit(long handle) throws TidesDBException;
238265
private static native void nativeRollback(long handle) throws TidesDBException;
239266
private static native void nativeSavepoint(long handle, String name) throws TidesDBException;

src/test/java/com/tidesdb/TidesDBTest.java

Lines changed: 77 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ void testCommitHookClear() throws TidesDBException {
10241024
return 0;
10251025
});
10261026

1027-
// First commit hook should fire
1027+
// First commit - hook should fire
10281028
try (Transaction txn = db.beginTransaction()) {
10291029
txn.put(cf, "key1".getBytes(), "value1".getBytes());
10301030
txn.commit();
@@ -1034,7 +1034,7 @@ void testCommitHookClear() throws TidesDBException {
10341034
// Clear the hook
10351035
cf.clearCommitHook();
10361036

1037-
// Second commit hook should NOT fire
1037+
// Second commit - hook should NOT fire
10381038
try (Transaction txn = db.beginTransaction()) {
10391039
txn.put(cf, "key2".getBytes(), "value2".getBytes());
10401040
txn.commit();
@@ -1505,21 +1505,91 @@ void testTransactionResetNullIsolation() throws TidesDBException {
15051505
.blockCacheSize(64 * 1024 * 1024)
15061506
.maxOpenSSTables(256)
15071507
.build();
1508-
1508+
15091509
try (TidesDB db = TidesDB.open(config)) {
15101510
ColumnFamilyConfig cfConfig = ColumnFamilyConfig.defaultConfig();
15111511
db.createColumnFamily("test_cf", cfConfig);
1512-
1512+
15131513
ColumnFamily cf = db.getColumnFamily("test_cf");
1514-
1514+
15151515
Transaction txn = db.beginTransaction();
15161516
txn.put(cf, "key1".getBytes(), "value1".getBytes());
15171517
txn.commit();
1518-
1518+
15191519
// Null isolation level should throw IllegalArgumentException
15201520
assertThrows(IllegalArgumentException.class, () -> txn.reset(null));
1521-
1521+
15221522
txn.free();
15231523
}
15241524
}
1525+
1526+
@Test
1527+
@Order(42)
1528+
void testTransactionSingleDelete() throws TidesDBException {
1529+
Config config = Config.builder(tempDir.resolve("testdb_single_delete").toString())
1530+
.numFlushThreads(2)
1531+
.numCompactionThreads(2)
1532+
.logLevel(LogLevel.INFO)
1533+
.blockCacheSize(64 * 1024 * 1024)
1534+
.maxOpenSSTables(256)
1535+
.build();
1536+
1537+
try (TidesDB db = TidesDB.open(config)) {
1538+
ColumnFamilyConfig cfConfig = ColumnFamilyConfig.defaultConfig();
1539+
db.createColumnFamily("test_cf", cfConfig);
1540+
1541+
ColumnFamily cf = db.getColumnFamily("test_cf");
1542+
1543+
byte[] key = "single_key".getBytes(StandardCharsets.UTF_8);
1544+
byte[] value = "single_value".getBytes(StandardCharsets.UTF_8);
1545+
1546+
try (Transaction txn = db.beginTransaction()) {
1547+
txn.put(cf, key, value);
1548+
txn.commit();
1549+
}
1550+
1551+
try (Transaction txn = db.beginTransaction()) {
1552+
byte[] result = txn.get(cf, key);
1553+
assertNotNull(result);
1554+
assertArrayEquals(value, result);
1555+
}
1556+
1557+
try (Transaction txn = db.beginTransaction()) {
1558+
txn.singleDelete(cf, key);
1559+
txn.commit();
1560+
}
1561+
1562+
try (Transaction txn = db.beginTransaction()) {
1563+
assertThrows(TidesDBException.class, () -> txn.get(cf, key));
1564+
}
1565+
}
1566+
}
1567+
1568+
@Test
1569+
@Order(43)
1570+
void testTransactionSingleDeleteNullArgs() throws TidesDBException {
1571+
Config config = Config.builder(tempDir.resolve("testdb_single_delete_null").toString())
1572+
.numFlushThreads(2)
1573+
.numCompactionThreads(2)
1574+
.logLevel(LogLevel.INFO)
1575+
.blockCacheSize(64 * 1024 * 1024)
1576+
.maxOpenSSTables(256)
1577+
.build();
1578+
1579+
try (TidesDB db = TidesDB.open(config)) {
1580+
ColumnFamilyConfig cfConfig = ColumnFamilyConfig.defaultConfig();
1581+
db.createColumnFamily("test_cf", cfConfig);
1582+
1583+
ColumnFamily cf = db.getColumnFamily("test_cf");
1584+
1585+
try (Transaction txn = db.beginTransaction()) {
1586+
assertThrows(IllegalArgumentException.class,
1587+
() -> txn.singleDelete(null, "k".getBytes()));
1588+
assertThrows(IllegalArgumentException.class,
1589+
() -> txn.singleDelete(cf, null));
1590+
assertThrows(IllegalArgumentException.class,
1591+
() -> txn.singleDelete(cf, new byte[0]));
1592+
}
1593+
}
1594+
}
15251595
}

0 commit comments

Comments
 (0)