当前位置: 首页>>代码示例>>C++>>正文


C++ DbTxn::abort方法代码示例

本文整理汇总了C++中DbTxn::abort方法的典型用法代码示例。如果您正苦于以下问题:C++ DbTxn::abort方法的具体用法?C++ DbTxn::abort怎么用?C++ DbTxn::abort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DbTxn的用法示例。


在下文中一共展示了DbTxn::abort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: fprintf

/**
 * Cursor must be closed before the transaction is aborted/commited.
 * http://download.oracle.com/docs/cd/E17076_02/html/programmer_reference/transapp_cursor.html
 */
Bdb::ResponseCode Bdb::
update(const std::string& key, const std::string& value)
{
    if (!inited_) {
        fprintf(stderr, "insert called on uninitialized database");
        return Error;
    }
    DbTxn* txn = NULL;
    Dbc* cursor = NULL;

    Dbt dbkey, dbdata;
    dbkey.set_data(const_cast<char*>(key.c_str()));
    dbkey.set_size(key.size());
    dbdata.set_data(const_cast<char*>(value.c_str()));
    dbdata.set_size(value.size());

    Dbt currentData;
    currentData.set_data(NULL);
    currentData.set_ulen(0);
    currentData.set_dlen(0);
    currentData.set_doff(0);
    currentData.set_flags(DB_DBT_USERMEM | DB_DBT_PARTIAL);

    int rc = 0;
    for (uint32_t idx = 0; idx < numRetries_; idx++) {
        env_->txn_begin(NULL, &txn, 0);
        (*db_).cursor(txn, &cursor, DB_READ_COMMITTED);

        // move the cursor to the record.
        rc = cursor->get(&dbkey, &currentData, DB_SET | DB_RMW);
        if (rc != 0) {
            cursor->close();
            txn->abort();
            if (rc == DB_NOTFOUND) {
                return KeyNotFound;
            } else if (rc != DB_LOCK_DEADLOCK) {
                fprintf(stderr, "Db::get() returned: %s", db_strerror(rc));
                return Error;
            }
            continue;
        }

        // update the record.
        rc = cursor->put(NULL, &dbdata, DB_CURRENT);
        cursor->close();
        if (rc == 0) {
            txn->commit(DB_TXN_SYNC);
            return Success;
        } else {
            txn->abort();
            if (rc != DB_LOCK_DEADLOCK) {
                fprintf(stderr, "Db::put() returned: %s", db_strerror(rc));
                return Error;
            }
        }
    }
    fprintf(stderr, "update failed %d times", numRetries_);
    return Error;
}
开发者ID:BigR-Lab,项目名称:mapkeeper,代码行数:63,代码来源:Bdb.cpp

示例2: recvNewUsr

/* Receive updated user information data from client. 
 * Returns 0 if everything is ok;
 * returns -1 if data size from client is invalid, and this error message is not sent out successfully;
 * returns  1 if data size from client is invalid, but this error message is sent out successfully;
 * returns -2 if user data is not received, and this error error message is not sent out successfully;
 * returns  2 if user data is not received, but this error error message is sent out successfully;
 * returns -3 if user account received already exists, and this error message is not sent out successfully;
 * returns  3 if user account received already exists, but this error message is sent out successfully;
 * returns -4 if error occurs when searching user table, and error message is not sent out successfully;
 * returns  4 if error occurs when searching user table, but error message is sent out successfully;
 * returns -5 if db error occurs when updating system time stamp, and error message is not sent out successfully;
 * returns  5 if db error occurs when updating system time stamp, but error message is sent out successfully;
 * returns -6 if server confirmation message is not sent out successfully. */
int srvSession::recvNewUsr()
{
  int32 dat_size;
  bool conv_stat = str2num(c_tokens[1], dat_size);
  if (!conv_stat || dat_size <= 0) {
    statMsg = "Invalid buffer size from client: " + c_tokens[1];
    if (sendStatMsg())
      return -1;
    return 1;
  }

  char buffer[dat_size];
  if (recvBuffer(g_session, dat_size, buffer)) {
    statMsg = "Failed to receive new user data from client";
    if (sendStatMsg())
      return -2;
    return 2;
  }

  DbTxn* txn = NULL;
  dbs.env.getEnv()->txn_begin(NULL, &txn, 0);
  int stat = addUser(dbs.userDB, dbs.sysDB, txn, buffer);
  if (stat == 1) {
    txn->commit(0);
    statMsg = "Account already exists.";
    if (sendStatMsg())
      return -3;
    return 3;
  }

  if (stat) {
    txn->abort();
    statMsg = "DB error when adding records into user table";
    if (sendStatMsg())
      return -4;
    return 4;
  }

  if (setSysUpdate(dbs.sysDB, txn, statMsg)) {
    txn->abort();
    statMsg = "DB error when updating time stamp in system table: " + statMsg;
    if (sendStatMsg())
      return -5;
    return 5;
  }

  txn->commit(0);
  statMsg = "success";
  if (sendStatMsg())
    return -6;

  dbs.sysDB.getDb().sync(0);
  dbs.userDB.getDb().sync(0); // write data on disk now
  return 0;
}
开发者ID:kimberg,项目名称:voxbo,代码行数:68,代码来源:server.cpp

