Skip to content

Commit ade6975

Browse files
committed
Add WaitForCompactions Java API
1 parent a9906f0 commit ade6975

2 files changed

Lines changed: 314 additions & 0 deletions

File tree

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2+
// This source code is licensed under both the GPLv2 (found in the
3+
// COPYING file in the root directory) and Apache 2.0 License
4+
// (found in the LICENSE.Apache file in the root directory).
5+
//
6+
// This file implements the "bridge" between Java and C++ for
7+
// ROCKSDB_NAMESPACE::WaitForCompactOptions.
8+
9+
#include <jni.h>
10+
11+
#include "include/org_rocksdb_WaitForCompactOptions.h"
12+
#include "rocksdb/options.h"
13+
#include "rocksjni/cplusplus_to_java_convert.h"
14+
#include "rocksjni/portal.h"
15+
16+
/*
17+
* Class: org_rocksdb_WaitForCompactOptions
18+
* Method: newWaitForCompactOptions
19+
* Signature: ()J
20+
*/
21+
jlong Java_org_rocksdb_WaitForCompactOptions_newWaitForCompactOptions(JNIEnv*,
22+
jclass) {
23+
auto* wait_for_compact_opts =
24+
new ROCKSDB_NAMESPACE::WaitForCompactOptions();
25+
return GET_CPLUSPLUS_POINTER(wait_for_compact_opts);
26+
}
27+
28+
/*
29+
* Class: org_rocksdb_WaitForCompactOptions
30+
* Method: setAbortOnPause
31+
* Signature: (JZ)V
32+
*/
33+
void Java_org_rocksdb_WaitForCompactOptions_setAbortOnPause(
34+
JNIEnv*, jclass, jlong jhandle, jboolean jabort_on_pause) {
35+
auto* wait_for_compact_opts =
36+
reinterpret_cast<ROCKSDB_NAMESPACE::WaitForCompactOptions*>(jhandle);
37+
wait_for_compact_opts->abort_on_pause = jabort_on_pause;
38+
}
39+
40+
/*
41+
* Class: org_rocksdb_WaitForCompactOptions
42+
* Method: abortOnPause
43+
* Signature: (J)Z
44+
*/
45+
jboolean Java_org_rocksdb_WaitForCompactOptions_abortOnPause(JNIEnv*, jclass,
46+
jlong jhandle) {
47+
auto* wait_for_compact_opts =
48+
reinterpret_cast<ROCKSDB_NAMESPACE::WaitForCompactOptions*>(jhandle);
49+
return static_cast<jboolean>(wait_for_compact_opts->abort_on_pause);
50+
}
51+
52+
/*
53+
* Class: org_rocksdb_WaitForCompactOptions
54+
* Method: setFlush
55+
* Signature: (JZ)V
56+
*/
57+
void Java_org_rocksdb_WaitForCompactOptions_setFlush(JNIEnv*, jclass,
58+
jlong jhandle,
59+
jboolean jflush) {
60+
auto* wait_for_compact_opts =
61+
reinterpret_cast<ROCKSDB_NAMESPACE::WaitForCompactOptions*>(jhandle);
62+
wait_for_compact_opts->flush = jflush;
63+
}
64+
65+
/*
66+
* Class: org_rocksdb_WaitForCompactOptions
67+
* Method: flush
68+
* Signature: (J)Z
69+
*/
70+
jboolean Java_org_rocksdb_WaitForCompactOptions_flush(JNIEnv*, jclass,
71+
jlong jhandle) {
72+
auto* wait_for_compact_opts =
73+
reinterpret_cast<ROCKSDB_NAMESPACE::WaitForCompactOptions*>(jhandle);
74+
return static_cast<jboolean>(wait_for_compact_opts->flush);
75+
}
76+
77+
/*
78+
* Class: org_rocksdb_WaitForCompactOptions
79+
* Method: setWaitForPurge
80+
* Signature: (JZ)V
81+
*/
82+
void Java_org_rocksdb_WaitForCompactOptions_setWaitForPurge(
83+
JNIEnv*, jclass, jlong jhandle, jboolean jwait_for_purge) {
84+
auto* wait_for_compact_opts =
85+
reinterpret_cast<ROCKSDB_NAMESPACE::WaitForCompactOptions*>(jhandle);
86+
wait_for_compact_opts->wait_for_purge = jwait_for_purge;
87+
}
88+
89+
/*
90+
* Class: org_rocksdb_WaitForCompactOptions
91+
* Method: waitForPurge
92+
* Signature: (J)Z
93+
*/
94+
jboolean Java_org_rocksdb_WaitForCompactOptions_waitForPurge(JNIEnv*, jclass,
95+
jlong jhandle) {
96+
auto* wait_for_compact_opts =
97+
reinterpret_cast<ROCKSDB_NAMESPACE::WaitForCompactOptions*>(jhandle);
98+
return static_cast<jboolean>(wait_for_compact_opts->wait_for_purge);
99+
}
100+
101+
/*
102+
* Class: org_rocksdb_WaitForCompactOptions
103+
* Method: setCloseDb
104+
* Signature: (JZ)V
105+
*/
106+
void Java_org_rocksdb_WaitForCompactOptions_setCloseDb(JNIEnv*, jclass,
107+
jlong jhandle,
108+
jboolean jclose_db) {
109+
auto* wait_for_compact_opts =
110+
reinterpret_cast<ROCKSDB_NAMESPACE::WaitForCompactOptions*>(jhandle);
111+
wait_for_compact_opts->close_db = jclose_db;
112+
}
113+
114+
/*
115+
* Class: org_rocksdb_WaitForCompactOptions
116+
* Method: closeDb
117+
* Signature: (J)Z
118+
*/
119+
jboolean Java_org_rocksdb_WaitForCompactOptions_closeDb(JNIEnv*, jclass,
120+
jlong jhandle) {
121+
auto* wait_for_compact_opts =
122+
reinterpret_cast<ROCKSDB_NAMESPACE::WaitForCompactOptions*>(jhandle);
123+
return static_cast<jboolean>(wait_for_compact_opts->close_db);
124+
}
125+
126+
/*
127+
* Class: org_rocksdb_WaitForCompactOptions
128+
* Method: setTimeout
129+
* Signature: (JJ)V
130+
*/
131+
void Java_org_rocksdb_WaitForCompactOptions_setTimeout(
132+
JNIEnv*, jclass, jlong jhandle, jlong jtimeout_micros) {
133+
auto* wait_for_compact_opts =
134+
reinterpret_cast<ROCKSDB_NAMESPACE::WaitForCompactOptions*>(jhandle);
135+
wait_for_compact_opts->timeout =
136+
std::chrono::microseconds(jtimeout_micros);
137+
}
138+
139+
/*
140+
* Class: org_rocksdb_WaitForCompactOptions
141+
* Method: timeout
142+
* Signature: (J)J
143+
*/
144+
jlong Java_org_rocksdb_WaitForCompactOptions_timeout(JNIEnv*, jclass,
145+
jlong jhandle) {
146+
auto* wait_for_compact_opts =
147+
reinterpret_cast<ROCKSDB_NAMESPACE::WaitForCompactOptions*>(jhandle);
148+
return static_cast<jlong>(wait_for_compact_opts->timeout.count());
149+
}
150+
151+
/*
152+
* Class: org_rocksdb_WaitForCompactOptions
153+
* Method: disposeInternalJni
154+
* Signature: (J)V
155+
*/
156+
void Java_org_rocksdb_WaitForCompactOptions_disposeInternalJni(JNIEnv*,
157+
jclass,
158+
jlong jhandle) {
159+
auto* wait_for_compact_opts =
160+
reinterpret_cast<ROCKSDB_NAMESPACE::WaitForCompactOptions*>(jhandle);
161+
assert(wait_for_compact_opts != nullptr);
162+
delete wait_for_compact_opts;
163+
}
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2+
// This source code is licensed under both the GPLv2 (found in the
3+
// COPYING file in the root directory) and Apache 2.0 License
4+
// (found in the LICENSE.Apache file in the root directory).
5+
6+
package org.rocksdb;
7+
8+
/**
9+
* WaitForCompactOptions is used to configure the behavior of
10+
* {@link RocksDB#waitForCompact(WaitForCompactOptions)}.
11+
* It allows waiting for flush and compaction operations to complete
12+
* with optional timeout and abort-on-pause settings.
13+
*/
14+
public class WaitForCompactOptions extends RocksObject {
15+
16+
/**
17+
* Creates a new WaitForCompactOptions with default settings.
18+
* <p>
19+
* Default values:
20+
* - abortOnPause: false
21+
* - flush: false
22+
* - waitForPurge: false
23+
* - closeDb: false
24+
* - timeout: 0 (no timeout)
25+
*/
26+
public WaitForCompactOptions() {
27+
super(newWaitForCompactOptions());
28+
}
29+
30+
/**
31+
* Sets whether to abort waiting when background work is paused.
32+
*
33+
* @param abortOnPause if true, waiting will be aborted if background
34+
* work is paused via PauseBackgroundWork()
35+
* @return this WaitForCompactOptions instance
36+
*/
37+
public WaitForCompactOptions setAbortOnPause(final boolean abortOnPause) {
38+
setAbortOnPause(nativeHandle_, abortOnPause);
39+
return this;
40+
}
41+
42+
/**
43+
* Returns whether abort-on-pause is enabled.
44+
*
45+
* @return true if abort-on-pause is enabled
46+
*/
47+
public boolean abortOnPause() {
48+
return abortOnPause(nativeHandle_);
49+
}
50+
51+
/**
52+
* Sets whether to wait for flush operations to complete in addition
53+
* to compaction operations.
54+
*
55+
* @param flush if true, also waits for flush operations
56+
* @return this WaitForCompactOptions instance
57+
*/
58+
public WaitForCompactOptions setFlush(final boolean flush) {
59+
setFlush(nativeHandle_, flush);
60+
return this;
61+
}
62+
63+
/**
64+
* Returns whether waiting for flush is enabled.
65+
*
66+
* @return true if waiting for flush is enabled
67+
*/
68+
public boolean flush() {
69+
return flush(nativeHandle_);
70+
}
71+
72+
/**
73+
* Sets whether to wait for purge to complete.
74+
*
75+
* @param waitForPurge if true, wait for purge to complete
76+
* @return this WaitForCompactOptions instance
77+
*/
78+
public WaitForCompactOptions setWaitForPurge(final boolean waitForPurge) {
79+
setWaitForPurge(nativeHandle_, waitForPurge);
80+
return this;
81+
}
82+
83+
/**
84+
* Returns whether waiting for purge is enabled.
85+
*
86+
* @return true if waiting for purge is enabled
87+
*/
88+
public boolean waitForPurge() {
89+
return waitForPurge(nativeHandle_);
90+
}
91+
92+
/**
93+
* Sets whether to call Close() after waiting is done.
94+
* By the time Close() is called here, there should be no background jobs
95+
* in progress and no new background jobs should be added.
96+
*
97+
* @param closeDb if true, close the database after waiting
98+
* @return this WaitForCompactOptions instance
99+
*/
100+
public WaitForCompactOptions setCloseDb(final boolean closeDb) {
101+
setCloseDb(nativeHandle_, closeDb);
102+
return this;
103+
}
104+
105+
/**
106+
* Returns whether the database will be closed after waiting.
107+
*
108+
* @return true if close is enabled
109+
*/
110+
public boolean closeDb() {
111+
return closeDb(nativeHandle_);
112+
}
113+
114+
/**
115+
* Sets a timeout for waiting.
116+
*
117+
* @param timeoutMicros timeout in microseconds. 0 means no timeout.
118+
* @return this WaitForCompactOptions instance
119+
*/
120+
public WaitForCompactOptions setTimeout(final long timeoutMicros) {
121+
setTimeout(nativeHandle_, timeoutMicros);
122+
return this;
123+
}
124+
125+
/**
126+
* Returns the timeout setting in microseconds.
127+
*
128+
* @return timeout in microseconds, 0 if no timeout
129+
*/
130+
public long timeout() {
131+
return timeout(nativeHandle_);
132+
}
133+
134+
@Override
135+
protected final void disposeInternal(final long handle) {
136+
disposeInternalJni(handle);
137+
}
138+
139+
private static native long newWaitForCompactOptions();
140+
private static native void setAbortOnPause(final long handle, final boolean abortOnPause);
141+
private static native boolean abortOnPause(final long handle);
142+
private static native void setFlush(final long handle, final boolean flush);
143+
private static native boolean flush(final long handle);
144+
private static native void setWaitForPurge(final long handle, final boolean waitForPurge);
145+
private static native boolean waitForPurge(final long handle);
146+
private static native void setCloseDb(final long handle, final boolean closeDb);
147+
private static native boolean closeDb(final long handle);
148+
private static native void setTimeout(final long handle, final long timeoutMicros);
149+
private static native long timeout(final long handle);
150+
private static native void disposeInternalJni(final long handle);
151+
}

0 commit comments

Comments
 (0)