vgritsenko 2003/12/21 17:34:12
Modified: java/src/org/apache/xindice/core/filer Paged.java
Log:
Synchronize access to fileHeader in unlinkPages.
Log errors during flush.
Revision Changes Path
1.24 +21 -19
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.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- Paged.java 19 Dec 2003 02:35:06 -0000 1.23
+++ Paged.java 22 Dec 2003 01:34:11 -0000 1.24
@@ -406,7 +406,6 @@
protected final void unlinkPages(Page page) throws IOException {
// Handle the page if it's in primary space by setting its status to
// DELETED and freeing any overflow pages linked to it.
- // FIXME: Revisit concurrency/synchronization issues
if (page.pageNum.longValue() < fileHeader.pageCount) {
long nextPage = page.header.nextPage;
page.header.setStatus(DELETED);
@@ -423,30 +422,31 @@
// Add any overflow pages to the list of free pages.
if (page != null) {
- // Get the first page in the chain.
+ // Get the first and last page in the chain.
long firstPage = page.pageNum.longValue();
-
- // Find the last page in the chain.
while (page.header.nextPage != NO_PAGE) {
page = getPage(page.header.nextPage);
}
long lastPage = page.pageNum.longValue();
- // If there are already some free pages, add the start of the
chain
- // to the list of free pages.
- if (fileHeader.lastFreePage != NO_PAGE) {
- Page p = getPage(fileHeader.lastFreePage);
- p.header.setNextPage(firstPage);
- p.write();
- }
+ // Free the chain
+ synchronized (fileHeader) {
+ // If there are already some free pages, add the start of
the chain
+ // to the list of free pages.
+ if (fileHeader.lastFreePage != NO_PAGE) {
+ Page p = getPage(fileHeader.lastFreePage);
+ p.header.setNextPage(firstPage);
+ p.write();
+ }
- // Otherwise set the chain as the list of free pages.
- if (fileHeader.firstFreePage == NO_PAGE) {
- fileHeader.setFirstFreePage(firstPage);
- }
+ // Otherwise set the chain as the list of free pages.
+ if (fileHeader.firstFreePage == NO_PAGE) {
+ fileHeader.setFirstFreePage(firstPage);
+ }
- // Add a reference to the end of the chain.
- fileHeader.setLastFreePage(lastPage);
+ // Add a reference to the end of the chain.
+ fileHeader.setLastFreePage(lastPage);
+ }
}
}
@@ -637,6 +637,7 @@
try {
p.flush();
} catch (Exception e) {
+ log.warn("Exception while flushing page", e);
error++;
}
}
@@ -646,6 +647,7 @@
try {
fileHeader.write();
} catch (Exception e) {
+ log.warn("Exception while flushing file header", e);
error++;
}
}