示例3: sendUsrInfo

/* Send user information to client. 
 * Message syntax check ignored !!!
 * Returns 0 if everything is ok;
 * retunrs -1 if user is not found and message is not sent out successfully;
 * returns  1 if user is not found but message is sent out successfully; 
 * returns -2 if error occurs when browsing user table, and error message is not sent out successfully;
 * returns  2 if error occurs when browsing user table, but error message is sent out successfully;
 * returns  3 if user data is not sent out successfully. */
int srvSession::sendUsrInfo()
{
  userRec myInfo;
  DbTxn* txn = NULL;
  dbs.env.getEnv()->txn_begin(NULL, &txn, 0);
  int foo = getUser(dbs.userDB, txn, c_tokens[1], myInfo);
  if (foo != 1) {
    if (foo == 0) {
      txn->commit(0);
      statMsg = "no_data: User not found";
      if (sendStatMsg())
	return -1;
      return 1;
    }
    else {
      txn->abort();
      statMsg = "no_data: DB error " + num2str(foo);
      if (sendStatMsg())
	return -2;
      return 2;
    }
  }

  txn->commit(0);
  int data_size = myInfo.getSize();
  char data_buf[data_size];
  myInfo.serialize(data_buf);
  // Send data to client
  if (sendData(data_size, data_buf)) {
    statMsg = "Error when sending user data to client: " + statMsg;
    return 3;
  }

  return 0;
}
开发者ID:kimberg,项目名称:voxbo,代码行数:43,代码来源:server.cpp

示例4: recvScoreNames

/* Receive score name data from client side. 
 * Returns 0 if everything is ok;
 * returns -1 if data size from client is invalid, and this error message is not sent out successfully;
 * returns  1 if data size from client is invalid, but this error message is sent out successfully;
 * returns -2 if data is not received, and this error error message is not sent out successfully;
 * returns  2 if data is not received, but this error error message is sent out successfully;
 * returns -3 if error occurs when searching db, and error message is not sent out successfully;
 * returns  3 if error occurs when searching db, but error message is sent out successfully;
 * returns -4 if db error occurs when updating system time stamp, and error message is not sent out successfully;
 * returns  4 if db error occurs when updating system time stamp, but error message is sent out successfully;
 * returns -5 if server confirmation message is not sent out successfully. */
