本文整理汇总了C++中Dbt::set_size方法的典型用法代码示例。如果您正苦于以下问题:C++ Dbt::set_size方法的具体用法?C++ Dbt::set_size怎么用?C++ Dbt::set_size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dbt
的用法示例。
在下文中一共展示了Dbt::set_size方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initializeOutDbt
void
Freeze::handleDbException(const DbException& dx,
Key& key, Dbt& dbKey,
Value& value, Dbt& dbValue,
const char* file, int line)
{
bool bufferSmallException =
#if (DB_VERSION_MAJOR == 4) && (DB_VERSION_MINOR == 2)
(dx.get_errno() == ENOMEM);
#else
(dx.get_errno() == DB_BUFFER_SMALL || dx.get_errno() == ENOMEM);
#endif
bool resized = false;
if(bufferSmallException)
{
if(dbKey.get_size() > dbKey.get_ulen())
{
size_t oldKeySize = key.size();
key.resize(dbKey.get_size());
initializeOutDbt(key, dbKey);
dbKey.set_size(static_cast<u_int32_t>(oldKeySize));
resized = true;
}
if(dbValue.get_size() > dbValue.get_ulen())
{
value.resize(dbValue.get_size());
initializeOutDbt(value, dbValue);
resized = true;
}
}
if(!resized)
{
handleDbException(dx, file, line);
}
}
示例2: readBlock
AntiCacheBlock AntiCacheDB::readBlock(std::string tableName, int16_t blockId) {
Dbt key;
key.set_data(&blockId);
key.set_size(sizeof(int16_t));
Dbt value;
value.set_flags(DB_DBT_MALLOC);
VOLT_DEBUG("Reading evicted block with id %d", blockId);
int ret_value = m_db->get(NULL, &key, &value, 0);
if (ret_value != 0) {
VOLT_ERROR("Invalid anti-cache blockId '%d' for table '%s'", blockId, tableName.c_str());
throw UnknownBlockAccessException(tableName, blockId);
}
else {
// m_db->del(NULL, &key, 0); // if we have this the benchmark won't end
assert(value.get_data() != NULL);
}
AntiCacheBlock block(blockId, value);
return (block);
}
示例3: deleteAllParts
void MultiPartHeader::deleteAllParts(Db* pDB)
{
int ret = 0;
Dbc *cursorp = 0;
Dbt key;
Dbt data;
//qDebug() << "Deleting all parts for key " << multiPartKey;
key.set_data(&multiPartKey);
key.set_size(sizeof(quint64));
// Get a cursor
pDB->cursor(NULL, &cursorp, DB_WRITECURSOR);
while ((ret = cursorp->get(&key, &data, DB_SET)) == 0)
cursorp->del(0);
pDB->sync(0);
if (cursorp != NULL)
cursorp->close();
}
示例4: run
void BtRecExample::run()
{
db_recno_t recno;
int ret;
char buf[1024];
// Acquire a cursor for the database.
dbp->cursor(NULL, &dbcp, 0);
//
// Prompt the user for a record number, then retrieve and display
// that record.
//
for (;;) {
// Get a record number.
cout << "recno #> ";
cout.flush();
if (fgets(buf, sizeof(buf), stdin) == NULL)
break;
recno = atoi(buf);
//
// Start with a fresh key each time,
// the dbp->get() routine returns
// the key and data pair, not just the key!
//
Dbt key(&recno, sizeof(recno));
Dbt data;
if ((ret = dbcp->get(&key, &data, DB_SET_RECNO)) != 0) {
dbp->err(ret, "DBcursor->get");
throw DbException(ret);
}
// Display the key and data.
show("k/d\t", &key, &data);
// Move the cursor a record forward.
if ((ret = dbcp->get(&key, &data, DB_NEXT)) != 0) {
dbp->err(ret, "DBcursor->get");
throw DbException(ret);
}
// Display the key and data.
show("next\t", &key, &data);
//
// Retrieve the record number for the following record into
// local memory.
//
data.set_data(&recno);
data.set_size(sizeof(recno));
data.set_ulen(sizeof(recno));
data.set_flags(data.get_flags() | DB_DBT_USERMEM);
if ((ret = dbcp->get(&key, &data, DB_GET_RECNO)) != 0) {
if (ret != DB_NOTFOUND && ret != DB_KEYEMPTY) {
dbp->err(ret, "DBcursor->get");
throw DbException(ret);
}
}
else {
cout << "retrieved recno: " << (u_long)recno << "\n";
}
}
dbcp->close();
dbcp = NULL;
}
示例5: modifyPart
// Modify or create a part based on the following information
MultiPartHeader::Add_Code MultiPartHeader::modifyPart(Db* pdb, quint16 partNo, RawHeader *rh, quint16 hostId)
{
//qDebug() << "Entering modifyPart";
Add_Code retCode = New_Part;
int ret = 0;
bool createPart = false;
Header* h = 0;
char *phead = 0;
Dbc *cursorp = 0;
Dbt key;
Dbt data;
//qDebug() << "Creating part for key " << multiPartKey;
key.set_data(&multiPartKey);
key.set_size(sizeof(quint64));
data.set_data(&partNo);
data.set_size(sizeof(quint16));
// Get a cursor
pdb->cursor(NULL, &cursorp, DB_WRITECURSOR);
//qDebug("1");
// Position the cursor to the first record in the database whose
// key matches the search key and whose data begins with the search
// data.
ret = cursorp->get(&key, &data, DB_GET_BOTH);
if (ret == 0)
{
//qDebug("2");
// update the data
h = new Header((char*)data.get_data(), (char*)key.get_data());
//qDebug("3");
if (h->isHeldByServer(hostId))
{
retCode = Duplicate_Part;
}
else
retCode = Updated_Part;
// qDebug() << "Found an update for part " << partNo << ", existing part " << h->getPartNo() << ", existing msgid " << h->getMessageId() << ", new msgid " << rh->m_mid;
// Always update the article number
h->setServerPartNum(hostId, rh->m_num);
//qDebug("4");
phead=h->data();
data.set_data(phead);
data.set_size(h->getRecordSize());
//qDebug("5");
cursorp->put(&key, &data, DB_CURRENT);
//qDebug("6");
Q_DELETE_ARRAY(phead);
}
else if (ret == DB_NOTFOUND) // create the part
{
//qDebug("7");
createPart = true;
}
else // encountered an error
{
qDebug() << "Unable to find part " << partNo << " for key " << multiPartKey << ", result = " << ret;
retCode = Error_Part;
}
// Close the cursor
if (cursorp != NULL)
cursorp->close();
if (createPart == true)
{
//qDebug("8");
quint32 partSize = rh->m_bytes.toULong();
h = new Header(multiPartKey, partNo, partSize);
//qDebug("9");
h->setMessageId(rh->m_mid);
h->setServerPartNum(hostId, rh->m_num);
//save in the parts db
phead=h->data();
data.set_data(phead);
data.set_size(h->getRecordSize());
//qDebug("10");
ret = pdb->put(0, &key, &data, 0);
if (ret)
{
qDebug() << "Unable to create part " << partNo << " for key " << multiPartKey << ", result = " << ret;
retCode = Error_Part;
}
//.........这里部分代码省略.........
示例6: lookupByIndex
int* ROSWOSSegment::lookupByIndex( char* key, int size, Dbc *iter,
u_int32_t flags, void **_ptr, void **buf )
{
size_t retklen, retdlen;
Dbt skey;
void *retkey, *retdata;
bool second_pass = false;
int answer;
memset(&skey, 0, sizeof(skey));
memset(&_bulk_data, 0, sizeof(_bulk_data));
//memset( (*buf), 0, sizeof( (*buf) ) );
//_bulk_data.set_data( _bulk_buffer );
_bulk_data.set_data( (*buf) );
_bulk_data.set_ulen( BUFFER_LENGTH );
_bulk_data.set_flags( DB_DBT_USERMEM );
skey.set_data( key );
skey.set_size( size );
//if ( _debug ) return NULL;
do
{
// if bulk buffer is done, get a new one.
//if ( _p_bulk == NULL )
if ( ((*_ptr)) == NULL )
{
//cout << " Request from iter " << iter << " key " << *(int *)key << " FLAGS? " << flags << endl;
memset( (*buf), 0, sizeof( (*buf) ) );
answer = iter->/*_sort_key_cursor->*/get( &skey, &_bulk_data,
flags | DB_MULTIPLE_KEY );
if ( answer == DB_NOTFOUND )
return NULL;
//DB_MULTIPLE_INIT(_p_bulk, _bulk_data.get_DBT());
DB_MULTIPLE_INIT((*_ptr), _bulk_data.get_DBT());
//cout << " DB_NOTFOUND " << DB_NOTFOUND << " ans " << answer << " -- Getting answers, page size " << BUFFER_LENGTH << " ITER " << iter << " PTR " << (*_ptr) <<endl;
}
//else
//cout << " ROSWOSSegment, *_ptr is not NULL, go go go" << endl;
/*if ( answer == DB_NOTFOUND )
{
//_debug = true;
// THAT really does NOT close the iterator. WHY, I have not
// a faintest idea!
//cout << " ITERATOR " << iter << " IS CLOSED " << endl;
//iter->close();
return NULL;
}*/
//if ( !_p_bulk )
if ( !((*_ptr)) )
return NULL;
// I don't understand that.
//if ( !_p_bulk && second_pass )
//cout << " PTR " << (*_ptr) << " SECOND PASS " << second_pass << endl;
if ( !((*_ptr)) && second_pass )
return NULL;
DB_MULTIPLE_KEY_NEXT((*_ptr), _bulk_data.get_DBT(), retkey, retklen, retdata, retdlen);
//DB_MULTIPLE_KEY_NEXT(_p_bulk, _bulk_data.get_DBT(), retkey, retklen, retdata, retdlen);
// cout << " ANd now, ptr is " << *_ptr << " int ptr " << ((int*)retkey) << endl;
second_pass = true;
}
//while( !_p_bulk ); // if bulk is null, get the buffer.
while( !(*_ptr) ); // if bulk is null, get the buffer.
/*if ( (*((int*)retkey)) > 10500 )
{
cout << DB_NOTFOUND << " <=> " << answer << " Ret answer " << *((int *)retkey) << " retDATA " << *((int *)retdata) << endl;
cout << " Recieved buffer " << buf << " points to buf " << (*buf) << " and ptr " << *_ptr << endl;
*/
/*if ( *((int *)retdata) == 596992 &&
10511 == *((int *)retkey) )
*(int *)retdata = 597221;
if ( *((int *)retdata) == 598272 &&
10524 == *((int *)retkey) )
*(int *)retdata = 598362;*/
//cout << " Finally returning " << ( ((int *)retdata) ) << endl << endl;
return( ((int *)retdata) );
/*
// THIS IS AN ITERATION SEQUENCE. DO NOT ERASE.
while ( _sort_key_cursor->get( &skey, &data, DB_NEXT | DB_MULTIPLE_KEY ) == 0 )
{
for (DB_MULTIPLE_INIT(p, data.get_DBT());;)
{
DB_MULTIPLE_KEY_NEXT(p, data.get_DBT(), retkey, retklen, retdata, retdlen);
if (p == NULL)
break;
//.........这里部分代码省略.........
示例7: deactivateGuard
vector<Identity>::const_iterator
Freeze::EvictorIteratorI::nextBatch()
{
DeactivateController::Guard
deactivateGuard(_store->evictor()->deactivateController());
_batch.clear();
if(!_more)
{
return _batch.end();
}
vector<EvictorElementPtr> evictorElements;
evictorElements.reserve(_batchSize);
Key firstKey = _key;
CommunicatorPtr communicator = _store->communicator();
try
{
for(;;)
{
_batch.clear();
evictorElements.clear();
Dbt dbKey;
initializeOutDbt(_key, dbKey);
Dbt dbValue;
dbValue.set_flags(DB_DBT_USERMEM | DB_DBT_PARTIAL);
Dbc* dbc = 0;
try
{
//
// Move to the first record
//
u_int32_t flags = DB_NEXT;
if(_initialized)
{
//
// _key represents the next element not yet returned
// if it has been deleted, we want the one after
//
flags = DB_SET_RANGE;
//
// Will be used as input as well
//
dbKey.set_size(static_cast<u_int32_t>(firstKey.size()));
}
_store->db()->cursor(0, &dbc, 0);
bool done = false;
do
{
for(;;)
{
try
{
//
// It is critical to set key size to key capacity before the
// get, as a resize that increases the size inserts 0
//
_key.resize(_key.capacity());
_more = (dbc->get(&dbKey, &dbValue, flags) == 0);
if(_more)
{
_key.resize(dbKey.get_size());
_initialized = true;
flags = DB_NEXT;
Ice::Identity ident;
ObjectStore::unmarshal(ident, _key, communicator);
if(_batch.size() < _batchSize)
{
_batch.push_back(ident);
}
else
{
//
// Keep the last element in _key
//
done = true;
}
}
break;
}
catch(const DbDeadlockException&)
{
throw;
}
catch(const DbException& dx)
{
//.........这里部分代码省略.........