I enclose the OracleContentStore in this mail. I use Slide 1.0.14, not the latest from CVS.
When the Slide is initialized, there is only one database connection initialized. This is what I saw in my test. The Slide code caches the sore in memory. Please see Namespace.getUri(uri). Each Uri has store. But each store is coned from the original one and does re-connect if it is already connected. In the test, multiple threads do the different transactions on the same database connection. It will returns error. The Oracle error is one of them. It looks like this problem is related to "Slide connection pool" problem. If we at least have one database connection for each transaction, we are OK. Or we need to implement the XA store. Ting --- Dirk Verbeeck <[EMAIL PROTECTED]> wrote: > Is it possible to send me your OracleContentStore ? > Are you using the latest CVS version ? > > When a thread starts a transaction with begin(), it > reserves the store > for private use. > The other threads have to wait, they sleep 20x 50ms. > (that code is in > AbstractStore) > If they can't reserve a store they get a > ServiceAccessException. > Below is what I get with cloudscape, with > transactions enabled for the > read. > Thread 0 is able to grab the store and store > /ORACLE0 > Thread 1 tries to get a store but is put to sleep. > Thread 0 continues to put /ORACLE1, ... > Thread 1 gets an ServiceAccessException and cannot > store /IBM0 and tries > to store /IBM1 > Thread 0 after putting /ORACLE9, start getting > /ORACLE0 (inside a > transaction and thus locking the store) > Thread 1 gets an ServiceAccessException and cannot > store /IBM1 and tries > to store /IBM2 > Thread 0 is finished getting /ORACLE9 > Thread 1 can use the store to put /IBM2, ... (It > receives > ObjectNotFoundException for /IBM0 and /IBM1, they > are not stored) > > When that ORA-22990 is solved everything should be > OK. > > Some work is needed on the "read" methods, they > should be synchronized > on the DB connection I think. > > > Regards > Dirk > > > ========================================================= > 03 Oct 2001 23:15:15 - > org.apache.slide.common.Domain - INFO - Domain > initialization complete > > Thread-0: Put uri = /ORACLE0 > > Thread-1: Put uri = /IBM0 > > Thread-0: Put uri = /ORACLE1 > > Thread-0: Put uri = /ORACLE2 > > Thread-0: Put uri = /ORACLE3 > > Thread-0: Put uri = /ORACLE4 > > Thread-0: Put uri = /ORACLE5 > > Thread-0: Put uri = /ORACLE6 > > Thread-0: Put uri = /ORACLE7 > > Thread-0: Put uri = /ORACLE8 > > Thread-0: Put uri = /ORACLE9 > > 03 Oct 2001 23:15:17 - > org.apache.slide.common.Domain - WARNING - > Service jdbc(org.apache.slide.store.StandardStore) > access error : Failed > to enlist service > slidestore.cloudscape.CloudscapeDescriptorsStore@18d189 > in active > transaction > > >>>> org.apache.slide.common.ServiceAccessException: > Service jdbc(org.apache.slide.store.StandardStore) > access error : Failed to enlist service > slidestore.cloudscape.CloudscapeDescriptorsStore@18d189 > in active transaction > > Thread-1: Put uri = /IBM1 > > Thread-0: Get uri = /ORACLE0 > > Thread-0: Get uri = /ORACLE1 > > Thread-0: Get uri = /ORACLE2 > > Thread-0: Get uri = /ORACLE3 > > Thread-0: Get uri = /ORACLE4 > > Thread-0: Get uri = /ORACLE5 > > Thread-0: Get uri = /ORACLE6 > > Thread-0: Get uri = /ORACLE7 > > Thread-0: Get uri = /ORACLE8 > > Thread-0: Get uri = /ORACLE9 > > 03 Oct 2001 23:15:18 - > org.apache.slide.common.Domain - WARNING - > Service jdbc(org.apache.slide.store.StandardStore) > access error : Failed > to enlist service > slidestore.cloudscape.CloudscapeDescriptorsStore@18d189 > in active > transaction > > >>>> org.apache.slide.common.ServiceAccessException: > Service jdbc(org.apache.slide.store.StandardStore) > access error : Failed to enlist service > slidestore.cloudscape.CloudscapeDescriptorsStore@18d189 > in active transaction > > Thread-1: Put uri = /IBM2 > > Thread-1: Put uri = /IBM3 > > Thread-1: Put uri = /IBM4 > > Thread-1: Put uri = /IBM5 > > Thread-1: Put uri = /IBM6 > > Thread-1: Put uri = /IBM7 > > Thread-1: Put uri = /IBM8 > > Thread-1: Put uri = /IBM9 > > Thread-1: Get uri = /IBM0 > > >>>> > org.apache.slide.structure.ObjectNotFoundException: > No object found at /IBM0 > > Thread-1: Get uri = /IBM1 > > >>>> > org.apache.slide.structure.ObjectNotFoundException: > No object found at /IBM1 > > Thread-1: Get uri = /IBM2 > > Thread-1: Get uri = /IBM3 > > Thread-1: Get uri = /IBM4 > > Thread-1: Get uri = /IBM5 > > Thread-1: Get uri = /IBM6 > > Thread-1: Get uri = /IBM7 > > Thread-1: Get uri = /IBM8 > > Thread-1: Get uri = /IBM9 __________________________________________________ Do You Yahoo!? NEW from Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month. http://geocities.yahoo.com/ps/info1
/* * $Header: /home/cvs/jakarta-slide/src/stores/slidestore/reference/JDBCContentStore.java,v 1.10 2001/08/31 21:37:32 dirkv Exp $ * $Revision: 1.10 $ * $Date: 2001/08/31 21:37:32 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * [Additional notices, if required by prior licensing conditions] * */ package slidestore.reference; import java.lang.reflect.Constructor; import java.util.Hashtable; import java.util.Enumeration; import java.util.Vector; import java.util.Date; import java.io.FileWriter; import java.io.InputStream; import java.io.OutputStream; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.File; import java.sql.*; import javax.transaction.xa.XAException; import javax.transaction.xa.Xid; import org.apache.slide.common.*; import org.apache.slide.store.*; import org.apache.slide.structure.*; import org.apache.slide.security.*; import org.apache.slide.content.*; import org.apache.slide.util.logger.Logger; /** * JDBC 2.0 compliant implementation of ContentStore. * * @author <a href="mailto:[EMAIL PROTECTED]">Remy Maucherat</a> * @version $Revision: 1.10 $ */ public class OracleContentStore extends AbstractService implements ContentStore { // -------------------------------------------------------------- Constants public static final int BUFFER_SIZE = 2048; public static final String CHARACTER_ENCODING = "8859_1"; protected static final int REVISION_URI = 1; protected static final int REVISION_NUMBER = 2; protected static final int REVISION_CONTENT = 3; // ----------------------------------------------------- Instance Variables /** * Database connection. */ protected Connection connection; /** * Driver class name. */ protected String driver; /** * Connection URL. */ protected String url; /** * User name. */ protected String user; /** * Password. */ protected String password; // -------------------------------------------------------- Service Methods /** * Read parameters. * * @param parameters Hashtable containing the parameters' name * and associated value */ public synchronized void setParameters(Hashtable parameters) throws ServiceParameterErrorException, ServiceParameterMissingException { // Driver classname driver = (String) parameters.get("driver"); // Connection url url = (String) parameters.get("url"); // FIXME: before slide 1.0.12 the database url was passed without "jdbc:" // this compatibility code sould be removed in the future // code changed 18 jul 2001 if (!url.startsWith("jdbc:")) url="jdbc:" + url; // end compatibility code // User name user = (String) parameters.get("user"); if (user == null) { user = new String(); } // Password password = (String) parameters.get("password"); if (password == null) { password = new String(); } } /** * Connects to JDBC and creates the basic table structure. * * @exception ServiceConnectionFailedException Connection to the * database failed */ public synchronized void connect() throws ServiceConnectionFailedException { getLogger().log("Connecting to \"" + url + "\" as user \"" + user + "\"",LOG_CHANNEL,Logger.INFO); try { connection = DriverManager.getConnection (url, user, password); } catch (SQLException e) { getLogger().log("Connecting to \"" + url + "\" as user \"" + user + "\" failed",LOG_CHANNEL,Logger.ERROR); getLogger().log(e.toString(),LOG_CHANNEL,Logger.ERROR); throw new ServiceConnectionFailedException(this, e); } Statement statement = null; try { statement = connection.createStatement(); String s = "create table revisioncontent(uri varchar(65536), " + "xnumber varchar(20), content LONGVARBINARY)"; statement.execute(s); } catch (SQLException e) { } finally { closeStatement(statement); } } /** * Disconnects from content store. * * @exception ServiceDisconnectionFailedException */ public synchronized void disconnect() throws ServiceDisconnectionFailedException { getLogger().log("Disconnecting from \"" + url + "\" as user \"" + user + "\"",LOG_CHANNEL,Logger.INFO); try { if (connection != null) connection.close(); connection = null; } catch (SQLException e) { getLogger().log("Disconnecting from \"" + url + "\" as user \"" + user + "\" failed",LOG_CHANNEL,Logger.ERROR); getLogger().log(e.toString(),LOG_CHANNEL,Logger.ERROR); throw new ServiceDisconnectionFailedException(this, e); } } /** * Initializes content store. * * @exception ServiceInitializationFailedException Throws an exception * if the store has already been initialized before */ public synchronized void initialize(NamespaceAccessToken token) throws ServiceInitializationFailedException { try { // Loading and registering driver token.getLogger().log("Loading and registering driver: " + driver,LOG_CHANNEL,Logger.INFO); Class driverClass = Class.forName(driver); Driver databaseDriver = (Driver) driverClass.newInstance(); DriverManager.registerDriver(databaseDriver); } catch (ClassNotFoundException e) { token.getLogger().log("Loading and registering driver " + driver + " failed",LOG_CHANNEL,Logger.ERROR); token.getLogger().log(e.toString(),LOG_CHANNEL,Logger.ERROR); throw new ServiceInitializationFailedException(this, e.getMessage()); } catch (InstantiationException e) { token.getLogger().log("Loading and registering driver " + driver + " failed",LOG_CHANNEL,Logger.ERROR); token.getLogger().log(e.toString(),LOG_CHANNEL,Logger.ERROR); throw new ServiceInitializationFailedException(this, e.getMessage()); } catch (IllegalAccessException e) { token.getLogger().log("Loading and registering driver " + driver + " failed",LOG_CHANNEL,Logger.ERROR); token.getLogger().log(e.toString(),LOG_CHANNEL,Logger.ERROR); throw new ServiceInitializationFailedException(this, e.getMessage()); } catch (SQLException e) { token.getLogger().log("Loading and registering driver " + driver + " failed",LOG_CHANNEL,Logger.ERROR); token.getLogger().log(e.toString(),LOG_CHANNEL,Logger.ERROR); throw new ServiceInitializationFailedException(this, e.getMessage()); } catch (ClassCastException e) { token.getLogger().log("Loading and registering driver " + driver + " failed",LOG_CHANNEL,Logger.ERROR); token.getLogger().log(e.toString(),LOG_CHANNEL,Logger.ERROR); throw new ServiceInitializationFailedException(this, e.getMessage()); } catch (Exception e) { token.getLogger().log("Loading and registering driver " + driver + " failed",LOG_CHANNEL,Logger.ERROR); token.getLogger().log(e.toString(),LOG_CHANNEL,Logger.ERROR); throw new ServiceInitializationFailedException(this, e.getMessage()); } } /** * Deletes content store. * * @exception ServiceResetFailedException */ public void reset() throws ServiceResetFailedException { try { connectIfNeeded(); Statement statement = connection.createStatement(); String s = "drop table revisioncontent"; statement.execute(s); statement.close(); disconnect(); } catch (SQLException e) { throw new ServiceResetFailedException(this, e.getMessage()); } catch (ServiceAccessException e) { throw new ServiceResetFailedException(this, e.getMessage()); } catch (ServiceConnectionFailedException e) { throw new ServiceResetFailedException(this, e.getMessage()); } catch (ServiceDisconnectionFailedException e) { throw new ServiceResetFailedException(this, e.getMessage()); } } /** * This function tells whether or not the service is connected. * * @return boolean true if we are connected * @exception ServiceAccessException Service access error */ public boolean isConnected() throws ServiceAccessException { try { return ((connection != null) && (!connection.isClosed())); } catch (SQLException e) { throw new ServiceAccessException(this, e); } } // ----------------------------------------------------- XAResource Methods /** * Commit the global transaction specified by xid. */ public void commit(Xid xid, boolean onePhase) throws XAException { super.commit(xid, onePhase); try { connection.commit(); connection.setAutoCommit(true); } catch (SQLException e) { throw new XAException(XAException.XA_RBCOMMFAIL); } } /** * Inform the resource manager to roll back work done on behalf of a * transaction branch. */ public void rollback(Xid xid) throws XAException { super.rollback(xid); try { connection.rollback(); connection.setAutoCommit(true); } catch (SQLException e) { throw new XAException(XAException.XA_HEURCOM); } } /** * Start work on behalf of a transaction branch specified in xid. */ public void start(Xid xid, int flags) throws XAException { super.start(xid, flags); try { connection.setAutoCommit(false); } catch (SQLException e) { throw new XAException(XAException.XAER_RMERR); } } // --------------------------------------------------- ContentStore Methods /** * Retrive revision content. * * @param uri Uri * @param revisionNumber Node revision number */ public NodeRevisionContent retrieveRevisionContent (Uri uri, NodeRevisionDescriptor revisionDescriptor) throws ServiceAccessException, RevisionNotFoundException { NodeRevisionContent result = null; String revisionUri = uri.toString(); String revisionNumber = revisionDescriptor.getRevisionNumber().toString(); try { PreparedStatement selectStatement = connection.prepareStatement ("select * from revisioncontent where uri = ? and " + "xnumber = ?"); selectStatement.setString(1, revisionUri); selectStatement.setString(2, revisionNumber); ResultSet rs = selectStatement.executeQuery(); if (!rs.next()) { rs.close(); selectStatement.close(); throw new RevisionNotFoundException (uri.toString(), revisionDescriptor.getRevisionNumber()); } InputStream is = rs.getBinaryStream(REVISION_CONTENT); if (is == null) { throw new RevisionNotFoundException (uri.toString(), revisionDescriptor.getRevisionNumber()); } InputStreamReader reader = new InputStreamReader (is, CHARACTER_ENCODING); result = new NodeRevisionContent(); result.setContent(reader); result.setContent(is); // Don't close the statement or the result set here (because // otherwise the is and the reader returned would be closed). // If this proves to be a problem, then the binary content of the // resource must either be buffer to the disk or to memory. // FIXME ? } catch (SQLException e) { getLogger().log(e,LOG_CHANNEL,Logger.ERROR); throw new ServiceAccessException(this, e.getMessage()); } catch (RevisionNotFoundException e) { // we do NOT want this caught by next clause. throw e; } catch (Exception e) { getLogger().log(e,LOG_CHANNEL,Logger.ERROR); throw new ServiceAccessException(this, e.getMessage()); } return result; } /** * Create a new revision * * @param uri Uri * @param revisionDescriptor Node revision descriptor * @param revisionContent Node revision content */ public void createRevisionContent (Uri uri, NodeRevisionDescriptor revisionDescriptor, NodeRevisionContent revisionContent) throws ServiceAccessException, RevisionAlreadyExistException { String revisionUri = uri.toString(); String revisionNumber = revisionDescriptor.getRevisionNumber().toString(); long contentLength = revisionDescriptor.getContentLength(); PreparedStatement selectStatement = null; try { selectStatement = connection.prepareStatement ("select * from revisioncontent where uri = ? and " + "xnumber = ?"); selectStatement.setString(1, revisionUri); selectStatement.setString(2, revisionNumber); ResultSet rs = selectStatement.executeQuery(); if (rs.next()) { rs.close(); throw new RevisionAlreadyExistException (uri.toString(), revisionDescriptor.getRevisionNumber()); } rs.close(); storeContent(revisionUri, revisionNumber, revisionDescriptor, revisionContent); } catch (SQLException e) { getLogger().log(e,LOG_CHANNEL,Logger.ERROR); throw new ServiceAccessException(this, e.getMessage()); } catch (IOException e) { getLogger().log(e,LOG_CHANNEL,Logger.ERROR); throw new ServiceAccessException(this, e.getMessage()); } catch(RevisionAlreadyExistException e) { throw e; // we do NOT want this caught by next clause. } catch (Exception e) { getLogger().log(e,LOG_CHANNEL,Logger.ERROR); throw new ServiceAccessException(this, e.getMessage()); } finally { closeStatement(selectStatement); } } /** * Modify the latest revision of an object. * * @param uri Uri * @param revisionDescriptor Node revision descriptor * @param revisionContent Node revision content */ public void storeRevisionContent (Uri uri, NodeRevisionDescriptor revisionDescriptor, NodeRevisionContent revisionContent) throws ServiceAccessException, RevisionNotFoundException { String revisionUri = uri.toString(); String revisionNumber = revisionDescriptor.getRevisionNumber().toString(); PreparedStatement selectStatement = null; try { selectStatement = connection.prepareStatement ("select * from revisioncontent where uri = ? and " + "xnumber = ?"); selectStatement.setString(1, revisionUri); selectStatement.setString(2, revisionNumber); ResultSet rs = selectStatement.executeQuery(); if (!rs.next()) { rs.close(); selectStatement.close(); throw new RevisionNotFoundException (uri.toString(), revisionDescriptor.getRevisionNumber()); } rs.close(); removeContent(revisionUri, revisionNumber); storeContent(revisionUri, revisionNumber, revisionDescriptor, revisionContent); } catch (SQLException e) { getLogger().log(e,LOG_CHANNEL,Logger.ERROR); throw new ServiceAccessException(this, e.getMessage()); } catch (IOException e) { getLogger().log(e,LOG_CHANNEL,Logger.ERROR); throw new ServiceAccessException(this, e.getMessage()); } catch(RevisionNotFoundException e) { throw e; // we do NOT want this caught by next clause. } catch (Exception e) { getLogger().log(e,LOG_CHANNEL,Logger.ERROR); throw new ServiceAccessException(this, e.getMessage()); } finally { closeStatement(selectStatement); } } /** * Remove revision. * * @param uri Uri * @param revisionNumber Node revision number */ public void removeRevisionContent (Uri uri, NodeRevisionDescriptor revisionDescriptor) throws ServiceAccessException { String revisionUri = uri.toString(); String revisionNumber = revisionDescriptor.getRevisionNumber().toString(); try { removeContent(revisionUri, revisionNumber); } catch (Exception e) { getLogger().log(e,LOG_CHANNEL,Logger.ERROR); throw new ServiceAccessException(this, e.getMessage()); } } // ------------------------------------------------------ Protected Methods /** * Store a revision. */ protected void storeContent(String revisionUri, String revisionNumber, NodeRevisionDescriptor revisionDescriptor, NodeRevisionContent revisionContent) throws IOException, SQLException { PreparedStatement insertStatement = connection.prepareStatement ("insert into revisioncontent (uri, xnumber, content) values(?, ?, ?)"); insertStatement.setString(1, revisionUri); insertStatement.setString(2, revisionNumber); byte[] ba = " ".getBytes(); int len = ba.length; ByteArrayInputStream bis = new ByteArrayInputStream(ba); insertStatement.setBinaryStream(3, bis, len); insertStatement.executeUpdate(); insertStatement.close(); bis.close(); InputStream is = revisionContent.streamContent(); if (null != is) { // Need to update the blob for Oracle to put the blob into databse PreparedStatement selForUpdateStatement = connection.prepareStatement ("select content from revisioncontent where uri = ? and xnumber = ? for update"); selForUpdateStatement.setString(1, revisionUri); selForUpdateStatement.setString(2, revisionNumber); ResultSet rs = selForUpdateStatement.executeQuery(); int contentLength = -1; if (rs.next()) { OutputStream os = ((oracle.sql.BLOB) rs.getBlob(1)). getBinaryOutputStream(); byte[] buf = new byte[BUFFER_SIZE]; int num = -1; while ((num = is.read(buf)) > 0) { os.write(buf, 0, num); contentLength = contentLength + num; } os.close(); } rs.close(); selForUpdateStatement.close(); revisionDescriptor.setContentLength(contentLength); } } /** * Remove content. */ protected void removeContent(String revisionUri, String revisionNumber) throws SQLException { PreparedStatement deleteStatement = connection.prepareStatement ("delete from revisioncontent where uri = ? and xnumber = ?"); deleteStatement.setString(1, revisionUri); deleteStatement.setString(2, revisionNumber); deleteStatement.executeUpdate(); deleteStatement.close(); } /** * Close specified statement. */ protected void closeStatement(Statement statement) { if (statement != null) { try { statement.close(); } catch (SQLException e) { } } } }