int srvSession::recvScoreNames()
{
  int32 dat_size;
  bool conv_stat = str2num(c_tokens[1], dat_size); 
  if (!conv_stat || dat_size <= 0) {
    statMsg = "Invalid score name data size from client: " + c_tokens[1];
    if (sendStatMsg())
      return -1;
    return 1;
  }

  char buffer[dat_size];
  if (recvBuffer(g_session, dat_size, buffer)) {
    statMsg = "Failed to receive score names from client";
    if (sendStatMsg())
      return -2;
    return 2;
  }

  vector<DBscorename> snList;
  deserialize(dat_size, buffer, snList);
  DbTxn* txn = NULL;
  dbs.env.getEnv()->txn_begin(NULL, &txn, 0);
  if (addScoreName(dbs.scoreNameDB, txn, snList)) {
    txn->abort();
    statMsg = "DB error when adding score name record into score name table";
    if (sendStatMsg())
      return -3;
    return 3;
  }  

  if (setSysUpdate(dbs.sysDB, txn, statMsg)) {
    txn->abort();
    statMsg = "DB error when updating time stamp in system table: " + statMsg;
    if (sendStatMsg())
      return -4;
    return 4;
  }

  txn->commit(0);
  dbs.scoreNameDB.getDb().sync(0);
  dbs.sysDB.getDb().sync(0);
  // Update score name maps on server side
  vbforeach(DBscorename sn, snList) {
    dbs.add_scorename(sn);
  }
开发者ID:kimberg,项目名称:voxbo,代码行数:57,代码来源:server.cpp

示例5: initDb

/* Initialize the database. */
void BulkExample::initDb(int dups, int sflag, int pagesize) {

	DbTxn *txnp;
	int ret;

	txnp = NULL;
	ret = 0;

	dbp = new Db(dbenv, 0);

	dbp->set_error_stream(&cerr);
	dbp->set_errpfx(progname);

	try{
		if ((ret = dbp->set_bt_compare(compare_int)) != 0)
			throwException(dbenv, NULL, ret, "DB->set_bt_compare");

		if ((ret = dbp->set_pagesize(pagesize)) != 0)
			throwException(dbenv, NULL, ret, "DB->set_pagesize");

		if (dups && (ret = dbp->set_flags(DB_DUP)) != 0)
			throwException(dbenv, NULL, ret, "DB->set_flags");

		if ((ret = dbenv->txn_begin(NULL, &txnp, 0)) != 0)
			throwException(dbenv, NULL, ret, "DB_ENV->txn_begin");

		if ((ret = dbp->open(txnp, DATABASE, "primary", DB_BTREE,
		    DB_CREATE, 0664)) != 0)
			throwException(dbenv, txnp, ret, "DB->open");

		if (sflag) {
			sdbp = new Db(dbenv, 0);

			if ((ret = sdbp->set_flags(DB_DUPSORT)) != 0)
				throwException(dbenv, txnp,
				    ret, "DB->set_flags");

			if ((ret = sdbp->open(txnp, DATABASE, "secondary",
			    DB_BTREE, DB_CREATE, 0664)) != 0)
				throwException(dbenv, txnp, ret, "DB->open");

			if ((ret =  dbp->associate(
			    txnp, sdbp, get_first_str, 0)) != 0)
				throwException(dbenv, txnp,
				    ret, "DB->associate");
		}

		ret = txnp->commit(0);
		txnp = NULL;
		if (ret != 0)
			throwException(dbenv, NULL, ret, "DB_TXN->commit");
	} catch(DbException &dbe) {
		cerr << "initDb " << dbe.what() << endl;
		if (txnp != NULL)
			(void)txnp->abort();
		throw dbe;
	}
}
开发者ID:crossbuild,项目名称:db,代码行数:59,代码来源:BulkExample.cpp

示例6: log

//##############################################################################
//##############################################################################
BerkeleyDBCXXDb::BerkeleyDBCXXDb(const std::string &name,
        boost::shared_ptr<BerkeleyDB> backend,
        const boost::shared_ptr<db::ConfigIface> db_config, boost::shared_ptr<BerkeleyDBCXXEnv> env)
    : name_(name), backend_(backend), env_(env), db_config_(db_config), log(BerkeleyDBCXXDbLogModule)
{
    RANGE_LOG_FUNCTION();
    inst_ = boost::make_shared<Db>(env_->getEnv(), 0);

    int rval = 0;
    DbTxn * txn;
    try { 
        rval = env_->getEnv()->txn_begin(NULL, &txn, DB_TXN_SYNC | DB_TXN_WAIT | DB_TXN_SNAPSHOT);
    }
    catch(DbException &e) {
        THROW_STACK(UnknownTransactionException(e.what()));
    }
    try { 
        inst_->open(txn, name.c_str(), name.c_str(), DB_HASH,
                DB_CREATE | DB_MULTIVERSION | DB_THREAD, 0);
    }
    catch(DbException &e) {
        txn->abort();
        THROW_STACK(DatabaseEnvironmentException(e.what()));
    }
    catch(std::exception &e) {
        txn->abort();
        THROW_STACK(DatabaseEnvironmentException(e.what()));
    }
    switch(rval) {
        case 0:
            break;
        case ENOMEM:
            THROW_STACK(DatabaseEnvironmentException("The maximum number of concurrent transactions has been reached."));
    }
    txn->commit(0);
}
开发者ID:jbeverly,项目名称:rangexx,代码行数:38,代码来源:berkeley_dbcxx_db.cpp

示例7: sendPatientMatches

/* Get a brief list of patients that matched cleint search criteria. 
 * Returns  0 if patient is found and data are sent out successfully, 
 * or no patient is found and message is sent out successfully;
 * returns -1 if permission is denied and error message is not sent out successfully;
 * returns  1 if permission is denied but error message is sent out successfully;
 * returns -2 if search criterion is invalid and error message is not sent out successfully;
 * returns  2 if search criterion is invalid but error message is sent out successfully;
 * returns -3 if error occurs when searching patient and error message is not sent out successfully;
 * returns  3 if error occurs when searching patient but error message is sent out successfully;
 * returns -4 if no patient is found in db and message is not sent out successfully;
 * returns -5 if patient is found but data are not sent out successfully. */
int srvSession::sendPatientMatches()
{
  if (!permissions.size()) {
    statMsg = "Permission denied";
    if (sendStatMsg())
      return -1;
    return 1;
  }

  patientSearchTags ps_tags;
  if (!parsePatientSearch(ps_tags)) {
    statMsg = ps_tags.err_msg;
    if (sendStatMsg())
      return -2;
    return 2;
  }

  DbTxn* txn = NULL;
  dbs.env.getEnv()->txn_begin(NULL, &txn, 0);
  vector<patientMatch> currentPatients;
  int foo = searchPatients(dbs.scoreValueDB, txn, ps_tags, permissions, currentPatients);
  if (foo < 0) {
    txn->abort();
    statMsg = "no_data: DB error ";
    if (sendStatMsg())
      return -3;
    return 3;
  }

  txn->commit(0);
  if (!currentPatients.size()) {
    statMsg = "no_data: Patient not found";   
    if (sendStatMsg())
      return -4;
    return 0;
  }

  int32 dat_size = getSize(currentPatients);
  char dat_buffer[dat_size];
  serialize(currentPatients, dat_buffer);
  if (sendData(dat_size, dat_buffer)) {
    statMsg = "Error when sending patient search results to client: " + statMsg;
    return -5;
  }

  return 0;
}
开发者ID:kimberg,项目名称:voxbo,代码行数:58,代码来源:server.cpp

示例8: main

int main(int argc, char* argv[])
{
  if (argc != 3) {
    cout << "Usage: delRecord <db filename> <record id>" << endl;
    exit(1);
  }

  string dbPath = argv[1];
  string envHome;
  string dbName;
  if (!parseEnvPath(dbPath, envHome, dbName)) {
    exit(1);
  }

  int32 id = atol(argv[2]);
  if (id <= 0) {
    cout << "Invalid ID: " << argv[2] << endl;
    exit(1);
  }
    
  myEnv env(envHome);
  if (!env.isOpen())
    exit(1);

  mydb currentDB(dbName, env);
  if (!currentDB.isOpen()) {
    env.close();
    exit(1);
  }

  DbTxn* txn = NULL;
  env.getEnv().txn_begin(NULL, &txn, 0);
  Dbt key(&id, sizeof(id));
  if (currentDB.getDb().del(txn, &key, 0) == 0) {
    cout << "Record " << id << " is deleted" << endl;
    txn->commit(0);
  }
  else {
    cout << "Failed to delete record ID " << id << endl;
    txn->abort();
  }

  currentDB.close();
  env.close();

  return 0;
}
开发者ID:Ampelbein,项目名称:voxbo,代码行数:47,代码来源:delRecord.cpp

示例9: deleteOset

bool wb_db::deleteOset(pwr_tStatus *sts, wb_oset *o)
{
  DbTxn *txn = 0;

  m_env->txn_begin(m_txn, &txn, 0);

  try {
    //del_family(txn, o);
    //unadopt(txn, wb_Position(o));
    //del_ohead(txn, o);
    //del_clist(txn, o);
    //del_name(txn, o);
    //del_body(txn, o);

    txn->commit(0);
  }
  catch (DbException &e) {
    txn->abort();
  }

  return true;
}
开发者ID:jordibrus,项目名称:proview,代码行数:22,代码来源:wb_db.cpp

示例10: sendID

/* Send unique IDs to client side. 
 * Returns  0 if everything is ok;
 * returns -1 if request from client is invalid and error message is not sent out successfully;
 * returns  1 if request from client is invalid but error message is sent out successfully;
 * returns -2 if error occurs when getting ID from db and error message is not sent out successfully; 
 * returns  2 if error occurs when getting ID from db but error message is sent out successfully; 
 * returns -3 if size of data is not sent out successfully;
 * returns -4 if data are not sent out successfully. */
int srvSession::sendID()
{
  int32 id_num;
  bool conv_stat = str2num(c_tokens[1], id_num);
  if (!conv_stat || id_num <= 0) { 
    statMsg = "no_data: Invalid number from client: " + c_tokens[1];
    if (sendStatMsg())
      return -1;
    return 1;
  }

  DbTxn* txn = NULL;
  dbs.env.getEnv()->txn_begin(NULL, &txn, 0);
  int32 startID = getSysID(dbs.sysDB, txn, id_num);
  if (startID <= 0) {
    txn->abort();
    statMsg = "no_data: DB error";
    if (sendStatMsg())
      return -2;
    return 2;
  }

  txn->commit(0);
  dbs.sysDB.getDb().sync(0); // write data on disk now    
  statMsg = "server_data_size: " + num2str(sizeof(startID)); 
  if (sendStatMsg()) {
    statMsg = "Error when sending ID to client: failed to send data size message"; 
    return -3;
  }

  if (ntohs(1) == 1)
    swap(&startID);
  if (gnutls_record_send(g_session, &startID, sizeof(startID)) != sizeof(startID)) {
    statMsg = "Error when sending ID to client: failed to send data";
    return 4;
  }

  return 0;
}
开发者ID:kimberg,项目名称:voxbo,代码行数:47,代码来源:server.cpp

示例11: bulkRead


//.........这里部分代码省略.........
	Dbt data, dp, key, kp;
	DbTxn *txnp;
	DbMultipleDataIterator *ptrd;
	DbMultipleKeyDataIterator *ptrkd;
	u_int32_t flags;
	int count, i, j, ret;

	count = klen = ret = 0;
	dbcp = NULL;
	txnp = NULL;

	/* Initialize key Dbt and data Dbt, malloc bulk buffer. */
	memset(&key, 0, sizeof(key));
	memset(&data, 0, sizeof(data));
	key.set_size(sizeof(j));
	if (dlen != DATALEN * 16 * 1024) {
		dlen = DATALEN * 16 * 1024;
		dbuf = realloc(dbuf, dlen);
	}
	memset(dbuf, 0, dlen);
	data.set_flags(DB_DBT_USERMEM);
	data.set_data(dbuf);
	data.set_ulen(dlen);
	data.set_size(dlen);

	flags = DB_SET;
	flags |= (dups) ? DB_MULTIPLE: DB_MULTIPLE_KEY;
	try {
		for (i = 0; i < iter; i++) {
			if ((ret =
			    dbenv->txn_begin(NULL, &txnp, 0)) != 0)
				throwException(dbenv, NULL,
				    ret, "DB_ENV->txn_begin");
			if ((ret = dbp->cursor(txnp, &dbcp, 0)) != 0)
				throwException(dbenv, txnp,
				    ret, "DB->cursor");

			/*
			 * Bulk retrieve by a random key which is a random
			 * non-negative integer smaller than "num".
			 * If there are duplicates in the database, retrieve
			 * with DB_MULTIPLE and use the DbMultipleDataIterator
			 * to iterate the data of the random key in the data
			 * Dbt. Otherwise retrieve with DB_MULTIPLE_KEY and use
			 * the DbMultipleKeyDataIterator to iterate the
			 * key/data pairs of the specific set of keys which
			 * includes all integers >= the random key and < "num".
			 */
			j = rand() % num;
			key.set_data(&j);
			if ((ret = dbcp->get(&key, &data, flags)) != 0) 
				throwException(dbenv, NULL, ret, "DBC->get");

			if (dups) {
				ptrd = new DbMultipleDataIterator(data);
				while (ptrd->next(dp) == true) {
					count++;
					if (verbose)
						printf(
"Retrieve key: %d, \tdata: (id %d, str %s)\n", j, ((struct data *)(
						   dp.get_data()))->id,
						   (char *)((struct data *)(
						   dp.get_data()))->str);
				}
			} else {
				ptrkd = new DbMultipleKeyDataIterator(data);
				while (ptrkd->next(kp, dp) == true) {
					count++;
					if (verbose)
						printf(
"Retrieve key: %d, \tdata: (id %d, str %s)\n", *((int *)kp.get_data()),
						    ((struct data *)(
						    dp.get_data()))->id,
						    (char *)((struct data *)(
						    dp.get_data()))->str);
				}
			}

			ret = dbcp->close();
			dbcp = NULL;
			if (ret != 0)
				throwException(dbenv, txnp, ret, "DBC->close");

			ret = txnp->commit(0);
			txnp = NULL;
			if (ret != 0)
				throwException(dbenv, NULL,
				    ret, "DB_TXN->commit");
		} 

		*countp = count;
	} catch (DbException &dbe) {
		cerr << "bulkRead " << dbe.what() << endl;
		if (dbcp != NULL)
			(void)dbcp->close();
		if (txnp != NULL)
			(void)txnp->abort();
		throw dbe;
	}
}
开发者ID:crossbuild,项目名称:db,代码行数:101,代码来源:BulkExample.cpp

