Skip to content

Commit 0b50d20

Browse files
committed
QFS java shim:
* Change qfs-access to use java 9 and later finalizer style APIs. * Retain compatibility with pre-java 9 versions by creating a new module qfs-access-pre-9 that uses the old finalizer style APIs. * Update the build scripts to include the new module. * Fix java 9 finalizer handling in qfs-access module.
1 parent b8a32d4 commit 0b50d20

File tree

18 files changed

+134
-96
lines changed

18 files changed

+134
-96
lines changed

src/java/javabuild.sh

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,25 @@ until javac --release $min_supported_release -version >/dev/null 2>&1; do
100100
fi
101101
min_supported_release=$(expr $min_supported_release + 1)
102102
done
103+
if [ x"${qfs_access_profile-}" = x ]; then
104+
if [ $min_supported_release -lt 9 ]; then
105+
qfs_access_profile="qfs_access_java_pre_9"
106+
else
107+
qfs_access_profile="qfs_access_java_9"
108+
fi
109+
fi
103110
min_supported_release=1.$min_supported_release
104111

105112
echo "qfs_release_version = $qfs_release_version"
106113
echo "qfs_source_revision = $qfs_source_revision"
107114
echo "hadoop_qfs_profile = $hadoop_qfs_profile"
108115
echo "test_build_data = $test_build_data"
116+
echo "qfs_access_profile = $qfs_access_profile"
117+
if [ x"$qfs_access_profile" = x'qfs_access_java_9' ]; then
118+
qfs_access_project='qfs-access'
119+
else
120+
qfs_access_project='qfs-access-pre-9'
121+
fi
109122

