Is there a truncate function similar to posix truncate? HDFS now has some form of truncate, but I can't find a similar function in the MapRFS C API
Bgd Rdc: apologies for the delay. Has this been resolved?
No. I assumed there is no way to truncate currently. But I'm still interested to get any response on this. Is there a plan to add truncate or maybe there is now some undocumented way to do it? To be clear, by truncate I mean to truncate the file to an arbitrary size (not just 0 size).
Raghunadha Kondapalli Any comments? :-)
I ran into the same restriction , as far as I can see there is no way to do this currently. It was added to the HDFS interface circa 2.7.something.
FWIW My application truncates on file recovery after node failuer, and my work around in MapR has been to use seek instead of truncate, and just overwrite the garbage at the end of the file.
Ted Dunning Looking forward to your comments on the above observation from the user. Thank you.
One hacky way to do this is to seek to a particular offset and write 0 bytes. If writing zero bytes doesn't work, back up one byte before the end, read that byte, seek back and overwrite the byte with the same contents.
If truncating to zero length, simply opening for write should do the job.
Seek in include/hdfs/hdfs.h officially says that you can't seek a writable file, but that is likely only true for HDFS.
This doesn't count as an answer, of course, since it only suggests a solution that might work. But it might work.
Retrieving data ...