Skip to content

Commit b745465

Browse files
committed
fix the problems after the feedback
1 parent 52b26e7 commit b745465

File tree

3 files changed

+25
-37
lines changed

3 files changed

+25
-37
lines changed

cpp/src/plasma/lib/java/org_apache_arrow_plasma_PlasmaClientJNI.cc

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@
3030

3131
#include "plasma/client.h"
3232

33-
const jsize LEN_OF_OBJECTID = sizeof(plasma::ObjectID) / sizeof(jbyte);
33+
const jsize OBJECT_ID_SIZE = sizeof(plasma::ObjectID) / sizeof(jbyte);
3434

3535
inline void jbyteArray_to_object_id(JNIEnv* env, jbyteArray a, plasma::ObjectID* oid) {
36-
env->GetByteArrayRegion(a, 0, LEN_OF_OBJECTID, reinterpret_cast<jbyte*>(oid));
36+
env->GetByteArrayRegion(a, 0, OBJECT_ID_SIZE, reinterpret_cast<jbyte*>(oid));
3737
}
3838

3939
inline void object_id_to_jbyteArray(JNIEnv* env, jbyteArray a, plasma::ObjectID* oid) {
40-
env->SetByteArrayRegion(a, 0, LEN_OF_OBJECTID, reinterpret_cast<jbyte*>(oid));
40+
env->SetByteArrayRegion(a, 0, OBJECT_ID_SIZE, reinterpret_cast<jbyte*>(oid));
4141
}
4242

