You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2015/03/29 22:03:11 UTC
[1/2] mesos git commit: Fix memory corruption in AbstractState JNI
bindings. MESOS-2161.
Repository: mesos
Updated Branches:
refs/heads/master 4809d161e -> 5d0b5fdb5
Fix memory corruption in AbstractState JNI bindings. MESOS-2161.
Review: https://reviews.apache.org/r/32152
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/5d0b5fdb
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/5d0b5fdb
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/5d0b5fdb
Branch: refs/heads/master
Commit: 5d0b5fdb5d8d78b44537cb01916263a3769b5d7d
Parents: 9706bb0
Author: Joris Van Remoortere <jo...@gmail.com>
Authored: Sun Mar 29 12:20:24 2015 -0700
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Sun Mar 29 12:44:36 2015 -0700
----------------------------------------------------------------------
.../org_apache_mesos_state_AbstractState.cpp | 514 +++++++++++++++++++
.../org/apache/mesos/state/AbstractState.java | 165 +++++-
2 files changed, 678 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/5d0b5fdb/src/java/jni/org_apache_mesos_state_AbstractState.cpp
----------------------------------------------------------------------
diff --git a/src/java/jni/org_apache_mesos_state_AbstractState.cpp b/src/java/jni/org_apache_mesos_state_AbstractState.cpp
index 1accc8a..2be377c 100644
--- a/src/java/jni/org_apache_mesos_state_AbstractState.cpp
+++ b/src/java/jni/org_apache_mesos_state_AbstractState.cpp
@@ -23,6 +23,16 @@ using std::string;
extern "C" {
+// TODO(jmlvanre): Deprecate the JNI functions that are in the AbstractState
+// scope that we have replaced with the ones in the names classes 'FetchFuture',
+// 'StoreFuture', 'ExpungeFuture', and 'NamesFuture'. (MESOS-2161). The
+// anonymous futures that used these function accidentally captured the 'thiz'
+// for the 'AbstractState' class, which was not intended and caused the C++
+// Future to be prematurely deleted as a result of the anonymous Future getting
+// garbaged collected by the JVM and invoking the finalizer which deleted the
+// C++ Future. The intent was to capture the 'thiz' for the 'Future'. This is
+// done correctly by using the named inner classes.
+
/*
* Class: org_apache_mesos_state_AbstractState
* Method: finalize
@@ -228,6 +238,132 @@ JNIEXPORT void JNICALL Java_org_apache_mesos_state_AbstractState__1_1fetch_1fina
/*
+ * Class: org_apache_mesos_state_AbstractState$FetchFuture
+ * Method: cancel
+ * Signature: (Z)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_mesos_state_AbstractState_00024FetchFuture_cancel
+ (JNIEnv* env, jobject thiz, jboolean mayInterruptIfRunning)
+{
+ if (mayInterruptIfRunning) {
+ static jclass clazz = (jclass)env->NewGlobalRef(env->GetObjectClass(thiz));
+ static jfieldID field = env->GetFieldID(clazz, "future", "J");
+ jlong jfuture = env->GetLongField(thiz, field);
+
+ // See TODO at top of file for why we proxy this call.
+ return Java_org_apache_mesos_state_AbstractState__1_1fetch_1cancel(
+ env,
+ thiz,
+ jfuture);
+ }
+
+ return false; // Should not interrupt and already running (or finished).
+}
+
+
+/*
+ * Class: org_apache_mesos_state_AbstractState$FetchFuture
+ * Method: is_cancelled
+ * Signature: ()Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_mesos_state_AbstractState_00024FetchFuture_is_1cancelled
+ (JNIEnv* env, jobject thiz)
+{
+ static jclass clazz = (jclass)env->NewGlobalRef(env->GetObjectClass(thiz));
+ static jfieldID field = env->GetFieldID(clazz, "future", "J");
+ jlong jfuture = env->GetLongField(thiz, field);
+
+ // See TODO at top of file for why we proxy this call.
+ return Java_org_apache_mesos_state_AbstractState__1_1fetch_1is_1cancelled(
+ env,
+ thiz,
+ jfuture);
+}
+
+
+/*
+ * Class: org_apache_mesos_state_AbstractState$FetchFuture
+ * Method: is_done
+ * Signature: ()Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_mesos_state_AbstractState_00024FetchFuture_is_1done
+ (JNIEnv* env, jobject thiz)
+{
+ static jclass clazz = (jclass)env->NewGlobalRef(env->GetObjectClass(thiz));
+ static jfieldID field = env->GetFieldID(clazz, "future", "J");
+ jlong jfuture = env->GetLongField(thiz, field);
+
+ // See TODO at top of file for why we proxy this call.
+ return Java_org_apache_mesos_state_AbstractState__1_1fetch_1is_1done(
+ env,
+ thiz,
+ jfuture);
+}
+
+
+/*
+ * Class: org_apache_mesos_state_AbstractState$FetchFuture
+ * Method: get
+ * Signature: ()Lorg/apache/mesos/state/Variable;
+ */
+JNIEXPORT jobject JNICALL Java_org_apache_mesos_state_AbstractState_00024FetchFuture_get
+ (JNIEnv* env, jobject thiz)
+{
+ static jclass clazz = (jclass)env->NewGlobalRef(env->GetObjectClass(thiz));
+ static jfieldID field = env->GetFieldID(clazz, "future", "J");
+ jlong jfuture = env->GetLongField(thiz, field);
+
+ // See TODO at top of file for why we proxy this call.
+ return Java_org_apache_mesos_state_AbstractState__1_1fetch_1get(
+ env,
+ thiz,
+ jfuture);
+}
+
+
+/*
+ * Class: org_apache_mesos_state_AbstractState$FetchFuture
+ * Method: get_timeout
+ * Signature: (JLjava/util/concurrent/TimeUnit;)Lorg/apache/mesos/state/Variable;
+ */
+JNIEXPORT jobject JNICALL Java_org_apache_mesos_state_AbstractState_00024FetchFuture_get_1timeout
+ (JNIEnv* env, jobject thiz, jlong jtimeout, jobject junit)
+{
+ static jclass clazz = (jclass)env->NewGlobalRef(env->GetObjectClass(thiz));
+ static jfieldID field = env->GetFieldID(clazz, "future", "J");
+ jlong jfuture = env->GetLongField(thiz, field);
+
+ // See TODO at top of file for why we proxy this call.
+ return Java_org_apache_mesos_state_AbstractState__1_1fetch_1get_1timeout(
+ env,
+ thiz,
+ jfuture,
+ jtimeout,
+ junit);
+}
+
+
+/*
+ * Class: org_apache_mesos_state_AbstractState$FetchFuture
+ * Method: finalize
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_org_apache_mesos_state_AbstractState_00024FetchFuture_finalize
+ (JNIEnv* env, jobject thiz)
+{
+ static jclass clazz = (jclass)env->NewGlobalRef(env->GetObjectClass(thiz));
+ static jfieldID field = env->GetFieldID(clazz, "future", "J");
+ jlong jfuture = env->GetLongField(thiz, field);
+
+ // See TODO at top of file for why we proxy this call.
+ Java_org_apache_mesos_state_AbstractState__1_1fetch_1finalize(
+ env,
+ thiz,
+ jfuture);
+}
+
+
+/*
* Class: org_apache_mesos_state_AbstractState
* Method: __store
* Signature: (Lorg/apache/mesos/state/Variable;)J
@@ -422,6 +558,132 @@ JNIEXPORT void JNICALL Java_org_apache_mesos_state_AbstractState__1_1store_1fina
/*
+ * Class: org_apache_mesos_state_AbstractState$StoreFuture
+ * Method: cancel
+ * Signature: (Z)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_mesos_state_AbstractState_00024StoreFuture_cancel
+ (JNIEnv* env, jobject thiz, jboolean mayInterruptIfRunning)
+{
+ if (mayInterruptIfRunning) {
+ static jclass clazz = (jclass)env->NewGlobalRef(env->GetObjectClass(thiz));
+ static jfieldID field = env->GetFieldID(clazz, "future", "J");
+ jlong jfuture = env->GetLongField(thiz, field);
+
+ // See TODO at top of file for why we proxy this call.
+ return Java_org_apache_mesos_state_AbstractState__1_1store_1cancel(
+ env,
+ thiz,
+ jfuture);
+ }
+
+ return false; // Should not interrupt and already running (or finished).
+}
+
+
+/*
+ * Class: org_apache_mesos_state_AbstractState$StoreFuture
+ * Method: is_cancelled
+ * Signature: ()Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_mesos_state_AbstractState_00024StoreFuture_is_1cancelled
+ (JNIEnv* env, jobject thiz)
+{
+ static jclass clazz = (jclass)env->NewGlobalRef(env->GetObjectClass(thiz));
+ static jfieldID field = env->GetFieldID(clazz, "future", "J");
+ jlong jfuture = env->GetLongField(thiz, field);
+
+ // See TODO at top of file for why we proxy this call.
+ return Java_org_apache_mesos_state_AbstractState__1_1store_1is_1cancelled(
+ env,
+ thiz,
+ jfuture);
+}
+
+
+/*
+ * Class: org_apache_mesos_state_AbstractState$StoreFuture
+ * Method: is_done
+ * Signature: ()Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_mesos_state_AbstractState_00024StoreFuture_is_1done
+ (JNIEnv* env, jobject thiz)
+{
+ static jclass clazz = (jclass)env->NewGlobalRef(env->GetObjectClass(thiz));
+ static jfieldID field = env->GetFieldID(clazz, "future", "J");
+ jlong jfuture = env->GetLongField(thiz, field);
+
+ // See TODO at top of file for why we proxy this call.
+ return Java_org_apache_mesos_state_AbstractState__1_1store_1is_1done(
+ env,
+ thiz,
+ jfuture);
+}
+
+
+/*
+ * Class: org_apache_mesos_state_AbstractState$StoreFuture
+ * Method: get
+ * Signature: ()Lorg/apache/mesos/state/Variable;
+ */
+JNIEXPORT jobject JNICALL Java_org_apache_mesos_state_AbstractState_00024StoreFuture_get
+ (JNIEnv* env, jobject thiz)
+{
+ static jclass clazz = (jclass)env->NewGlobalRef(env->GetObjectClass(thiz));
+ static jfieldID field = env->GetFieldID(clazz, "future", "J");
+ jlong jfuture = env->GetLongField(thiz, field);
+
+ // See TODO at top of file for why we proxy this call.
+ return Java_org_apache_mesos_state_AbstractState__1_1store_1get(
+ env,
+ thiz,
+ jfuture);
+}
+
+
+/*
+ * Class: org_apache_mesos_state_AbstractState$StoreFuture
+ * Method: get_timeout
+ * Signature: (JLjava/util/concurrent/TimeUnit;)Lorg/apache/mesos/state/Variable;
+ */
+JNIEXPORT jobject JNICALL Java_org_apache_mesos_state_AbstractState_00024StoreFuture_get_1timeout
+ (JNIEnv* env, jobject thiz, jlong jtimeout, jobject junit)
+{
+ static jclass clazz = (jclass)env->NewGlobalRef(env->GetObjectClass(thiz));
+ static jfieldID field = env->GetFieldID(clazz, "future", "J");
+ jlong jfuture = env->GetLongField(thiz, field);
+
+ // See TODO at top of file for why we proxy this call.
+ return Java_org_apache_mesos_state_AbstractState__1_1store_1get_1timeout(
+ env,
+ thiz,
+ jfuture,
+ jtimeout,
+ junit);
+}
+
+
+/*
+ * Class: org_apache_mesos_state_AbstractState$StoreFuture
+ * Method: finalize
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_org_apache_mesos_state_AbstractState_00024StoreFuture_finalize
+ (JNIEnv* env, jobject thiz)
+{
+ static jclass clazz = (jclass)env->NewGlobalRef(env->GetObjectClass(thiz));
+ static jfieldID field = env->GetFieldID(clazz, "future", "J");
+ jlong jfuture = env->GetLongField(thiz, field);
+
+ // See TODO at top of file for why we proxy this call.
+ Java_org_apache_mesos_state_AbstractState__1_1store_1finalize(
+ env,
+ thiz,
+ jfuture);
+}
+
+
+/*
* Class: org_apache_mesos_state_AbstractState
* Method: __expunge
* Signature: (Lorg/apache/mesos/state/Variable;)J
@@ -601,6 +863,132 @@ JNIEXPORT void JNICALL Java_org_apache_mesos_state_AbstractState__1_1expunge_1fi
/*
+ * Class: org_apache_mesos_state_AbstractState$ExpungeFuture
+ * Method: cancel
+ * Signature: (Z)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_mesos_state_AbstractState_00024ExpungeFuture_cancel
+ (JNIEnv* env, jobject thiz, jboolean mayInterruptIfRunning)
+{
+ if (mayInterruptIfRunning) {
+ static jclass clazz = (jclass)env->NewGlobalRef(env->GetObjectClass(thiz));
+ static jfieldID field = env->GetFieldID(clazz, "future", "J");
+ jlong jfuture = env->GetLongField(thiz, field);
+
+ // See TODO at top of file for why we proxy this call.
+ return Java_org_apache_mesos_state_AbstractState__1_1expunge_1cancel(
+ env,
+ thiz,
+ jfuture);
+ }
+
+ return false; // Should not interrupt and already running (or finished).
+}
+
+
+/*
+ * Class: org_apache_mesos_state_AbstractState$ExpungeFuture
+ * Method: is_cancelled
+ * Signature: ()Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_mesos_state_AbstractState_00024ExpungeFuture_is_1cancelled
+ (JNIEnv* env, jobject thiz)
+{
+ static jclass clazz = (jclass)env->NewGlobalRef(env->GetObjectClass(thiz));
+ static jfieldID field = env->GetFieldID(clazz, "future", "J");
+ jlong jfuture = env->GetLongField(thiz, field);
+
+ // See TODO at top of file for why we proxy this call.
+ return Java_org_apache_mesos_state_AbstractState__1_1expunge_1is_1cancelled(
+ env,
+ thiz,
+ jfuture);
+}
+
+
+/*
+ * Class: org_apache_mesos_state_AbstractState$ExpungeFuture
+ * Method: is_done
+ * Signature: ()Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_mesos_state_AbstractState_00024ExpungeFuture_is_1done
+ (JNIEnv* env, jobject thiz)
+{
+ static jclass clazz = (jclass)env->NewGlobalRef(env->GetObjectClass(thiz));
+ static jfieldID field = env->GetFieldID(clazz, "future", "J");
+ jlong jfuture = env->GetLongField(thiz, field);
+
+ // See TODO at top of file for why we proxy this call.
+ return Java_org_apache_mesos_state_AbstractState__1_1expunge_1is_1done(
+ env,
+ thiz,
+ jfuture);
+}
+
+
+/*
+ * Class: org_apache_mesos_state_AbstractState$ExpungeFuture
+ * Method: __get
+ * Signature: ()Ljava/lang/Boolean;
+ */
+JNIEXPORT jobject JNICALL Java_org_apache_mesos_state_AbstractState_00024ExpungeFuture_get
+ (JNIEnv* env, jobject thiz)
+{
+ static jclass clazz = (jclass)env->NewGlobalRef(env->GetObjectClass(thiz));
+ static jfieldID field = env->GetFieldID(clazz, "future", "J");
+ jlong jfuture = env->GetLongField(thiz, field);
+
+ // See TODO at top of file for why we proxy this call.
+ return Java_org_apache_mesos_state_AbstractState__1_1expunge_1get(
+ env,
+ thiz,
+ jfuture);
+}
+
+
+/*
+ * Class: org_apache_mesos_state_AbstractState$ExpungeFuture
+ * Method: get_timeout
+ * Signature: (JLjava/util/concurrent/TimeUnit;)Ljava/lang/Boolean;
+ */
+JNIEXPORT jobject JNICALL Java_org_apache_mesos_state_AbstractState_00024ExpungeFuture_get_1timeout
+ (JNIEnv* env, jobject thiz, jlong jtimeout, jobject junit)
+{
+ static jclass clazz = (jclass)env->NewGlobalRef(env->GetObjectClass(thiz));
+ static jfieldID field = env->GetFieldID(clazz, "future", "J");
+ jlong jfuture = env->GetLongField(thiz, field);
+
+ // See TODO at top of file for why we proxy this call.
+ return Java_org_apache_mesos_state_AbstractState__1_1expunge_1get_1timeout(
+ env,
+ thiz,
+ jfuture,
+ jtimeout,
+ junit);
+}
+
+
+/*
+ * Class: org_apache_mesos_state_AbstractState$ExpungeFuture
+ * Method: finalize
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_org_apache_mesos_state_AbstractState_00024ExpungeFuture_finalize
+ (JNIEnv* env, jobject thiz)
+{
+ static jclass clazz = (jclass)env->NewGlobalRef(env->GetObjectClass(thiz));
+ static jfieldID field = env->GetFieldID(clazz, "future", "J");
+ jlong jfuture = env->GetLongField(thiz, field);
+
+ // See TODO at top of file for why we proxy this call.
+ Java_org_apache_mesos_state_AbstractState__1_1expunge_1finalize(
+ env,
+ thiz,
+ jfuture);
+}
+
+
+/*
* Class: org_apache_mesos_state_AbstractState
* Method: __names
* Signature: ()J
@@ -792,4 +1180,130 @@ JNIEXPORT void JNICALL Java_org_apache_mesos_state_AbstractState__1_1names_1fina
delete future;
}
+
+/*
+ * Class: org_apache_mesos_state_AbstractState$NamesFuture
+ * Method: cancel
+ * Signature: (Z)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_mesos_state_AbstractState_00024NamesFuture_cancel
+ (JNIEnv* env, jobject thiz, jboolean mayInterruptIfRunning)
+{
+ if (mayInterruptIfRunning) {
+ static jclass clazz = (jclass)env->NewGlobalRef(env->GetObjectClass(thiz));
+ static jfieldID field = env->GetFieldID(clazz, "future", "J");
+ jlong jfuture = env->GetLongField(thiz, field);
+
+ // See TODO at top of file for why we proxy this call.
+ return Java_org_apache_mesos_state_AbstractState__1_1names_1cancel(
+ env,
+ thiz,
+ jfuture);
+ }
+
+ return false; // Should not interrupt and already running (or finished).
+}
+
+
+/*
+ * Class: org_apache_mesos_state_AbstractState$NamesFuture
+ * Method: is_cancelled
+ * Signature: (J)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_mesos_state_AbstractState_00024NamesFuture_is_1cancelled
+ (JNIEnv* env, jobject thiz)
+{
+ static jclass clazz = (jclass)env->NewGlobalRef(env->GetObjectClass(thiz));
+ static jfieldID field = env->GetFieldID(clazz, "future", "J");
+ jlong jfuture = env->GetLongField(thiz, field);
+
+ // See TODO at top of file for why we proxy this call.
+ return Java_org_apache_mesos_state_AbstractState__1_1names_1is_1cancelled(
+ env,
+ thiz,
+ jfuture);
+}
+
+
+/*
+ * Class: org_apache_mesos_state_AbstractState$NamesFuture
+ * Method: is_done
+ * Signature: ()Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_mesos_state_AbstractState_00024NamesFuture_is_1done
+ (JNIEnv* env, jobject thiz)
+{
+ static jclass clazz = (jclass)env->NewGlobalRef(env->GetObjectClass(thiz));
+ static jfieldID field = env->GetFieldID(clazz, "future", "J");
+ jlong jfuture = env->GetLongField(thiz, field);
+
+ // See TODO at top of file for why we proxy this call.
+ return Java_org_apache_mesos_state_AbstractState__1_1names_1is_1done(
+ env,
+ thiz,
+ jfuture);
+}
+
+
+/*
+ * Class: org_apache_mesos_state_AbstractState$NamesFuture
+ * Method: get
+ * Signature: ()Ljava/util/Iterator;
+ */
+JNIEXPORT jobject JNICALL Java_org_apache_mesos_state_AbstractState_00024NamesFuture_get
+ (JNIEnv* env, jobject thiz)
+{
+ static jclass clazz = (jclass)env->NewGlobalRef(env->GetObjectClass(thiz));
+ static jfieldID field = env->GetFieldID(clazz, "future", "J");
+ jlong jfuture = env->GetLongField(thiz, field);
+
+ // See TODO at top of file for why we proxy this call.
+ return Java_org_apache_mesos_state_AbstractState__1_1names_1get(
+ env,
+ thiz,
+ jfuture);
+}
+
+
+/*
+ * Class: org_apache_mesos_state_AbstractState$NamesFuture
+ * Method: get_timeout
+ * Signature: (JLjava/util/concurrent/TimeUnit;)Ljava/util/Iterator;
+ */
+JNIEXPORT jobject JNICALL Java_org_apache_mesos_state_AbstractState_00024NamesFuture_get_1timeout
+ (JNIEnv* env, jobject thiz, jlong jtimeout, jobject junit)
+{
+ static jclass clazz = (jclass)env->NewGlobalRef(env->GetObjectClass(thiz));
+ static jfieldID field = env->GetFieldID(clazz, "future", "J");
+ jlong jfuture = env->GetLongField(thiz, field);
+
+ // See TODO at top of file for why we proxy this call.
+ return Java_org_apache_mesos_state_AbstractState__1_1names_1get_1timeout(
+ env,
+ thiz,
+ jfuture,
+ jtimeout,
+ junit);
+}
+
+
+/*
+ * Class: org_apache_mesos_state_AbstractState$NamesFuture
+ * Method: finalize
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_org_apache_mesos_state_AbstractState_00024NamesFuture_finalize
+ (JNIEnv* env, jobject thiz)
+{
+ static jclass clazz = (jclass)env->NewGlobalRef(env->GetObjectClass(thiz));
+ static jfieldID field = env->GetFieldID(clazz, "future", "J");
+ jlong jfuture = env->GetLongField(thiz, field);
+
+ // See TODO at top of file for why we proxy this call.
+ Java_org_apache_mesos_state_AbstractState__1_1names_1finalize(
+ env,
+ thiz,
+ jfuture);
+}
+
} // extern "C" {
http://git-wip-us.apache.org/repos/asf/mesos/blob/5d0b5fdb/src/java/src/org/apache/mesos/state/AbstractState.java
----------------------------------------------------------------------
diff --git a/src/java/src/org/apache/mesos/state/AbstractState.java b/src/java/src/org/apache/mesos/state/AbstractState.java
index c66bf05..6514954 100644
--- a/src/java/src/org/apache/mesos/state/AbstractState.java
+++ b/src/java/src/org/apache/mesos/state/AbstractState.java
@@ -38,6 +38,11 @@ public abstract class AbstractState implements State {
@Override
public Future<Variable> fetch(final String name) {
+ if (!MesosNativeLibrary.version().before(MESOS_2161_JIRA_FIX_VERSION)) {
+ return new FetchFuture(name);
+ }
+
+ // TODO(jmlvanre): Deprecate anonymous future in 0.24 (MESOS-2161).
final long future = __fetch(name); // Asynchronously start the operation.
return new Future<Variable>() {
@Override
@@ -78,6 +83,11 @@ public abstract class AbstractState implements State {
@Override
public Future<Variable> store(Variable variable) {
+ if (!MesosNativeLibrary.version().before(MESOS_2161_JIRA_FIX_VERSION)) {
+ return new StoreFuture(variable);
+ }
+
+ // TODO(jmlvanre): Deprecate anonymous future in 0.24 (MESOS-2161).
final long future = __store(variable); // Asynchronously start the operation.
return new Future<Variable>() {
@Override
@@ -118,6 +128,11 @@ public abstract class AbstractState implements State {
@Override
public Future<Boolean> expunge(Variable variable) {
+ if (!MesosNativeLibrary.version().before(MESOS_2161_JIRA_FIX_VERSION)) {
+ return new ExpungeFuture(variable);
+ }
+
+ // TODO(jmlvanre): Deprecate anonymous future in 0.24 (MESOS-2161).
final long future = __expunge(variable); // Asynchronously start the operation.
return new Future<Boolean>() {
@Override
@@ -157,6 +172,11 @@ public abstract class AbstractState implements State {
}
public Future<Iterator<String>> names() {
+ if (!MesosNativeLibrary.version().before(MESOS_2161_JIRA_FIX_VERSION)) {
+ return new NamesFuture();
+ }
+
+ // TODO(jmlvanre): Deprecate anonymous future in 0.24 (MESOS-2161).
final long future = __names(); // Asynchronously start the operation.
return new Future<Iterator<String>>() {
@Override
@@ -198,8 +218,46 @@ public abstract class AbstractState implements State {
protected native void finalize();
- // Native implementations of 'fetch', 'store', 'expunge', and 'names'.
+ // Native implementations of 'fetch', 'store', 'expunge', and 'names'. We wrap
+ // them in classes to carry the java references correctly through the JNI
+ // bindings (MESOS-2161). The native functions in AbstractState will be
+ // deprecated in 0.24.
+
+ private class FetchFuture implements Future<Variable> {
+
+ public FetchFuture(String name) {
+ future = __fetch(name);
+ }
+
+ @Override
+ public native boolean cancel(boolean mayInterruptIfRunning);
+
+ @Override
+ public native boolean isCancelled();
+
+ @Override
+ public native boolean isDone();
+
+ @Override
+ public native Variable get()
+ throws InterruptedException, ExecutionException;
+
+ @Override
+ public native Variable get(long timeout, TimeUnit unit)
+ throws InterruptedException, ExecutionException, TimeoutException;
+
+ @Override
+ protected native void finalize();
+
+ private long future;
+ }
+
private native long __fetch(String name);
+
+ // TODO(jmlvanre): Deprecate below functions in 0.24 because we can't track
+ // the java object references correctly. (MESOS-2161). The above 'FetchFuture'
+ // class fixes this bug. We leave the below functions for backwards
+ // compatibility.
private native boolean __fetch_cancel(long future);
private native boolean __fetch_is_cancelled(long future);
private native boolean __fetch_is_done(long future);
@@ -208,7 +266,41 @@ public abstract class AbstractState implements State {
long future, long timeout, TimeUnit unit);
private native void __fetch_finalize(long future);
+ private class StoreFuture implements Future<Variable> {
+
+ public StoreFuture(Variable variable) {
+ future = __store(variable);
+ }
+
+ @Override
+ public native boolean cancel(boolean mayInterruptIfRunning);
+
+ @Override
+ public native boolean isCancelled();
+
+ @Override
+ public native boolean isDone();
+
+ @Override
+ public native Variable get()
+ throws InterruptedException, ExecutionException;
+
+ @Override
+ public native Variable get(long timeout, TimeUnit unit)
+ throws InterruptedException, ExecutionException, TimeoutException;
+
+ @Override
+ protected native void finalize();
+
+ private long future;
+ }
+
private native long __store(Variable variable);
+
+ // TODO(jmlvanre): Deprecate below functions in 0.24 because we can't track
+ // the java object references correctly. (MESOS-2161). The above 'StoreFuture'
+ // class fixes this bug. We leave the below functions for backwards
+ // compatibility.
private native boolean __store_cancel(long future);
private native boolean __store_is_cancelled(long future);
private native boolean __store_is_done(long future);
@@ -217,7 +309,41 @@ public abstract class AbstractState implements State {
long future, long timeout, TimeUnit unit);
private native void __store_finalize(long future);
+ private class ExpungeFuture implements Future<Boolean> {
+
+ public ExpungeFuture(Variable variable) {
+ future = __expunge(variable);
+ }
+
+ @Override
+ public native boolean cancel(boolean mayInterruptIfRunning);
+
+ @Override
+ public native boolean isCancelled();
+
+ @Override
+ public native boolean isDone();
+
+ @Override
+ public native Boolean get()
+ throws InterruptedException, ExecutionException;
+
+ @Override
+ public native Boolean get(long timeout, TimeUnit unit)
+ throws InterruptedException, ExecutionException, TimeoutException;
+
+ @Override
+ protected native void finalize();
+
+ private long future;
+ }
+
private native long __expunge(Variable variable);
+
+ // TODO(jmlvanre): Deprecate below functions in 0.24 because we can't track
+ // the java object references correctly. (MESOS-2161). The above
+ // 'ExpungeFuture' class fixes this bug. We leave the below functions for
+ // backwards compatibility.
private native boolean __expunge_cancel(long future);
private native boolean __expunge_is_cancelled(long future);
private native boolean __expunge_is_done(long future);
@@ -226,7 +352,41 @@ public abstract class AbstractState implements State {
long future, long timeout, TimeUnit unit);
private native void __expunge_finalize(long future);
+ private class NamesFuture implements Future<Iterator<String>> {
+
+ public NamesFuture() {
+ future = __names();
+ }
+
+ @Override
+ public native boolean cancel(boolean mayInterruptIfRunning);
+
+ @Override
+ public native boolean isCancelled();
+
+ @Override
+ public native boolean isDone();
+
+ @Override
+ public native Iterator<String> get()
+ throws InterruptedException, ExecutionException;
+
+ @Override
+ public native Iterator<String> get(long timeout, TimeUnit unit)
+ throws InterruptedException, ExecutionException, TimeoutException;
+
+ @Override
+ protected native void finalize();
+
+ private long future;
+ }
+
private native long __names();
+
+ // TODO(jmlvanre): Deprecate below functions in 0.24 because we can't track
+ // the java object references correctly. (MESOS-2161). The above 'NamesFuture'
+ // class fixes this bug. We leave the below functions for backwards
+ // compatibility.
private native boolean __names_cancel(long future);
private native boolean __names_is_cancelled(long future);
private native boolean __names_is_done(long future);
@@ -237,4 +397,7 @@ public abstract class AbstractState implements State {
private long __storage;
private long __state;
+
+ private final static MesosNativeLibrary.Version MESOS_2161_JIRA_FIX_VERSION =
+ new MesosNativeLibrary.Version(0, 22, 1);
}
[2/2] mesos git commit: Add MESOS_{MAJOR|MINOR|PATCH}_VERSION.
Posted by be...@apache.org.
Add MESOS_{MAJOR|MINOR|PATCH}_VERSION.
Also exposed the library version to Java via MesosNativeLibrary.
Review: https://reviews.apache.org/r/32151
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/9706bb0e
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/9706bb0e
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/9706bb0e
Branch: refs/heads/master
Commit: 9706bb0e4f36120f5882f7cfa091251f6fcbc234
Parents: 4809d16
Author: Joris Van Remoortere <jo...@gmail.com>
Authored: Sun Mar 29 11:54:00 2015 -0700
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Sun Mar 29 12:44:36 2015 -0700
----------------------------------------------------------------------
configure.ac | 14 ++
include/mesos/version.hpp.in | 6 +-
src/Makefile.am | 1 +
.../org/apache/mesos/MesosNativeLibrary.java.in | 158 ++++++++++++++++++-
.../jni/org_apache_mesos_MesosNativeLibrary.cpp | 26 +++
5 files changed, 203 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/9706bb0e/configure.ac
----------------------------------------------------------------------
diff --git a/configure.ac b/configure.ac
index 9b2d7f1..868c041 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1319,4 +1319,18 @@ AM_CONDITIONAL([WITHOUT_PYTHON_DEPS],
AM_CONDITIONAL([GIT_REPO], [test -d ${srcdir}"/.git"])
+# Provide more granular version numbers based on the version string,
+# using the format MAJOR.MINOR.PATCH[-SUFFIX], where SUFFIX can itself
+# contain dashes.
+#
+# NOTE: This definition must not be named such that it conflicts with
+# existing definitions, e.g., 'version', 'ver'.
+m4_define([major_minor_patch],
+ m4_split(m4_translit(AC_PACKAGE_VERSION, [-], [.]), [\.]))
+
+AC_SUBST(MESOS_MAJOR_VERSION, m4_car(major_minor_patch))
+AC_SUBST(MESOS_MINOR_VERSION, m4_car(m4_shift(major_minor_patch)))
+AC_SUBST(MESOS_PATCH_VERSION, m4_car(m4_shift2(major_minor_patch)))
+
+
AC_OUTPUT
http://git-wip-us.apache.org/repos/asf/mesos/blob/9706bb0e/include/mesos/version.hpp.in
----------------------------------------------------------------------
diff --git a/include/mesos/version.hpp.in b/include/mesos/version.hpp.in
index 524cebc..c8fbc82 100644
--- a/include/mesos/version.hpp.in
+++ b/include/mesos/version.hpp.in
@@ -21,6 +21,10 @@
#define MESOS_VERSION "@PACKAGE_VERSION@"
-// TODO(benh): MESOS_MAJOR_VERSION, MESOS_MINOR_VERSION, MESOS_PATCH_VERSION.
+#define MESOS_MAJOR_VERSION "@MESOS_MAJOR_VERSION@"
+
+#define MESOS_MINOR_VERSION "@MESOS_MINOR_VERSION@"
+
+#define MESOS_PATCH_VERSION "@MESOS_PATCH_VERSION@"
#endif // __MESOS_VERSION_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/9706bb0e/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index 9ce85a6..56ed9d9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -966,6 +966,7 @@ libjava_la_SOURCES = \
java/jni/construct.cpp \
java/jni/construct.hpp \
java/jni/org_apache_mesos_Log.cpp \
+ java/jni/org_apache_mesos_MesosNativeLibrary.cpp \
java/jni/org_apache_mesos_MesosSchedulerDriver.cpp \
java/jni/org_apache_mesos_MesosExecutorDriver.cpp \
java/jni/org_apache_mesos_state_AbstractState.cpp \
http://git-wip-us.apache.org/repos/asf/mesos/blob/9706bb0e/src/java/generated/org/apache/mesos/MesosNativeLibrary.java.in
----------------------------------------------------------------------
diff --git a/src/java/generated/org/apache/mesos/MesosNativeLibrary.java.in b/src/java/generated/org/apache/mesos/MesosNativeLibrary.java.in
index 668647f..c54d903 100644
--- a/src/java/generated/org/apache/mesos/MesosNativeLibrary.java.in
+++ b/src/java/generated/org/apache/mesos/MesosNativeLibrary.java.in
@@ -20,11 +20,116 @@ package org.apache.mesos;
public class MesosNativeLibrary {
/**
+ * Represent a 'libmesos' version with Major, Minor, and Patch versions. We
+ * use a class here to make it easier to do version compatibility checking.
+ * For example:
+ * static Version BugFixVersion = new Version(0, 22, 1);
+ * public static void myFunction() {
+ * if (version().compareTo(BugFixVersion) >= 0) {
+ * // New behavior with bug fix.
+ * } else {
+ * // Old behavior for backwards compatibility.
+ * }
+ * }
+ */
+ public static class Version implements Comparable<Version> {
+ public Version(long major, long minor, long patch) {
+ if (major < 0) {
+ throw new IllegalArgumentException(
+ "Major version must not be negative");
+ }
+
+ if (minor < 0) {
+ throw new IllegalArgumentException(
+ "Minor version must not be negative");
+ }
+
+ if (patch < 0) {
+ throw new IllegalArgumentException(
+ "Patch version must not be negative");
+ }
+
+ this.major = major;
+ this.minor = minor;
+ this.patch = patch;
+ }
+
+ public Version(long major, long minor) {
+ this(major, minor, 0);
+ }
+
+ public Version(long major) {
+ this(major, 0, 0);
+ }
+
+ public boolean equals(Version other) {
+ return other != null &&
+ major == other.major &&
+ minor == other.minor &&
+ patch == other.patch;
+ }
+
+ /**
+ * Compare this version to an 'other' one. The comparison is done
+ * lexicographically. This returns -1 if this version is 'lesser' than the
+ * other, 0 if they are equivalent, and 1 if this version is 'greater'.
+ */
+ @Override
+ public int compareTo(Version other) {
+ if (other == null) {
+ throw new IllegalArgumentException("other Version must not be null");
+ }
+
+ if (major < other.major) {
+ return -1;
+ } else if (major > other.major) {
+ return 1;
+ }
+
+ if (minor < other.minor) {
+ return -1;
+ } else if (minor > other.minor) {
+ return 1;
+ }
+
+ if (patch < other.patch) {
+ return -1;
+ } else if (patch > other.patch) {
+ return 1;
+ }
+
+ return 0;
+ }
+
+ /**
+ * A helper that is easier to use than 'compareTo', this returns
+ * true if 'this' version is strictly 'less than', not 'less than
+ * or equal to' the 'other' version.
+ */
+ public boolean before(Version other) {
+ return this.compareTo(other) < 0;
+ }
+
+ /**
+ * A helper that is easier to use than 'compareTo', this returns
+ * true if 'this' version is strictly 'greater than', not 'greater
+ * than or equal to' the 'other' version.
+ */
+ public boolean after(Version other) {
+ return this.compareTo(other) > 0;
+ }
+
+ public final long major;
+ public final long minor;
+ public final long patch;
+ }
+
+ /**
* Attempts to load the native library (if it was not previously loaded)
* from the given path. If the path is null 'java.library.path' is used to
* load the library.
*/
- public static void load(String path) {
+ public static synchronized void load(String path) {
// Our JNI library will actually set 'loaded' to true once it is
// loaded, that way the library can get loaded by a user via
// 'System.load' in the event that they want to specify an
@@ -79,7 +184,58 @@ public class MesosNativeLibrary {
load(path);
}
+ /**
+ * Returns the version of the native loaded library, or throws a
+ * runtime exception if the library is not loaded. This was
+ * introduced in MESOS 0.22.1. Any version prior to that will be
+ * 0.0.0. This means you should not make version specific decision
+ * before the 0.22.1 version boundary. For example, if you found a
+ * bug that was fixed in 0.19.0, you will *not* be able to perform
+ * the following check correctly:
+ *
+ * if (version().before(new Version(0, 19, 0))) {
+ * ...
+ * }
+ *
+ * This predicate will return true for all versions up until 0.22.1.
+ */
+ public static synchronized Version version() {
+ // Since we allow 'load' to be called with a parameter, we can not load on
+ // behalf of the user here. Instead, we throw an exception if the library
+ // has not been loaded.
+ if (!loaded) {
+ throw new RuntimeException("'libmesos' not loaded");
+ }
+
+ if (version == null) {
+ // Try to load the libmesos version identifier. If we get an
+ // 'UnsatisfiedLinkError' then this means we are loading a 'libmesos' with
+ // a version prior to 0.22.1, which is when the 'MAJOR', 'MINOR', and
+ // 'PATCH' version identifiers were introduced.
+ try {
+ version = _version();
+ } catch (UnsatisfiedLinkError error) {
+ System.err.println(
+ "WARNING: using an old version of 'libmesos'" +
+ " without proper version information: " + error.getMessage());
+
+ // If we're using a version of 'libmesos' less than 0.22.1, then we set
+ // the version to 0.0.0.
+ version = new Version(0, 0, 0);
+ }
+ }
+
+ return version;
+ }
+
public static final String VERSION = "@PACKAGE_VERSION@";
+ private static Version version = null;
+
private static boolean loaded = false;
+
+ /**
+ * Native implementation of 'libmesos' version identifier function.
+ */
+ private static native Version _version();
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/9706bb0e/src/java/jni/org_apache_mesos_MesosNativeLibrary.cpp
----------------------------------------------------------------------
diff --git a/src/java/jni/org_apache_mesos_MesosNativeLibrary.cpp b/src/java/jni/org_apache_mesos_MesosNativeLibrary.cpp
new file mode 100644
index 0000000..39e342f
--- /dev/null
+++ b/src/java/jni/org_apache_mesos_MesosNativeLibrary.cpp
@@ -0,0 +1,26 @@
+#include <jni.h>
+
+#include <mesos/version.hpp>
+
+extern "C" {
+
+/*
+ * Class: org_apache_mesos_MesosNativeLibrary
+ * Method: version
+ * Signature: ()Lorg/apache/mesos/MesosNativeLibrary$Version;
+ */
+JNIEXPORT jobject JNICALL Java_org_apache_mesos_MesosNativeLibrary__1version
+ (JNIEnv* env)
+{
+ jclass clazz = env->FindClass("org/apache/mesos/MesosNativeLibrary$Version");
+ jmethodID _init_ = env->GetMethodID(clazz, "<init>", "(JJJ)V");
+ jobject jversion = env->NewObject(
+ clazz,
+ _init_,
+ (jlong) MESOS_MAJOR_VERSION,
+ (jlong) MESOS_MINOR_VERSION,
+ (jlong) MESOS_PATCH_VERSION);
+ return jversion;
+}
+
+} // extern "C" {
\ No newline at end of file