示例12: bulkUpdate


//.........这里部分代码省略.........
		dlen = (u_int32_t) UPDATES_PER_BULK_PUT *
		    (sizeof(u_int32_t) + DATALEN) * 1024;
		dbuf = realloc(dbuf, dlen);
	}
	memset(dbuf, 0, dlen);
	data.set_ulen(dlen);
	data.set_flags(DB_DBT_USERMEM | DB_DBT_BULK);
	data.set_data(dbuf);

	/*
	 * Bulk insert with either DB_MULTIPLE in two buffers or
	 * DB_MULTIPLE_KEY in a single buffer. With DB_MULTIPLE, all keys are
	 * constructed in the key Dbt, and all data is constructed in the data
	 * Dbt. With DB_MULTIPLE_KEY, all key/data pairs are constructed in the
	 * key Dbt. We use DB_MULTIPLE mode when there are duplicate records.
	 */
	flag |= (dups) ? DB_MULTIPLE : DB_MULTIPLE_KEY;
	if (dups) {
		ptrk = new DbMultipleDataBuilder(key);
		ptrd = new DbMultipleDataBuilder(data);
	} else
		ptrkd = new DbMultipleKeyDataBuilder(key);

	try {
		for (i = 0; i < num; i++) {
			if (i % UPDATES_PER_BULK_PUT == 0) {
				if (txnp != NULL) {
					ret = txnp->commit(0);
					txnp = NULL;
					if (ret != 0)
						throwException(dbenv, NULL,
						    ret, "DB_TXN->commit");
				}
				if ((ret = dbenv->txn_begin(NULL,
				    &txnp, 0)) != 0)
					throwException(dbenv,
					    NULL, ret, "DB_ENV->txn_begin");
			}
			data_val->id = 0;
			get_string(tstring, data_val->str, i);
			do {
				if (dups) {
					if (ptrk->append(&i,
					    sizeof(i)) == false)
						throwException(dbenv,
						    txnp, EXIT_FAILURE,
"DbMultipleDataBuilder->append");
					if (ptrd->append(data_val,
					    DATALEN) == false)
						throwException(dbenv,
						    txnp, EXIT_FAILURE,
"DbMultipleDataBuilder->append");
				} else {
					if (ptrkd->append(&i, sizeof(i),
					    data_val, DATALEN) == false)
						throwException(dbenv,
						    txnp, EXIT_FAILURE,
"DbMultipleKeyDataBuilder->append");
				}
				if (verbose)
					printf(
"Insert key: %d, \t data: (id %d, str %s)\n",
					    i, data_val->id, data_val->str);
				count++;
			} while (data_val->id++ < dups);
			if ((i + 1) % UPDATES_PER_BULK_PUT == 0) {
				if ((ret = dbp->put(txnp,
					    &key, &data, flag)) != 0)
					throwException(dbenv,
					    txnp, ret, "Bulk DB->put");
				iter++;
				if (dups) {
					ptrk = new DbMultipleDataBuilder(key);
					ptrd = new DbMultipleDataBuilder(data);
				} else
					ptrkd = new
					    DbMultipleKeyDataBuilder(key);
			}
		} 
		if ((num % UPDATES_PER_BULK_PUT) != 0) {
			if ((ret = dbp->put(txnp, &key, &data, flag)) != 0)
				throwException(dbenv,
				    txnp, ret, "Bulk DB->put");
			iter++;
		}

		ret = txnp->commit(0);
		txnp = NULL;
		if (ret != 0)
			throwException(dbenv, NULL, ret, "DB_TXN->commit");

		*countp = count;
		*iterp = iter;
	} catch (DbException &dbe) {
		cerr << "bulkUpdate " << dbe.what() << endl;
		if (txnp != NULL)
			(void)txnp->abort();
		throw dbe;
	}
}
开发者ID:crossbuild,项目名称:db,代码行数:101,代码来源:BulkExample.cpp

