comparison src/org/tmatesoft/hg/internal/DataAccessProvider.java @ 494:2743641f2f12

Defect: use of 0 as configuration value for mapio boundary results in every file being memmap-ed
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 18 Oct 2012 19:51:07 +0200
parents 909306e412e2
children 243202f1bda5
comparison
equal deleted inserted replaced
493:ba36f66c32b4 494:2743641f2f12
53 private final SessionContext context; 53 private final SessionContext context;
54 54
55 public DataAccessProvider(SessionContext ctx) { 55 public DataAccessProvider(SessionContext ctx) {
56 context = ctx; 56 context = ctx;
57 PropertyMarshal pm = new PropertyMarshal(ctx); 57 PropertyMarshal pm = new PropertyMarshal(ctx);
58 mapioMagicBoundary = pm.getInt(CFG_PROPERTY_MAPIO_LIMIT, DEFAULT_MAPIO_LIMIT); 58 mapioMagicBoundary = mapioBoundaryValue(pm.getInt(CFG_PROPERTY_MAPIO_LIMIT, DEFAULT_MAPIO_LIMIT));
59 bufferSize = pm.getInt(CFG_PROPERTY_FILE_BUFFER_SIZE, DEFAULT_FILE_BUFFER); 59 bufferSize = pm.getInt(CFG_PROPERTY_FILE_BUFFER_SIZE, DEFAULT_FILE_BUFFER);
60 mapioBufSize = pm.getInt(CFG_PROPERTY_MAPIO_BUFFER_SIZE, DEFAULT_MAPIO_BUFFER); 60 mapioBufSize = pm.getInt(CFG_PROPERTY_MAPIO_BUFFER_SIZE, DEFAULT_MAPIO_BUFFER);
61 } 61 }
62 62
63 public DataAccessProvider(SessionContext ctx, int mapioBoundary, int regularBufferSize, int mapioBufferSize) { 63 public DataAccessProvider(SessionContext ctx, int mapioBoundary, int regularBufferSize, int mapioBufferSize) {
64 context = ctx; 64 context = ctx;
65 mapioMagicBoundary = mapioBoundary == 0 ? Integer.MAX_VALUE : mapioBoundary; 65 mapioMagicBoundary = mapioBoundaryValue(mapioBoundary);
66 bufferSize = regularBufferSize; 66 bufferSize = regularBufferSize;
67 mapioBufSize = mapioBufferSize; 67 mapioBufSize = mapioBufferSize;
68 }
69
70 // ensure contract of CFG_PROPERTY_MAPIO_LIMIT, for mapioBoundary == 0 use MAX_VALUE so that no file is memmap-ed
71 private static int mapioBoundaryValue(int mapioBoundary) {
72 return mapioBoundary == 0 ? Integer.MAX_VALUE : mapioBoundary;
68 } 73 }
69 74
70 public DataAccess create(File f) { 75 public DataAccess create(File f) {
71 if (!f.exists()) { 76 if (!f.exists()) {
72 return new DataAccess(); 77 return new DataAccess();