Пример #1
0
Transaction::~Transaction()
{
  // Either this Transaction shell was not committed (first condition)
  // or the commit failed (we are still active and need to rollback)
  if (!committed_ || impl_->needsRollback_) {
    // A commit attempt failed (and thus we need to rollback) or we
    // are unwinding a stack while an exception is thrown
    if (impl_->needsRollback_ || std::uncaught_exception()) {
      try {
	rollback();
      } catch (std::exception& e) {
	release();
	throw;
      }
    } else {
      try {
	commit();
      } catch (std::exception& e) {
	try {
	  if (impl_->transactionCount_ == 1)
	    rollback();
	} catch (std::exception& e) {
	  std::cerr << "Unexpected transaction during Transaction::rollback()"
		    << std::endl;
	}

	release();
	throw;
      }
    }
  }

  release();
}
Пример #2
0
void zmq::pipe_t::terminate (bool delay_)
{
    //  Overload the value specified at pipe creation.
    delay = delay_;

    //  If terminate was already called, we can ignore the duplicate invocation.
    if (state == term_req_sent1 || state == term_req_sent2) {
        return;
    }
    //  If the pipe is in the final phase of async termination, it's going to
    //  closed anyway. No need to do anything special here.
    else if (state == term_ack_sent) {
        return;
    }
    //  The simple sync termination case. Ask the peer to terminate and wait
    //  for the ack.
    else if (state == active) {
        send_pipe_term (peer);
        state = term_req_sent1;
    }
    //  There are still pending messages available, but the user calls
    //  'terminate'. We can act as if all the pending messages were read.
    else if (state == waiting_for_delimiter && !delay) {
        //  Drop any unfinished outbound messages.
        rollback ();
        outpipe = NULL;
        send_pipe_term_ack (peer);
        state = term_ack_sent;
    }
    //  If there are pending messages still available, do nothing.
    else if (state == waiting_for_delimiter) {
    }
    //  We've already got delimiter, but not term command yet. We can ignore
    //  the delimiter and ack synchronously terminate as if we were in
    //  active state.
    else if (state == delimiter_received) {
        send_pipe_term (peer);
        state = term_req_sent1;
    }
    //  There are no other states.
    else {
        zmq_assert (false);
    }

    //  Stop outbound flow of messages.
    out_active = false;

    if (outpipe) {

        //  Drop any unfinished outbound messages.
        rollback ();

        //  Write the delimiter into the pipe. Note that watermarks are not
        //  checked; thus the delimiter can be written even when the pipe is full.
        msg_t msg;
        msg.init_delimiter ();
        outpipe->write (msg, false);
        flush ();
    }
}
Пример #3
0
int RecorderDAO::DeleteRecorder(SITE_T * site, RECORDER_T * recorder, sqlite3 * connection)
{
	int value = DAO_FAIL;
	sqlite3_stmt *stmt;

	sqlite3 *conn;
	if (connection == 0)
		conn = _db;
	else
		conn = connection;

	if (!site || !recorder)
		return value;

	begin(conn);

	if (sqlite3_prepare(conn, "DELETE FROM tb_site_recorder WHERE site_uuid=? and recorder_uuid=?;", -1, &stmt, 0) == SQLITE_OK)
	{
		sqlite3_bind_text16(stmt, 1, site->uuid, -1, 0);
		sqlite3_bind_text16(stmt, 2, recorder->uuid, -1, 0);
		int result = sqlite3_step(stmt);
		if (result == SQLITE_DONE)
		{
			value = DAO_SUCCESS;
		}
	}
	sqlite3_reset(stmt);
	sqlite3_finalize(stmt);
	if (value != DAO_SUCCESS)
	{
		rollback(conn);
		return value;
	}

	if (sqlite3_prepare(conn, "DELETE FROM tb_recorder WHERE uuid=?;", -1, &stmt, 0) == SQLITE_OK)
	{
		sqlite3_bind_text16(stmt, 1, recorder->uuid, -1, 0);
		int result = sqlite3_step(stmt);
		if (result == SQLITE_DONE)
		{
			value = DAO_SUCCESS;
		}
	}
	sqlite3_reset(stmt);
	sqlite3_finalize(stmt);
	if (value != DAO_SUCCESS)
	{
		rollback(conn);
		return value;
	}

	commit(conn);
	return value;
}
Пример #4
0
Файл: 101.c Проект: a147017/acm
int main(){
    while(scanf("%d" , &total) == 1){
        if((total >= 0) && (total < 25)){
            break;
        }
    }
    init_list();
    char act[5] , kind[5];
    int a , b , cmd;
    while(scanf("%s" , act) == 1){
        if(act[0] == 'q'){
            break;
        }else{
            scanf("%d %s %d" , &a , kind , &b);
            if((a == b ) || ((a > total) && (b > total))){
                continue;
            }
            Blocks *a_block = find_node(a);
            Blocks *b_block = find_node(b);
            if(a_block->cur_addr == b_block->cur_addr){
                continue;
            }

            if(act[0] == 'm'){
                cmd = 10;
            }else{
                cmd = 20;
            }

            if(kind[1] == 'n'){
                cmd += 1;
            }else{
                cmd += 2;
            }
            switch(cmd){
                case 11:
                    rollback(a_block);
                    rollback(b_block);
                    break;
                case 12:
                    rollback(a_block);
                    break;
                case 21:
                    rollback(b_block);
                    break;
                case 22:
                    break;
            }
            move(a_block , b_block->cur_addr);
        }
    }
    display();
    return 0;
}
Пример #5
0
void 
xrecall (int *nerr) {
        /*=====================================================================
         * PURPOSE:  To execute the action command RECALL.
         *           Files in SAC are copied to SeisMgr 
         *=====================================================================
         * INPUT ARGUMENTS:
         *    KINPUT:  Character string containing options
         *             Note, this command is not parsed by the standard SAC
	 *             parsing mechanism.
         *=====================================================================
         * OUTPUT ARGUMENTS:
         *    NERR:    Error flag. Set to 0 if no error occurred.
         *=====================================================================
         * MODULE/LEVEL: SSI/2
         *=====================================================================
         * GLOBAL INPUT:
         *    SSI:     LDATA
         *=====================================================================
         * MODIFICATION HISTORY:
	 *	980915:	Original version.
         *=====================================================================*/

    *nerr = 0 ;

    sacToSeisMgr ( 0 , 1 , 0 , nerr ) ;
    rollback ( wfHeader , nerr ) ;
}
Пример #6
0
REAL   value(   PrivGlobs    globs,
                const REAL s0,
                const REAL strike,
                const REAL t,
                const REAL alpha,
                const REAL nu,
                const REAL beta,
                const unsigned int numX,
                const unsigned int numY,
                const unsigned int numT
) {
    initGrid(s0,alpha,nu,t, numX, numY, numT, globs);
    initOperator(globs.myX,globs.myDxx);
    initOperator(globs.myY,globs.myDyy);

    setPayoff(strike, globs);
    // globs is global and cannot be privatized thus this loop cannot be
    // parallelized yet.
    // If updateParams and rollback is independent on i and globs, loop can be
    // parallelized by privatization of initGrid, initOperator and setPayoff calls.
    // If they write indepedently to globs, privatization is not needed.
    for(int i = globs.myTimeline.size()-2;i>=0;--i) // seq
    {
        updateParams(i,alpha,beta,nu,globs);
        rollback(i, globs);
    }

    return globs.myResult[globs.myXindex][globs.myYindex];
}
Пример #7
0
bool CoreBase::runTransaction(TransactionBlock transaction,
                              TransactionEvent event,
                              Error &error)
{
#define TRANSATION_EVENT(eventType)                                            \
    if (event) {                                                               \
        event(eventType);                                                      \
    }
    if (!begin(StatementTransaction::Mode::Immediate, error)) {
        TRANSATION_EVENT(TransactionEventType::BeginFailed);
        return false;
    }
    if (transaction(error)) {
        error.reset(); //User discards error
        if (commit(error)) {
            return true;
        }
        TRANSATION_EVENT(TransactionEventType::CommitFailed);
    }
    TRANSATION_EVENT(TransactionEventType::Rollback);
    Error
        rollBackError; //Rollback errors do not need to be passed to the outside
    if (!rollback(rollBackError)) {
        TRANSATION_EVENT(TransactionEventType::RollbackFailed);
    }
    return false;
}
Пример #8
0
result Term() {
    result lhs = Factor(), rhs;
    token op;
    if(lhs.error !=  ERR_NONE) {
        return lhs;
    }
    for(op = next_token(); op.type == TT_ASTERISK || op.type == TT_SLASH; op = next_token() ) { 
        rhs = Factor();
#ifdef DEBUG_1
        print_result("Term:lhs:", lhs);
        printf("Term:op:%d\n", op.type);
        print_result("Term:rhs:", rhs);
#endif
        if(rhs.error != ERR_NONE) {
            return rhs;
        }
        if(op.type == TT_ASTERISK) {
            lhs.value *= rhs.value;
        }
        else if(op.type == TT_SLASH) {
            if(rhs.value != 0) {
                lhs.value /= rhs.value;
            }
            else {
                return make_result(ERR_DIVISION_BY_ZERO, 0); 
            }
        }
        else {
            return make_result(ERR_UNEXPECTED_TOKEN, 0);
        }
    }
    rollback();
    return make_result(ERR_NONE, lhs.value);
}
Пример #9
0
// cut selection to clipboard
void LLURLLineEditor::cut()
{
	if( canCut() )
	{
		// Prepare for possible rollback
		LLURLLineEditorRollback rollback( this );

		copyEscapedURLToClipboard();

		deleteSelection();

		// Validate new string and rollback the if needed.
		BOOL need_to_rollback = ( mPrevalidateFunc && !mPrevalidateFunc( mText.getWString() ) );
		if( need_to_rollback )
		{
			rollback.doRollback( this );
			LLUI::reportBadKeystroke();
		}
		else
		if( mKeystrokeCallback )
		{
			mKeystrokeCallback( this );
		}
	}
}
Пример #10
0
    bool commit()
    {
        std::atomic_signal_fence($)(std::memory_order_release);

        size_t i;
        for (i = 0; i != rset_idx($); ++i)
        {
            rdesc const* desc = &rset[i];
            if ((*(desc->addr($)))($).load(std::memory_order_relaxed) != desc->cmp($))
                break;
        }
        if (i != rset_idx($))
        {
            return rollback();
        }

        std::atomic_thread_fence($)(std::memory_order_release);

        for (i = 0; i != wset_idx($); ++i)
        {
            wdesc const* desc = &wset[i];
            (*(desc->addr($)))($).store(desc->xchg($), std::memory_order_relaxed);
        }

        //std::atomic_thread_fence(std::memory_order_acq_rel);

        return true;
    }
