kevinoneill 2003/12/06 14:55:56
Modified: java/src/org/apache/xindice/core/filer Paged.java
Log:
PR: 22321
Submitted by: [EMAIL PROTECTED] (Mario Cormier)
Reviewed by: Kevin O'Neill <[EMAIL PROTECTED]>
CVS: ----------------------------------------------------------------------
CVS: PR:
CVS: If this change addresses a PR in the problem report tracking
CVS: database, then enter the PR number(s) here.
CVS: Obtained from:
CVS: If this change has been taken from another system, such as NCSA,
CVS: then name the system in this line, otherwise delete it.
CVS: Submitted by:
CVS: If this code has been contributed to Apache by someone else; i.e.,
CVS: they sent us a patch or a new module, then include their name/email
CVS: address here. If this is your work then delete this line.
CVS: Reviewed by:
CVS: If we are doing pre-commit code reviews and someone else has
CVS: reviewed your changes, include their name(s) here.
CVS: If you have not had it reviewed then delete this line.
Revision Changes Path
1.21 +21 -11
xml-xindice/java/src/org/apache/xindice/core/filer/Paged.java
Index: Paged.java
===================================================================
RCS file:
/home/cvs/xml-xindice/java/src/org/apache/xindice/core/filer/Paged.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- Paged.java 9 Aug 2003 21:19:53 -0000 1.20
+++ Paged.java 6 Dec 2003 22:55:56 -0000 1.21
@@ -111,6 +111,8 @@
// Cache of modified pages waiting to be written out.
private Map dirty = new HashMap();
+ private Object dirtyLock = new Object();
+
// Random access file cache.
private Stack descriptors = new Stack();
@@ -202,6 +204,7 @@
Page p;
synchronized (this) {
// Check if it's in the dirty cache
+ // No need to synchronize on dirtyLock thanks to atomic
assignment
p = (Page) dirty.get(lp);
// if not check if it's already loaded in the page cache
@@ -549,7 +552,12 @@
// TODO: Clean up this code
boolean error = false;
synchronized (this) {
- Iterator i = dirty.values().iterator();
+ Map dirtyToFlush;
+ synchronized (dirtyLock) {
+ dirtyToFlush = dirty;
+ dirty = new HashMap();
+ }
+ Iterator i = dirtyToFlush.values().iterator();
while (i.hasNext()) {
Page p = (Page) i.next();
@@ -559,7 +567,7 @@
error = true;
}
}
- dirty.clear();
+ dirtyToFlush.clear();
if (fileHeader.dirty) {
try {
@@ -1149,13 +1157,15 @@
byte[] b = bos.toByteArray();
System.arraycopy(b, 0, data, 0, b.length);
- dirty.put(new Long(pageNum), this);
- if (dirty.size() > MAX_DIRTY_SIZE) {
- try {
- // Too many dirty pages... flush them
- Paged.this.flush();
- } catch (Exception e) {
- throw new IOException(e.getMessage());
+ synchronized (dirtyLock) {
+ dirty.put(new Long(pageNum), this);
+ if (dirty.size() > MAX_DIRTY_SIZE) {
+ try {
+ // Too many dirty pages... flush them
+ Paged.this.flush();
+ } catch (Exception e) {
+ throw new IOException(e.getMessage());
+ }
}
}
}