本文整理汇总了C++中KVEngine::getRecordStore方法的典型用法代码示例。如果您正苦于以下问题:C++ KVEngine::getRecordStore方法的具体用法?C++ KVEngine::getRecordStore怎么用?C++ KVEngine::getRecordStore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KVEngine
的用法示例。
在下文中一共展示了KVEngine::getRecordStore方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: opCtx
TEST( KVEngineTestHarness, SimpleRS1 ) {
scoped_ptr<KVHarnessHelper> helper( KVHarnessHelper::create() );
KVEngine* engine = helper->getEngine();
ASSERT( engine );
string ns = "a.b";
scoped_ptr<RecordStore> rs;
{
MyOperationContext opCtx( engine );
ASSERT_OK( engine->createRecordStore( &opCtx, ns, CollectionOptions() ) );
rs.reset( engine->getRecordStore( &opCtx, ns, ns, CollectionOptions() ) );
ASSERT( rs );
}
DiskLoc loc;
{
MyOperationContext opCtx( engine );
WriteUnitOfWork uow( &opCtx );
StatusWith<DiskLoc> res = rs->insertRecord( &opCtx, "abc", 4, false );
ASSERT_OK( res.getStatus() );
loc = res.getValue();
uow.commit();
}
{
MyOperationContext opCtx( engine );
ASSERT_EQUALS( string("abc"), rs->dataFor( &opCtx, loc ).data() );
}
}
示例2: opCtx
TEST(KVEngineTestHarness, Restart1) {
unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create());
KVEngine* engine = helper->getEngine();
ASSERT(engine);
string ns = "a.b";
// 'loc' holds location of "abc" and is referenced after restarting engine.
RecordId loc;
{
unique_ptr<RecordStore> rs;
{
MyOperationContext opCtx(engine);
ASSERT_OK(engine->createRecordStore(&opCtx, ns, ns, CollectionOptions()));
rs.reset(engine->getRecordStore(&opCtx, ns, ns, CollectionOptions()));
ASSERT(rs);
}
{
MyOperationContext opCtx(engine);
WriteUnitOfWork uow(&opCtx);
StatusWith<RecordId> res = rs->insertRecord(&opCtx, "abc", 4, false);
ASSERT_OK(res.getStatus());
loc = res.getValue();
uow.commit();
}
{
MyOperationContext opCtx(engine);
ASSERT_EQUALS(string("abc"), rs->dataFor(&opCtx, loc).data());
}
}
// returns null if the engine does not support restart (transient, test-only engines)
engine = helper->restartEngine();
if (engine != NULL) {
unique_ptr<RecordStore> rs;
MyOperationContext opCtx(engine);
rs.reset(engine->getRecordStore(&opCtx, ns, ns, CollectionOptions()));
ASSERT_EQUALS(string("abc"), rs->dataFor(&opCtx, loc).data());
}
}
示例3: opCtx
TEST_F(KVCatalogTest, Coll1) {
unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create());
KVEngine* engine = helper->getEngine();
unique_ptr<RecordStore> rs;
unique_ptr<KVCatalog> catalog;
{
MyOperationContext opCtx(engine);
WriteUnitOfWork uow(&opCtx);
ASSERT_OK(engine->createRecordStore(&opCtx, "catalog", "catalog", CollectionOptions()));
rs = engine->getRecordStore(&opCtx, "catalog", "catalog", CollectionOptions());
catalog.reset(new KVCatalog(rs.get(), false, false, nullptr));
uow.commit();
}
{
MyOperationContext opCtx(engine);
WriteUnitOfWork uow(&opCtx);
ASSERT_OK(newCollection(&opCtx,
NamespaceString("a.b"),
CollectionOptions(),
KVPrefix::kNotPrefixed,
catalog.get()));
ASSERT_NOT_EQUALS("a.b", catalog->getCollectionIdent("a.b"));
uow.commit();
}
string ident = catalog->getCollectionIdent("a.b");
{
MyOperationContext opCtx(engine);
WriteUnitOfWork uow(&opCtx);
catalog.reset(new KVCatalog(rs.get(), false, false, nullptr));
catalog->init(&opCtx);
uow.commit();
}
ASSERT_EQUALS(ident, catalog->getCollectionIdent("a.b"));
{
MyOperationContext opCtx(engine);
WriteUnitOfWork uow(&opCtx);
dropCollection(&opCtx, "a.b", catalog.get()).transitional_ignore();
newCollection(&opCtx,
NamespaceString("a.b"),
CollectionOptions(),
KVPrefix::kNotPrefixed,
catalog.get())
.transitional_ignore();
uow.commit();
}
ASSERT_NOT_EQUALS(ident, catalog->getCollectionIdent("a.b"));
}
示例4: opCtx
TEST(KVCatalogTest, DirectoryPerAndSplit1) {
unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create());
KVEngine* engine = helper->getEngine();
unique_ptr<RecordStore> rs;
unique_ptr<KVCatalog> catalog;
{
MyOperationContext opCtx(engine);
WriteUnitOfWork uow(&opCtx);
ASSERT_OK(engine->createRecordStore(&opCtx, "catalog", "catalog", CollectionOptions()));
rs = engine->getRecordStore(&opCtx, "catalog", "catalog", CollectionOptions());
catalog.reset(new KVCatalog(rs.get(), true, true));
uow.commit();
}
{
MyOperationContext opCtx(engine);
WriteUnitOfWork uow(&opCtx);
ASSERT_OK(
catalog->newCollection(&opCtx, "a.b", CollectionOptions(), KVPrefix::kNotPrefixed));
ASSERT_STRING_CONTAINS(catalog->getCollectionIdent("a.b"), "a/collection/");
ASSERT_TRUE(catalog->isUserDataIdent(catalog->getCollectionIdent("a.b")));
uow.commit();
}
{ // index
MyOperationContext opCtx(engine);
WriteUnitOfWork uow(&opCtx);
BSONCollectionCatalogEntry::MetaData md;
md.ns = "a.b";
md.indexes.push_back(BSONCollectionCatalogEntry::IndexMetaData(BSON("name"
<< "foo"),
false,
RecordId(),
false,
KVPrefix::kNotPrefixed,
false));
catalog->putMetaData(&opCtx, "a.b", md);
ASSERT_STRING_CONTAINS(catalog->getIndexIdent(&opCtx, "a.b", "foo"), "a/index/");
ASSERT_TRUE(catalog->isUserDataIdent(catalog->getIndexIdent(&opCtx, "a.b", "foo")));
uow.commit();
}
}
示例5: opCtx
TEST( KVEngineTestHarness, SimpleRS1 ) {
unique_ptr<KVHarnessHelper> helper( KVHarnessHelper::create() );
KVEngine* engine = helper->getEngine();
ASSERT( engine );
string ns = "a.b";
unique_ptr<RecordStore> rs;
{
MyOperationContext opCtx( engine );
ASSERT_OK( engine->createRecordStore( &opCtx, ns, ns, CollectionOptions() ) );
rs.reset( engine->getRecordStore( &opCtx, ns, ns, CollectionOptions() ) );
ASSERT( rs );
}
RecordId loc;
{
MyOperationContext opCtx( engine );
WriteUnitOfWork uow( &opCtx );
StatusWith<RecordId> res = rs->insertRecord( &opCtx, "abc", 4, false );
ASSERT_OK( res.getStatus() );
loc = res.getValue();
uow.commit();
}
{
MyOperationContext opCtx( engine );
ASSERT_EQUALS( string("abc"), rs->dataFor( &opCtx, loc ).data() );
}
{
MyOperationContext opCtx( engine );
std::vector<std::string> all = engine->getAllIdents( &opCtx );
ASSERT_EQUALS( 1U, all.size() );
ASSERT_EQUALS( ns, all[0] );
}
}
示例6: opCtx
TEST(KVCatalogTest, Idx1) {
unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create());
KVEngine* engine = helper->getEngine();
unique_ptr<RecordStore> rs;
unique_ptr<KVCatalog> catalog;
{
MyOperationContext opCtx(engine);
WriteUnitOfWork uow(&opCtx);
ASSERT_OK(engine->createRecordStore(&opCtx, "catalog", "catalog", CollectionOptions()));
rs = engine->getRecordStore(&opCtx, "catalog", "catalog", CollectionOptions());
catalog.reset(new KVCatalog(rs.get(), false, false));
uow.commit();
}
{
MyOperationContext opCtx(engine);
WriteUnitOfWork uow(&opCtx);
ASSERT_OK(
catalog->newCollection(&opCtx, "a.b", CollectionOptions(), KVPrefix::kNotPrefixed));
ASSERT_NOT_EQUALS("a.b", catalog->getCollectionIdent("a.b"));
ASSERT_TRUE(catalog->isUserDataIdent(catalog->getCollectionIdent("a.b")));
uow.commit();
}
{
MyOperationContext opCtx(engine);
WriteUnitOfWork uow(&opCtx);
BSONCollectionCatalogEntry::MetaData md;
md.ns = "a.b";
BSONCollectionCatalogEntry::IndexMetaData imd;
imd.spec = BSON("name"
<< "foo");
imd.ready = false;
imd.head = RecordId();
imd.multikey = false;
imd.prefix = KVPrefix::kNotPrefixed;
imd.isBackgroundSecondaryBuild = false;
md.indexes.push_back(imd);
catalog->putMetaData(&opCtx, "a.b", md);
uow.commit();
}
string idxIndent;
{
MyOperationContext opCtx(engine);
idxIndent = catalog->getIndexIdent(&opCtx, "a.b", "foo");
}
{
MyOperationContext opCtx(engine);
ASSERT_EQUALS(idxIndent, catalog->getIndexIdent(&opCtx, "a.b", "foo"));
ASSERT_TRUE(catalog->isUserDataIdent(catalog->getIndexIdent(&opCtx, "a.b", "foo")));
}
{
MyOperationContext opCtx(engine);
WriteUnitOfWork uow(&opCtx);
BSONCollectionCatalogEntry::MetaData md;
md.ns = "a.b";
catalog->putMetaData(&opCtx, "a.b", md); // remove index
BSONCollectionCatalogEntry::IndexMetaData imd;
imd.spec = BSON("name"
<< "foo");
imd.ready = false;
imd.head = RecordId();
imd.multikey = false;
imd.prefix = KVPrefix::kNotPrefixed;
imd.isBackgroundSecondaryBuild = false;
md.indexes.push_back(imd);
catalog->putMetaData(&opCtx, "a.b", md);
uow.commit();
}
{
MyOperationContext opCtx(engine);
ASSERT_NOT_EQUALS(idxIndent, catalog->getIndexIdent(&opCtx, "a.b", "foo"));
}
}