<P> MT- read only
*/
private long readControlFile(StorageFile logControlFileName, Properties startParams)
throws IOException, StandardException
{
StorageRandomAccessFile logControlFile = null;
ByteArrayInputStream bais = null;
DataInputStream dais = null;
logControlFile = privRandomAccessFile(logControlFileName, "r");
boolean upgradeNeeded = false;
long value = LogCounter.INVALID_LOG_INSTANT;
long onDiskChecksum = 0;
long controlFilelength = logControlFile.length();
byte barray[] = null;
try
{
// The length of the file is less than the minimum in any version
// It is possibly hosed , no point in reading data from this file
// skip reading checksum control file is before 1.5
if (controlFilelength < 16)
onDiskChecksum = -1;
else if (controlFilelength == 16)
{
barray = new byte[16];
logControlFile.readFully(barray);
}else if (controlFilelength > 16)
{
barray = new byte[(int) logControlFile.length() - 8];
logControlFile.readFully(barray);
onDiskChecksum = logControlFile.readLong();
if (onDiskChecksum !=0 )
{
checksum.reset();
checksum.update(barray, 0, barray.length);
}
}
if ( onDiskChecksum == checksum.getValue() || onDiskChecksum ==0)
{
bais = new ByteArrayInputStream(barray);
dais = new DataInputStream(bais);
if (dais.readInt() != fid)
{
throw StandardException.newException(
SQLState.LOG_INCOMPATIBLE_FORMAT, dataDirectory);
}
int obsoleteVersion = dais.readInt();
value = dais.readLong();
if (SanityManager.DEBUG)
{
if (SanityManager.DEBUG_ON(LogToFile.DBG_FLAG))
SanityManager.DEBUG(LogToFile.DBG_FLAG,
"log control file ckp instance = " +
LogCounter.toDebugString(value));
}
// from version 1.5 onward, we added an int for storing JBMS
// version and an int for storing checkpoint interval
// and log switch interval
onDiskMajorVersion = dais.readInt();
onDiskMinorVersion = dais.readInt();
int dbBuildNumber = dais.readInt();
int flags = dais.readByte();
// check if the database was booted previously at any time with
// derby.system.durability=test mode
// If yes, then on a boot error we report that this setting is
// probably the cause for the error and also log a warning
// in the derby.log that this mode was set previously
wasDBInDurabilityTestModeNoSync =
(flags & IS_DURABILITY_TESTMODE_NO_SYNC_FLAG) != 0;
if (SanityManager.DEBUG) {
if (SanityManager.DEBUG_ON(LogToFile.DBG_FLAG))
SanityManager.DEBUG(LogToFile.DBG_FLAG,
"log control file, was derby.system.durability set to test = " +
wasDBInDurabilityTestModeNoSync);
}
onDiskBeta = (flags & IS_BETA_FLAG) != 0;
if (onDiskBeta)
{
// if is beta, can only be booted by exactly the same
// version
if (!jbmsVersion.isBeta() ||
onDiskMajorVersion != jbmsVersion.getMajorVersion() ||
onDiskMinorVersion != jbmsVersion.getMinorVersion())
{
boolean forceBetaUpgrade = false;
if (SanityManager.DEBUG)
{
// give ourselves an out for this beta check for debugging purposes
if (SanityManager.DEBUG_ON("forceBetaUpgrade"))
{
Monitor.logMessage("WARNING !! : forcing beta upgrade.");
forceBetaUpgrade =true;
}
}
if (!forceBetaUpgrade)
{
throw StandardException.newException(
SQLState.LOG_CANNOT_UPGRADE_BETA,
dataDirectory,
ProductVersionHolder.simpleVersionString(onDiskMajorVersion, onDiskMinorVersion, onDiskBeta));
}
}
}
// JBMS_VERSION must be numbered in a way so that it is ever
// increasing. We are backwards compatible but not forwards
// compatible
//
if (onDiskMajorVersion > jbmsVersion.getMajorVersion() ||
(onDiskMajorVersion == jbmsVersion.getMajorVersion() &&
onDiskMinorVersion > jbmsVersion.getMinorVersion()))
{
// don't need to worry about point release, no format
// upgrade is allowed.
throw StandardException.newException(
SQLState.LOG_INCOMPATIBLE_VERSION,
dataDirectory,
ProductVersionHolder.simpleVersionString(onDiskMajorVersion, onDiskMinorVersion, onDiskBeta));
}
// Ensure that upgrade has been requested for a major or minor upgrade
// maintaince (point) versions should not require an upgrade.
if ((onDiskMajorVersion != jbmsVersion.getMajorVersion()) ||
(onDiskMinorVersion != jbmsVersion.getMinorVersion()))
{
upgradeNeeded = true;
}
// if checksum is zeros in version > 3.5 file is hosed
// except incase of upgrade from versions <= 3.5
if (onDiskChecksum == 0 &&
(!(onDiskMajorVersion <= 3 && onDiskMinorVersion <=5) ||
onDiskMajorVersion == 0))
value = LogCounter.INVALID_LOG_INSTANT;
}
}
finally
{
if (logControlFile != null)
logControlFile.close();
if (bais != null)
bais.close();
if (dais != null)
dais.close();
}