// ----------------------------------------------------------------------------- // CSendObject::DoHandleResponsePhasePropListL // SendObjectPropList // ----------------------------------------------------------------------------- // TBool CSendObject::DoHandleResponsePhasePropListL() { PRINT( _L("MM MTP => CSendObject::DoHandleResponsePhasePropListL" ) ); TMTPResponseCode responseCode = EMTPRespCodeOK; TInt invalidParameterIndex = KErrNotFound; responseCode = VerifyObjectPropListL( invalidParameterIndex ); TInt err = KErrNone; if ( responseCode != EMTPRespCodeOK ) { TUint32 parameters[4]; parameters[0] = 0; parameters[1] = 0; parameters[2] = 0; parameters[3] = invalidParameterIndex; SendResponseL( responseCode, 4, parameters ); Rollback(); } else if ( ExistsL( iFullPath ) ) { SendResponseL( EMTPRespCodeAccessDenied ); Rollback(); } else err = ReserveObjectL(); PRINT( _L( "MM MTP <= CSendObject::DoHandleResponsePhasePropListL" ) ); return ( responseCode == EMTPRespCodeOK && err == KErrNone); }
// ----------------------------------------------------------------------------- // CSendObject::CheckSendingState // Helper Functions // Verify if the SendObject request comes after SendObjectInfo request // @return EMTPRespCodeOK if SendObject request comes after a valid SendObjectInfo request, otherwise // EMTPRespCodeNoValidObjectInfo // ----------------------------------------------------------------------------- // TMTPResponseCode CSendObject::CheckSendingStateL() { PRINT( _L( "MM MTP => CSendObject::CheckSendingState" ) ); TMTPResponseCode result = EMTPRespCodeOK; iOperationCode = Request().Uint16( TMTPTypeRequest::ERequestOperationCode ); PRINT1( _L( "MM MTP <> CSendObject iOperationCode = 0x%x" ), iOperationCode ); if ( iOperationCode == EMTPOpCodeSendObject ) { // In ParseRouter everytime SendObject gets resolved then will be removed from Registry // right away therefore we need reRegister it here again in case possible cancelRequest // against this SendObject being raised. iExpectedSendObjectRequest.SetUint32( TMTPTypeRequest::ERequestSessionID, iSessionId ); iFramework.RouteRequestRegisterL( iExpectedSendObjectRequest, iConnection ); } if ( iProgress == EObjectNone ) { if ( iOperationCode == EMTPOpCodeSendObject ) { PRINT( _L( "MM MTP <> CSendObject::CheckSendingState EMTPRespCodeNoValidObjectInfo" ) ); result = EMTPRespCodeNoValidObjectInfo; } } else if ( iProgress == EObjectInfoSucceed ) { if ( iOperationCode == EMTPOpCodeSendObjectInfo ) { delete iObjectInfo; iObjectInfo = NULL; Rollback(); iProgress = EObjectNone; } else if ( iOperationCode == EMTPOpCodeSendObjectPropList ) { delete iObjectPropList; iObjectPropList = NULL; Rollback(); iProgress = EObjectNone; } } else { Panic( EMmMTPDpSendObjectStateInvalid ); } PRINT1( _L( "MM MTP <= CSendObject::CheckSendingState result = 0x%x" ), result ); return result; }
bool AutopatcherMySQLRepository::CreateAutopatcherTables(void) { if (!IsConnected()) return false; ExecuteBlockingCommand("BEGIN;"); if (!ExecuteBlockingCommand( "CREATE TABLE Applications (" "applicationID INT AUTO_INCREMENT," "applicationName VARCHAR(255) NOT NULL UNIQUE," "changeSetID integer NOT NULL DEFAULT 0," "userName TEXT NOT NULL," "PRIMARY KEY (applicationID));" )) {Rollback(); return false;} if (!ExecuteBlockingCommand( "CREATE TABLE FileVersionHistory (" "fileID INT AUTO_INCREMENT," "applicationID INT NOT NULL, " "filename TEXT NOT NULL," "fileLength INT," "content LONGBLOB," "contentHash TINYBLOB," "patch LONGBLOB," "createFile TINYINT NOT NULL," "modificationDate TIMESTAMP NOT NULL DEFAULT LOCALTIMESTAMP," "lastSentDate TIMESTAMP," "timesSent INT NOT NULL DEFAULT 0," "changeSetID INT NOT NULL," "userName TEXT NOT NULL," "PRIMARY KEY (fileID)); " )) {Rollback(); return false;} if (!ExecuteBlockingCommand( "CREATE VIEW AutoPatcherView AS SELECT " "FileVersionHistory.applicationid," "Applications.applicationName," "FileVersionHistory.fileID," "FileVersionHistory.fileName," "FileVersionHistory.createFile," "FileVersionHistory.fileLength," "FileVersionHistory.changeSetID," "FileVersionHistory.lastSentDate," "FileVersionHistory.modificationDate," "FileVersionHistory.timesSent " "FROM (FileVersionHistory JOIN Applications ON " "( FileVersionHistory.applicationID = Applications.applicationID )) " "ORDER BY Applications.applicationID ASC, FileVersionHistory.fileID ASC;" )) {Rollback(); return false;} return ExecuteBlockingCommand("COMMIT;"); }
CAutoTrans::~CAutoTrans(void) { try { const int curr_TranCount = GetTranCount(); if (curr_TranCount >= m_TranCount) { if (curr_TranCount > m_TranCount) { // A nested transaction is started and not finished yet ... ERR_POST_X(1, Warning << "A nested transaction was started and " "it is not finished yet."); } // Assume that we are on the same level of transaction nesting. if(m_Abort) { Rollback(); } else { Commit(); } } // Skip commit/rollback if this transaction was previously // explicitly finished ... } NCBI_CATCH_ALL_X( 10, NCBI_CURRENT_FUNCTION ) }
void RefactoringStorage::StoreTokens(const wxString& filename, const CppToken::List_t& tokens, bool startTx) { if ( !IsCacheReady() ) { return; } if ( !m_db.IsOpen() ) return; try { if ( startTx ) { Begin(); } DoDeleteFile(filename); CppToken::List_t::const_iterator iter = tokens.begin(); for(; iter != tokens.end(); ++iter ) { iter->store( &m_db ); } DoUpdateFileTimestamp(filename); if ( startTx ) { Commit(); } } catch (wxSQLite3Exception &e) { if ( startTx ) { Rollback(); } wxUnusedVar(e); } }
Ydb_RetCode Ydb_Scheduler::AddOp(Ydb_Trans* trans, Ydb_Op* op) { // TODO(aporter): Upgrading a lock cause it to be unlocked only once? bool ret = false; mutex_->Lock(); do { // TODO(aporter): get a result code indicating that the lock is held or // that a deadlock would occur ret = lock_table_->Lock(trans, op); if (!ret) { // Another transaction already holds a lock on the key. To prevent // deadlocks, we check for a cycle in a dependancy graph. const TransList* trans_list = lock_table_->GetLockHolders(op->key()); assert(trans_list->size() != 0); // For each transaction for (TransList::const_iterator iter = trans_list->begin(); iter != trans_list->end(); ++iter) { if (!deadlock_tree_->AddDependency(*iter, trans)) { // Blocking this transaction will cause a deadlock, so it must abort mutex_->Unlock(); Rollback(trans); return YDB_DEADLOCK; } } condvar_->Wait(); // atomicly releses and re-grabs mutex_ } } while (!ret); mutex_->Unlock(); trans->AddOp(op); return op->Execute(*map_); }
// execution sql statement. int OracleDB::ExecSql(const string& aSql, int aCommitFlag) { try { if (!isOtlConnOK_ && RET_ERROR == ConnDb()) { LOG_ERROR("can not connect to db."); return RET_ERROR; } LOG_DEBUG("sql=(%s)", aSql.c_str()); otl_cursor::direct_exec(otlConn_, aSql.c_str(), otl_exception::enabled); if (aCommitFlag == 1) { otl_cursor::direct_exec(otlConn_, "commit", otl_exception::enabled); } LOG_DEBUG("OK.End"); return RET_OK; } catch (otl_exception &p) { LOG_ERROR("{%s} error, msg=(%s),stm_text=(%s)," "sqlstate=(%s),var_info=(%s).", aSql.c_str(), p.msg, p.stm_text, p.sqlstate, p.var_info); } catch (...) { LOG_ERROR("{%s} error.", aSql.c_str()); } if (aCommitFlag == 1) { int retv = Rollback(); LOG_INFO("rollback-(%s)", (RET_OK == retv) ? "OK":"Fail"); } LOG_INFO("Err.End"); return RET_ERROR; }
bool PostgreSQLInterface::IsResultSuccessful(PGresult *result, bool rollbackOnFailure) { if (result==0) return false; bool success=false; ExecStatusType execStatus = PQresultStatus(result); strcpy(lastError,PQresultErrorMessage(result)); switch (execStatus) { case PGRES_COMMAND_OK: success=true; break; case PGRES_EMPTY_QUERY: break; case PGRES_TUPLES_OK: success=true; break; case PGRES_COPY_OUT: break; case PGRES_COPY_IN: break; case PGRES_BAD_RESPONSE: break; case PGRES_NONFATAL_ERROR: break; case PGRES_FATAL_ERROR: if (rollbackOnFailure) Rollback(); break; } return success; }
/// Single forward execution step void spec::Step() { Event *ev; POSE_TimeType lastGVT = localPVT->getGVT(); int iter = 0; if (!parent->cancels.IsEmpty()) CancelUnexecutedEvents(); if (eq->RBevent) Rollback(); if (!parent->cancels.IsEmpty()) CancelEvents(); parent->Status(); // Shorten the leash as we near POSE_endtime if ((POSE_endtime > POSE_UnsetTS) && (lastGVT + timeLeash > POSE_endtime)) timeLeash = POSE_endtime - lastGVT + 1; // Prepare to execute an event ev = eq->currentPtr; while ((ev->timestamp > POSE_UnsetTS) && (ev->timestamp <= lastGVT + timeLeash)) { // do all events within the speculative window iter++; currentEvent = ev; ev->done = 2; parent->ResolveFn(ev->fnIdx, ev->msg); // execute it ev->done = 1; // complete the event execution eq->mem_usage++; eq->ShiftEvent(); // shift to next event ev = eq->currentPtr; // reset ev } #if !CMK_TRACE_DISABLED if(pose_config.stats) if (iter > 0) localStats->Loop(); #endif }
void Transaction::Rollback() { IgniteError err; Rollback(err); IgniteError::ThrowIfNeeded(err); }
CDscDatabase::~CDscDatabase() { if(iIsEnumOpened) { Rollback(); } iView.Close(); iDatabase.Close(); iDbsSession.Close(); }
//Close the view opened by EnumOpenLC() and rollback the transaction void CDscDatabase::EnumClose() { //To avoid double close if (iIsEnumOpened) { iView.Close(); iIsEnumOpened=EFalse; //Roll back transaction Rollback(); } }
/** * @brief Generic update in Media Library database * * @param p_ml the media library object * @param selected_type the type of the element we're selecting * @param where the list of ids or uri to change * @param changes list of changes to make in the entries * @return VLC_SUCCESS or VLC_EGENERIC * @note This function is transactional */ int Update( media_library_t *p_ml, ml_select_e selected_type, const char* psz_lvalue, ml_ftree_t *where, vlc_array_t *changes ) { int i_ret = VLC_EGENERIC; char *psz_query = NULL; char *psz_id_query = NULL; char **pp_results = NULL; int i_rows = 0, i_cols = 0; i_ret = BuildUpdate( p_ml, &psz_query, &psz_id_query, psz_lvalue, selected_type, where, changes ); if( i_ret != VLC_SUCCESS ) { msg_Err(p_ml,"Failed to generate update query" ); return i_ret; } i_ret = VLC_EGENERIC; Begin( p_ml ); if( QuerySimple( p_ml, "%s", psz_query ) != VLC_SUCCESS ) { msg_Err( p_ml, "Couldn't run the generated update query successfully" ); goto quitdelete; } /* Get the updated IDs to send events! */ if( Query( p_ml, &pp_results, &i_rows, &i_cols, psz_id_query ) != VLC_SUCCESS ) goto quitdelete; i_ret = VLC_SUCCESS; quitdelete: if( i_ret != VLC_SUCCESS ) Rollback( p_ml ); else { Commit( p_ml ); if( i_rows > 0 ) { for( int i = 0; i < i_rows; i++ ) { var_SetInteger( p_ml, "media-meta-change", atoi( pp_results[i*i_cols] ) ); } } } FreeSQLResult( p_ml, pp_results ); free( psz_id_query ); free( psz_query ); return i_ret; }
Transaction::~Transaction() { if (!Commited) { try { Rollback(); } catch (std::exception &) { } } SQLSetConnectOption(Conn.GetHolder().GetHandle(), SQL_AUTOCOMMIT, SavedOption); }
Transaction::~Transaction() { if(m_intrans) { __try { Rollback(); } __except(EXCEPTION_EXECUTE_HANDLER) { return; } } }
// ----------------------------------------------------------------------------- // CSendObject::~CSendObject // Destructor // ----------------------------------------------------------------------------- // EXPORT_C CSendObject::~CSendObject() { Rollback(); iRollbackList.Close(); delete iFileReceived; delete iParentSuid; delete iObjectInfo; delete iObjectPropList; delete iDateMod; delete iReceivedObjectInfo; PRINT( _L( "MM MTP <= CSendObject::~CSendObject" ) ); }
NS_IMETHODIMP nsAutoSyncState::TryCurrentGroupAgain(uint32_t aRetryCount) { SetState(stReadyToDownload); nsresult rv; if (++mRetryCounter > aRetryCount) { ResetRetryCounter(); rv = NS_ERROR_FAILURE; } else rv = Rollback(); return rv; }
void Tokenizer::SkipUntil(Token const& aToken) { nsACString::const_char_iterator rollback = mCursor; const Token eof = Token::EndOfFile(); Token t; while (Next(t)) { if (aToken.Equals(t) || eof.Equals(t)) { Rollback(); break; } } mRollback = rollback; }
void opt3::Step() { Event *ev; POSE_TimeType lastGVT = localPVT->getGVT(); int iter = 0; if (!parent->cancels.IsEmpty()) CancelUnexecutedEvents(); if (eq->RBevent) Rollback(); if (!parent->cancels.IsEmpty()) CancelEvents(); parent->Status(); // Prepare to execute an event ev = eq->currentPtr; // Shorten the leash as we near POSE_endtime if ((POSE_endtime > POSE_UnsetTS) && (lastGVT + timeLeash > POSE_endtime)) timeLeash = POSE_endtime - lastGVT + 1; if ((ev->timestamp > POSE_UnsetTS) && (ev->timestamp <= lastGVT + timeLeash)) { POSE_TimeType fix_time = ev->timestamp; while (ev->timestamp == fix_time) { // do all events at the first available timestamp iter++; currentEvent = ev; ev->done = 2; parent->ResolveFn(ev->fnIdx, ev->msg); // execute it ev->done = 1; // complete the event execution eq->mem_usage++; eq->ShiftEvent(); // shift to next event ev = eq->currentPtr; // reset ev } #ifndef CMK_OPTIMIZE if(pose_config.stats) if (iter > 0) localStats->Loop(); #endif if (eq->currentPtr->timestamp > POSE_UnsetTS) { // execute next event if there is one prioMsg *pm = new prioMsg; pm->setPriority(eq->currentPtr->timestamp-POSE_TimeMax); POSE_Objects[parent->thisIndex].Step(pm); } } }
//---------------------------------------------------------------------------------------- void DeviceContext::ProcessCommand(size_t deviceIndex, const DeviceContextCommand& command, volatile ReferenceCounterType& remainingThreadCount) { switch(command.type) { case DeviceContextCommand::TYPE_SUSPENDEXECUTION: SuspendExecution(); break; case DeviceContextCommand::TYPE_COMMIT: Commit(); break; case DeviceContextCommand::TYPE_ROLLBACK: Rollback(); break; case DeviceContextCommand::TYPE_GETNEXTTIMINGPOINT:{ unsigned int accessContext = 0; command.timesliceResult[deviceIndex] = GetNextTimingPoint(accessContext); command.contextResult[deviceIndex] = accessContext; break;} case DeviceContextCommand::TYPE_NOTIFYUPCOMINGTIMESLICE: NotifyUpcomingTimeslice(command.timeslice); break; case DeviceContextCommand::TYPE_NOTIFYBEFOREEXECUTECALLED: NotifyBeforeExecuteCalled(); break; case DeviceContextCommand::TYPE_NOTIFYAFTEREXECUTECALLED: NotifyAfterExecuteCalled(); break; case DeviceContextCommand::TYPE_EXECUTETIMESLICE: if(ActiveDevice()) { ExecuteTimeslice(command.timeslice); } break; case DeviceContextCommand::TYPE_WAITFOREXECUTECOMPLETE: if(ActiveDevice()) { WaitForCompletionAndDetectSuspendLock(*suspendedThreadCountPointer, remainingThreadCount, *commandMutexPointer, suspendManager); } break; } }
/// Single forward execution step void adapt2::Step() { Event *ev; POSE_TimeType lastGVT = localPVT->getGVT(); int iter=0; rbFlag = 0; if (!parent->cancels.IsEmpty()) CancelUnexecutedEvents(); if (eq->RBevent) Rollback(); if (!parent->cancels.IsEmpty()) CancelEvents(); parent->Status(); if (rbFlag) { timeLeash = eq->currentPtr->timestamp - lastGVT; if (timeLeash < pose_config.min_leash) timeLeash = pose_config.min_leash; } else if (timeLeash < pose_config.max_leash) timeLeash += pose_config.leash_flex; // Shorten the leash as we near POSE_endtime if ((POSE_endtime > POSE_UnsetTS) && (lastGVT + timeLeash > POSE_endtime)) timeLeash = POSE_endtime - lastGVT; // Prepare to execute an event ev = eq->currentPtr; while ((ev->timestamp > POSE_UnsetTS) && (ev->timestamp <= lastGVT + timeLeash)) { // do all events at under timeLeash iter++; currentEvent = ev; ev->done = 2; parent->ResolveFn(ev->fnIdx, ev->msg); // execute it ev->done = 1; // complete the event execution eq->mem_usage++; eq->ShiftEvent(); // shift to next event ev = eq->currentPtr; } #if !CMK_TRACE_DISABLED if(pose_config.stats) if (iter > 0) localStats->Loop(); #endif }
bool AutopatcherMySQLRepository::UpdateApplicationFiles(const char *applicationName, const char *applicationDirectory, const char *userName, FileListProgress *cb) { MYSQL_STMT *stmt; MYSQL_BIND bind[3]; char query[512]; FileList filesOnHarddrive; filesOnHarddrive.SetCallback(cb); int prepareResult; my_bool falseVar=false; RakNet::RakString escapedApplicationName = GetEscapedString(applicationName); filesOnHarddrive.AddFilesFromDirectory(applicationDirectory,"", true, true, true, FileListNodeContext(0,0)); if (filesOnHarddrive.fileList.Size()==0) { sprintf(lastError,"ERROR: Can't find files at %s in UpdateApplicationFiles\n",applicationDirectory); return false; } sprintf(query, "SELECT applicationID FROM Applications WHERE applicationName='%s';", escapedApplicationName.C_String()); int applicationID; if (!ExecuteQueryReadInt(query, &applicationID)) { sprintf(lastError,"ERROR: %s not found in UpdateApplicationFiles\n",escapedApplicationName.C_String()); return false; } if (!ExecuteBlockingCommand("BEGIN;")) { return false; } sprintf(query, "UPDATE Applications SET changeSetId = changeSetId + 1 where applicationID=%i;", applicationID); if (!ExecuteBlockingCommand(query)) { Rollback (); return false; } int changeSetId = 0; sprintf(query, "SELECT changeSetId FROM Applications WHERE applicationID=%i;", applicationID); if (!ExecuteQueryReadInt(query, &changeSetId)) { Rollback (); return false; } // +1 was added in the update changeSetId--; // Gets all newest files sprintf(query, "SELECT filename, contentHash, createFile FROM FileVersionHistory " "JOIN (SELECT max(fileId) maxId FROM FileVersionHistory WHERE applicationId=%i GROUP BY fileName) MaxId " "ON FileVersionHistory.fileId = MaxId.maxId " "ORDER BY filename DESC;", applicationID); MYSQL_RES *result = 0; if (!ExecuteBlockingCommand(query, &result)) { Rollback(); return false; } DataStructures::List <FileInfo> newestFiles; MYSQL_ROW row; while ((row = mysql_fetch_row (result)) != 0) { FileInfo fi; fi.filename = row [0]; fi.createFile = (atoi (row [2]) != 0); if (fi.createFile) { RakAssert(mysql_fetch_lengths (result) [1] == HASH_LENGTH); // check the data is sensible memcpy (fi.contentHash, row [1], HASH_LENGTH); } newestFiles.Insert (fi); } mysql_free_result(result); FileList newFiles; // Loop through files on filesOnHarddrive // If the file in filesOnHarddrive does not exist in the query result, or if it does but the hash is different or non-existent, add this file to the create list for (unsigned fileListIndex=0; fileListIndex < filesOnHarddrive.fileList.Size(); fileListIndex++) { bool addFile=true; if (fileListIndex%10==0) printf("Hashing files %i/%i\n", fileListIndex+1, filesOnHarddrive.fileList.Size()); const char * hardDriveFilename=filesOnHarddrive.fileList[fileListIndex].filename; const char * hardDriveHash=filesOnHarddrive.fileList[fileListIndex].data; for (unsigned i = 0; i != newestFiles.Size (); ++i) { const FileInfo & fi = newestFiles [i]; if (_stricmp(hardDriveFilename, fi.filename)==0) { if (fi.createFile && memcmp(fi.contentHash, hardDriveHash, HASH_LENGTH)==0) { // File exists in database and is the same addFile=false; } break; } } // Unless set to false, file does not exist in query result or is different. if (addFile) { newFiles.AddFile(hardDriveFilename,hardDriveFilename, filesOnHarddrive.fileList[fileListIndex].data, filesOnHarddrive.fileList[fileListIndex].dataLengthBytes, filesOnHarddrive.fileList[fileListIndex].fileLengthBytes, FileListNodeContext(0,0), false); } } // Go through query results that are marked as create // If a file that is currently in the database is not on the harddrive, add it to the delete list FileList deletedFiles; for (unsigned i = 0; i != newestFiles.Size (); ++i) { const FileInfo & fi = newestFiles [i]; if (!fi.createFile) continue; // If already false don't mark false again. bool fileOnHarddrive=false; for (unsigned fileListIndex=0; fileListIndex < filesOnHarddrive.fileList.Size(); fileListIndex++) { const char * hardDriveFilename=filesOnHarddrive.fileList[fileListIndex].filename; //hardDriveHash=filesOnHarddrive.fileList[fileListIndex].data; if (_stricmp(hardDriveFilename, fi.filename)==0) { fileOnHarddrive=true; break; } } if (!fileOnHarddrive) deletedFiles.AddFile(fi.filename,fi.filename,0,0,0,FileListNodeContext(0,0), false); } // files on harddrive no longer needed. Free this memory since generating all the patches is memory intensive. filesOnHarddrive.Clear(); // For each file in the delete list add a row indicating file deletion for (unsigned fileListIndex=0; fileListIndex < deletedFiles.fileList.Size(); fileListIndex++) { if (fileListIndex%10==0) printf("Tagging deleted files %i/%i\n", fileListIndex+1, deletedFiles.fileList.Size()); sprintf(query, "INSERT INTO FileVersionHistory(applicationID, filename, createFile, changeSetID, userName) VALUES (%i, '%s', FALSE,%i,'%s');", applicationID, GetEscapedString(deletedFiles.fileList[fileListIndex].filename).C_String(), changeSetId, GetEscapedString(userName).C_String()); if (!ExecuteBlockingCommand (query)) { Rollback(); deletedFiles.Clear(); newFiles.Clear(); return false; } } // Clear the delete list as it is no longer needed. deletedFiles.Clear(); // For each file in the create list for (unsigned fileListIndex=0; fileListIndex < newFiles.fileList.Size(); fileListIndex++) { if (fileListIndex%10==0) printf("Adding file %i/%i\n", fileListIndex+1, newFiles.fileList.Size()); const char * hardDriveFilename=newFiles.fileList[fileListIndex].filename; const char * hardDriveData=newFiles.fileList[fileListIndex].data+HASH_LENGTH; const char * hardDriveHash=newFiles.fileList[fileListIndex].data; unsigned hardDriveDataLength=newFiles.fileList[fileListIndex].fileLengthBytes; sprintf( query, "SELECT fileID from FileVersionHistory WHERE applicationID=%i AND filename='%s' AND createFile=TRUE;", applicationID, GetEscapedString(hardDriveFilename).C_String() ); MYSQL_RES * res = 0; if (!ExecuteBlockingCommand (query, &res)) { Rollback(); newFiles.Clear(); return false; } // Create new patches for every create version MYSQL_ROW row; while ((row = mysql_fetch_row (res)) != 0) { const char * fileID = row [0]; // The last query handled all the relevant comparisons sprintf(query, "SELECT content from FileVersionHistory WHERE fileID=%s", fileID ); MYSQL_RES * queryResult = 0; if (!ExecuteBlockingCommand (query, &queryResult)) { Rollback(); newFiles.Clear(); mysql_free_result(res); return false; } MYSQL_ROW queryRow = mysql_fetch_row (queryResult); const unsigned contentLength=mysql_fetch_lengths (queryResult) [0]; const char * content=queryRow [0]; char *patch; unsigned patchLength; if (!CreatePatch(content, contentLength, (char *) hardDriveData, hardDriveDataLength, &patch, &patchLength)) { strcpy(lastError,"CreatePatch failed."); Rollback(); newFiles.Clear(); mysql_free_result(res); mysql_free_result(queryResult); return false; } char buf[512]; stmt = mysql_stmt_init(mySqlConnection); sprintf (buf, "UPDATE FileVersionHistory SET patch=? where fileID=%s;", fileID); if ((prepareResult=mysql_stmt_prepare(stmt, buf, (unsigned long) strlen(buf)))!=0) { strcpy (lastError, mysql_stmt_error (stmt)); mysql_stmt_close(stmt); Rollback(); return false; } memset(bind, 0, sizeof(bind)); unsigned long l1; l1=patchLength; bind[0].buffer_type= MYSQL_TYPE_LONG_BLOB; bind[0].buffer= patch; bind[0].buffer_length= patchLength; bind[0].is_null= &falseVar; bind[0].length=&l1; if (mysql_stmt_bind_param(stmt, bind)) { strcpy (lastError, mysql_stmt_error (stmt)); mysql_stmt_close(stmt); Rollback(); return false; } if (mysql_stmt_execute(stmt)) { strcpy (lastError, mysql_stmt_error (stmt)); mysql_stmt_close(stmt); Rollback(); newFiles.Clear(); mysql_free_result(res); mysql_free_result(queryResult); delete [] patch; return false; } mysql_stmt_close(stmt); delete [] patch; mysql_free_result(queryResult); } mysql_free_result(res); stmt = mysql_stmt_init(mySqlConnection); sprintf(query, "INSERT INTO FileVersionHistory (applicationID, filename, fileLength, content, contentHash, createFile, changeSetID, userName) " "VALUES (%i, ?, %i,?,?, TRUE, %i, '%s' );", applicationID, hardDriveDataLength, changeSetId, GetEscapedString(userName).C_String()); if ((prepareResult=mysql_stmt_prepare(stmt, query, (unsigned long) strlen(query)))!=0) { strcpy (lastError, mysql_stmt_error (stmt)); mysql_stmt_close(stmt); Rollback(); return false; } memset(bind, 0, sizeof(bind)); unsigned long l2,l3,l4; l2=(unsigned long) strlen(hardDriveFilename); l3=hardDriveDataLength; l4=HASH_LENGTH; bind[0].buffer_type= MYSQL_TYPE_STRING; bind[0].buffer= (void*) hardDriveFilename; bind[0].buffer_length= (unsigned long) strlen(hardDriveFilename); bind[0].is_null= &falseVar; bind[0].length=&l2; bind[1].buffer_type= MYSQL_TYPE_LONG_BLOB; bind[1].buffer= (void*) hardDriveData; bind[1].buffer_length= hardDriveDataLength; bind[1].is_null= &falseVar; bind[1].length=&l3; bind[2].buffer_type= MYSQL_TYPE_TINY_BLOB; bind[2].buffer= (void*) hardDriveHash; bind[2].buffer_length= HASH_LENGTH; bind[2].is_null= &falseVar; bind[2].length=&l4; if (mysql_stmt_bind_param(stmt, bind)) { strcpy (lastError, mysql_stmt_error (stmt)); mysql_stmt_close(stmt); Rollback(); return false; } if (mysql_stmt_execute(stmt)) { strcpy (lastError, mysql_stmt_error (stmt)); mysql_stmt_close(stmt); Rollback(); return false; } mysql_stmt_close(stmt); } if (!ExecuteBlockingCommand("COMMIT;")) { Rollback (); return false; } return true; }
bool c4_Persist::SetAside(c4_Storage &aside_) { delete _differ; _differ = d4_new c4_Differ(aside_); Rollback(false); return true; //! true if the generation matches }
CSqliteTransaction::~CSqliteTransaction() { Rollback(); }
// ----------------------------------------------------------------------------- // CSendObject::ReserveObjectL // ----------------------------------------------------------------------------- // TInt CSendObject::ReserveObjectL() { PRINT( _L( "MM MTP => CSendObject::ReserveObjectL" ) ); TInt err = KErrNone; iReceivedObjectInfo->SetUint( CMTPObjectMetaData::EStorageId, iStorageId ); iReceivedObjectInfo->SetUint( CMTPObjectMetaData::EParentHandle, iParentHandle ); iReceivedObjectInfo->SetDesCL( CMTPObjectMetaData::ESuid, iFullPath ); iReceivedObjectInfo->SetUint( CMTPObjectMetaData::EFormatCode, iObjectFormat ); // Reserves space for and assigns an object handle to the object described // by the specified object information record. TRAP( err, iObjectMgr.ReserveObjectHandleL( *iReceivedObjectInfo, iObjectSize ) ); iRollbackList.Append( &CSendObject::UnreserveObjectL ); PRINT2( _L( "MM MTP => CSendObject::ReserveObjectL iObjectsize = %Lu, Operation: 0x%x" ), iObjectSize, iOperationCode ); if ( err != KErrNone ) { PRINT1( _L( "MM MTP <> ReserveObjectHandleL err = %d" ), err ); } if ( err == KErrNone ) { delete iFileReceived; iFileReceived = NULL; PRINT2( _L( "MM MTP <> CSendObject::ServiceObjectL, iFullPath is %S, iObjectSize: %Lu" ), &iFullPath, iObjectSize ); iRollbackList.Append( &CSendObject::RemoveObjectFromFs ); TRAP( err, iFileReceived = CMTPTypeFile::NewL( iFs, iFullPath, EFileWrite ) ); PRINT1( _L("MM MTP <> CMTPTypeFile::NewL Leave Code is: %d"), err ); } if ( err == KErrNone ) { TRAP( err, iFileReceived->SetSizeL( iObjectSize ) ); PRINT1( _L( "MM MTP <> SetSizeL leave code:%d" ), err ); if ( err == KErrDiskFull ) { SendResponseL( EMTPRespCodeStoreFull ); Rollback(); return err; } } if ( err == KErrNone && iObjectSize == 0 ) { // Already trapped inside SaveEmptyFileL. SaveEmptyFileL(); if ( iOperationCode == EMTPOpCodeSendObjectPropList ) { // Only leave when getting proplist element from data received by fw. // It should not happen after ReceiveDataL in which construction of proplist already succeed. SetObjectPropListL(); } iObjectMgr.CommitReservedObjectHandleL( *iReceivedObjectInfo ); iRollbackList.Reset(); } if ( err == KErrNone ) { iExpectedSendObjectRequest.SetUint32( TMTPTypeRequest::ERequestSessionID, iSessionId ); iFramework.RouteRequestRegisterL( iExpectedSendObjectRequest, iConnection ); TUint32 parameters[3]; parameters[0] = iStorageId; parameters[1] = iParentHandle; parameters[2] = iReceivedObjectInfo->Uint( CMTPObjectMetaData::EHandle ); SendResponseL( EMTPRespCodeOK, 3, parameters ); } else { SendResponseL( EMTPRespCodeGeneralError ); Rollback(); } PRINT( _L( "MM MTP <= CSendObject::ReserveObjectL" ) ); return err; }
// ----------------------------------------------------------------------------- // CSendObject::UsbDisconnect // // ----------------------------------------------------------------------------- // EXPORT_C void CSendObject::UsbDisconnect() { PRINT( _L( "MM MTP => CSendObject::UsbDisconnect" ) ); Rollback(); PRINT( _L( "MM MTP <= CSendObject::UsbDisconnect" ) ); }
// ----------------------------------------------------------------------------- // CSendObject::DoHandleResponsePhaseInfoL // Handle Response - Checks whether the request was successful // ----------------------------------------------------------------------------- // TBool CSendObject::DoHandleResponsePhaseInfoL() { PRINT( _L( "MM MTP => CSendObject::DoHandleResponsePhaseInfoL" ) ); TBool result = ETrue; // cache the width and height of video file iObjectFormat = iObjectInfo->Uint16L( CMTPTypeObjectInfo::EObjectFormat ); iWidth = iObjectInfo->Uint32L( CMTPTypeObjectInfo::EImagePixWidth ); iHeight = iObjectInfo->Uint32L( CMTPTypeObjectInfo::EImagePixWidth ); PRINT3( _L("MM MTP <> CSendObject::DoHandleResponsePhaseInfoL iObjectFormat = 0x%x, iWidth = %d, iHeight = %d"), iObjectFormat, iWidth, iHeight ); delete iDateMod; iDateMod = NULL; iDateMod = iObjectInfo->StringCharsL( CMTPTypeObjectInfo::EDateModified ).AllocL(); // check if storage is full iObjectSize = iObjectInfo->Uint32L( CMTPTypeObjectInfo::EObjectCompressedSize ); PRINT1( _L("MM MTP <> CSendObject::DoHandleResponsePhaseInfoL, iObjectSize = %Lu"), iObjectSize ); if ( IsTooLarge( iObjectSize ) ) { SendResponseL( EMTPRespCodeObjectTooLarge ); Rollback(); result = EFalse; } if ( result ) { iProtectionStatus = iObjectInfo->Uint16L( CMTPTypeObjectInfo::EProtectionStatus ); PRINT1( _L( "MM MTP <> CSendObject::DoHandleResponsePhaseInfoL iProtectionStatus = %d" ), iProtectionStatus ); if ( iProtectionStatus != EMTPProtectionNoProtection && iProtectionStatus != EMTPProtectionReadOnly ) { SendResponseL( EMTPRespCodeParameterNotSupported ); Rollback(); result = EFalse; } } if ( result ) { result = GetFullPathNameL( iObjectInfo->StringCharsL( CMTPTypeObjectInfo::EFilename ) ); if ( !result ) { // File and/or parent pathname invalid. SendResponseL( EMTPRespCodeInvalidDataset ); Rollback(); } } if ( result ) { if ( ExistsL( iFullPath ) ) { SendResponseL( EMTPRespCodeAccessDenied ); Rollback(); result = EFalse; } } if ( result ) { if ( KErrNone != ReserveObjectL() ) { result = EFalse; } } PRINT1( _L( "MM MTP <= CSendObject::DoHandleResponsePhaseInfoL result = %d" ), result ); return result; }
// // dtor. remove our reference from the database engine // CDbTableDatabase::CInterface::~CInterface() { if (Database().Transaction().InTransaction(*this)) Rollback(); // release the lock if we have it Database().Close(); }
/// Single forward execution step void adapt5::Step() { Event *ev; POSE_TimeType lastGVT = localPVT->getGVT(); POSE_TimeType maxTimeLeash, offset; double critStart; rbFlag = 0; if (!parent->cancels.IsEmpty()) CancelUnexecutedEvents(); if (eq->RBevent) Rollback(); if (!parent->cancels.IsEmpty()) CancelEvents(); parent->Status(); /* if (rbFlag) { // adjust leash according to rollback timeLeash = avgRBoffset; } else if (timeLeash < theMaxLeash) { // adjust according to state if (eq->currentPtr->timestamp > POSE_UnsetTS) { // adjust to next event if (eq->currentPtr->timestamp - lastGVT > timeLeash) timeLeash == eq->currentPtr->timestamp - lastGVT; // else leave it alone } // no next event; leave it alone } // Put leash back into reasonable bounds if (timeLeash > theMaxLeash) { timeLeash = theMaxLeash; } else if (timeLeash < 0) timeLeash = 0; */ /* int i = timeLeash >> 6; if (i > 1) { if (rbFlag) { timeLeash -= i; } else { timeLeash += i; } } else { if (rbFlag) { timeLeash--; } else { timeLeash++; } } if (timeLeash <= 0) { timeLeash = 10; } */ /* if (rbFlag) { timeLeash = timeLeash >> 1; } else { timeLeash++; } */ // other possibilities: // -run for a number of events with a fixed timeleash, then analyze // and adjust // -simply use recentAvgEventSparsity * avgEventsPerRB // -add code that looks at the number of RBs this poser is responsible // for and don't punish it if it doesn't have a lot ev = eq->currentPtr; if (parent->basicStats[1] > 0) { avgEventsPerRB = (int)(parent->basicStats[0] / parent->basicStats[1]); if (avgEventsPerRB < 1) { avgEventsPerRB = 1; } } // ======== attempt 1 ======== #if ALGORITHM_TO_USE == 1 if (rbFlag) { recentAvgRBLeashCount++; recentTotalRBLeash += timeLeash; // initial rollback calculation to quickly set recentAvgRBLeash to a reasonable value if (initialAvgRBLeashCalc) { recentAvgRBLeash = avgRBoffset; recentTotalRBLeash = 0; recentAvgRBLeashCount = 0; initialAvgRBLeashCalc = false; } // calculate the recent average timeleash when rollbacks occur if (recentAvgRBLeashCount >= AVG_LEASH_CALC_PERIOD) { recentAvgRBLeash = recentTotalRBLeash / recentAvgRBLeashCount; recentTotalRBLeash = 0; recentAvgRBLeashCount = 0; } if (timeLeash > recentAvgRBLeash) { timeLeash = recentAvgRBLeash; } else { timeLeash = recentAvgRBLeash / 2; } } else { timeLeash += recentAvgEventSparsity; } if (avgRBsPerGVTIter > MAX_RB_PER_GVT_ITER) { maxTimeLeash = recentAvgRBLeash / 2; } else { maxTimeLeash = (POSE_TimeType)MAX_LEASH_MULTIPLIER * (POSE_TimeType)recentAvgEventSparsity * (POSE_TimeType)avgEventsPerRB; } if (maxTimeLeash > 50000) { maxTimeLeash = 50000; } if (timeLeash > maxTimeLeash) { timeLeash = maxTimeLeash; } if (timeLeash < 1) { timeLeash = 1; } #endif // ======== attempt 2 ======== #if ALGORITHM_TO_USE == 2 timeLeash = recentAvgEventSparsity * avgEventsPerRB; if (timeLeash > 50000) { timeLeash = 50000; } if (timeLeash < 1) { timeLeash = 1; } #endif // ======== attempt 3 ======== #if ALGORITHM_TO_USE == 3 timeLeash += recentAvgEventSparsity; if (avgRBsPerGVTIter > MAX_RB_PER_GVT_ITER) { maxTimeLeash = ((POSE_TimeType)MAX_LEASH_MULTIPLIER * (POSE_TimeType)recentAvgEventSparsity * (POSE_TimeType)avgEventsPerRB) / (4 * (POSE_TimeType)avgRBsPerGVTIter); } else { maxTimeLeash = 1000; } if (maxTimeLeash > 50000) { maxTimeLeash = 50000; } if (timeLeash > maxTimeLeash) { timeLeash = maxTimeLeash; } if (timeLeash < 1) { timeLeash = 1; } #endif // ======== attempt 4 ======== #if ALGORITHM_TO_USE == 4 if (timeLeash > 10000) { timeLeash = 10000; } if (timeLeash < 1) { timeLeash = 1; } #endif /* if (rbFlag) { GVT *localGVT = (GVT *)CkLocalBranch(TheGVT); int numRollbacks = parent->basicStats[1]; int numGVTIters = localGVT->gvtIterationCount; if (userObj->myHandle == 32) { CkPrintf("*** ROLLBACK: numRollbacks=%d numGVTIters=%d\n", numRollbacks, numGVTIters); } if ((numGVTIters > 0) && (((96 * numRollbacks) / numGVTIters) > 2)) { timeLeash = avgRBoffset; } else { timeLeash++; } } else { timeLeash++; } if (timeLeash > (avgRBoffset << 1)) { timeLeash = avgRBoffset << 1; } */ // can also just hard-code the time leash // timeLeash = 1000; // if (stepCalls == 0) { // timeLeashTotal = 0LL; // } // if (timeLeash < 1000000) { // stepCalls++; // timeLeashTotal += timeLeash; // } /* if (itersAllowed < 1) { itersAllowed = 1; } else { itersAllowed = (int)((double)specEventCount * specTol); itersAllowed -= specEventCount - eventCount; if (itersAllowed < 1) itersAllowed = 1; } */ // Prepare to execute an event offset = lastGVT + timeLeash; // Shorten the leash as we near POSE_endtime if ((POSE_endtime > POSE_UnsetTS) && ((offset > POSE_endtime) || (offset <= POSE_UnsetTS))) offset = POSE_endtime; while ((ev->timestamp > POSE_UnsetTS) && (ev->timestamp <= offset) ){ #ifdef MEM_COARSE // Check to see if we should hold off on forward execution to save on // memory. // NOTE: to avoid deadlock, make sure we have executed something // beyond current GVT before worrying about memory usage if (((ev->timestamp > lastGVT) || (userObj->OVT() > lastGVT)) && (eq->mem_usage > objUsage)) { // don't deadlock break; } #endif iter++; currentEvent = ev; ev->done = 2; localPVT->incSpecEventCount(); localPVT->incEventCount(); specEventCount++; eventCount++; #ifndef CMK_OPTIMIZE if(pose_config.trace) critStart = CmiWallTimer(); // trace timing #endif parent->ResolveFn(ev->fnIdx, ev->msg); // execute it #ifndef CMK_OPTIMIZE if(pose_config.trace) traceUserBracketEvent(10, critStart, CmiWallTimer()); #endif ev->done = 1; // flag the event as executed eq->mem_usage++; eq->ShiftEvent(); // shift to next event ev = eq->currentPtr; } #ifndef CMK_OPTIMIZE if(pose_config.stats) if (iter > 0) localStats->Loop(); #endif }
// ----------------------------------------------------------------------------- // CSendObject::DoHandleResponsePhaseObjectL // SendObject // ----------------------------------------------------------------------------- // TBool CSendObject::DoHandleResponsePhaseObjectL() { PRINT( _L( "MM MTP => CSendObject::DoHandleResponsePhaseObjectL" ) ); TBool result = ETrue; TEntry fileEntry; User::LeaveIfError( iFs.Entry( iFullPath, fileEntry ) ); if ( fileEntry.FileSize() != iObjectSize ) { iFs.Delete( iFullPath ); iObjectMgr.UnreserveObjectHandleL( *iReceivedObjectInfo ); TMTPResponseCode responseCode = EMTPRespCodeObjectTooLarge; if ( fileEntry.FileSize() < iObjectSize ) { responseCode = EMTPRespCodeIncompleteTransfer; } SendResponseL( responseCode ); Rollback(); result = EFalse; } // SendObject is cancelled or connection is dropped. if ( result && iCancelled ) { iFramework.RouteRequestUnregisterL( iExpectedSendObjectRequest, iConnection ); SendResponseL( EMTPRespCodeTransactionCancelled ); Rollback(); } else if ( result && !iCancelled ) { if ( iObjectSize > 0 ) // media file { TRAPD( err, AddMediaToStoreL() ); PRINT1( _L( "MM MTP <= CSendObject::DoHandleResponsePhaseObjectL err = %d" ), err ); if ( ( iPreviousOperation == EMTPOpCodeSendObjectPropList ) && ( err == KErrNone ) ) { // Only leave when getting proplist element from data received by fw. // It should not happen after ReceiveDataL in which construction of proplist already succeed. SetObjectPropListL(); } // Commits into MTP data object enumeration store the object handle and // storage space previously reserved for the specified object. iFramework.ObjectMgr().CommitReservedObjectHandleL( *iReceivedObjectInfo ); iRollbackList.Append( &CSendObject::RemoveObjectFromDbL ); } // Commit object to MTP data store iFramework.RouteRequestUnregisterL( iExpectedSendObjectRequest, iConnection ); SendResponseL( EMTPRespCodeOK ); } iCancelled = EFalse; PRINT1( _L( "MM MTP <= CSendObject::DoHandleResponsePhaseObjectL result = %d" ), result ); return result; }