Пример #11
0
void zmq::writer_t::terminate ()
{
    //  Prevent double termination.
    if (terminating)
        return;
    terminating = true;

    //  Mark the pipe as not available for writing.
    active = false;

    //  Rollback any unfinished messages.
    rollback ();

    if (swapping) {
        pending_delimiter = true;
        return;
    }

    //  Push delimiter into the pipe. Trick the compiler to belive that
    //  the tag is a valid pointer. Note that watermarks are not checked
    //  thus the delimiter can be written even though the pipe is full.
    zmq_msg_t msg;
    const unsigned char *offset = 0;
    msg.content = (void*) (offset + ZMQ_DELIMITER);
    msg.flags = 0;
    pipe->write (msg, false);
    flush ();
}
Пример #12
0
result Expr() {
    result lhs = Term(), rhs;
    token op;
    if(lhs.error !=  ERR_NONE) {
        return lhs;
    }
    for(op = next_token(); op.type == TT_PLUS || op.type == TT_MINUS; op = next_token() ) { 
        rhs = Term();
#ifdef DEBUG_1        
        print_result("Expr:lhs:", lhs);
        printf("Expr:op:%d\n", op.type);
        print_result("Expr:rhs:", rhs);
#endif
        if(rhs.error !=  ERR_NONE) {
            return rhs;
        }
        if(op.type == TT_PLUS) {
            lhs.value += rhs.value;
        }
        else if(op.type == TT_MINUS) {
            lhs.value -= rhs.value;
        } 
        else {
            return make_result(ERR_UNEXPECTED_TOKEN, 0);
        }
    }
    if(op.type !=  TT_END && op.type != TT_BR_CLOSE) {
        return make_result(ERR_UNEXPECTED_TOKEN, (int) op.type);    
    }
    else {
        rollback();
        return make_result(ERR_NONE, lhs.value); 
    }
}
Пример #13
0
REAL
value(const unsigned i,
      const REAL s0,
      const REAL t,
      const REAL alpha,
      const REAL nu,
      const REAL beta,
      const unsigned int numX,
      const unsigned int numY,
      const unsigned int numT)
{
  REAL strike;
  PrivGlobs    globs(numX, numY, numT);
  strike = 0.001*i;
  initGrid(s0, alpha, nu, t, numX, numY, numT, globs);
  initOperator(globs.myX, globs.myDxx);
  initOperator(globs.myY, globs.myDyy);

  setPayoff(strike, globs);
  for(int i = globs.myTimeline.size()-2; i >= 0; i--) {
    updateParams(i,alpha,beta,nu,globs);
    rollback(i, globs);
  }

  return globs.myResult[globs.myXindex][globs.myYindex];
}
Пример #14
0
void DataImporterThread::importData()
{
    if(!beforeImportQuery.isEmpty()){
        emit statusChanged(tr("Executing before import query..."));
        sourceDb->executeQueryAndCleanup(beforeImportQuery);
    }

    emit statusChanged(tr("Importing data"));

    QStringList fileFieldNames;
    for(int i=0; i<columnMappings.size(); ++i){
        ColumnMapping *mapping = columnMappings.at(i);
        tableOptions.addColumnToCompare(mapping->columnName);

        fileFieldNames.append(mapping->fileFieldName);
    }

    QStringList originalFileFieldNames = fileFieldNames;

    qSort(fileFieldNames.begin(), fileFieldNames.end(), stringLengthDescLessThan); //first sort by length in descending order to prevent in name replacements
    for(int i=0; i<fileFieldNames.size(); ++i){
        insertQuery.replace(QString(":%1").arg(fileFieldNames.at(i)),
                            QString(":%1_%2").arg(BIND_VAR_PREFIX).arg(originalFileFieldNames.indexOf(fileFieldNames.at(i))), Qt::CaseInsensitive);
    }


    prepareBindArrays(true);

    stmt->lockConnection();
    stmt->prepare(insertQuery);
    stmt->setBindArraySize(BULK_DATA_OPERATION_CHUNK_SIZE);
    bulkHelper.bindArrays(stmt, BIND_VAR_PREFIX);
    currentOffset = 0;

    importer->resetPosition();
    importer->resetBuffer();
    importer->readRows(this);

    if(currentOffset>0){
        if(currentOffset < BULK_DATA_OPERATION_CHUNK_SIZE){
            bulkHelper.nullifyArrayData(stmt, currentOffset);
            stmt->setBindArraySize(currentOffset);
        }

        stmt->execute();
        emit chunkImported(currentOffset);
    }

    stmt->unlockConnection();

    if(!afterImportQuery.isEmpty() && !stopped){
        emit statusChanged(tr("Executing after import query..."));
        sourceDb->executeQueryAndCleanup(afterImportQuery);
    }

    if(stopped){
        rollback();
    }
}
Пример #15
0
void RepoTxn::step(RepoQuery& query) {
  try {
    query.step();
  } catch (const std::exception&) {
    rollback();
    throw;
  }
}
Пример #16
0
void RepoTxn::prepare(RepoStmt& stmt, const std::string& sql) {
  try {
    stmt.prepare(sql);
  } catch (const std::exception&) {
    rollback();
    throw;
  }
}
Пример #17
0
void Processor::onTrigger(const std::shared_ptr<ProcessContext> &context, const std::shared_ptr<ProcessSessionFactory> &sessionFactory) {
  auto session = sessionFactory->createSession();

  try {
    // Call the virtual trigger function
    onTrigger(context, session);
    session->commit();
  } catch (std::exception &exception) {
    logger_->log_debug("Caught Exception %s", exception.what());
    session->rollback();
    throw;
  } catch (...) {
    logger_->log_debug("Caught Exception Processor::onTrigger");
    session->rollback();
    throw;
  }
}
Пример #18
0
 static void allocate_individual(Allocator &a, size_type n, multiallocation_chain &m)
 {
    allocate_individual_rollback rollback(a, m);
    while(n--){
       m.push_front(a.allocate(1));
    }
    rollback.release();
 }
