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


C++ Transaction::Commit方法代码示例

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


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

示例1: Push

bool LogCache::Push(uint64_t paxosID, ByteString value, bool commit)
{
	ByteArray<128> buf;
	Transaction* transaction;
	
	Log_Trace("Storing paxosID %" PRIu64 " with length %d", paxosID, value.length);
	
	transaction = RLOG->GetTransaction();
	
	if (!transaction->IsActive())
		transaction->Begin();
	
	WriteRoundID(buf, paxosID);
	table->Set(transaction, buf, value);
	
	// delete old
	if ((int64_t)(paxosID - logCacheSize) >= 0)
	{
		paxosID -= logCacheSize;
		WriteRoundID(buf, paxosID);
		table->Delete(transaction, buf);
	}
	
	if (commit)
		transaction->Commit();
	
	return true;
}
开发者ID:agazso,项目名称:keyspace,代码行数:28,代码来源:LogCache.cpp

示例2: DeleteOldRounds

void LogCache::DeleteOldRounds(uint64_t paxosID)
{
	Cursor			cursor;
	ByteArray<128>	buf;
	DynArray<128>	key;
	DynArray<128>	value;
	Transaction*	transaction;
	
	transaction = RLOG->GetTransaction();
	
	transaction->Begin();
	
	WriteRoundID(buf, paxosID);
	table->Iterate(transaction, cursor);
	if (!cursor.Start(buf))
	{
		cursor.Close();
		transaction->Rollback();
		return;
	}
		
	while (cursor.Prev(key, value))
	{
		if (key.length > sizeof("@@pround:") - 1 &&
		strncmp(key.buffer, "@@pround:", sizeof("@@pround:") - 1) == 0)
			cursor.Delete();
		else
			break;
	}
	
	cursor.Close();

	transaction->Commit();
}
开发者ID:agazso,项目名称:keyspace,代码行数:34,代码来源:LogCache.cpp

示例3: Request

//-----------------------------------------------------------------
Transaction*  RadioResources::Request(RRC2RRMMessageAddRadioAccessBearerConfirm &confirmP)
//-----------------------------------------------------------------
{
    cell_id_t e_node_b_id = confirmP.GetENodeBId();
    if (IsENodeBRegistered(e_node_b_id)) {
        mobile_id_t mobile_id  = confirmP.GetMobileId();
        if (!IsMobileRegistered(e_node_b_id, mobile_id)) {
            throw mobile_not_connected_error() << mobile_id_info(mobile_id);
        } else {
            // TO DO CHECK RADIO BEARER
            fprintf(stderr, "[RadioResources] Confirming new DRB %d\n", confirmP.GetRadioBearerId());
            Transaction* transaction =  Transactions::Instance()->GetTransaction(confirmP.GetTransactionId());
            transaction->Commit(); transaction = NULL;
            Transactions::Instance()->RemoveTransaction(confirmP.GetTransactionId());
            return NULL;
        }
    } else {
        throw enodeb_not_connected_error() << enodeb_id_info(e_node_b_id);
    }
}
开发者ID:a4a881d4,项目名称:oai,代码行数:21,代码来源:RadioResources.cpp

示例4: main