示例13: bulkSecondaryDelete


//.........这里部分代码省略.........
	if (klen != (u_int32_t)UPDATES_PER_BULK_PUT *
	    (sizeof(u_int32_t) + DATALEN) * 1024) {
		klen = (u_int32_t)UPDATES_PER_BULK_PUT *
		    (sizeof(u_int32_t) + DATALEN) * 1024;
		kbuf = realloc(kbuf, klen);
	}
	memset(kbuf, 0, klen);
	key.set_ulen(klen);
	key.set_flags(DB_DBT_USERMEM | DB_DBT_BULK);
	key.set_data(kbuf);

	/*
	 * Bulk delete all records of a specific set of keys which includes all
	 * characters before the random key in the tstring. The random key is
	 * one of the characters in the tstring.
	 * If DB_MULTIPLE, construct the key Dbt by the DbMultipleDataBuilder
	 * with the specific set of keys. If DB_MULTIPLE_KEY, construct the key
	 * Dbt by the DbMultipleKeyDataBuilder with all key/data pairs of the
	 * specific set of keys.
	 */
	flag |= (pair) ? DB_MULTIPLE_KEY : DB_MULTIPLE;
	if (pair)
		ptrkd = new DbMultipleKeyDataBuilder(key);
	else
		ptrd = new DbMultipleDataBuilder(key);
	try {
		for (i = 0; i <= rc; i++) {
			if (i % UPDATES_PER_BULK_PUT == 0) {
				if (txnp != NULL) {
					ret = txnp->commit(0);
					txnp = NULL;
					if (ret != 0)
						throwException(dbenv, NULL,
						    ret, "DB_TXN->commit");
				}
				if ((ret = dbenv->txn_begin(NULL,
				    &txnp, 0)) != 0)
					throwException(dbenv,
					    NULL, ret, "DB_ENV->txn_begin");
			}

			ch = tstring[i];
			if (!pair) {
				if (ptrd->append(&ch, sizeof(ch)) == false)
					throwException(dbenv,
					    txnp, EXIT_FAILURE,
					    "DbMultipleDataBuilder->append");
				count++;
				if (verbose)
					printf("Delete key: %c\n", ch);
			} else {
				j = 0;
				do {
					k = j * (STRLEN - 1) + i;
					if (ptrkd->append(&ch, sizeof(ch),
					    &k, sizeof(k)) == false)
						throwException(dbenv,
						    txnp, EXIT_FAILURE,
"DbMultipleKeyDataBuilder->append");
					count++;
					if (verbose)
						printf(
"Delete secondary key: %c, \tdata: %d\n", 
						    ch, k);
				} while (++j < (int)(num / (STRLEN - 1)));
			}

			if ((i + 1) % UPDATES_PER_BULK_PUT == 0) {
				if ((ret = sdbp->del(txnp, &key, flag)) != 0)
					throwException(dbenv,
					    txnp, ret, "Bulk DB->del");
				iter++;
				if (pair)
					ptrkd = new
					    DbMultipleKeyDataBuilder(key);
				else
					ptrd = new DbMultipleDataBuilder(key);
			}
		}
		if ((rc % UPDATES_PER_BULK_PUT) != 0) {
			if ((ret = sdbp->del(txnp, &key, flag)) != 0)
				throwException(dbenv,
				    txnp, ret, "Bulk DB->del");
			iter++;
		}

		ret = txnp->commit(0);
		txnp = NULL;
		if (ret != 0)
			throwException(dbenv, NULL, ret, "DB_TXN->commit");

		*countp = count;
		*iterp = iter;
	} catch (DbException &dbe) {
		cerr << "bulkSecondaryDelete " << dbe.what() << endl;
		if (txnp != NULL)
			(void)txnp->abort();
		throw dbe;
	}
}
开发者ID:crossbuild,项目名称:db,代码行数:101,代码来源:BulkExample.cpp

