本文整理汇总了C++中MojDbQuery::from方法的典型用法代码示例。如果您正苦于以下问题:C++ MojDbQuery::from方法的具体用法?C++ MojDbQuery::from怎么用?C++ MojDbQuery::from使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MojDbQuery
的用法示例。
在下文中一共展示了MojDbQuery::from方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testInsertMedNestedObj
MojErr MojDbPerfCreateTest::testInsertMedNestedObj(MojDb& db, const MojChar* kindId)
{
// register all the kinds again
MojUInt64 time = 0;
MojErr err = putKinds(db, time);
MojTestErrCheck(err);
// time put with med nested objects (2 levels of nesting, 10 properties)
MojUInt64 medNestedObjTime = 0;
for (int i = 0; i < numRepetitions; i++) {
err = putMedNestedObj(db, kindId, medNestedObjTime);
MojTestErrCheck(err);
MojDbQuery q;
err = q.from(kindId);
MojTestErrCheck(err);
MojUInt32 count = 0;
err = db.del(q, count, MojDb::FlagPurge);
MojTestErrCheck(err);
}
err = MojPrintF("\n -------------------- \n");
MojTestErrCheck(err);
err = MojPrintF(" time to put %llu %s objects %d times: %llu nanosecs\n", numInsert, kindId, numRepetitions, medNestedObjTime);
MojTestErrCheck(err);
err = MojPrintF(" time per object: %llu nanosecs", (medNestedObjTime) / (numInsert * numRepetitions));
MojTestErrCheck(err);
err = MojPrintF("\n\n");
MojTestErrCheck(err);
MojString buf;
err = buf.format("put %llu objects %d times,%s,%llu,%llu,%llu,\n", numInsert, numRepetitions, kindId, medNestedObjTime, medNestedObjTime/numRepetitions, medNestedObjTime / (numInsert * numRepetitions));
MojTestErrCheck(err);
err = fileWrite(file, buf);
MojTestErrCheck(err);
return MojErrNone;
}
示例2: testInsertLgArrayObj
MojErr MojDbPerfCreateTest::testInsertLgArrayObj(MojDb& db, const MojChar* kindId)
{
// register all the kinds again
MojUInt64 time = 0;
MojErr err = putKinds(db, time);
MojTestErrCheck(err);
// time put with large array objects (20 properties + 2 arrays of 5 elements each)
MojUInt64 lgArrayObjTime = 0;
for (int i = 0; i < numRepetitions; i++) {
err = putLargeArrayObj(db, kindId, lgArrayObjTime);
MojTestErrCheck(err);
MojDbQuery q;
err = q.from(kindId);
MojTestErrCheck(err);
MojUInt32 count = 0;
err = db.del(q, count);
MojTestErrCheck(err);
}
err = MojPrintF("\n -------------------- \n");
MojTestErrCheck(err);
err = MojPrintF(" time to put %llu %s objects %d times: %llu nanosecs\n", numInsert, kindId, numRepetitions, lgArrayObjTime);
MojTestErrCheck(err);
err = MojPrintF(" time per object: %llu nanosecs", (lgArrayObjTime) / (numInsert * numRepetitions));
MojTestErrCheck(err);
err = MojPrintF("\n\n");
MojTestErrCheck(err);
MojString buf;
err = buf.format("put %llu objects %d times,%s,%llu,%llu,%llu,\n", numInsert, numRepetitions, kindId, lgArrayObjTime, lgArrayObjTime/numRepetitions, lgArrayObjTime / (numInsert * numRepetitions));
MojTestErrCheck(err);
err = fileWrite(file, buf);
MojTestErrCheck(err);
return MojErrNone;
}
示例3: addBuddyToDb
/*
* Add buddy record to the buddyStatus and contact DB
*/
MojErr SendOneCommandHandler::addBuddyToDb() {
// first we have to figure out the accountId - query ImLoginState
//construct our where clause - find by username and servicename
MojDbQuery query;
query.where("serviceName", MojDbQuery::OpEq, m_serviceName);
query.where("username", MojDbQuery::OpEq, m_username);
query.from(IM_LOGINSTATE_KIND);
// call del
// virtual MojErr del(Signal::SlotRef handler, const MojDbQuery& query,
// MojUInt32 flags = MojDb::FlagNone);
MojErr err = m_dbClient.find(this->m_findAccountIdForAddSlot, query);
if (err) {
MojString error;
MojErrToString(err, error);
MojLogError(IMServiceApp::s_log, _T("addBuddy: dbClient.find() failed: error %d - %s"), err, error.data());
// query failed - not much we can do here...
m_outgoingIMHandler->messageFinished();
}
return MojErrNone;
}
示例4: GetDeletedEmails
void MojoDatabase::GetDeletedEmails(Signal::SlotRef slot, const MojObject& folderId, const MojInt64& rev, MojDbQuery::Page& page, MojInt32 limit)
{
MojErr err;
MojDbQuery query;
err = query.from(PopEmailAdapter::POP_EMAIL_KIND);
ErrorToException(err);
// Select relevant fields
err = query.select(PopEmailAdapter::ID);
ErrorToException(err);
err = query.select(PopEmailAdapter::SERVER_UID);
ErrorToException(err);
err = query.where(EmailSchema::FOLDER_ID, MojDbQuery::OpEq, folderId);
ErrorToException(err);
err = query.where("_del", MojDbQuery::OpEq, true);
ErrorToException(err);
// Set limit
if(limit > 0) {
query.limit(limit);
}
// Make sure deleted objects are returned
query.includeDeleted(true);
// Set page
query.page(page);
slot.cancel(); // cancel existing slot in case we're in a callback
err = m_dbClient.find(slot, query);
ErrorToException(err);
}
示例5: run
MojErr MojDbTxnTest::run()
{
MojErr err;
MojDb db;
err = MojDbTestEnv::run(MojDbTestDir);
MojTestErrCheck(err);
// open
err = db.open(MojDbTestDir, env());
MojTestErrCheck(err);
// add type
MojObject obj;
err = obj.fromJson(MojKindStr);
MojTestErrCheck(err);
err = db.putKind(obj);
MojTestErrCheck(err);
for (int i = 0; i < 100; ++i) {
MojObject obj;
MojErr err = obj.putString(MojDb::KindKey, _T("Test:1"));
MojTestErrCheck(err);
err = obj.put(_T("foo"), (i + 25) % 100);
MojTestErrCheck(err);
err = obj.put(_T("bar"), i % 3);
MojTestErrCheck(err);
err = db.put(obj);
MojTestErrCheck(err);
}
// db: x0 = (25, 0), (26, 1), (27, 2), (28, 0) .. x74 = (99,2), x75 = (0,0) .. x99 = (24,0)
{
MojDbQuery query;
err = query.from(_T("Test:1"));
MojTestErrCheck(err);
err = query.where(_T("foo"), MojDbQuery::OpLessThan, 50);
MojTestErrCheck(err);
MojObject update;
err = update.put(_T("bar"), -1);
MojTestErrCheck(err);
MojUInt32 count = 0;
err = db.merge(query, update, count);
MojTestErrCheck(err);
MojTestAssert(count == 50);
}
// db: x0 = (25, -1) .. x24 = (49,-1), x25 = (50,1)i .. x74 = (99,2), x75 = (0,-1) .. x99 = (24, -1)
// test visibility with update
{
MojDbReq req;
// start transaction
req.begin(&db, false);
MojDbQuery query;
err = query.from(_T("Test:1"));
MojTestErrCheck(err);
err = query.where(_T("bar"), MojDbQuery::OpEq, -1);
MojTestErrCheck(err);
MojObject update;
err = update.put(_T("bar"), -2);
MojTestErrCheck(err);
MojUInt32 count = 0;
err = db.merge(query, update, count, MojDb::FlagNone, req);
MojTestErrCheck(err);
MojTestAssert(count == 50);
// txn: x0 = (25, -2) .. x24 = (49,-2), x25 = (50,1) .. x74 = (99,2), x75 = (0,-2) .. x99 = (24, -2)
// visible within transaction
{
MojDbQuery query;
err = query.from(_T("Test:1"));
MojTestErrCheck(err);
err = query.where(_T("bar"), MojDbQuery::OpEq, -2);
MojTestErrCheck(err);
MojObject update;
err = update.put(_T("bar"), -2);
MojTestErrCheck(err);
MojUInt32 count = 0;
err = db.merge(query, update, count, MojDb::FlagNone, req);
MojTestErrCheck(err);
MojTestAssert(count == 50);
}
// With BerkeleyDB parallel transaction is locked
// invisible outside of transaction
if (engineName().compare(_T("leveldb")) == 0)
{
MojDbQuery query;
err = query.from(_T("Test:1"));
//.........这里部分代码省略.........
示例6: eqTest
MojErr MojDbWatchTest::eqTest(MojDb& db)
{
MojDbQuery query;
MojErr err = query.from(_T("WatchTest:1"));
MojTestErrCheck(err);
err = query.where(_T("foo"), MojDbQuery::OpEq, 1);
MojTestErrCheck(err);
MojRefCountedPtr<TestWatcher> watcher(new TestWatcher);
MojTestAssert(watcher.get());
MojDbCursor cursor;
err = db.find(query, cursor, watcher->m_slot);
MojTestErrCheck(err);
err = cursor.close();
MojTestErrCheck(err);
MojTestAssert(watcher->m_count == 0);
MojRefCountedPtr<TestWatcher> watcher2(new TestWatcher);
MojTestAssert(watcher2.get());
bool fired = false;
err = db.watch(query, cursor, watcher2->m_slot, fired);
MojTestErrCheck(err);
err = cursor.close();
MojTestErrCheck(err);
MojTestAssert(!fired);
// puts
MojObject id;
err = put(db, 0, 0, id, m_rev);
MojTestErrCheck(err);
MojTestAssert(watcher->m_count == 0);
MojTestAssert(watcher2->m_count == 0);
err = put(db, 2, 2, id, m_rev);
MojTestErrCheck(err);
MojTestAssert(watcher->m_count == 0);
MojTestAssert(watcher2->m_count == 0);
err = put(db, 1, 1, id, m_rev);
MojTestErrCheck(err);
MojTestAssert(watcher->m_count == 1);
MojTestAssert(watcher2->m_count == 1);
err = put(db, 1, 1, id, m_rev);
MojTestErrCheck(err);
MojTestAssert(watcher->m_count == 1);
MojTestAssert(watcher2->m_count == 1);
// put, changing property not in index
watcher.reset(new TestWatcher);
MojTestAssert(watcher.get());
err = db.find(query, cursor, watcher->m_slot);
MojTestErrCheck(err);
err = cursor.close();
MojTestErrCheck(err);
err = put(db, 1, 2, id, m_rev);
MojTestErrCheck(err);
MojTestAssert(watcher->m_count == 1);
// dels
watcher.reset(new TestWatcher);
MojTestAssert(watcher.get());
err = db.find(query, cursor, watcher->m_slot);
MojTestErrCheck(err);
err = cursor.close();
MojTestErrCheck(err);
watcher2.reset(new TestWatcher);
MojTestAssert(watcher2.get());
MojDbQuery queryWithRev;
err = queryWithRev.from(_T("WatchTest:1"));
MojTestErrCheck(err);
err = queryWithRev.where(_T("foo"), MojDbQuery::OpEq, 1);
MojTestErrCheck(err);
err = queryWithRev.where(_T("_rev"), MojDbQuery::OpGreaterThan, m_rev);
MojTestErrCheck(err);
err = queryWithRev.includeDeleted();
MojTestErrCheck(err);
fired = false;
err = db.watch(queryWithRev, cursor, watcher2->m_slot, fired);
MojTestErrCheck(err);
err = cursor.close();
MojTestErrCheck(err);
MojTestAssert(!fired);
MojTestAssert(watcher->m_count == 0);
MojTestAssert(watcher2->m_count == 0);
bool found;
err = db.del(id, found);
MojTestErrCheck(err);
MojTestAssert(found);
MojTestAssert(watcher->m_count == 1);
MojTestAssert(watcher2->m_count == 1);
// ordering
watcher.reset(new TestWatcher);
MojTestAssert(watcher.get());
err = db.find(query, cursor, watcher->m_slot);
MojTestErrCheck(err);
err = put(db, 1, 1, id, m_rev);
MojTestErrCheck(err);
MojTestAssert(watcher->m_count == 0);
err = cursor.close();
MojTestErrCheck(err);
MojTestAssert(watcher->m_count == 1);
return MojErrNone;
}
示例7: accountDisabled
/*
* Disabling an account means doing the following
* delete com.palm.imloginstate.libpurple record
* delete com.palm.immessage.libpurple records
* delete com.palm.imcommand.libpurple records
* delete com.palm.contact.libpurple records
* delete com.palm.imbuddystatus.libpurple records
* delete com.palm.imgroupchat.libpurple records -- groupchats not currently supported
* Note: the ChatThreader service takes care of removing empty chats
*/
MojErr OnEnabledHandler::accountDisabled()
{
MojLogTrace(IMServiceApp::s_log);
MojLogInfo(IMServiceApp::s_log, _T("accountDisabled id=%s, serviceName=%s"), m_accountId.data(), m_serviceName.data());
// delete com.palm.imloginstate.libpurple record
MojDbQuery queryLoginState;
queryLoginState.from(IM_LOGINSTATE_KIND);
// we can get multiple calls to onEnabled(false) even after we have deleted the account records, so search by account Id so
// we don't delete a new account with same username/servicename (see DFISH-16682)
// queryLoginState.where(_T("serviceName"), MojDbQuery::OpEq, m_serviceName);
// queryLoginState.where(_T("username"), MojDbQuery::OpEq, m_username);
queryLoginState.where(_T("accountId"), MojDbQuery::OpEq, m_accountId);
MojErr err = m_dbClient.del(m_deleteImLoginStateSlot, queryLoginState);
if (err != MojErrNone) {
MojString error;
MojErrToString(err, error);
MojLogError(IMServiceApp::s_log, _T("OnEnabledHandler db.del(imloginstate) failed: error %d - %s"), err, error.data());
}
// delete com.palm.immessage.libpurple records
//TODO: need to query both from & recipient addresses. Simplify this???
MojDbQuery queryMessage;
queryMessage.from(IM_IMMESSAGE_KIND);
queryMessage.where(_T("serviceName"), MojDbQuery::OpEq, m_serviceName);
queryMessage.where(_T("username"), MojDbQuery::OpEq, m_username);
err = m_dbClient.del(m_deleteImMessagesSlot, queryMessage);
if (err != MojErrNone) {
MojString error;
MojErrToString(err, error);
MojLogError(IMServiceApp::s_log, _T("OnEnabledHandler db.del(immessage) failed: error %d - %s"), err, error.data());
}
// delete com.palm.imcommand.libpurple records
MojDbQuery queryCommand;
queryCommand.from(IM_IMCOMMAND_KIND);
queryCommand.where(_T("serviceName"), MojDbQuery::OpEq, m_serviceName);
queryCommand.where(_T("fromUsername"), MojDbQuery::OpEq, m_username);
err = m_dbClient.del(m_deleteImCommandsSlot, queryCommand);
if (err != MojErrNone) {
MojString error;
MojErrToString(err, error);
MojLogError(IMServiceApp::s_log, _T("OnEnabledHandler db.del(imcommand) failed: error %d - %s"), err, error.data());
}
// delete com.palm.contact.libpurple record
MojDbQuery queryContact;
queryContact.from(IM_CONTACT_KIND);
queryContact.where(_T("accountId"), MojDbQuery::OpEq, m_accountId);
err = m_dbClient.del(m_deleteContactsSlot, queryContact);
if (err != MojErrNone) {
MojString error;
MojErrToString(err, error);
MojLogError(IMServiceApp::s_log, _T("OnEnabledHandler db.del(contact) failed: error %d - %s"), err, error.data());
}
// delete com.palm.imbuddystatus.libpurple record
MojDbQuery queryBuddyStatus;
queryBuddyStatus.from(IM_BUDDYSTATUS_KIND);
queryBuddyStatus.where(_T("accountId"), MojDbQuery::OpEq, m_accountId);
err = m_tempdbClient.del(m_deleteImBuddyStatusSlot, queryBuddyStatus);
if (err != MojErrNone) {
MojString error;
MojErrToString(err, error);
MojLogError(IMServiceApp::s_log, _T("OnEnabledHandler db.del(imbuddystatus) failed: error %d - %s"), err, error.data());
}
// now we need to tell libpurple to disconnect the account so we don't get more messages for it
// LoginCallbackInterface is null because we don't need to do any processing on the callback - all the DB kinds are already gone.
LibpurpleAdapter::logout(m_serviceName, m_username, NULL);
return MojErrNone;
}
示例8: updateObjsViaMerge
MojErr MojDbPerfUpdateTest::updateObjsViaMerge(MojDb& db, const MojChar* kindId, MojErr (MojDbPerfTest::*createFn) (MojObject&, MojUInt64))
{
// register all the kinds
MojTime time;
MojErr err = putKinds(db, time);
MojTestErrCheck(err);
// put objects using createFn
MojObject objs;
err = putObjs(db, kindId, numInsertForPut, createFn, objs);
MojTestErrCheck(err);
MojObject midObj;
bool found = objs.at(numInsertForPut/2, midObj);
MojTestAssert(found);
MojTime objTime;
err = mergeObj(db, midObj, objTime);
MojTestErrCheck(err);
MojUInt64 mergeTime = objTime.microsecs();
err = MojPrintF("\n -------------------- \n");
MojTestErrCheck(err);
err = MojPrintF(" merging single object - index %llu - of kind %s %llu times took: %llu microsecs\n", numInsertForPut/2, kindId, numMergeIterations, mergeTime);
MojTestErrCheck(err);
err = MojPrintF(" time per merge: %llu microsecs", (mergeTime) / (numMergeIterations));
MojTestErrCheck(err);
err = MojPrintF("\n\n");
MojTestErrCheck(err);
MojString buf;
err = buf.format("Merge single object - index %llu - %llu times,%s,%llu,%llu,%llu,\n", numInsertForPut/2, numMergeIterations, kindId, mergeTime, mergeTime/numMergeIterations, mergeTime/(1*numMergeIterations));
MojTestErrCheck(err);
err = fileWrite(file, buf);
MojTestErrCheck(err);
MojTime batchTime;
MojObject::ArrayIterator beginArr;
err = objs.arrayBegin(beginArr);
MojErrCheck(err);
err = batchMergeObj(db, beginArr, beginArr + (numInsertForPut / 10), batchTime);
MojTestErrCheck(err);
mergeTime = batchTime.microsecs();
err = MojPrintF(" merging batch - %llu objects - of kind %s %llu times took: %llu microsecs\n", numInsertForPut/10, kindId, numBatchMergeIterations, mergeTime);
MojTestErrCheck(err);
err = MojPrintF(" time per batch merge: %llu microsecs\n", (mergeTime) / (numBatchMergeIterations));
MojTestErrCheck(err);
err = MojPrintF(" time per object: %llu microsecs", (mergeTime) / (numInsertForPut/10 * numBatchMergeIterations));
MojTestErrCheck(err);
err = MojPrintF("\n\n");
MojTestErrCheck(err);
err = buf.format("Batch merge %llu objects %llu times,%s,%llu,%llu,%llu,\n", numInsertForPut/10, numBatchMergeIterations, kindId, mergeTime, mergeTime/numBatchMergeIterations, mergeTime/(numInsertForPut/10*numBatchMergeIterations));
MojTestErrCheck(err);
err = fileWrite(file, buf);
MojTestErrCheck(err);
MojTime mergeQueryTime;
MojTestErrCheck(err);
MojDbQuery query;
err = query.from(kindId);
MojTestErrCheck(err);
query.limit(numInsertForPut/5);
query.desc(true);
MojObject queryObj;
err = query.toObject(queryObj);
MojTestErrCheck(err);
MojString queryStr;
err = queryObj.stringValue(queryStr);
MojTestErrCheck(err);
MojObject props;
err = props.putString(_T("newKey"), _T("here's a new value"));
MojTestErrCheck(err);
MojUInt32 count;
err = queryMergeObj(db, query, props, count, mergeQueryTime);
MojTestErrCheck(err);
mergeTime = mergeQueryTime.microsecs();
err = MojPrintF(" merging with query - %d objects - of kind %s %llu times took: %llu microsecs\n", count, kindId, numBatchMergeIterations, mergeTime);
MojTestErrCheck(err);
err = MojPrintF(" time per merge: %llu microsecs\n", (mergeTime) / (numBatchMergeIterations));
MojTestErrCheck(err);
err = MojPrintF(" time per object: %llu microsecs", (mergeTime) / (count * numBatchMergeIterations));
MojTestErrCheck(err);
err = MojPrintF("\n\n");
MojTestErrCheck(err);
err = buf.format("Merge with query %s,,,,,\nMerge with query - %d objects - %llu times,%s,%llu,%llu,%llu,\n", queryStr.data(), count, numBatchMergeIterations, kindId, mergeTime, mergeTime/numBatchMergeIterations, mergeTime/(count*numBatchMergeIterations));
MojTestErrCheck(err);
err = fileWrite(file, buf);
MojTestErrCheck(err);
return MojErrNone;
}
示例9: UpdateSyncState
void SyncStateUpdater::UpdateSyncState(MojSignal<>::SlotRef slot, const SyncState& syncState, bool clearSyncState)
{
m_doneSignal.connect(slot);
MojErr err;
MojObject batchPayload;
MojObject batchOperations;
// Delete old sync state
MojObject delPayload;
MojDbQuery query;
err = query.from(SyncStateAdapter::SYNC_STATE_KIND);
ErrorToException(err);
MojString capabilityProvider;
capabilityProvider.assign(m_capabilityProvider.c_str());
err = query.where(SyncStateAdapter::CAPABILITY_PROVIDER, MojDbQuery::OpEq, capabilityProvider);
ErrorToException(err);
err = query.where(SyncStateAdapter::ACCOUNT_ID, MojDbQuery::OpEq, syncState.GetAccountId());
ErrorToException(err);
err = query.where(SyncStateAdapter::COLLECTION_ID, MojDbQuery::OpEq, syncState.GetCollectionId());
ErrorToException(err);
MojObject queryObj;
err = query.toObject(queryObj);
ErrorToException(err);
err = delPayload.put("query", queryObj);
ErrorToException(err);
MojObject delOperation;
err = delOperation.putString("method", "del");
ErrorToException(err);
err = delOperation.put("params", delPayload);
ErrorToException(err);
err = batchOperations.push(delOperation);
ErrorToException(err);
if(!clearSyncState) { // Store new sync state
MojObject putPayload;
MojObject syncStateObj;
SyncStateAdapter::SerializeToDatabaseObject(syncState, syncStateObj, m_capabilityProvider.c_str(), m_busAddress.c_str());
MojObject objects;
err = objects.push(syncStateObj);
ErrorToException(err);
err = putPayload.put("objects", objects);
ErrorToException(err);
MojObject putOperation;
err = putOperation.putString("method", "put");
ErrorToException(err);
err = putOperation.put("params", putPayload);
ErrorToException(err);
err = batchOperations.push(putOperation);
ErrorToException(err);
}
err = batchPayload.put("operations", batchOperations);
ErrorToException(err);
// Note: batch operations are not atomic, this is just for convenience and performance
m_busClient.SendRequest(m_updateSlot, "com.palm.tempdb", "batch", batchPayload);
}
示例10: verifyIndex
MojErr MojDbKind::verifyIndex(MojDbIndex *pIndex, MojObject &iinfo, MojDbReq& req)
{
// Goes throudh each index entry and verifies that it points to a valid object
// For debugging purposes as stats for indexes does not access the target objects
// Index->stats function does not have enough context to find the object
// db/stats usage '{"verify":true,"kind":"xyz"}' - each optional
MojDbQuery query;
MojErr err = query.from(m_id);
MojErrCheck(err);
err = query.includeDeleted(true);
MojErrCheck(err);
MojDbCursor cursor;
query.m_forceIndex = pIndex; // Important: Otherwise, it will pick the default index
cursor.verifymode(true); // to get the errors
err = m_kindEngine->find(query, cursor, NULL, req, OpRead);
MojLogInfo(s_log, _T("Kind_verifyIndex: Kind: %s; Index: %s; idIndex: %zX; size: %zu; CursorIndex: %s \n"), m_name.data(),
pIndex->name().data(), pIndex->idIndex(), pIndex->size(), cursor.m_dbIndex->name().data());
MojErrCheck(err);
MojSize count = 0;
MojSize delCount = 0;
MojSize warnCount = 0;
char s[1024];
for (;;) {
MojDbStorageItem* item = NULL;
bool found = false;
err = cursor.get(item, found);
if (err == MojErrInternalIndexOnFind) {
warnCount++;
MojDbIsamQuery *iquery = (MojDbIsamQuery *)cursor.m_storageQuery.get();
MojErr err2 = MojByteArrayToHex(iquery->m_keyData, iquery->m_keySize, s);
MojErrCheck(err2);
MojChar *ids = (iquery->m_keySize > 18) ? (MojChar *)(iquery->m_keyData + iquery->m_keySize - 17) : NULL;
MojLogInfo(s_log, _T("VerifyIndex Warning: %s; KeySize: %zu; %s ;id: %s \n"),
cursor.m_dbIndex->name().data(), iquery->m_keySize, s, ids);
continue;
}
MojErrCheck(err);
if (!found)
break;
MojObject obj;
err = item->toObject(obj, *m_kindEngine, true);
MojErrCheck(err);
bool deleted = false;
if (obj.get(MojDb::DelKey, deleted) && deleted) {
delCount++;
} else {
count++;
}
}
MojLogInfo(s_log, _T("Kind_verifyIndex Counts: Kind: %s; Index: %s; count: %zu; delcount: %zu; warnings: %zu \n"), m_name.data(),
pIndex->name().data(), count, delCount, warnCount);
err = iinfo.put(VerifyCountKey, (MojInt64)count);
MojErrCheck(err);
err = iinfo.put(VerifyWarnCountKey, (MojInt64) warnCount);
MojErrCheck(err);
err = iinfo.put(VerifyDelCountKey, (MojInt64) delCount);
MojErrCheck(err);
return MojErrNone;
}
示例11: purgeImpl
MojErr MojDb::purgeImpl(MojObject& obj, MojUInt32& countOut, MojDbReq& req)
{
MojLogTrace(s_log);
MojObject val;
MojErr err = obj.getRequired(RevNumKey, val);
MojErrCheck(err);
MojObject timestamp;
err = obj.getRequired(TimestampKey, timestamp);
MojErrCheck(err);
// purge all objects that were deleted on or prior to this rev num
// query for objects in two passes - once where backup is true and once where backup is false
MojDbQuery objQuery;
err = objQuery.from(MojDbKindEngine::RootKindId);
MojErrCheck(err);
err = objQuery.where(DelKey, MojDbQuery::OpEq, true);
MojErrCheck(err);
err = objQuery.where(SyncKey, MojDbQuery::OpEq, true);
MojErrCheck(err);
err = objQuery.where(RevKey, MojDbQuery::OpLessThanEq, val);
MojErrCheck(err);
MojUInt32 backupCount = 0;
req.autobatch(true);
req.fixmode(true);
objQuery.limit(AutoBatchSize);
err = delImpl(objQuery, backupCount, req, FlagPurge);
MojErrCheck(err);
MojDbQuery objQuery2;
err = objQuery2.from(MojDbKindEngine::RootKindId);
MojErrCheck(err);
err = objQuery2.where(DelKey, MojDbQuery::OpEq, true);
MojErrCheck(err);
err = objQuery2.where(SyncKey, MojDbQuery::OpEq, false);
MojErrCheck(err);
err = objQuery2.where(RevKey, MojDbQuery::OpLessThanEq, val);
MojErrCheck(err);
MojUInt32 count = 0;
MojUInt32 batchRemain = 0;
if (backupCount <= AutoBatchSize)
batchRemain = AutoBatchSize - backupCount;
req.autobatch(true); // enable auto batch
req.fixmode(true); // force deletion of bad entries
if (batchRemain > 0) {
objQuery2.limit(batchRemain);
err = delImpl(objQuery2, count, req, FlagPurge);
MojErrCheck(err);
}
countOut = count + backupCount;
req.autobatch(false);
// if we actually deleted objects, store this rev num as the last purge rev
if (countOut > 0) {
err = updateState(LastPurgedRevKey, val, req);
MojErrCheck(err);
}
// delete all the RevTimestamp entries prior to this one
MojDbQuery revTimestampQuery;
err = revTimestampQuery.from(MojDbKindEngine::RevTimestampId);
MojErrCheck(err);
err = revTimestampQuery.where(TimestampKey, MojDbQuery::OpLessThanEq, timestamp);
MojErrCheck(err);
count = 0;
err = delImpl(revTimestampQuery, count, req, FlagPurge);
MojErrCheck(err);
return MojErrNone;
}
示例12: dumpImpl
MojErr MojDb::dumpImpl(MojFile& file, bool backup, bool incDel, const MojObject& revParam, const MojObject& delRevParam, bool skipKinds, MojUInt32& countOut, MojDbReq& req,
MojObject* response, const MojChar* keyName, MojSize& bytesWritten, MojSize& warns, MojUInt32 maxBytes)
{
// query for objects, adding the backup key and rev key if necessary
MojDbQuery query;
MojErr err = query.from(MojDbKindEngine::RootKindId);
MojErrCheck(err);
err = query.where(MojDb::DelKey, MojDbQuery::OpEq, incDel);
MojErrCheck(err);
if (backup) {
err = query.where(MojDb::SyncKey, MojDbQuery::OpEq, true);
MojErrCheck(err);
if (incDel) {
err = query.where(MojDb::RevKey, MojDbQuery::OpGreaterThan, delRevParam);
MojErrCheck(err);
} else {
err = query.where(MojDb::RevKey, MojDbQuery::OpGreaterThan, revParam);
MojErrCheck(err);
}
}
MojDbCursor cursor;
err = findImpl(query, cursor, NULL, req, OpRead);
MojErrCheck(err);
warns = 0;
MojObject curRev;
for(;;) {
bool found = false;
MojObject obj;
err = cursor.get(obj, found);
// So that we can get as much data as possible from a corrupt database
// We simply skip ghost keys and continue
if (err == MojErrInternalIndexOnFind) {
warns++;
continue;
}
MojErrCheck(err);
if (!found)
break;
if (skipKinds) {
MojString kind;
err = obj.getRequired(KindKey, kind);
MojErrCheck(err);
if (kind == MojDbKindEngine::KindKindId) {
continue;
}
}
// write out each object, if the backup is full, insert the appropriate incremental key
err = dumpObj(file, obj, bytesWritten, maxBytes);
MojErrCatch(err, MojErrDbBackupFull) {
if (response) {
MojErr errBackup = MojErrNone;
if (!curRev.undefined()) {
errBackup = insertIncrementalKey(*response, keyName, curRev);
MojErrCheck(errBackup);
} else {
errBackup = insertIncrementalKey(*response, keyName, incDel ? delRevParam: revParam);
MojErrCheck(errBackup);
}
errBackup = handleBackupFull(revParam, delRevParam, *response, keyName);
MojErrCheck(errBackup);
}
return MojErrNone;
}
MojErrCheck(err);
err = obj.getRequired(MojDb::RevKey, curRev);
MojErrCheck(err);
countOut++;
}
err = cursor.close();
MojErrCheck(err);
if (warns > 0) {
MojLogWarning(s_log, _T("Finished Backup with %d warnings \n"), (int)warns);
} else {
MojLogDebug(s_log, _T("Finished Backup with no warnings \n"));
}
// construct the next incremental key
if (response && !curRev.undefined()) {
err = insertIncrementalKey(*response, keyName, curRev);
MojErrCheck(err);
}
return MojErrNone;
}
示例13: dump
MojErr MojDb::dump(const MojChar* path, MojUInt32& countOut, bool incDel, MojDbReqRef req, bool backup,
MojUInt32 maxBytes, const MojObject* incrementalKey, MojObject* backupResponse)
{
MojAssert(path);
MojLogTrace(s_log);
MojErr err = beginReq(req);
MojErrCheck(err);
if (!req->admin()) {
MojLogError(s_log, _T("access denied: '%s' cannot dump db to path: '%s'"), req->domain().data(), path);
MojErrThrow(MojErrDbAccessDenied);
}
MojFile file;
err = file.open(path, MOJ_O_WRONLY | MOJ_O_CREAT | MOJ_O_TRUNC, MOJ_S_IRUSR | MOJ_S_IWUSR);
MojErrCheck(err);
// write out kinds first, then existing objects, then deleted objects
MojSize bytesWritten = 0;
MojSize totalwarns = 0;
MojSize newwarns = 0;
MojDbQuery objQuery;
MojVector<MojObject> kindVec;
MojObject revParam = -1;
MojObject delRevParam = -1;
// if we were given an incremental key, pull out the revs now
if (incrementalKey) {
incrementalKey->get(MojDbServiceDefs::RevKey, revParam);
incrementalKey->get(MojDbServiceDefs::DeletedRevKey, delRevParam);
}
err = m_kindEngine.getKinds(kindVec);
MojErrCheck(err);
// write kinds - if incremental, only write the kinds that have changed since the respective revs
MojString countStr;
for (MojVector<MojObject>::ConstIterator i = kindVec.begin(); i != kindVec.end(); ++i) {
if (backup) {
bool backupKind = false;
i->get(MojDbKind::SyncKey, backupKind);
if (!backupKind)
continue;
MojString id;
err = i->getRequired(MojDbServiceDefs::IdKey, id);
MojErrCheck(err);
MojDbQuery countQuery;
err = countQuery.from(id);
MojErrCheck(err);
MojDbCursor cursor;
err = find(countQuery, cursor, req);
MojErrCheck(err);
MojUInt32 count = 0;
err = cursor.count(count);
MojErrCheck(err);
if (count > 0) {
if (i != kindVec.begin()) {
err = countStr.appendFormat(_T(", "));
MojErrCheck(err);
}
err = countStr.appendFormat("%s=%u", id.data(), count);
MojErrCheck(err);
}
}
bool deleted = false;
i->get(DelKey, deleted);
MojObject kindRev;
err = i->getRequired(RevKey, kindRev);
MojErrCheck(err);
if ((deleted && kindRev > delRevParam) || (!deleted && kindRev > revParam)) {
err = dumpObj(file, (*i), bytesWritten, maxBytes);
MojErrCheck(err);
countOut++;
}
}
// dump all the non-deleted objects
err = dumpImpl(file, backup, false, revParam, delRevParam, true, countOut, req, backupResponse, MojDbServiceDefs::RevKey, bytesWritten, newwarns, maxBytes);
MojErrCheck(err);
totalwarns += newwarns;
// If we're supposed to include deleted objects, dump the deleted objects now.
// There's a chance that we may have run out of space in our backup. If that's the case,
// we don't want to try to dump deleted objects - we can detect this by looking for the HasMoreKey
if (incDel && backupResponse && !backupResponse->contains(MojDbServiceDefs::HasMoreKey)) {
err = dumpImpl(file, backup, true, revParam, delRevParam, false, countOut, req, backupResponse, MojDbServiceDefs::DeletedRevKey, bytesWritten, newwarns, maxBytes);
MojErrCheck(err);
}
totalwarns += newwarns;
// Add the Full and Version keys
if (backup && backupResponse) {
bool incremental = (incrementalKey != NULL);
err = backupResponse->putBool(MojDbServiceDefs::FullKey, !incremental);
MojErrCheck(err);
err = backupResponse->put(MojDbServiceDefs::VersionKey, DatabaseVersion);
MojErrCheck(err);
err = backupResponse->put(MojDbServiceDefs::WarningsKey, (MojInt32)totalwarns);
MojErrCheck(err);
MojString description;
//.........这里部分代码省略.........
示例14: purge
MojErr MojDb::purge(MojUInt32& countOut, MojInt64 numDays, MojDbReqRef req)
{
MojLogTrace(s_log);
countOut = 0;
if (numDays <= -1) {
numDays = m_purgeWindow;
}
MojErr err = beginReq(req);
MojErrCheck(err);
MojLogDebug(s_log, _T("purging objects deleted more than %lld days ago..."), numDays);
MojTime time;
err = MojGetCurrentTime(time);
MojErrCheck(err);
// store the revision number to current timestamp mapping
MojObject revTimeMapping;
MojInt64 rev;
err = nextId(rev);
MojErrCheck(err);
err = revTimeMapping.put(RevNumKey, rev);
MojErrCheck(err);
err = revTimeMapping.put(TimestampKey, time.microsecs());
MojErrCheck(err);
err = revTimeMapping.putString(KindKey, MojDbKindEngine::RevTimestampId);
MojErrCheck(err);
err = putImpl(revTimeMapping, MojDb::FlagNone, req);
MojErrCheck(err);
// find the revision number for numDays prior to now
MojInt64 purgeTime = time.microsecs() - (MojTime::UnitsPerDay * numDays);
MojDbQuery query;
err = query.from(MojDbKindEngine::RevTimestampId);
MojErrCheck(err);
query.limit(1);
err = query.where(TimestampKey, MojDbQuery::OpLessThanEq, purgeTime);
MojErrCheck(err);
err = query.order(TimestampKey);
MojErrCheck(err);
query.desc(true);
MojDbCursor cursor;
err = findImpl(query, cursor, NULL, req, OpDelete);
MojErrCheck(err);
bool found = false;
MojObject obj;
err = cursor.get(obj, found);
MojErrCheck(err);
err = cursor.close();
MojErrCheck(err);
MojUInt32 batchCount = 0;
MojUInt32 totalCount = 0;
while ((found))
{
// Do it in AutoBatchSize batches
batchCount = 0;
req->fixmode(true); // purge even if index mis-matches
err = purgeImpl(obj, batchCount, req);
MojLogDebug(s_log, _T("purge batch processed: batch: %d; total: %d; err = %d\n"),
batchCount, (totalCount + batchCount), err);
MojErrCheck(err);
totalCount += batchCount;
countOut = totalCount;
if (batchCount < AutoBatchSize) // last batch
break;
err = commitBatch(req);
MojErrCheck(err);
continue;
}
// end request
err = req->end();
MojErrCheck(err);
MojLogDebug(s_log, _T("purged %d objects"), countOut);
return MojErrNone;
}
示例15: delKindTest
MojErr MojDbPurgeTest::delKindTest(MojDb& db)
{
// start from scratch - purge everything
MojUInt32 count = 0;
MojErr err = db.purge(count, 0);
MojTestErrCheck(err);
MojTestAssert(count > 0);
// purge again, make sure nothing is left
err = db.purge(count, 0);
MojTestErrCheck(err);
MojTestAssert(count == 0);
// make sure at least 2 objects exist
MojDbQuery q;
err = q.from(_T("PurgeTest:1"));
MojTestErrCheck(err);
MojDbCursor cursor;
err = db.find(q, cursor);
MojTestErrCheck(err);
MojUInt32 objCount;
err = cursor.count(objCount);
MojTestErrCheck(err);
err = cursor.close();
MojTestErrCheck(err);
if (objCount <= 1) {
for (int i = objCount; i < 2; i++) {
MojObject obj;
err = obj.fromJson(MojTestObjStr1);
MojTestErrCheck(err);
err = db.put(obj);
MojTestErrCheck(err);
objCount++;
}
}
// delete half the objects
q.limit(objCount / 2);
MojUInt32 delCount;
err = db.del(q, delCount);
MojTestErrCheck(err);
// delete the kind
MojString idStr;
err = idStr.assign(_T("PurgeTest:1"));
MojTestErrCheck(err);
MojObject id(idStr);
bool found;
err = db.delKind(id, found);
MojTestErrCheck(err);
MojTestAssert(found);
/*MojUInt32 deletedObjCount;
err = q.where(_T("_del"), MojDbQuery::OpEq, true);
MojTestErrCheck(err);
q.includeDeleted(true);
err = db.find(q, cursor);
MojTestErrCheck(err);
err = cursor.count(deletedObjCount);
MojTestErrCheck(err);
err = cursor.close();
MojTestErrCheck(err);
// now all the objects should be deleted
MojTestAssert(deletedObjCount == objCount);*/
// purge now
err = db.purge(count, 0);
MojTestErrCheck(err);
return MojErrNone;
}