4343
class JByteArrayGetter {
@@ -74,7 +74,7 @@ JNIEXPORT jlong JNICALL Java_org_apache_arrow_plasma_PlasmaClientJNI_connect(
7474

7575
JNIEXPORT void JNICALL Java_org_apache_arrow_plasma_PlasmaClientJNI_disconnect(
7676
JNIEnv* env, jclass cls, jlong conn) {
77-
plasma::PlasmaClient* client = (plasma::PlasmaClient*)conn;
77+
plasma::PlasmaClient* client = reinterpret_cast<plasma::PlasmaClient*>(conn);
7878

7979
ARROW_CHECK_OK(client->Disconnect());
8080
delete client;
@@ -84,7 +84,7 @@ JNIEXPORT void JNICALL Java_org_apache_arrow_plasma_PlasmaClientJNI_disconnect(
8484
JNIEXPORT jobject JNICALL Java_org_apache_arrow_plasma_PlasmaClientJNI_create(
8585
JNIEnv* env, jclass cls, jlong conn, jbyteArray object_id, jint size,
8686
jbyteArray metadata) {
87-
plasma::PlasmaClient* client = (plasma::PlasmaClient*)conn;
87+
plasma::PlasmaClient* client = reinterpret_cast<plasma::PlasmaClient*>(conn);
8888
plasma::ObjectID oid;
8989
jbyteArray_to_object_id(env, object_id, &oid);
9090

@@ -102,13 +102,13 @@ JNIEXPORT jobject JNICALL Java_org_apache_arrow_plasma_PlasmaClientJNI_create(
102102
std::shared_ptr<Buffer> data;
103103
Status s = client->Create(oid, size, md, md_size, &data);
104104
if (s.IsPlasmaObjectExists()) {
105-
jclass Exception = env->FindClass("org/ray/spi/impl/PlasmaObjectExistsException");
105+
jclass Exception = env->FindClass("java/lang/Exception");
106106
env->ThrowNew(Exception,
107107
"An object with this ID already exists in the plasma store.");
108108
return NULL;
109109
}
110110
if (s.IsPlasmaStoreFull()) {
111-
jclass Exception = env->FindClass("org/ray/spi/impl/PlasmaOutOfMemoryException");
111+
jclass Exception = env->FindClass("java/lang/Exception");
112112
env->ThrowNew(Exception,
113113
"The plasma store ran out of memory and could not create this object.");
114114
return NULL;
@@ -120,7 +120,7 @@ JNIEXPORT jobject JNICALL Java_org_apache_arrow_plasma_PlasmaClientJNI_create(
120120

121121
JNIEXPORT jbyteArray JNICALL Java_org_apache_arrow_plasma_PlasmaClientJNI_hash(
122122
JNIEnv* env, jclass cls, jlong conn, jbyteArray object_id) {
123-
plasma::PlasmaClient* client = (plasma::PlasmaClient*)conn;
123+
plasma::PlasmaClient* client = reinterpret_cast<plasma::PlasmaClient*>(conn);
124124
plasma::ObjectID oid;
125125
jbyteArray_to_object_id(env, object_id, &oid);
126126

@@ -139,7 +139,7 @@ JNIEXPORT jbyteArray JNICALL Java_org_apache_arrow_plasma_PlasmaClientJNI_hash(
139139

140140
JNIEXPORT void JNICALL Java_org_apache_arrow_plasma_PlasmaClientJNI_seal(
141141
JNIEnv* env, jclass cls, jlong conn, jbyteArray object_id) {
142-
plasma::PlasmaClient* client = (plasma::PlasmaClient*)conn;
142+
plasma::PlasmaClient* client = reinterpret_cast<plasma::PlasmaClient*>(conn);
143143
plasma::ObjectID oid;
144144
jbyteArray_to_object_id(env, object_id, &oid);
145145

@@ -148,7 +148,7 @@ JNIEXPORT void JNICALL Java_org_apache_arrow_plasma_PlasmaClientJNI_seal(
148148

149149
JNIEXPORT void JNICALL Java_org_apache_arrow_plasma_PlasmaClientJNI_release(
150150
JNIEnv* env, jclass cls, jlong conn, jbyteArray object_id) {
151-
plasma::PlasmaClient* client = (plasma::PlasmaClient*)conn;
151+
plasma::PlasmaClient* client = reinterpret_cast<plasma::PlasmaClient*>(conn);
152152
plasma::ObjectID oid;
153153
jbyteArray_to_object_id(env, object_id, &oid);
154154

@@ -157,13 +157,13 @@ JNIEXPORT void JNICALL Java_org_apache_arrow_plasma_PlasmaClientJNI_release(
157157

158158
JNIEXPORT jobjectArray JNICALL Java_org_apache_arrow_plasma_PlasmaClientJNI_get(
159159
JNIEnv* env, jclass cls, jlong conn, jobjectArray object_ids, jint timeout_ms) {
160-
plasma::PlasmaClient* client = (plasma::PlasmaClient*)conn;
160+
plasma::PlasmaClient* client = reinterpret_cast<plasma::PlasmaClient*>(conn);
161161

162162
jsize num_oids = env->GetArrayLength(object_ids);
163163
std::vector<plasma::ObjectID> oids(num_oids);
164164
std::vector<plasma::ObjectBuffer> obufs(num_oids);
165165
for (int i = 0; i < num_oids; ++i) {
166-
jbyteArray_to_object_id(env, (jbyteArray)env->GetObjectArrayElement(object_ids, i),
166+
jbyteArray_to_object_id(env, reinterpret_cast<jbyteArray>(env->GetObjectArrayElement(object_ids, i)),
167167
&oids[i]);
168168
}
169169
// TODO: may be blocked. consider to add the thread support
@@ -200,7 +200,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_apache_arrow_plasma_PlasmaClientJNI_get(
200200

201201
JNIEXPORT jboolean JNICALL Java_org_apache_arrow_plasma_PlasmaClientJNI_contains(
202202
JNIEnv* env, jclass cls, jlong conn, jbyteArray object_id) {
203-
plasma::PlasmaClient* client = (plasma::PlasmaClient*)conn;
203+
plasma::PlasmaClient* client = reinterpret_cast<plasma::PlasmaClient*>(conn);
204204
plasma::ObjectID oid;
205205
jbyteArray_to_object_id(env, object_id, &oid);
206206

@@ -216,20 +216,12 @@ JNIEXPORT jboolean JNICALL Java_org_apache_arrow_plasma_PlasmaClientJNI_contains
216216

217217
JNIEXPORT void JNICALL Java_org_apache_arrow_plasma_PlasmaClientJNI_fetch(
218218
JNIEnv* env, jclass cls, jlong conn, jobjectArray object_ids) {
219-
plasma::PlasmaClient* client = (plasma::PlasmaClient*)conn;
219+
plasma::PlasmaClient* client = reinterpret_cast<plasma::PlasmaClient*>(conn);
220220
jsize num_oids = env->GetArrayLength(object_ids);
221221

222-
/*
223-
if (!plasma_manager_is_connected(client)) {
224-
jclass Exception = env->FindClass("java/lang/RuntimeException");
225-
env->ThrowNew(Exception, "Not connected to the plasma manager.");
226-
return;
227-
}
228-
*/
229-
230222
std::vector<plasma::ObjectID> oids(num_oids);
231223
for (int i = 0; i < num_oids; ++i) {
232-
jbyteArray_to_object_id(env, (jbyteArray)env->GetObjectArrayElement(object_ids, i),
224+
jbyteArray_to_object_id(env, reinterpret_cast<jbyteArray>(env->GetObjectArrayElement(object_ids, i)),
233225
&oids[i]);
234226
}
235227

@@ -241,17 +233,9 @@ JNIEXPORT void JNICALL Java_org_apache_arrow_plasma_PlasmaClientJNI_fetch(
241233
JNIEXPORT jobjectArray JNICALL Java_org_apache_arrow_plasma_PlasmaClientJNI_wait(
242234
JNIEnv* env, jclass cls, jlong conn, jobjectArray object_ids, jint timeout_ms,
243235
jint num_returns) {
244-
plasma::PlasmaClient* client = (plasma::PlasmaClient*)conn;
236+
plasma::PlasmaClient* client = reinterpret_cast<plasma::PlasmaClient*>(conn);
245237
jsize num_oids = env->GetArrayLength(object_ids);
246238

247-
/*
248-
if (!plasma_manager_is_connected(client)) {
249-
jclass Exception = env->FindClass("java/lang/RuntimeException");
250-
env->ThrowNew(Exception, "Not connected to the plasma manager.");
251-
return NULL;
252-
}
253-
*/
254-
255239
if (num_returns < 0) {
256240
jclass Exception = env->FindClass("java/lang/RuntimeException");
257241
env->ThrowNew(Exception, "The argument num_returns cannot be less than zero.");
@@ -267,15 +251,15 @@ JNIEXPORT jobjectArray JNICALL Java_org_apache_arrow_plasma_PlasmaClientJNI_wait
267251
std::vector<plasma::ObjectRequest> oreqs(num_oids);
268252

269253
for (int i = 0; i < num_oids; ++i) {
270-
jbyteArray_to_object_id(env, (jbyteArray)env->GetObjectArrayElement(object_ids, i),
254+
jbyteArray_to_object_id(env, reinterpret_cast<jbyteArray>(env->GetObjectArrayElement(object_ids, i)),
271255
&oreqs[i].object_id);
272256
oreqs[i].type = plasma::PLASMA_QUERY_ANYWHERE;
273257
}
274258

275259
int num_return_objects;
276260
// TODO: may be blocked. consider to add the thread support
277261
ARROW_CHECK_OK(client->Wait(static_cast<int>(num_oids), oreqs.data(), num_returns,
278-
(uint64_t)timeout_ms, &num_return_objects));
262+
static_cast<uint64_t>(timeout_ms), &num_return_objects));
279263

280264
int num_to_return = std::min(num_return_objects, num_returns);
281265
jclass clsByteArray = env->FindClass("[B");
@@ -290,7 +274,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_apache_arrow_plasma_PlasmaClientJNI_wait
290274

291275
if (oreqs[i].status == plasma::ObjectStatusLocal ||
292276
oreqs[i].status == plasma::ObjectStatusRemote) {
293-
oid = env->NewByteArray(LEN_OF_OBJECTID);
277+
oid = env->NewByteArray(OBJECT_ID_SIZE);
294278
object_id_to_jbyteArray(env, oid, &oreqs[i].object_id);
295279
env->SetObjectArrayElement(ret, num_returned, oid);
296280
num_returned++;
@@ -305,7 +289,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_apache_arrow_plasma_PlasmaClientJNI_wait
305289

306290
JNIEXPORT jlong JNICALL Java_org_apache_arrow_plasma_PlasmaClientJNI_evict(
307291
JNIEnv* env, jclass cls, jlong conn, jlong num_bytes) {
308-
plasma::PlasmaClient* client = (plasma::PlasmaClient*)conn;
292+
plasma::PlasmaClient* client = reinterpret_cast<plasma::PlasmaClient*>(conn);
309293

310294
int64_t evicted_bytes;
311295
ARROW_CHECK_OK(client->Evict((int64_t)num_bytes, evicted_bytes));

java/plasma/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ Install:
2929
## Build the jar of plasma client
3030

3131
```
32-
mvn clean install -Dmaven.test.skip
32+
cd ..
33+
mvn clean install -pl plasma -am -Dmaven.test.skip
3334
```
3435

3536
## Building and running tests

java/plasma/src/test/java/org/apache/arrow/plasma/PlasmaClientTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ public void doTest() {
143143
assert Arrays.equals(values.get(0), value1);
144144
assert Arrays.equals(values.get(1), value2);
145145
System.out.println("Plasma java client get multi-object test success.");
146+
pLink.put(id1, value1, null);
147+
System.out.println("Plasma java client put same object twice exception test success.");
148+
146149
cleanup();
147150
System.out.println("All test success.");
148151

0 commit comments

Comments
 (0)