示例14: bulkDelete


//.........这里部分代码省略.........
		klen = (u_int32_t)UPDATES_PER_BULK_PUT *
		    (sizeof(u_int32_t) + DATALEN) * 1024;
		kbuf = realloc(kbuf, klen);
	}
	memset(kbuf, 0, klen);
	key.set_ulen(klen);
	key.set_flags(DB_DBT_USERMEM | DB_DBT_BULK);
	key.set_data(kbuf);
	if (data_val == NULL)
		data_val = (data *)malloc(DATALEN);
	memset(data_val, 0, DATALEN);

	/*
	 * Bulk delete all records of a specific set of keys which includes all
	 * non-negative integers smaller than the random key. The random key is
	 * a random non-negative integer smaller than "num".
	 * If DB_MULTIPLE, construct the key Dbt by the DbMultipleDataBuilder
	 * with the specific set of keys. If DB_MULTIPLE_KEY, construct the key
	 * Dbt by the DbMultipleKeyDataBuilder with all key/data pairs of the
	 * specific set of keys.
	 */
	flag |= (dups) ? DB_MULTIPLE_KEY : DB_MULTIPLE;
	if (dups)
		ptrkd = new DbMultipleKeyDataBuilder(key);
	else
		ptrd = new DbMultipleDataBuilder(key);
	try {
		for (i = 0; i < j; i++) {
			if (i % UPDATES_PER_BULK_PUT == 0) {
				if (txnp != NULL) {
					ret = txnp->commit(0);
					txnp = NULL;
					if (ret != 0)
						throwException(dbenv, NULL,
						    ret, "DB_TXN->commit");
				}
				if ((ret = dbenv->txn_begin(NULL,
				    &txnp, 0)) != 0)
					throwException(dbenv, NULL,
					    ret, "DB_ENV->txn_begin");
			}

			if (dups) {
				data_val->id = 0;
				get_string(tstring, data_val->str, i);
				do {
					if(ptrkd->append(&i,sizeof(i),
					    data_val, DATALEN) == false)
						throwException(dbenv,
						    txnp, EXIT_FAILURE,
"DbMultipleKeyDataBuilder->append");
					count++;
					if (verbose)
						printf(
"Delete key: %d, \tdata: (id %d, str %s)\n",
						    i, data_val->id,
						    data_val->str);
				} while (data_val->id++ < dups);
			} else {
				if(ptrd->append(&i,sizeof(i)) == false)
					throwException(dbenv, txnp, ret,
					    "DbMultipleDataBuilder->append");
				count++;
				if (verbose)
					printf("Delete key: %d\n", i);
			}

			if ((i + 1) % UPDATES_PER_BULK_PUT == 0) {
				if ((ret = dbp->del(txnp, &key, flag)) != 0)
					throwException(dbenv,
					    txnp, ret, "Bulk DB->del");
				iter++;
				if (dups)
					ptrkd = new
					    DbMultipleKeyDataBuilder(key);
				else
					ptrd = new DbMultipleDataBuilder(key);
			}
		}
		if ((j % UPDATES_PER_BULK_PUT) != 0) {
			if ((ret = dbp->del(txnp, &key, flag)) != 0)
				throwException(dbenv,
				    txnp, ret, "Bulk DB->del");
			iter++;
		}

		ret = txnp->commit(0);
		txnp = NULL;
		if (ret != 0)
			throwException(dbenv, NULL, ret, "DB_TXN->commit");

		*countp = count;
		*iterp = iter;
	} catch (DbException &dbe) {
		cerr << "bulkDelete " << dbe.what() << endl;
		if (txnp != NULL)
			(void)txnp->abort();
		throw dbe;
	}
}
开发者ID:crossbuild,项目名称:db,代码行数:101,代码来源:BulkExample.cpp

