TEST_F(TransactionCoordinatorServiceTest, CoordinateCommitReturnsNoneIfCoordinatorWasRemoved) {
    auto coordinatorService = TransactionCoordinatorService::get(operationContext());

    coordinatorService->createCoordinator(operationContext(), _lsid, _txnNumber, kCommitDeadline);
    commitTransaction(*coordinatorService, _lsid, _txnNumber, kTwoShardIdSet);

    auto commitDecisionFuture =
        coordinatorService->coordinateCommit(operationContext(), _lsid, _txnNumber, kTwoShardIdSet);
    ASSERT(boost::none == commitDecisionFuture);
}
Exemplo n.º 2
0
void fCacheDB::createTable()
{
    beginTransaction();
    executeSQL(std::string("CREATE TABLE IF NOT EXISTS " + std::string(TABLE_NAME) +
                "(id TEXT PRIMARY KEY, timestamp INTEGER, persistent INTEGER DEFAULT 0, data BLOB)").c_str());
    executeSQL(std::string("CREATE INDEX IF NOT EXISTS idx_id ON '" + std::string(TABLE_NAME) + "' (id);").c_str());
    executeSQL(std::string("CREATE INDEX IF NOT EXISTS idx_timestamp ON '" + std::string(TABLE_NAME) + "' (timestamp);").c_str());
    executeSQL(std::string("CREATE INDEX IF NOT EXISTS idx_persistent ON '" + std::string(TABLE_NAME) + "' (persistent);").c_str());
    commitTransaction();
}
TEST_F(TransactionCoordinatorServiceTest,
       RetryingCreateCoordinatorForSameLsidAndTxnNumberSucceeds) {
    auto coordinatorService = TransactionCoordinatorService::get(operationContext());

    coordinatorService->createCoordinator(operationContext(), _lsid, _txnNumber, kCommitDeadline);
    // Retry create. This should succeed but not replace the old coordinator.
    coordinatorService->createCoordinator(operationContext(), _lsid, _txnNumber, kCommitDeadline);

    commitTransaction(*coordinatorService, _lsid, _txnNumber, kTwoShardIdSet);
}
Exemplo n.º 4
0
static void deleteWay(void* abstractSelf) {
    osm2olm* self = (osm2olm*) abstractSelf;
    //printf("Deleting way %i\n", self->way.id);
    for(int c = 0; c < self->countriesCount; c++) {
        beginTransaction(self->countries[c].db);
        deleteWayFromCountry(self->countries + c, self->way.id);
        commitTransaction(self->countries[c].db);
    }    
    removeAllPlainTags(&(self->tags));
    removeAllWayNodes(&(self->wayNodes));
}
Exemplo n.º 5
0
  void IncrementalParser::Initialize() {
    if (hasCodeGenerator())
      getCodeGenerator()->Initialize(getCI()->getASTContext());

    CompilationOptions CO;
    CO.DeclarationExtraction = 0;
    CO.ValuePrinting = CompilationOptions::VPDisabled;
    CO.CodeGeneration = hasCodeGenerator();

    // pull in PCHs
    const std::string& PCHFileName
      = m_CI->getInvocation ().getPreprocessorOpts().ImplicitPCHInclude;
    if (!PCHFileName.empty()) {
      
      Transaction* CurT = beginTransaction(CO);
      m_CI->createPCHExternalASTSource(PCHFileName,
                                       true /*DisablePCHValidation*/,
                                       true /*AllowPCHWithCompilerErrors*/,
                                       0 /*DeserializationListener*/);
      Transaction* EndedT = endTransaction(CurT);
      commitTransaction(EndedT);
    }

    Transaction* CurT = beginTransaction(CO);
    Sema* TheSema = &m_CI->getSema();
    m_Parser.reset(new Parser(m_CI->getPreprocessor(), *TheSema,
                              false /*skipFuncBodies*/));
    m_CI->getPreprocessor().EnterMainSourceFile();
    // Initialize the parser after we have entered the main source file.
    m_Parser->Initialize();
    // Perform initialization that occurs after the parser has been initialized
    // but before it parses anything. Initializes the consumers too.
    TheSema->Initialize();

    ExternalASTSource *External = TheSema->getASTContext().getExternalSource();
    if (External)
      External->StartTranslationUnit(m_Consumer);

    Transaction* EndedT = endTransaction(CurT);
    commitTransaction(EndedT);
  }