110123
run_maven_exit_if_success() {
111124
set -x
@@ -125,11 +138,13 @@ mytry=0
125138
while true; do
126139
if [ x"$1" = x'--' ]; then
127140
shift
128-
run_maven_exit_if_success ${1+"$@"}
141+
run_maven_exit_if_success -P "$qfs_access_profile" ${1+"$@"}
129142
elif [ x"$hadoop_qfs_profile" = x'none' ]; then
130-
run_maven_exit_if_success --projects qfs-access package
143+
run_maven_exit_if_success -P "$qfs_access_profile" \
144+
--projects "$qfs_access_project" package
131145
else
132-
run_maven_exit_if_success -P "$hadoop_qfs_profile" \
146+
run_maven_exit_if_success \
147+
-P "$hadoop_qfs_profile","$qfs_access_profile" \
133148
-Dhadoop.release.version="$1" package
134149
fi
135150
mytry=$(expr $mytry + 1)

src/java/pom.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ permissions and limitations under the License.
6060
</dependency>
6161
</dependencies>
6262
<modules>
63-
<module>qfs-access</module>
6463
<module>hadoop-qfs</module>
6564
</modules>
6665
<profiles>
@@ -70,5 +69,17 @@ permissions and limitations under the License.
7069
<module>hadoop-qfs-2</module>
7170
</modules>
7271
</profile>
72+
<profile>
73+
<id>qfs_access_java_pre_9</id>
74+
<modules>
75+
<module>qfs-access-pre-9</module>
76+
</modules>
77+
</profile>
78+
<profile>
79+
<id>qfs_access_java_9</id>
80+
<modules>
81+
<module>qfs-access</module>
82+
</modules>
83+
</profile>
7384
</profiles>
7485
</project>

src/java/qfs-access-pre-9/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../qfs-access/pom.xml
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../../../../qfs-access/src/main/java/com/quantcast/qfs/access/BufferPool.java

src/java/qfs-access-9/src/main/java/com/quantcast/qfs/access/KfsAccess.java renamed to src/java/qfs-access-pre-9/src/main/java/com/quantcast/qfs/access/KfsAccess.java

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,44 +22,29 @@
2222
* License for the specific language governing permissions and limitations under
2323
* the License.
2424
*
25-
* \brief QFS access java 9 style cleanup.
25+
* \brief Java wrappers to get to the KFS client.
2626
*/
2727
package com.quantcast.qfs.access;
2828

2929
import java.io.IOException;
30-
import java.lang.ref.Cleaner;
3130

3231
final public class KfsAccess extends KfsAccessBase {
3332

34-
private static Cleaner cleaner = Cleaner.create();
35-
36-
static Cleaner.Cleanable registerCleanup(Object obj, Runnable action) {
37-
return cleaner.register(obj, action);
38-
}
39-
40-
private static void registerCleanupSelf(KfsAccess ka) {
41-
// Ensure that the native resource is cleaned up when this object is
42-
// garbage collected.
43-
// Make sure that this and ka are not referenced by the cleaner closure
44-
// otherwise it will never be cleaned up.
45-
final long ptr = ka.getCPtr();
46-
registerCleanup(ka, () -> {
47-
destroy(ptr);
48-
});
49-
}
50-
51-
private void registerCleanupConstructed() {
52-
registerCleanupSelf(this);
53-
}
54-
5533
public KfsAccess(String configFn) throws IOException {
5634
super(configFn);
57-
registerCleanupConstructed();
5835
}
5936

6037
public KfsAccess(String metaServerHost,
6138
int metaServerPort) throws IOException {
6239
super(metaServerHost, metaServerPort);
63-
registerCleanupConstructed();
40+
}
41+
42+
@Override
43+
protected void finalize() throws Throwable {
44+
try {
45+
kfs_destroy();
46+
} finally {
47+
super.finalize();
48+
}
6449
}
6550
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../../../../qfs-access/src/main/java/com/quantcast/qfs/access/KfsAccessBase.java
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../../../../qfs-access/src/main/java/com/quantcast/qfs/access/KfsDelegation.java
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../../../../qfs-access/src/main/java/com/quantcast/qfs/access/KfsFileAttr.java
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/**
22
* $Id$
33
*
4-
* Created 2025/04/20
4+
* Created 2007/09/11
55
*
6-
* @author: Mike Ovsiannikov (Quantcast Corporation)
6+
* @author: Sriram Rao (Kosmix Corp.)
77
*
8-
* Copyright 2025 Quantcast Corporation. All rights reserved.
8+
* Copyright 2008-2012,2016 Quantcast Corporation. All rights reserved.
99
* Copyright 2007 Kosmix Corp.
1010
*
1111
* This file is part of Kosmos File System (KFS).
@@ -22,30 +22,24 @@
2222
* implied. See the License for the specific language governing
2323
* permissions and limitations under the License.
2424
*
25-
* \brief Input channel java 9 style cleanup.
25+
* \brief An input channel that does buffered I/O. This is to reduce
26+
* the overhead of JNI calls.
2627
*/
2728
package com.quantcast.qfs.access;
2829

29-
import java.lang.ref.Cleaner;
30-
30+
/* A byte channel interface with seek support */
3131
final public class KfsInputChannel extends KfsInputChannelBase {
3232

33-
final private Cleaner.Cleanable cleanable;
34-
3533
KfsInputChannel(KfsAccessBase ka, int fd) {
3634
super(ka, fd);
37-
cleanable = registerCleanup();
38-
}
39-
40-
private Cleaner.Cleanup registerCleanup() {
41-
return KfsAccess.registerCleanup(this, state);
4235
}
4336

44-
final public synchronized void close() throws IOException {
37+
@Override
38+
protected void finalize() throws Throwable {
4539
try {
46-
super.close();
40+
state.release();
4741
} finally {
48-
cleanable.clean();
42+
super.finalize();
4943
}
5044
}
5145
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../../../../qfs-access/src/main/java/com/quantcast/qfs/access/KfsInputChannelBase.java
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/**
22
* $Id$
33
*
4-
* Created 2025/04/20
4+
* Created 2007/09/11
55
*
6-
* @author: Mike Ovsiannikov (Quantcast Corporation)
6+
* @author: Sriram Rao (Kosmix Corp.)
77
*
8-
* Copyright 2025 Quantcast Corporation. All rights reserved.
8+
* Copyright 2008-2012,2016 Quantcast Corporation. All rights reserved.
99
* Copyright 2007 Kosmix Corp.
1010
*
1111
* This file is part of Kosmos File System (KFS).
@@ -22,30 +22,22 @@
2222
* implied. See the License for the specific language governing
2323
* permissions and limitations under the License.
2424
*
25-
* \brief Input channel java 9 style cleanup.
25+
* \brief An output channel pre java 9 style cleanup.
2626
*/
2727
package com.quantcast.qfs.access;
2828

29-
import java.lang.ref.Cleaner;
29+
public class KfsOutputChannel extends KfsOutputChannelBase {
3030

31-
final public class KfsOutputChannel extends KfsOutputChannelBase {
32-
33-
final private Cleaner.Cleanable cleanable;
34-
35-
KfsOutputChannel(KfsAccessBase ka, int fd) {
36-
super(ka, fd);
37-
cleanable = registerCleanup();
38-
}
39-
40-
private Cleaner.Cleanable registerCleanup() {
41-
return KfsAccess.registerCleanup(this, state);
31+
KfsOutputChannel(KfsAccessBase kfsAccess, int fd, boolean append) {
32+
super(kfsAccess, fd, append);
4233
}
4334

44-
public synchronized void close() throws IOException {
35+
@Override
36+
protected void finalize() throws Throwable {
4537
try {
46-
super.close();
38+
state.run();
4739
} finally {
48-
cleanable.clean();
40+
super.finalize();
4941
}
5042
}
5143
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../../../../qfs-access/src/main/java/com/quantcast/qfs/access/KfsOutputChannelBase.java
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../../../../qfs-access/src/main/java/com/quantcast/qfs/access/KfsTest.java
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../../../../qfs-access/src/main/java/com/quantcast/qfs/access/Positionable.java

src/java/qfs-access-pre-9/src/test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../qfs-access/src/test

src/java/qfs-access/src/main/java/com/quantcast/qfs/access/KfsAccess.java

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,44 @@
2222
* License for the specific language governing permissions and limitations under
2323
* the License.
2424
*
25-
* \brief Java wrappers to get to the KFS client.
25+
* \brief QFS access java 9 style cleanup.
2626
*/
2727
package com.quantcast.qfs.access;
2828

2929
import java.io.IOException;
30+
import java.lang.ref.Cleaner;
3031

3132
final public class KfsAccess extends KfsAccessBase {
3233

34+
private static Cleaner cleaner = Cleaner.create();
35+
36+
static Cleaner.Cleanable registerCleanup(Object obj, Runnable action) {
37+
return cleaner.register(obj, action);
38+
}
39+
40+
private static void registerCleanupSelf(KfsAccess ka) {
41+
// Ensure that the native resource is cleaned up when this object is
42+
// garbage collected.
43+
// Make sure that this and ka are not referenced by the cleaner closure
44+
// otherwise it will never be cleaned up.
45+
final long ptr = ka.getCPtr();
46+
registerCleanup(ka, () -> {
47+
destroy(ptr);
48+
});
49+
}
50+
51+
private void registerCleanupConstructed() {
52+
registerCleanupSelf(this);
53+
}
54+
3355
public KfsAccess(String configFn) throws IOException {
3456
super(configFn);
57+
registerCleanupConstructed();
3558
}
3659

3760
public KfsAccess(String metaServerHost,
38-
int metaServerPort) throws IOException {
61+
int metaServerPort) throws IOException {
3962
super(metaServerHost, metaServerPort);
40-
}
41-
42-
@Override
43-
protected void finalize() throws Throwable {
44-
try {
45-
kfs_destroy();
46-
} finally {
47-
super.finalize();
48-
}
63+
registerCleanupConstructed();
4964
}
5065
}
Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/**
22
* $Id$
33
*
4-
* Created 2007/09/11
4+
* Created 2025/04/20
55
*
6-
* @author: Sriram Rao (Kosmix Corp.)
6+
* @author: Mike Ovsiannikov (Quantcast Corporation)
77
*
8-
* Copyright 2008-2012,2016 Quantcast Corporation. All rights reserved.
8+
* Copyright 2025 Quantcast Corporation. All rights reserved.
99
* Copyright 2007 Kosmix Corp.
1010
*
1111
* This file is part of Kosmos File System (KFS).
@@ -22,24 +22,31 @@
2222
* implied. See the License for the specific language governing
2323
* permissions and limitations under the License.
2424
*
25-
* \brief An input channel that does buffered I/O. This is to reduce
26-
* the overhead of JNI calls.
25+
* \brief Input channel java 9 style cleanup.
2726
*/
2827
package com.quantcast.qfs.access;
2928

30-
/* A byte channel interface with seek support */
29+
import java.io.IOException;
30+
import java.lang.ref.Cleaner;
31+
3132
final public class KfsInputChannel extends KfsInputChannelBase {
3233

34+
final private Cleaner.Cleanable cleanable;
35+
3336
KfsInputChannel(KfsAccessBase ka, int fd) {
3437
super(ka, fd);
38+
cleanable = registerCleanup();
39+
}
40+
41+
private Cleaner.Cleanable registerCleanup() {
42+
return KfsAccess.registerCleanup(this, state);
3543
}
3644

37-
@Override
38-
protected void finalize() throws Throwable {
45+
final public synchronized void close() throws IOException {
3946
try {
40-
state.release();
47+
super.close();
4148
} finally {
42-
super.finalize();
49+
cleanable.clean();
4350
}
4451
}
4552
}

0 commit comments

Comments
 (0)