views:

77

answers:

4

Hi.

Is there a good way to detect that particular disk went offline on server on Linux, via Java?

I have an application, that due to performance reasons, writes to all disks directly (without any RAID in middle).

I need to detect if Linux would unmount any disk due to disk crash during run-time, so I would stop using it. The problem is that each mount has a root directory, so without proper detection, the application will just fill-up the root partition.

Will appreciate any advice on this.

+3  A: 

In Linux, everything is accessible through text files. I don't really understand what is the exact information you require, but check /proc/diskstat, /proc/mounts, /proc/mdstat (for raids), etc...

And (sorry I really need to make this remark) why the hell would you be concerned about speed when coding in Java. That's like trying to pimp your old 486 so it will run the best it can :-D

Let_Me_Be
Sorry as well, but I really need to comment on your remark ;-) It seems that you havent used much of Java recently ... IO performances can be pretty amazing now ...
Guillaume
+1 Reading proc is the unix way to do this.
Zoe Gagnon
@Guillaume Well, pretty amazing is obviously not enough for the OP. He is trying to do a micro optimization (several percent tops), why not use raw system calls and C then?
Let_Me_Be
@SyBer u can also use df command to know disk space occupied.
Suresh S
@Let_Me_Be : I am resisting very hard to go down the flamewar path ... Anyway, you can argue both ways in comparisons of perfs between C and Java ... so let's try to forget it and hope that the OP actually needs those micro optimisations ...
Guillaume
@Guillaume Actually I was talking more about direct system calls (although I guess you can do that in Java as well) not language vs. language.
Let_Me_Be
I'm using pure Java to write to disks, which indeed as Guillaume said, improved significantly and provides very descent performance. The reason of why I'm bringing the speed, is because there are no HW raid planned for the target machines (due to several reasons), and from our benchmarks, the software raid is pretty slow for heavy duty writing. Hence we coding our way around by spreading data over several disks, and it works quite fine, just need this bit of detection working.
SyBer
Checking the proc looks like the way to go, thanks!
SyBer
It's a religious issue, let's move on. http://www.jargondb.org/glossary/religious-issues
Alan Krueger
+1  A: 

I don't have any experience with this so there might be a better way, but one option would be to run commands like mount directly from Java and read the output. See: http://download.oracle.com/javase/1.5.0/docs/api/java/lang/ProcessBuilder.html

Plaudit Design - Web Design
+2  A: 

If it's for linux only, you can read and parse /proc/mounts and check for that directory there.

krico
+1  A: 

As anyone with sysadmin experience could tell you, disks crashing or otherwise going away has a nasty habit of making any process that touches anything under the mountpoint wait in uninterruptible sleep. Additionally, in my experience, this can include things like trying to read /proc/mounts, or running the 'df' command.

My recommendation would be to use RAID, and if necessary, invest your way out of the problem. Say, if performance is limited by small random writes, a RAID card with a battery backed write cache can do wonders.

janneb
Thanks for advice, unfortunately not using RAID was one of "strategic" decisions taken early in development :).
SyBer