From derby-commits-return-9086-apmail-db-derby-commits-archive=db.apache.org@db.apache.org Thu Jan 03 10:23:03 2008 Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 67696 invoked from network); 3 Jan 2008 10:23:03 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Jan 2008 10:23:03 -0000 Received: (qmail 58129 invoked by uid 500); 3 Jan 2008 10:22:51 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 58106 invoked by uid 500); 3 Jan 2008 10:22:51 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 58080 invoked by uid 99); 3 Jan 2008 10:22:51 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Jan 2008 02:22:51 -0800 X-ASF-Spam-Status: No, hits=-98.8 required=10.0 tests=ALL_TRUSTED,FS_REPLICA X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Jan 2008 10:22:46 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id BAA5A1A9832; Thu, 3 Jan 2008 02:22:37 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r608419 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/services/replication/slave/ impl/services/replication/net/ impl/services/replication/slave/ impl/store/raw/ impl/store/raw/log/ loc/ Date: Thu, 03 Jan 2008 10:22:36 -0000 To: derby-commits@db.apache.org From: oysteing@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080103102237.BAA5A1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: oysteing Date: Thu Jan 3 02:22:35 2008 New Revision: 608419 URL: http://svn.apache.org/viewvc?rev=608419&view=rev Log: Contributed by Jorgen Loland: I encountered a few bugs while working on a new implementation of the Database interface. The attached patch fixes these bugs, which are all part of the replication functionality and is not in use in non-replicated databases. Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/replication/slave/SlaveFactory.java db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/net/ReplicationMessageReceive.java db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/slave/SlaveController.java db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/LogAccessFile.java db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/replication/slave/SlaveFactory.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/replication/slave/SlaveFactory.java?rev=608419&r1=608418&r2=608419&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/replication/slave/SlaveFactory.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/replication/slave/SlaveFactory.java Thu Jan 3 02:22:35 2008 @@ -49,14 +49,6 @@ /* Strings used as keys in the Properties objects*/ - /** Property key to specify which host to listen to */ - public static final String SLAVE_HOST = - Property.PROPERTY_RUNTIME_PREFIX + "replication.slave.slavehost"; - - /** Property key to specify which port to listen to */ - public static final String SLAVE_PORT = - Property.PROPERTY_RUNTIME_PREFIX + "replication.slave.slaveport"; - /** Property key to specify the name of the database */ public static final String SLAVE_DB = Property.PROPERTY_RUNTIME_PREFIX + "replication.slave.dbname"; Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/net/ReplicationMessageReceive.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/net/ReplicationMessageReceive.java?rev=608419&r1=608418&r2=608419&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/net/ReplicationMessageReceive.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/net/ReplicationMessageReceive.java Thu Jan 3 02:22:35 2008 @@ -45,6 +45,11 @@ private final SlaveAddress slaveAddress; /** + * Contains the ServerSocket used to listen for + * connections from the replication master. */ + private ServerSocket serverSocket; + + /** * Contains the methods used to read and write to the Object streams * obtained from a Socket connection. */ @@ -101,9 +106,12 @@ StandardException, ClassNotFoundException { - //Contains the ServerSocket used to listen for - //connections from the replication master. - final ServerSocket serverSocket = createServerSocket(); + // Create the ServerSocket object if this is the first + // initConnection attempt. Otherwise, we reuse the existing + // server socket + if (serverSocket == null) { + serverSocket = createServerSocket(); + } serverSocket.setSoTimeout(timeout); //Start listening on the socket and accepting the connection Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/slave/SlaveController.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/slave/SlaveController.java?rev=608419&r1=608418&r2=608419&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/slave/SlaveController.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/slave/SlaveController.java Thu Jan 3 02:22:35 2008 @@ -23,6 +23,7 @@ package org.apache.derby.impl.services.replication.slave; import org.apache.derby.iapi.error.StandardException; +import org.apache.derby.iapi.reference.Attribute; import org.apache.derby.iapi.reference.MessageId; import org.apache.derby.iapi.reference.SQLState; import org.apache.derby.iapi.services.monitor.ModuleControl; @@ -112,9 +113,9 @@ public void boot(boolean create, Properties properties) throws StandardException { - slavehost = properties.getProperty(SlaveFactory.SLAVE_HOST); + slavehost = properties.getProperty(Attribute.REPLICATION_SLAVE_HOST); - String port = properties.getProperty(SlaveFactory.SLAVE_PORT); + String port = properties.getProperty(Attribute.REPLICATION_SLAVE_PORT); if (port != null) { slaveport = new Integer(port).intValue(); } Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java?rev=608419&r1=608418&r2=608419&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java Thu Jan 3 02:22:35 2008 @@ -314,6 +314,20 @@ dataFactory.setDatabaseEncrypted(); } + // If SlaveFactory is to be booted, the boot has to happen + // before logFactory.recover since that method will be blocked + // when in replication slave mode. + if (inReplicationSlaveMode) { + // The LogFactory has already been booted in slave mode. + // Can now start slave replication by booting the + // SlaveFactory service + slaveFactory = (SlaveFactory) + Monitor.bootServiceModule(create, this, + getSlaveFactoryModule(), + properties); + slaveFactory.startSlave(this, logFactory); + } + // no need to tell log factory which raw store factory it belongs to // since this is passed into the log factory for recovery // after the factories are loaded, recover the database @@ -324,17 +338,6 @@ if (encryptDatabase) { configureDatabaseForEncryption(properties, newCipherFactory); - } - - if (inReplicationSlaveMode) { - // The LogFactory has already been booted in slave mode. - // Can now start slave replication by booting the - // SlaveFactory service - slaveFactory = (SlaveFactory) - Monitor.bootServiceModule(create, this, - getSlaveFactoryModule(), - properties); - slaveFactory.startSlave(this, logFactory); } } Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/LogAccessFile.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/LogAccessFile.java?rev=608419&r1=608418&r2=608419&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/LogAccessFile.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/LogAccessFile.java Thu Jan 3 02:22:35 2008 @@ -111,6 +111,7 @@ // the MasterFactory that will accept log when in replication master mode MasterFactory masterFac; boolean inReplicationMasterMode = false; + boolean inReplicationSlaveMode = false; //streams used to generated check sume log record ; see if there is any simpler way private ArrayOutputStream logOutputBuffer; @@ -134,6 +135,10 @@ bufferSize = 10; // make it very tiny } + // Puts this LogAccessFile object in replication slave or + // master mode if the database has such a role + logFactory.checkForReplication(this); + this.log = log; logFileSemaphore = log; this.logFactory = logFactory; @@ -162,6 +167,9 @@ // soft upgrade mode. writeChecksum = logFactory.checkVersion(RawStoreFactory.DERBY_STORE_MAJOR_VERSION_10, RawStoreFactory.DERBY_STORE_MINOR_VERSION_1); + + // Checksums are received from the master if in slave replication mode + if (inReplicationSlaveMode) writeChecksum = false; if(writeChecksum) { /** @@ -206,7 +214,6 @@ } currentBuffer.init(checksumLogRecordSize); - logFactory.checkForReplication(this); } @@ -729,6 +736,31 @@ protected void stopReplicationMasterRole() { inReplicationMasterMode = false; masterFac = null; + } + + /** + * Method to put this LogAccessFile object in replication slave + * mode, effectively disabling checksum writes. + * + * Because checksums are received from the replication master, the + * slave can not be allowed to add it's own checksums - that would + * invalidate the checksums and would stop the database from + * recovering. Replication slave mode must therefore be set before + * LogAccessFile decides whether to write it's own checksums, and + * this method is therefore indirectly called from the constructor + * of this class by calling LogFactory.checkForReplication + * + * If replication slave mode for the database is stopped after + * this object has been created, checksums cannot be reenabled + * without creating a new instance of this class. That is + * conveniently handled as LogToFile.recover completes (which + * automatically happens once replication slave mode is no longer + * active) + * + * @see LogToFile#checkForReplication + */ + protected void setReplicationSlaveRole() { + inReplicationSlaveMode = true; } /* write to the log file */ Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java?rev=608419&r1=608418&r2=608419&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java Thu Jan 3 02:22:35 2008 @@ -5076,6 +5076,8 @@ protected void checkForReplication(LogAccessFile log) { if (inReplicationMasterMode) { log.setReplicationMasterRole(masterFactory); + } else if (inReplicationSlaveMode) { + log.setReplicationSlaveRole(); } } Modified: db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml?rev=608419&r1=608418&r2=608419&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml Thu Jan 3 02:22:35 2008 @@ -4740,7 +4740,7 @@ XRE04 - Could not establish a connection to the master of the replicated database '{0}'. + Could not establish a connection to the peer of the replicated database '{0}'. dbname