[
https://issues.apache.org/jira/browse/HDFS-7838?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14353421#comment-14353421
]
Colin Patrick McCabe commented on HDFS-7838:
--------------------------------------------
FileSystem.java says:
{code}
* @return <code>true</code> if the file has been truncated to the desired
* <code>newLength</code> and is immediately available to be reused for
* write operations such as <code>append</code>, or
* <code>false</code> if a background process of adjusting the length of
* the last block has been started, and clients should wait for it to
* complete before proceeding with further file updates.
*/
public boolean truncate(Path f, long newLength) throws IOException {
{code}
hdfs.h says:
{code}
403 * @return 0 if the file has been truncated to the desired
newlength
404 * and is immediately available to be reused for write
operations
405 * such as append.
406 * 1 if a background process of adjusting the length of the
last
407 * block has been started, and clients should wait for it to
408 * complete before proceeding with further file updates.
409 * -1 on error.
{code}
code says:
{code}
1063 jthr = invokeMethod(env, &jVal, INSTANCE, jFS, HADOOP_FS,
1064 "truncate", JMETHOD2(JPARAM(HADOOP_PATH), "J",
"Z"),
1065 jPath, newlength);
1066 destroyLocalReference(env, jPath);
1067 if (jthr) {
1068 errno = printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
1069 "hdfsTruncateFile(%s): FileSystem#truncate", path);
1070 return -1;
1071 }
1072 if (!jVal.z) {
1073 return 1;
1074 }
1075 return 0;
1076 }
{code}
It seems confusing to translate false => 1 and true => 0. I realize that
returning 0 on success is an old C convention, but both returns of truncate are
"successful". It seems a lot more intuitive to have true => 1, false => 0,
error => negative.
Also, this is a little pedantic, but please check against JNI_TRUE rather than
doing {{!jVal.z}} or similar.
bq. I file HDFS-7902 for \[libwebhdfs\], thanks.
Thanks for that. In the meantime, can you add a stub function to libwebhdfs
that does nothing but set errno to ENOTSUP and return -1? Thanks.
+1 once those are addressed.
> Expose truncate API for libhdfs
> -------------------------------
>
> Key: HDFS-7838
> URL: https://issues.apache.org/jira/browse/HDFS-7838
> Project: Hadoop HDFS
> Issue Type: Sub-task
> Components: datanode, namenode
> Affects Versions: 2.7.0
> Reporter: Yi Liu
> Assignee: Yi Liu
> Fix For: 2.7.0
>
> Attachments: HDFS-7838.001.patch, HDFS-7838.002.patch
>
>
> It's good to expose truncate in libhdfs.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)