Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/DataAccessProvider.java @ 440:299870249a28
Issue 30: bogus IOException for mmap file on linux
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 19 Apr 2012 19:18:25 +0200 |
parents | 48f993aa2f41 |
children | 909306e412e2 |
comparison
equal
deleted
inserted
replaced
439:2bf6f917a7e5 | 440:299870249a28 |
---|---|
165 private void fill() throws IOException { | 165 private void fill() throws IOException { |
166 if (buffer != null) { | 166 if (buffer != null) { |
167 position += buffer.position(); | 167 position += buffer.position(); |
168 } | 168 } |
169 long left = size - position; | 169 long left = size - position; |
170 buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, position, left < memBufferSize ? left : memBufferSize); | 170 for (int i = 0; i < 3; i++) { |
171 try { | |
172 buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, position, left < memBufferSize ? left : memBufferSize); | |
173 return; | |
174 } catch (IOException ex) { | |
175 if (i == 2) { | |
176 throw ex; | |
177 } | |
178 if (i == 0) { | |
179 // if first attempt failed, try to free some virtual memory, see Issue 30 for details | |
180 logFacility.warn(getClass(), ex, "Memory-map failed, gonna try gc() to free virtual memory"); | |
181 } | |
182 try { | |
183 buffer = null; | |
184 System.gc(); | |
185 Thread.sleep((1+i) * 1000); | |
186 } catch (Throwable t) { | |
187 logFacility.error(getClass(), t, "Bad luck"); | |
188 } | |
189 } | |
190 } | |
171 } | 191 } |
172 | 192 |
173 @Override | 193 @Override |
174 public void readBytes(byte[] buf, int offset, int length) throws IOException { | 194 public void readBytes(byte[] buf, int offset, int length) throws IOException { |
175 if (buffer == null || !buffer.hasRemaining()) { | 195 if (buffer == null || !buffer.hasRemaining()) { |