db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1102421 - in /db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/store/raw/log: LogAccessFile.java LogCounter.java LogToFile.java
Date Thu, 12 May 2011 18:58:01 GMT
Author: rhillegas
Date: Thu May 12 18:58:01 2011
New Revision: 1102421

URL: http://svn.apache.org/viewvc?rev=1102421&view=rev
Log:
DERBY-2254: Ported 1102417 from trunk to 10.8 branch.

Modified:
    db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/store/raw/log/LogAccessFile.java
    db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/store/raw/log/LogCounter.java
    db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java

Modified: db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/store/raw/log/LogAccessFile.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/store/raw/log/LogAccessFile.java?rev=1102421&r1=1102420&r2=1102421&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/store/raw/log/LogAccessFile.java
(original)
+++ db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/store/raw/log/LogAccessFile.java
Thu May 12 18:58:01 2011
@@ -930,6 +930,9 @@ public class LogAccessFile 
 
 	}
 
+    /** Return the length of a checksum record */
+    public  int getChecksumLogRecordSize() { return checksumLogRecordSize; }
+
 
 	protected void writeEndMarker(int marker) throws IOException, StandardException 
 	{

Modified: db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/store/raw/log/LogCounter.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/store/raw/log/LogCounter.java?rev=1102421&r1=1102420&r2=1102421&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/store/raw/log/LogCounter.java
(original)
+++ db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/store/raw/log/LogCounter.java
Thu May 12 18:58:01 2011
@@ -90,9 +90,9 @@ public class LogCounter implements LogIn
 			SanityManager.ASSERT(position > 0, "illegal file position");
 
 			SanityManager.ASSERT(position < MAX_LOGFILE_SIZE,
-							 "log file position exceeded max log file size");
+							 "log file position exceeded max log file size. log file position = " + position );
 			SanityManager.ASSERT(fileNumber < MAX_LOGFILE_NUMBER,
-							 "log file number exceeded max log file number");
+							 "log file number exceeded max log file number. log file number = " + fileNumber );
 		}
 
 		this.fileNumber = fileNumber;
@@ -118,9 +118,9 @@ public class LogCounter implements LogIn
 			SanityManager.ASSERT(filepos > 0, "illegal file position");
 
 			SanityManager.ASSERT(filepos < MAX_LOGFILE_SIZE,
-							 "log file position exceeded max log file size");
+							 "log file position exceeded max log file size. log file position = " + filepos );
 			SanityManager.ASSERT(filenum < MAX_LOGFILE_NUMBER,
-							 "log file number exceeded max log file number");
+							 "log file number exceeded max log file number. log file number = " + filenum );
 		}
 
 		return ((filenum << FILE_NUMBER_SHIFT) | filepos);

Modified: db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java?rev=1102421&r1=1102420&r2=1102421&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java
(original)
+++ db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java
Thu May 12 18:58:01 2011
@@ -225,6 +225,8 @@ public final class LogToFile implements 
 								  Serviceable, java.security.PrivilegedExceptionAction
 {
 
+	private static final    long INT_LENGTH = 4L;
+
 	private static int fid = StoredFormatIds.FILE_STREAM_LOG_FILE; 
 
 	// format Id must fit in 4 bytes
@@ -1032,7 +1034,7 @@ public final class LogToFile implements 
 
                         // successfully init'd the log file - set up markers,
                         // and position at the end of the log.
-						endPosition = theLog.getFilePointer();
+						setEndPosition( theLog.getFilePointer() );
 						lastFlush   = endPosition;
 						
 						//if write sync is true , prellocate the log file
@@ -1103,7 +1105,7 @@ public final class LogToFile implements 
 
 					if (!ReadOnlyDB)
 					{
-						endPosition = LogCounter.getLogFilePosition(logEnd);
+						setEndPosition( LogCounter.getLogFilePosition(logEnd) );
 
 						//
 						// The end of the log is at endPosition.  Which is where
@@ -2098,7 +2100,7 @@ public final class LogToFile implements 
 					
 					logOut.writeEndMarker(0);
 
-					endPosition += 4;
+					setEndPosition( endPosition + INT_LENGTH );
 					//set that we are in log switch to prevent flusher 
 					//not requesting  to switch log again 
 					inLogSwitch = true; 
@@ -2118,7 +2120,7 @@ public final class LogToFile implements 
 					
 					logWrittenFromLastCheckPoint += endPosition;
 
-					endPosition = newLog.getFilePointer();
+					setEndPosition( newLog.getFilePointer() );
 					lastFlush = endPosition;
 					
 					if(isWriteSynced)
@@ -3380,7 +3382,7 @@ public final class LogToFile implements 
                             SQLState.LOG_SEGMENT_NOT_EXIST, logFile.getPath());
                     }
 