Exemplo n.º 6
0
static void deleteNode(void* abstractSelf) {
    osm2olm* self = (osm2olm*) abstractSelf;
    
    //    printf("Deleting node %i\n", self->node.id);
    for(int c = 0; c < self->countriesCount; c++) {
        beginTransaction(self->countries[c].db);
        deleteNodeFromCountry(self->countries + c, self->node.id);
        commitTransaction(self->countries[c].db);
    }
    //printf("Delete node - end\n");
    removeAllPlainTags(&(self->tags));
}
Exemplo n.º 7
0
bool QgsTransaction::commit( QString& errorMsg )
{
  if ( !mTransactionActive )
    return false;

  if ( !commitTransaction( errorMsg ) )
    return false;

  setLayerTransactionIds( nullptr );
  mTransactionActive = false;
  return true;
}
Exemplo n.º 8
0
// Call Customer Position Frame 3
void CCustomerPositionDB::DoCustomerPositionFrame3()
{
#ifdef DEBUG
	pthread_t pid = pthread_self();
	cout << pid << " <<< CPF3" << endl;
#endif

	commitTransaction();

#ifdef DEBUG
	cout << pid << " >>> CPF3" << endl;
#endif
}
TEST_F(TransactionCoordinatorServiceTestSingleTxn,
       ConcurrentCallsToCoordinateCommitReturnSameDecisionOnCommit) {

    auto commitDecisionFuture1 = *coordinatorService()->coordinateCommit(
        operationContext(), _lsid, _txnNumber, kTwoShardIdSet);
    auto commitDecisionFuture2 = *coordinatorService()->coordinateCommit(
        operationContext(), _lsid, _txnNumber, kTwoShardIdSet);

    commitTransaction(*coordinatorService(), _lsid, _txnNumber, kTwoShardIdSet);

    ASSERT_EQ(static_cast<int>(commitDecisionFuture1.get()),
              static_cast<int>(commitDecisionFuture2.get()));
}
Exemplo n.º 10
0
bool CassandraStorage::read(const Bucket& bucket, const Key& key, const CommitCallback& cb, const String& timestamp) {
    bool is_new = false;
    Transaction* trans = getTransaction(bucket, &is_new);
    trans->push_back(StorageAction());
    StorageAction& action = trans->back();
    action.type = StorageAction::Read;
    action.key = key;

    // Run commit if this is a one-off transaction
    if (is_new)
        commitTransaction(bucket, cb, timestamp);

    return true;
}
Exemplo n.º 11
0
// Call Trade Status Frame 1
void CTradeStatusDB::DoTradeStatusFrame1(const TTradeStatusFrame1Input *pIn,
		TTradeStatusFrame1Output *pOut)
{
#ifdef DEBUG
	pthread_t pid = pthread_self();
	cout << pid << " <<< TSF1" << endl;
	cout << pid << " - Trade Status Frame 1 (input)" << endl <<
			pid << " -- acct_id: " << pIn->acct_id << endl;
#endif // DEBUG

	startTransaction();
#ifdef DB_PGSQL
	// Isolation level required by Clause 7.4.1.3
	setReadCommitted();
#endif
	execute(pIn, pOut);
	commitTransaction();

#ifdef DEBUG
	cout << pid << " - Trade Status Frame 1 (output)" << endl <<
			pid << " -- cust_l_name: " << pOut->cust_l_name << endl <<
			pid << " -- cust_f_name: " << pOut->cust_f_name << endl <<
			pid << " -- broker_name: " << pOut->broker_name << endl;
	for (int i = 0; i < max_trade_status_len; i++) {
		cout << pid << " -- charge[" << i << "]: " << pOut->charge[i] << endl <<
				pid << " -- exec_name[" << i << "]: " << pOut->exec_name[i] <<
						endl <<
				pid << " -- ex_name[" << i << "]: " << pOut->ex_name[i] <<
						endl <<
				pid << " -- s_name[" << i << "]: " << pOut->s_name[i] << endl <<
				pid << " -- status_name[" << i << "]: " <<
						pOut->status_name[i] << endl <<
				pid << " -- symbol[" << i << "]: " << pOut->symbol[i] << endl <<
				pid << " -- trade_dts[" << i << "]: " <<
						pOut->trade_dts[i].year << "-" <<
						pOut->trade_dts[i].month << "-" <<
						pOut->trade_dts[i].day << " " <<
						pOut->trade_dts[i].hour << ":" <<
						pOut->trade_dts[i].minute << ":" <<
						pOut->trade_dts[i].second << endl <<
				pid << " -- trade_id[" << i << "]: " << pOut->trade_id[i] <<
						endl <<
				pid << " -- trade_qty[" << i << "]: " << pOut->trade_qty[i] <<
						endl <<
				pid << " -- type_name[" << i << "]: " << pOut->type_name[i] <<
						endl;
	}
	cout << pid << " >>> TSF1" << endl;
#endif // DEBUG
}
// Call Customer Position Frame 3
void CCustomerPositionDB::DoCustomerPositionFrame3(
		TCustomerPositionFrame3Output *pOut)
{
#ifdef DEBUG
	cout << "<<< CPF3" << endl;
#endif

	commitTransaction();
	pOut->status = CBaseTxnErr::SUCCESS;

#ifdef DEBUG
	cout << ">>> CPF3" << endl;
#endif
}
Exemplo n.º 13
0
uint32_t LayerBase::doTransaction(uint32_t flags)
{
    const Layer::State& front(drawingState());
    const Layer::State& temp(currentState());

    if (temp.sequence != front.sequence) {
        // invalidate and recompute the visible regions if needed
        flags |= eVisibleRegion;
        this->invalidate = true;
    }
    
    // Commit the transaction
    commitTransaction(flags & eRestartTransaction);
    return flags;
}
Exemplo n.º 14
0
void DragTool::dragLeaveEvent(const QList<QGraphicsItem*> &/*itemList*/, QGraphicsSceneDragDropEvent *event)
{
    if (canHandleMimeData(event->mimeData())) {
        event->accept();

        m_moveManipulator.end();
        clear();
        if (m_dragNode.isValid())
            m_dragNode.destroy();

        commitTransaction();

        view()->changeToSelectionTool();
    }
}
Exemplo n.º 15
0
//TODO: make one command
static void bulkRemoveRecords(stKVDatabase *database, stList *records) {
    startTransaction(database);
    stTry {
        for(int32_t i=0; i<stList_length(records); i++) {
            stInt64Tuple *j = stList_get(records, i);
            removeRecord(database, stInt64Tuple_getPosition(j, 0));
        }
        commitTransaction(database);
    }stCatch(ex) {
        abortTransaction(database);
        stThrowNewCause(
                ex,
                ST_KV_DATABASE_EXCEPTION_ID,
                "MySQL bulk remove records failed");
    }stTryEnd;
}
Exemplo n.º 16
0
  Transaction* IncrementalParser::Compile(llvm::StringRef input,
                                          const CompilationOptions& Opts) {

    Transaction* CurT = beginTransaction(Opts);
    EParseResult ParseRes = ParseInternal(input);

    if (ParseRes == kSuccessWithWarnings)
      CurT->setIssuedDiags(Transaction::kWarnings);
    else if (ParseRes == kFailed)
      CurT->setIssuedDiags(Transaction::kErrors);

    endTransaction();
    commitTransaction(CurT);

    return CurT;
  }
