cvsimport
[beagle.git] / beagled / Lucene.Net / upstream-changes / 15_lock-timeout-verbose.patch
blob4b0f35334970787f5f639800e30a3129ec758c8f
1 From: Daniel Drake <dsd@gentoo.org>
3 When lock obtain times out, do a little bit of automatic investigation into
4 the possibly-stale lockfile.
6 Index: Store/Lock.cs
7 ===================================================================
8 RCS file: /cvs/gnome/beagle/beagled/Lucene.Net/Store/Lock.cs,v
9 retrieving revision 1.6.4.11
10 diff -u -3 -p -r1.6.4.11 Lock.cs
11 --- Store/Lock.cs 30 Sep 2006 02:44:49 -0000 1.6.4.11
12 +++ Store/Lock.cs 30 Sep 2006 02:47:16 -0000
13 @@ -58,17 +58,38 @@ namespace Lucene.Net.Store
14 /// <throws> IOException if lock wait times out or obtain() throws an IOException </throws>
15 public virtual bool Obtain(long lockWaitTimeout)
17 - bool locked = Obtain();
18 int maxSleepCount = (int) (lockWaitTimeout / LOCK_POLL_INTERVAL);
19 int sleepCount = 0;
20 maxSleepCount = System.Math.Max (maxSleepCount, 1);
21 + FSDirectory.Log ("Lock.Obtain timeout={0} maxsleepcount={1}", lockWaitTimeout, maxSleepCount);
22 + bool locked = Obtain();
24 while (!locked)
26 if (sleepCount++ == maxSleepCount)
28 - throw new System.IO.IOException("Lock obtain timed out: " + this.ToString());
29 - }
30 + // Try and be a little more verbose on failure
31 + string lockpath = this.ToString ();
32 + System.Text.StringBuilder ex = new System.Text.StringBuilder();
33 + ex.Append ("Lock obain timed out: ");
34 + ex.Append (lockpath);
35 + if (System.IO.File.Exists (lockpath)) {
36 + System.IO.FileStream fs = System.IO.File.Open (lockpath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
37 + System.IO.StreamReader sr = new System.IO.StreamReader (fs);
38 + string pid = sr.ReadToEnd ().Trim ();
39 + sr.Close ();
40 + fs.Close ();
41 + ex.Append (" -- pid ").Append (pid);
43 + if (System.IO.Directory.Exists ("/proc/" + pid))
44 + ex.Append (" -- process exists");
45 + else
46 + ex.Append (" -- process does not exist, stale lockfile?");
47 + } else {
48 + ex.Append (" -- lock file doesn't exist!?");
49 + }
50 + throw new System.IO.IOException(ex.ToString ());
51 + }
52 System.Threading.Thread.Sleep((int) LOCK_POLL_INTERVAL);
53 locked = Obtain();
55 Index: Store/FSDirectory.cs
56 ===================================================================
57 RCS file: /cvs/gnome/beagle/beagled/Lucene.Net/Store/FSDirectory.cs,v
58 retrieving revision 1.19.2.17
59 diff -u -3 -p -r1.19.2.17 FSDirectory.cs
60 --- Store/FSDirectory.cs 30 Sep 2006 01:54:32 -0000 1.19.2.17
61 +++ Store/FSDirectory.cs 30 Sep 2006 02:47:17 -0000
62 @@ -172,7 +172,7 @@ namespace Lucene.Net.Store
64 public override System.String ToString()
66 - return "Lock@" + lockFile;
67 + return lockFile.FullName;