-					endPosition = firstLog.getFilePointer();
+					setEndPosition( firstLog.getFilePointer() );
 					lastFlush = firstLog.getFilePointer();
 
                     //if write sync is true , prellocate the log file
@@ -3800,15 +3802,18 @@ public final class LogToFile implements 
 				 */
 
 				// see if the log file is too big, if it is, switch to the next
-				// log file
-				if ((endPosition + LOG_RECORD_OVERHEAD + length) >=
-					LogCounter.MAX_LOGFILE_SIZE)
+				// log file. account for an extra INT_LENGTH because switchLogFile()
+                // writes an extra 0 at the end of the log. in addition, a checksum log record
+                // may need to be written (see DERBY-2254).
+                int     checksumLogRecordSize = logOut.getChecksumLogRecordSize();
+				if ( (endPosition + LOG_RECORD_OVERHEAD + length + INT_LENGTH + checksumLogRecordSize)
>=
+                     LogCounter.MAX_LOGFILE_SIZE)
 				{
 					switchLogFile();
 
 					// still too big??  Giant log record?
-					if ((endPosition + LOG_RECORD_OVERHEAD + length) >=
-						LogCounter.MAX_LOGFILE_SIZE) 
+                    if ( (endPosition + LOG_RECORD_OVERHEAD + length + INT_LENGTH + checksumLogRecordSize)
>=
+                         LogCounter.MAX_LOGFILE_SIZE)
                     {
 						throw StandardException.newException(
                                 SQLState.LOG_EXCEED_MAX_LOG_FILE_SIZE, 
@@ -3820,7 +3825,7 @@ public final class LogToFile implements 
 				}
 
 				//reserve the space for the checksum log record
-				endPosition += logOut.reserveSpaceForChecksum(length, logFileNumber,endPosition);
+				setEndPosition( endPosition + logOut.reserveSpaceForChecksum(length, logFileNumber,endPosition)
);
 
 				// don't call currentInstant since we are already in a
 				// synchronzied block 
@@ -3849,7 +3854,7 @@ public final class LogToFile implements 
 					}
 				}
 
-				endPosition += (length + LOG_RECORD_OVERHEAD);
+				setEndPosition( endPosition + (length + LOG_RECORD_OVERHEAD) );
 			}
 		}
 		catch (IOException ioe)
@@ -4665,19 +4670,19 @@ public final class LogToFile implements 
 				{
 					// reserve the space for the checksum log record
 					// NOTE:  bytesToWrite include the log record overhead.
-					endPosition += 
+					setEndPosition( endPosition +
 						logOut.reserveSpaceForChecksum(((length + LOG_RECORD_OVERHEAD) 
 														< bytesToWrite ? length :
 														(bytesToWrite - LOG_RECORD_OVERHEAD)),
-													   logFileNumber,endPosition);
+													   logFileNumber,endPosition) );
 					instant = currentInstant();
 
 					//check if the length of the records to be written is 
 					//actually smaller than the number of bytesToWrite 
 					if(length + LOG_RECORD_OVERHEAD < bytesToWrite)
-						endPosition += (length + LOG_RECORD_OVERHEAD);
+                    { setEndPosition( endPosition + (length + LOG_RECORD_OVERHEAD) ); }
 					else
-						endPosition += bytesToWrite;
+                    { setEndPosition( endPosition + bytesToWrite ); }
 
 					while(true)		// so we can break out without returning out of
 						// sync block...
@@ -5300,7 +5305,7 @@ public final class LogToFile implements 
                 logEndInstant = scanOfHighestLogFile.getLogRecordEnd();
             }
 
-            endPosition = LogCounter.getLogFilePosition(logEndInstant);
+            setEndPosition( LogCounter.getLogFilePosition(logEndInstant) );
 
             // endPosition and logFileNumber now point to the end of the
             // highest log file. This is where a new log record should be
@@ -5738,6 +5743,17 @@ public final class LogToFile implements 
 		}
 	}
 
+    /** set the endPosition of the log and make sure the new position won't spill off the
end of the log */
+    private void    setEndPosition( long newPosition )
+    {
+		if (SanityManager.DEBUG)
+        {
+			SanityManager.ASSERT(newPosition < LogCounter.MAX_LOGFILE_SIZE,
+							 "log file would spill past its legal end if the end were set to = " + newPosition
);
+		}
+
+        endPosition = newPosition;
+    }
 
 	
 



Mime
View raw message