Author: vgritsenko
Date: Thu Dec 15 13:55:05 2005
New Revision: 357076
URL: http://svn.apache.org/viewcvs?rev=357076&view=rev
Log:
Make an attempt to lock a database before opening it up.
Prevents opening up same database by different processes,
resulting in database corruption.
Modified:
xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java
xml/xindice/trunk/java/src/org/apache/xindice/core/Database.java
xml/xindice/trunk/status.xml
Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java
URL: http://svn.apache.org/viewcvs/xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java?rev=357076&r1=357075&r2=357076&view=diff
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java Thu Dec 15 13:55:05 2005
@@ -68,7 +68,8 @@
*
* @version CVS $Revision$, $Date$
*/
-public class Collection extends CollectionManager implements Named, DBObject, Configurable {
+public class Collection extends CollectionManager
+ implements Named, DBObject, Configurable {
private static final Log log = LogFactory.getLog(Collection.class);
@@ -1414,7 +1415,6 @@
}
try {
filer = (Filer) Class.forName(className).newInstance();
- // filer.setCollection(this);
filer.setLocation(getCollectionRoot(), getName());
filer.setConfig(filerConfig);
if (!filer.exists()) {
Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/Database.java
URL: http://svn.apache.org/viewcvs/xml/xindice/trunk/java/src/org/apache/xindice/core/Database.java?rev=357076&r1=357075&r2=357076&view=diff
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/Database.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/Database.java Thu Dec 15 13:55:05 2005
@@ -20,7 +20,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-// import org.apache.xindice.core.meta.TimeRecord;
import org.apache.xindice.core.query.QueryEngine;
import org.apache.xindice.server.Xindice;
import org.apache.xindice.util.Configuration;
@@ -33,8 +32,11 @@
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
+
import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@@ -49,6 +51,7 @@
public static final String DBROOT = "dbroot";
public static final String NAME = "name";
+
private static final String QUERYENGINE = "queryengine";
private static final String COLKEY = "database.xml";
private static final String DATABASE = "database";
@@ -126,18 +129,27 @@
}
}
+
//
// Instance...
//
- private DocumentCache docCache = new DocumentCache();
- private QueryEngine engine = new QueryEngine(this);
- private boolean metaEnabled = false;
- private boolean metaInit = false;
- private MetaSystemCollection metaSystemCollection = null;
- private boolean sysInit = false;
- private SystemCollection systemCollection = null;
+
+ private DocumentCache docCache;
+ private QueryEngine engine;
+ private boolean metaEnabled;
+ private boolean metaInit;
+ private MetaSystemCollection metaSystemCollection;
+ private boolean sysInit;
+ private SystemCollection systemCollection;
+ private FileOutputStream lock;
+ public Database() {
+ super();
+ this.docCache = new DocumentCache();
+ this.engine = new QueryEngine(this);
+ }
+
/**
* @see org.apache.xindice.core.DBObject#close()
*/
@@ -149,6 +161,14 @@
flushConfig();
super.close();
+ // Release database lock
+ try {
+ this.lock.close();
+ } catch (IOException e) {
+ // Ignore IO exception
+ }
+ this.lock = null;
+
synchronized (databases) {
databases.remove(getName());
}
@@ -230,9 +250,11 @@
* @see org.apache.xindice.util.Configurable#setConfig(org.apache.xindice.util.Configuration)
*/
public void setConfig(Configuration config) throws XindiceException {
+ // FIXME Get rid of super.setConfig here?
super.setConfig(config);
setCanonicalName('/' + getName());
+ // Determine database root directory
String dbroot = config.getAttribute(DBROOT);
File dbrootDir = new File(dbroot);
if (!dbrootDir.isAbsolute()) {
@@ -256,12 +278,27 @@
throw new XindiceException("Can't get canonical path", e);
}
}
-
setCollectionRoot(dbrootDir);
if (log.isInfoEnabled()) {
log.info("Database points to " + dbrootDir.getAbsolutePath());
}
+ // Put a lock (at least attempt to) on the database
+ // FIXME: Use JDK1.4 FileLock
+ File lock = new File(getCollectionRoot(), "db.lock");
+ try {
+ if (lock.exists() && !lock.delete()) {
+ throw new IOException("Could not delete lock file.");
+ }
+ this.lock = new FileOutputStream(lock);
+ this.lock.write(new Date().toString().getBytes());
+ } catch (IOException e) {
+ throw new XindiceException("Unable to open lock file " + lock + ". " +
+ "Make sure database is not open by another process. " +
+ "Exception: " + e);
+ }
+
+ // Initialize query engine
try {
Configuration queryCfg = config.getChild(QUERYENGINE);
if (queryCfg != null) {
@@ -273,6 +310,7 @@
}
}
+ // Initialize system collection
if (!sysInit) {
systemCollection = new SystemCollection(this);
systemCollection.init();
Modified: xml/xindice/trunk/status.xml
URL: http://svn.apache.org/viewcvs/xml/xindice/trunk/status.xml?rev=357076&r1=357075&r2=357076&view=diff
==============================================================================
--- xml/xindice/trunk/status.xml (original)
+++ xml/xindice/trunk/status.xml Thu Dec 15 13:55:05 2005
@@ -73,7 +73,12 @@
</todo>
<changes>
- <release version="1.1b5-dev" date="May 25 2005">
+ <release version="1.1b5-dev" date="Dec 15 2005">
+ <action dev="VG" type="update">
+ Make an attempt to lock a database before opening it up.
+ Prevents opening up same database by different processes,
+ resulting in database corruption.
+ </action>
<action dev="VG" type="fix" fixes-bug="30878" due-to="Todd Byrne">
Make sure that XUpdate commands are run only once per document.
In case XUpdate command does not complete successfully, revert
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.