Exemplo n.º 17
0
// Call Trade Order Frame 6
void CTradeOrderDB::DoTradeOrderFrame6(TTradeOrderFrame6Output *pOut)
{
#ifdef DEBUG
	cout << "<<< TOF6" << endl;
#endif

	// commit the transaction we are inside
	commitTransaction();
	pOut->status = CBaseTxnErr::SUCCESS;

#ifdef DEBUG
	cout << "- Trade Order Frame 6 (output)" << endl <<
			"-- status: " << pOut->status << endl;
	cout << ">>> TOF6" << endl;
#endif
}
Exemplo n.º 18
0
void DragTool::dropEvent(const QList<QGraphicsItem*> &/*itemList*/, QGraphicsSceneDragDropEvent *event)
{
    if (canHandleMimeData(event->mimeData())) {
        event->accept();
        end(generateUseSnapping(event->modifiers()));

        commitTransaction();

        if (m_dragNode.isValid())
            view()->setSelectedModelNode(m_dragNode);


        m_dragNode = QmlItemNode();

        view()->changeToSelectionTool();
    }
}
Exemplo n.º 19
0
static stList *bulkGetRecordsRange(stKVDatabase *database, int64_t firstKey, int64_t numRecords) {
	stList* results = stList_construct3(numRecords, (void(*)(void *))stKVDatabaseBulkResult_destruct);
	startTransaction(database);
	stTry {
		for (int32_t i = 0; i < numRecords; ++i)
		{
			int64_t key = firstKey + i;
			int64_t recordSize;
			void* record = getRecord2(database, key, &recordSize);
			stKVDatabaseBulkResult* result = stKVDatabaseBulkResult_construct(record, recordSize);
			stList_set(results, i, result);
		}
		commitTransaction(database);
	}stCatch(ex) {
		abortTransaction(database);
		stThrowNewCause(ex, ST_KV_DATABASE_EXCEPTION_ID, "tokyo cabinet bulk get records failed");
	}stTryEnd;

	return results;
}
Exemplo n.º 20
0
static void writeWay(void* abstractSelf) {
    osm2olm* self = (osm2olm*) abstractSelf;
    
    for(int c = 0; c < self->countriesCount; c++) {
        if(wayBelongsCountry(self, self->countries + c)) {
            addTree16Node(&(self->countries[c].waysIndex), self->way.id, self->way.id);
            beginTransaction(self->countries[c].db);
            sqlite3_bind_int64(self->countries[c].insertWayStatement, 1, self->way.id);
            sqlite3_bind_int64(self->countries[c].insertWayStatement, 2, self->way.timestamp);
            sqlite3_step(self->countries[c].insertWayStatement);
            sqlite3_reset(self->countries[c].insertWayStatement);
            
            writeTags(self, &(self->tags), self->countries[c].insertWayTagStatement, self->way.id);
            writeWayNodes(self, self->countries+c);
            commitTransaction(self->countries[c].db);
        }
    }    
    removeAllPlainTags(&(self->tags));
    removeAllWayNodes(&(self->wayNodes));
}
Exemplo n.º 21
0
static int64_t incrementInt64(stKVDatabase *database, int64_t key, int64_t incrementAmount) {
    startTransaction(database);
    int64_t returnValue = INT64_MIN;
    stTry {
        int64_t recordSize;
        int64_t *record = getRecord2(database, key, &recordSize);
        assert(recordSize >= sizeof(int64_t));
        record[0] += incrementAmount;
        returnValue = record[0];
        updateRecord(database, key, record, recordSize);
        free(record);
        commitTransaction(database);
    }stCatch(ex) {
        abortTransaction(database);
        stThrowNewCause(
                ex,
                ST_KV_DATABASE_EXCEPTION_ID,
                "MySQL increment record failed");
    }stTryEnd;
    return returnValue;
}
Exemplo n.º 22
0
int Database::drain() {
	boost::mutex::scoped_lock lock(dbMutex);
	std::list<db_data>* workList;
	int drainCount = 0;

	workList = currentList;
	flipLists();

	startTransaction();

	for(std::list<db_data>::iterator ite = workList->begin(); ite != workList->end(); ++ite) {
		addToBatch(*ite);
		recordsWritten++;
		drainCount++;
	}

	commitTransaction();

	workList->clear();
	return drainCount;
}
Exemplo n.º 23
0
	void BaseDatabaseUnitImpl::runTransaction(std::vector<CppSQLite3Statement> & statements)
	{
		if (beginTransaction())
		{
			try
			{
				for (auto it = statements.begin(); it != statements.end(); ++it)
				{
					it->execDML();
				}
				commitTransaction();
			}
			catch (CppSQLite3Exception e)
			{
				LOG_ERR_R(DATABASE_MANAGER_LOG_TAG, _T("Failed to run transaction, error: %u"), e.errorCode());
				LOG_ERR_D_A(DATABASE_MANAGER_LOG_TAG_A, "Message: %s", e.errorMessage());

				rollbackTransaction();
			}
		}
	}