int main() {
  // open DB
  Options options;
  TransactionDBOptions txn_db_options;
  options.create_if_missing = true;
  TransactionDB* txn_db;

  Status s = TransactionDB::Open(options, txn_db_options, kDBPath, &txn_db);
  assert(s.ok());

  WriteOptions write_options;
  ReadOptions read_options;
  TransactionOptions txn_options;
  std::string value;

  ////////////////////////////////////////////////////////
  //
  // Simple Transaction Example ("Read Committed")
  //
  ////////////////////////////////////////////////////////

  // Start a transaction
  Transaction* txn = txn_db->BeginTransaction(write_options);
  assert(txn);

  // Read a key in this transaction
  s = txn->Get(read_options, "abc", &value);
  assert(s.IsNotFound());

  // Write a key in this transaction
  s = txn->Put("abc", "def");
  assert(s.ok());

  // Read a key OUTSIDE this transaction. Does not affect txn.
  s = txn_db->Get(read_options, "abc", &value);

  // Write a key OUTSIDE of this transaction.
  // Does not affect txn since this is an unrelated key.  If we wrote key 'abc'
  // here, the transaction would fail to commit.
  s = txn_db->Put(write_options, "xyz", "zzz");

  // Commit transaction
  s = txn->Commit();
  assert(s.ok());
  delete txn;

  ////////////////////////////////////////////////////////
  //
  // "Repeatable Read" (Snapshot Isolation) Example
  //   -- Using a single Snapshot
  //
  ////////////////////////////////////////////////////////

  // Set a snapshot at start of transaction by setting set_snapshot=true
  txn_options.set_snapshot = true;
  txn = txn_db->BeginTransaction(write_options, txn_options);

  const Snapshot* snapshot = txn->GetSnapshot();

  // Write a key OUTSIDE of transaction
  s = txn_db->Put(write_options, "abc", "xyz");
  assert(s.ok());

  // Attempt to read a key using the snapshot.  This will fail since
  // the previous write outside this txn conflicts with this read.
  read_options.snapshot = snapshot;
  s = txn->GetForUpdate(read_options, "abc", &value);
  assert(s.IsBusy());

  txn->Rollback();

  delete txn;
  // Clear snapshot from read options since it is no longer valid
  read_options.snapshot = nullptr;
  snapshot = nullptr;

  ////////////////////////////////////////////////////////
  //
  // "Read Committed" (Monotonic Atomic Views) Example
  //   --Using multiple Snapshots
  //
  ////////////////////////////////////////////////////////

  // In this example, we set the snapshot multiple times.  This is probably
  // only necessary if you have very strict isolation requirements to
  // implement.

  // Set a snapshot at start of transaction
  txn_options.set_snapshot = true;
  txn = txn_db->BeginTransaction(write_options, txn_options);

  // Do some reads and writes to key "x"
  read_options.snapshot = txn_db->GetSnapshot();
  s = txn->Get(read_options, "x", &value);
  txn->Put("x", "x");

  // Do a write outside of the transaction to key "y"
  s = txn_db->Put(write_options, "y", "y");

  // Set a new snapshot in the transaction
//.........这里部分代码省略.........
开发者ID:BossKwei,项目名称:temp,代码行数:101,代码来源:transaction_db_1.cpp

示例5: DatabaseSetTest

int DatabaseSetTest(TestConfig& conf)
{
	int			numTest;
	Table*		table;
	Transaction* tx;
	bool		ret;
	int			limit = 16*KB;
	int			sum;
    char        lacKee[20];

	if (DatabaseSetup())
	{
		//Log_Message("Cannot initialize database!", 1);
		return 1;
	}

	table = database.GetTable("keyspace");
	if (!table)
	{
		//Log_Message("Cannot initialize table!", 1);
		return 1;
	}

	tx = NULL;
	tx = new Transaction(table);
	tx->Begin();

	sum = 0;
	numTest = conf.datasetTotal / conf.valueSize;
	for (int i = 0; i < numTest; i++)
	{
//##		if (conf.rndkey)
//##			GenRandomString(conf.key, conf.keySize);
//##		else
        conf.key.append("key");
        snprintf(lacKee, sizeof(lacKee), "%d", conf.padding.length());
        conf.key.append(lacKee);
        conf.key.append(conf.padding.c_str());
        snprintf(lacKee, sizeof(lacKee), "%d", i);
        conf.key.append(lacKee);

//			conf.key.Writef("key%B:%d", conf.padding.length, conf.padding.buffer, i);

		ret = table->Set(tx, conf.key.c_str(), conf.value.c_str());
		if (!ret)
		{
			//Log_Message("Test failed, ret = %s (%s failed after %d)", ret ? "true" : "false", conf.typeString, i);
			return 1;
		}

		sum += conf.keySize + conf.valueSize;
		if (sum > limit)
		{
			tx->Commit();


			tx->Begin();

			sum = 0;
		}
	}

	tx->Commit();


	return 0;
}
开发者ID:msng4t,项目名称:network-etc,代码行数:67,代码来源:DatabaseStressTest.cpp

示例6: DatabaseSetTest

int DatabaseSetTest(TestConfig& conf)
{
	int			numTest;
	Stopwatch	sw;
	Table*		table;
	Transaction* tx;
	bool		ret;
	int			limit = 16*KB;
	int			sum;

	if (conf.argc < 5)
	{
		Log_Message("\n\tusage: %s <keySize> <valueSize>", conf.typeString);
		return 1;
	}
	
	Log_SetTrace(true);
	
	if (DatabaseSetup())
	{
		Log_Message("Cannot initialize database!", 1);
		return 1;
	}
	
	table = database.GetTable("keyspace");
	if (!table)
	{
		Log_Message("Cannot initialize table!", 1);
		return 1;
	}
	
	conf.SetKeySize(atoi(conf.argv[3]));
	conf.SetValueSize(atoi(conf.argv[4]));

	Log_Message("Test type = %s, keySize = %d, valueSize = %d",
			conf.typeString, conf.keySize, conf.valueSize);
	
	tx = NULL;
	tx = new Transaction(table);
	sw.Start();
	tx->Begin();
	sw.Stop();
	
	sum = 0;
	numTest = conf.datasetTotal / conf.valueSize;
	for (int i = 0; i < numTest; i++)
	{
		if (conf.rndkey)
			GenRandomString(conf.key, conf.keySize);
		else
			conf.key.Writef("key%B:%d", conf.padding.length, conf.padding.buffer, i);
		
		sw.Start();
		ret = table->Set(tx, conf.key, conf.value);
		sw.Stop();
		if (!ret)
		{
			Log_Message("Test failed, ret = %s (%s failed after %d)", ret ? "true" : "false", conf.typeString, i);
			return 1;
		}
		
		sum += conf.keySize + conf.valueSize;
		if (sum > limit)
		{			
			sw.Start();
			tx->Commit();
			sw.Stop();
			
			double mbps = sum / (sw.elapsed / 1000.0) / 1000000;
			Log_Message("num = %d, elapsed = %ld, thruput = %lf MB/s", i, sw.elapsed, mbps);
			sw.Reset();
			
			sw.Start();
			tx->Begin();
			sw.Stop();

			sum = 0;
		}
	}

	sw.Start();
	tx->Commit();
	sw.Stop();

	double mbps = (conf.valueSize + conf.keySize) * numTest / (sw.elapsed / 1000.0) / 1000000;
	Log_Message("Test succeeded, %s/sec = %lf (num = %d, elapsed = %ld, thruput = %lf MB/s)", conf.typeString, numTest / (sw.elapsed / 1000.0), numTest, sw.elapsed, mbps);
	
	return 0;
}
开发者ID:Kaperstone,项目名称:keyspace,代码行数:89,代码来源:DatabaseStressTest.cpp


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