// when instantiated, old data are upgraded
TidList(FileStore p, File topDir, File oldTop)
throws BrokerException {
File oldFile = new File(oldTop, BASENAME);
PHashMap olddata = null;
backingFile = new File(topDir, BASENAME);
try {
// load old data
// safe=false; reset=false
olddata = new PHashMap(oldFile, false, false);
} catch (IOException e) {
logger.log(logger.ERROR, br.X_UPGRADE_TRANSACTIONS_FAILED,
oldFile, backingFile, e);
throw new BrokerException(
br.getString(br.X_UPGRADE_TRANSACTIONS_FAILED,
oldFile, backingFile), e);
}
try {
olddata.load();
} catch (IOException e) {
logger.log(logger.ERROR, br.X_UPGRADE_TRANSACTIONS_FAILED,
oldFile, backingFile, e);
throw new BrokerException(
br.getString(br.X_UPGRADE_TRANSACTIONS_FAILED,
oldFile, backingFile), e);
} catch (ClassNotFoundException e) {
logger.log(logger.ERROR, br.X_UPGRADE_TRANSACTIONS_FAILED,
oldFile, backingFile, e);
throw new BrokerException(
br.getString(br.X_UPGRADE_TRANSACTIONS_FAILED,
oldFile, backingFile), e);
} catch (PHashMapLoadException le) {
while (le != null) {
logger.log(Logger.WARNING,
br.X_FAILED_TO_LOAD_A_TXN_FROM_OLDSTORE, le);
// save info in LoadException
LoadException e = new LoadException(le.getMessage(),
le.getCause());
e.setKey(le.getKey());
e.setValue(le.getValue());
e.setKeyCause(le.getKeyCause());
e.setValueCause(le.getValueCause());
e.setNextException(loadException);
loadException = e;
// get the chained exception
le = le.getNextException();
}
}
VRFileWarning w = olddata.getWarning();
if (w != null) {
logger.log(logger.WARNING,
"possible loss of transaction data in old store", w);
}
try {
useMemoryMappedFile = config.getBooleanProperty(
TXN_USE_MEMORY_MAPPED_FILE_PROP,
DEFAULT_TXN_USE_MEMORY_MAPPED_FILE);
updateOptimization = useMemoryMappedFile &&
config.getBooleanProperty(
TXN_UPDATE_OPTIMIZATION_PROP,
DEFAULT_TXN_UPDATE_OPTIMIZATION);
// pass in safe=false; caller decide when to sync
// safe=false; reset=false
if (useMemoryMappedFile) {
tidMap = new PHashMapMMF(
backingFile, oldFile.length(), 1024, false, false);
if (updateOptimization) {
((PHashMapMMF)tidMap).intClientData(CLIENT_DATA_SIZE);
}
} else {
tidMap = new PHashMap(
backingFile, oldFile.length(), 1024, false, false);
}
} catch (IOException e) {
logger.log(logger.ERROR, br.X_UPGRADE_TRANSACTIONS_FAILED,
oldFile, backingFile, e);
throw new BrokerException(
br.getString(br.X_UPGRADE_TRANSACTIONS_FAILED,
oldFile, backingFile), e);
}
try {
tidMap.load();
// Process client data
loadClientData();
} catch (ClassNotFoundException e) {
// should not happen so throw exception
logger.log(logger.ERROR, br.X_UPGRADE_TRANSACTIONS_FAILED,
oldFile, backingFile, e);
throw new BrokerException(
br.getString(br.X_UPGRADE_TRANSACTIONS_FAILED,
oldFile, backingFile), e);
} catch (IOException e) {
// should not happen so throw exception
logger.log(logger.ERROR, br.X_UPGRADE_TRANSACTIONS_FAILED,
oldFile, backingFile, e);
throw new BrokerException(
br.getString(br.X_UPGRADE_TRANSACTIONS_FAILED,
oldFile, backingFile), e);
} catch (PHashMapLoadException e) {
// should not happen so throw exception
logger.log(logger.ERROR, br.X_UPGRADE_TRANSACTIONS_FAILED,
oldFile, backingFile, e);
throw new BrokerException(
br.getString(br.X_UPGRADE_TRANSACTIONS_FAILED,
oldFile, backingFile), e);
}
w = tidMap.getWarning();
if (w != null) {
logger.log(logger.WARNING,
"possible loss of transaction data", w);
}
// just copy old data to new store
Iterator itr = olddata.entrySet().iterator();
while (itr.hasNext()) {
Map.Entry entry = (Map.Entry)itr.next();
Object key = entry.getKey();
Object value = entry.getValue();
// replace TransactionState obj with TransactionInfo obj
tidMap.put(key, new TransactionInfo((TransactionState)value));
}
olddata.close();
if (Store.getDEBUG()) {
logger.log(logger.DEBUG,
"TidList: upgraded " + tidMap.size() + " transactions");
}