示例15: main

int main(int argc, char *argv[])
{
	try {
		DbEnv *dbenv = new DbEnv(0);
		DbTxn *dbtxn;
		u_int8_t conflicts[10];

		dbenv->set_error_stream(&cerr);
		dbenv->set_timeout(0x90000000,
				   DB_SET_LOCK_TIMEOUT);
		dbenv->set_lg_bsize(0x1000);
		dbenv->set_lg_dir(".");
		dbenv->set_lg_max(0x10000000);
		dbenv->set_lg_regionmax(0x100000);
		dbenv->set_lk_conflicts(conflicts, sizeof(conflicts));
		dbenv->set_lk_detect(DB_LOCK_DEFAULT);
		dbenv->set_lk_max_lockers(100);
		dbenv->set_lk_max_locks(10);
		dbenv->set_lk_max_objects(1000);
		dbenv->set_mp_mmapsize(0x10000);

		// Need to open the environment so we
		// can get a transaction.
		//
		dbenv->open(".", DB_CREATE | DB_INIT_TXN |
			    DB_INIT_LOCK | DB_INIT_LOG |
			    DB_INIT_MPOOL,
			    0644);

		dbenv->txn_begin(NULL, &dbtxn, DB_TXN_NOWAIT);
		dbtxn->set_timeout(0xA0000000, DB_SET_TXN_TIMEOUT);
		dbtxn->abort();

		dbenv->close(0);

		// We get a db, one for each type.
		// That's because once we call (for instance)
		// set_bt_minkey, DB 'knows' that this is a
		// Btree Db, and it cannot be used to try Hash
		// or Recno functions.
		//
		Db *db_bt = new Db(NULL, 0);
		db_bt->set_bt_minkey(100);
		db_bt->set_cachesize(0, 0x100000, 0);
		db_bt->close(0);

		Db *db_h = new Db(NULL, 0);
		db_h->set_h_ffactor(0x10);
		db_h->set_h_nelem(100);
		db_h->set_lorder(0);
		db_h->set_pagesize(0x10000);
		db_h->close(0);

		Db *db_re = new Db(NULL, 0);
		db_re->set_re_delim('@');
		db_re->set_re_pad(10);
		db_re->set_re_source("re.in");
		db_re->close(0);

		Db *db_q = new Db(NULL, 0);
		db_q->set_q_extentsize(200);
		db_q->close(0);

	}
	catch (DbException &dbe) {
		cerr << "Db Exception: " << dbe.what() << "\n";
	}
	return 0;
}
开发者ID:HackLinux,项目名称:chandler,代码行数:69,代码来源:TestGetSetMethods.cpp


注:本文中的DbTxn::abort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。