void TransactionalRAMDirectory::transAbort() { if (!transOpen) _CLTHROWA(CL_ERR_RAMTransaction, "There is no open transaction."); // Delete each file in filesToRemoveOnAbort. FilenameSet::const_iterator itrDel = filesToRemoveOnAbort.begin(); for ( ; itrDel != filesToRemoveOnAbort.end(); ++itrDel) { size_t nameLength = itrDel->first.length(); // Special exception: Refrain from deleting a lock's flag file, as that // would interfere with the operation of the lock. if (!(nameLength >= 5 && itrDel->first.rightRef(5) == QLatin1String(".lock"))) { RAMDirectory::deleteFile(itrDel->first); } } // Ownership of the memory of both the key and the value never left files, // so there's no need for a special directive to filesToRemoveOnAbort. filesToRemoveOnAbort.clear(); // Now that any new-since-trans-start files with the same names as // already-present-at-trans-start files are out of the way, restore each // file in filesToRestoreOnAbort. TransFileMap::const_iterator itr = filesToRestoreOnAbort.begin(); for ( ; itr != filesToRestoreOnAbort.end(); ++itr) { files.put(itr->first, itr->second); filesToRestoreOnAbort.remove(itr->first); } CND_CONDITION(filesToRestoreOnAbort.size() == 0, "filesToRestoreOnAbort should be empty."); transResolved(); }
void TransactionalRAMDirectory::transCommit() { if (!transOpen) { _CLTHROWA(CL_ERR_RAMTransaction,"There is no open transaction."); } // All storage is in memory, so commit is ultra-simple. transResolved(); }
void TransactionalRAMDirectory::transAbort() { if (!transOpen) { _CLTHROWA(CL_ERR_RAMTransaction,"There is no open transaction."); } // Delete each file in filesToRemoveOnAbort. for (FilenameSet::const_iterator itrDel = filesToRemoveOnAbort.begin(); itrDel != filesToRemoveOnAbort.end(); ++itrDel ) { const char* name = itrDel->first; size_t nameLength = strlen(name); // Special exception: // Refrain from deleting a lock's flag file, as that would interfere with // the operation of the lock. if (!(nameLength >= 5 && strcmp(name + nameLength - 5, ".lock"))) { RAMDirectory::deleteFile(name); } } // Ownership of the memory of both the key and the value never left files, // so there's no need for a special directive to filesToRemoveOnAbort. filesToRemoveOnAbort.clear(); // Now that any new-since-trans-start files with the same names as // already-present-at-trans-start files are out of the way, restore each // file in filesToRestoreOnAbort. AStringArrayConst removeTheseWithoutDeletingMem; for (TransFileMap::const_iterator itr = filesToRestoreOnAbort.begin(); itr != filesToRestoreOnAbort.end(); ++itr ) { const char* name = itr->first; files.put(name, itr->second); // We've just transferred ownership of the memory of both the key and the // value to files; we must now direct filesToRestoreOnAbort not to delete // that memory as it removes the entry. This is performed in a separate // loop to avoid modifying filesToRestoreOnAbort while iterating over it. removeTheseWithoutDeletingMem.push_back(name); } for (AStringArrayConst::iterator itrRem = removeTheseWithoutDeletingMem.begin(); itrRem != removeTheseWithoutDeletingMem.end(); ++itrRem ) { filesToRestoreOnAbort.remove(*itrRem); //remove iterator } CND_CONDITION(filesToRestoreOnAbort.size() == 0, "filesToRestoreOnAbort should be empty."); transResolved(); }