Exemplo n.º 24
0
void SyncJournalDb::close()
{
    QMutexLocker locker(&_mutex);

    commitTransaction();

    _getFileRecordQuery.reset(0);
    _setFileRecordQuery.reset(0);
    _getDownloadInfoQuery.reset(0);
    _setDownloadInfoQuery.reset(0);
    _deleteDownloadInfoQuery.reset(0);
    _getUploadInfoQuery.reset(0);
    _setUploadInfoQuery.reset(0);
    _deleteUploadInfoQuery.reset(0);
    _deleteFileRecordPhash.reset(0);
    _deleteFileRecordRecursively.reset(0);
    _blacklistQuery.reset(0);

    _db.close();
    _db = QSqlDatabase(); // avoid the warning QSqlDatabasePrivate::removeDatabase: connection [...] still in use
    QSqlDatabase::removeDatabase(_dbFile);
}
Exemplo n.º 25
0
void SyncJournalDb::close()
{
    QMutexLocker locker(&_mutex);
    qDebug() << Q_FUNC_INFO << _dbFile;

    commitTransaction();

    _getFileRecordQuery.reset(0);
    _setFileRecordQuery.reset(0);
    _getDownloadInfoQuery.reset(0);
    _setDownloadInfoQuery.reset(0);
    _deleteDownloadInfoQuery.reset(0);
    _getUploadInfoQuery.reset(0);
    _setUploadInfoQuery.reset(0);
    _deleteUploadInfoQuery.reset(0);
    _deleteFileRecordPhash.reset(0);
    _deleteFileRecordRecursively.reset(0);
    _getErrorBlacklistQuery.reset(0);
    _setErrorBlacklistQuery.reset(0);

    _db.close();
    _avoidReadFromDbOnNextSyncFilter.clear();
}
Exemplo n.º 26
0
static void updateWay(void* abstractSelf) {
    osm2olm* self = (osm2olm*) abstractSelf;
    
    //    printf("Updating way %i\n", self->way.id);
    for(int c = 0; c < self->countriesCount; c++) {
        if(wayBelongsCountry(self, self->countries + c)) {
            addTree16Node(&(self->countries[c].waysIndex), self->way.id, self->way.id);
            beginTransaction(self->countries[c].db);
            sqlite3_bind_int64(self->countries[c].updateWayStatement, 1, self->way.id);
            sqlite3_step(self->countries[c].updateWayStatement);
            sqlite3_reset(self->countries[c].updateWayStatement);
            deleteFromDbById(self->countries[c].db, self->countries[c].deleteWayTagsStatement, self->way.id);
            writeTags(self, &(self->tags), self->countries[c].insertWayTagStatement, self->way.id);
            deleteFromDbById(self->countries[c].db, self->countries[c].deleteWayNodesStatement, self->way.id);
            writeWayNodes(self, self->countries+c);
            commitTransaction(self->countries[c].db);
        } else {
            deleteWayFromCountry(self->countries + c, self->way.id);
        }
    }    
    removeAllPlainTags(&(self->tags));
    removeAllWayNodes(&(self->wayNodes));
}
TEST_F(
    TransactionCoordinatorServiceTest,
    CreateCoordinatorWithHigherTxnNumberThanExistingButNotYetCommittingTxnCancelsPreviousTxnAndSucceeds) {
    auto coordinatorService = TransactionCoordinatorService::get(operationContext());
    coordinatorService->createCoordinator(operationContext(), _lsid, _txnNumber, kCommitDeadline);

    // Create a coordinator for a higher transaction number in the same session. This should
    // cancel commit on the old coordinator.
    coordinatorService->createCoordinator(
        operationContext(), _lsid, _txnNumber + 1, kCommitDeadline);
    auto newTxnCommitDecisionFuture = *coordinatorService->coordinateCommit(
        operationContext(), _lsid, _txnNumber + 1, kTwoShardIdSet);

    // Since this transaction has already been canceled, this should return boost::none.
    auto oldTxnCommitDecisionFuture =
        coordinatorService->coordinateCommit(operationContext(), _lsid, _txnNumber, kTwoShardIdSet);

    // The old transaction should now be committed.
    ASSERT(oldTxnCommitDecisionFuture == boost::none);

    // Make sure the newly created one works fine too.
    commitTransaction(*coordinatorService, _lsid, _txnNumber + 1, kTwoShardIdSet);
}
// Call Customer Position Frame 2
void CCustomerPositionDB::DoCustomerPositionFrame2(
		const TCustomerPositionFrame2Input *pIn,
		TCustomerPositionFrame2Output *pOut)
{
#ifdef DEBUG
	m_coutLock.lock();
	cout << "<<< CPF2" << endl;
	cout << "- Customer Position Frame 2 (input)" << endl <<
			"-- cust_id: " << pIn->acct_id << endl;
	m_coutLock.unlock();
#endif // DEBUG

	execute(pIn, pOut);
	commitTransaction();

#ifdef DEBUG
	m_coutLock.lock();
	cout << "- Customer Position Frame 2 (output)" << endl <<
			"-- hist_len: " << pOut->hist_len << endl;
	for (int i = 0; i < pOut->hist_len; i++) {
		cout << "-- trade_id[" << i << "]: " << pOut->trade_id[i] << endl <<
				"-- symbol[" << i << "]: " << pOut->symbol[i] << endl <<
				"-- qty[" << i << "]: " << pOut->qty[i] << endl <<
				"-- trade_status[" << i << "]: " << pOut->trade_status[i] <<
						endl <<
				"-- hist_dts[" << i << "]: " <<
						pOut->hist_dts[i].year << "-" <<
						pOut->hist_dts[i].month << "-" <<
						pOut->hist_dts[i].day << " " <<
						pOut->hist_dts[i].hour << ":" <<
						pOut->hist_dts[i].minute << ":" <<
						pOut->hist_dts[i].second << endl;
	}
	cout << ">>> CPF2" << endl;
	m_coutLock.unlock();
#endif // DEBUG
}
Exemplo n.º 29
0
bool QgsTransaction::commit( QString& errorMsg )
{
  if ( !mTransactionActive )
  {
    return false;
  }

  Q_FOREACH ( QgsVectorLayer* l, mLayers )
  {
    if ( !l || l->isEditable() )
    {
      return false;
    }
  }

  if ( !commitTransaction( errorMsg ) )
  {
    return false;
  }

  setLayerTransactionIds( 0 );
  mTransactionActive = false;
  return true;
}
Exemplo n.º 30
0
// Call Trade Lookup Frame 4
void CTradeLookupDB::DoTradeLookupFrame4(const TTradeLookupFrame4Input *pIn,
		TTradeLookupFrame4Output *pOut)
{
#ifdef DEBUG
	pthread_t pid = pthread_self();
	cout << pid << " <<< TLF4" << endl;
	cout << pid << " - Trade Lookup Frame 4 (input)" << endl <<
			pid << " -- acct_id: " << pIn->acct_id << endl <<
			pid << " -- trade_dts: " << pIn->trade_dts.year << "-" <<
					pIn->trade_dts.month << "-" << pIn->trade_dts.day <<
					" " << pIn->trade_dts.hour << ":" <<
					pIn->trade_dts.minute << ":" <<
					pIn->trade_dts.second << endl;
#endif //DEBUG

	startTransaction();
	// Isolation level required by Clause 7.4.1.3
	setReadCommitted();
	execute(pIn, pOut);
	commitTransaction();

#ifdef DEBUG
	cout << pid << " - Trade Lookup Frame 4 (output)" << endl <<
			pid << " -- holding_history_id[0]: " <<
					pOut->trade_info[0].holding_history_id << endl <<
			pid << " -- holding_history_trade_id[0]: " <<
					pOut->trade_info[0].holding_history_trade_id << endl <<
			pid << " -- quantity_before[0]: " <<
					pOut->trade_info[0].quantity_before << endl <<
			pid << " -- quantity_after[0]: " <<
					pOut->trade_info[0].quantity_after << endl <<
			pid << " -- num_found: " << pOut->num_found << endl <<
			pid << " -- trade_id: " << pOut->trade_id << endl;
	cout << pid << " >>> TLF4" << endl;
#endif //DEBUG
}