Пример #19
0
void RepoTxn::rollback_guard(const char* func, F f) {
  try {
    f();
  } catch (const std::exception& e) {
    TRACE(4, "RepoTxn::%s(repo=%p) caught '%s'\n", func, &m_repo, e.what());
    rollback();
    throw;
  }
}
Пример #20
0
	transaction::~transaction()
	{
		try {
			rollback();
		}
		catch(...)
		{
		}
	}
Пример #21
0
//-------------------------------------------------------------
//------------------------------ 
CSqlite3Transaction& CSqlite3Transaction::operator=(CSqlite3Transaction& transaction)
{
	rollback();
	m_bEnd		= transaction.m_bEnd;
	m_pDBCon	= transaction.m_pDBCon;
	transaction.m_pDBCon	= NULL;

	return *this;
}
Пример #22
0
TransactionDialog::TransactionDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::TransactionDialog)
{
    ui->setupUi(this);

    connect(ui->commitButton, SIGNAL(clicked()), this, SLOT(commit()));
    connect(ui->rollbackButton, SIGNAL(clicked()), this, SLOT(rollback()));
}
Пример #23
0
int print_each_vg(int file,
		  char *vgname,
		  perfstat_disk_t *curr,
		  perfstat_disk_t *last, 
		  int interval, int nr)
{
	if(curr == NULL || last==NULL) {
		//printf("curr = %x, last =%x\n", curr, last);
		return -1;
	}

	unsigned long long traffic_in, traffic_out;
	float avg_r_io_time,avg_w_io_time;
	float avg_in_size, avg_out_size;
	float r_serv, w_serv, disk_util; 
	unsigned long iops,iops_in,iops_out;
        time_t now = time(0);
        struct tm *ptm = NULL;
        now = time(0);
        ptm = localtime(&now);

	int n;
	traffic_in = (curr->rblks - last->rblks) * 512 / interval; 
	traffic_out = (curr->wblks - last->wblks) * 512 / interval;
	iops = (curr->xfers - last->xfers)  / interval;
	iops_in = (curr->xrate - last->xrate) / interval;
	iops_out = iops - iops_in;
	r_serv = (curr->xrate - last->xrate) ? 
		HTIC2NANOSEC(curr->rserv, last->rserv) * 1.0/1000000/(curr->xrate - last->xrate) : 0;
	w_serv = ((curr->xfers - last->xfers) - (curr->xrate - last->xrate)) ?
		 HTIC2NANOSEC(curr->wserv, last->wserv) * 1.0/1000000/((curr->xfers - last->xfers) - (curr->xrate - last->xrate)) : 0;
	disk_util = (curr->time - last->time) * 1.0 /100 / interval;
	avg_in_size = ((curr->rblks - last->rblks)&& (curr->xrate - last->xrate)) ? 
		(curr->rblks - last->rblks) *512 /  (curr->xrate - last->xrate):0;
	avg_out_size = ((curr->rblks - last->rblks) && ((curr->xfers - last->xfers)-(curr->xrate - last->xrate))) ? 
		(curr->wblks - last->wblks) * 512 / ((curr->xfers - last->xfers)-(curr->xrate - last->xrate)) : 0;
	n = sprintf(gbuf,
		"%04d-%02d-%02d %02d:%02d:%02d," 
		"%s,"
		"%lu,%lu,%lu,%llu,%llu,%.2f,%.2f,"
		"%.2f,%.2f,%.2f\n",
		ptm->tm_year + 1900, ptm->tm_mon + 1,
                ptm->tm_mday, ptm->tm_hour,
                ptm->tm_min, ptm->tm_sec,
		vgname,
		iops, iops_in, iops_out,
		traffic_in, traffic_out,
		avg_in_size,avg_out_size,
		r_serv, w_serv, disk_util);
	gbuf[n]='\0';
	if(file)
		rollback(gbuf);
	else 
		puts(gbuf);
	free(ptm);
	return 0;
}
Пример #24
0
RepoTxn::RepoTxn(Repo& repo)
  : m_repo(repo), m_pending(true), m_error(false) {
  try {
    m_repo.begin();
  } catch (RepoExc& re) {
    rollback();
    throw;
  }
}
Пример #25
0
void KSimpleConfig::sync()
{
   if (isReadOnly())
       return;
   backEnd->sync(false);

   if (isDirty())
     rollback();
}
Пример #26
0
Transaction::~Transaction() {
    if (needRollback) {
        try {
            rollback();
        } catch (...) {
            // Ignore failed rollbacks in destructor.
        }
    }
}
Пример #27
0
void Lite3Connector::rollback()
{
  if (conn == 0)
    throw Lite3Exception(CONNECT_NOT_INITIALISED, "Connection not initialised", LITE3_MARK);
  Lite3Query rollback(this);
  rollback.init("rollback", 0);
  rollback.exec();
  rollback.close();
}
Пример #28
0
 transaction::~transaction()
 {
     if (is_active()) {
         if (is_successful()) {
             commit();
         } else {
             rollback();
         }
     }
 }
Пример #29
0
void RepoTxn::exec(const std::string& sQuery) {
  try {
    m_repo.exec(sQuery);
  } catch (const std::exception& e) {
    rollback();
    TRACE(4, "RepoTxn::%s(repo=%p) caught '%s'\n",
          __func__, &m_repo, e.what());
    throw;
  }
}
Пример #30
0
sqlite3_transaction::~sqlite3_transaction() {
	if(intrans) {
		try {
			rollback();
		}
		catch(...) {
			return;
		}
	}
}