Skip to Main Content

Berkeley DB Family

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Possible bug in bulk update?

518667Mar 23 2011 — edited Apr 12 2011
Due to none is answering to my previous thread I will try it with a new one.

The following test does not contain pure BDB API calls, instead it uses my own wrapper. What I am doing is creating a database with one index, adding some values using a DbSequence (with a range 0-4) internally to create auto increment id's using bulk update (DbtMultipleKeyDataBuilder) and close the database.

After that I open the same database, create one more index, associate it to the primary and make an bulk update with new data. During that bulk update I got an exception "Db::put: DB_SECONDARY_BAD: Secondary index inconsistent with primary" When using single updates the same error occurs too.

I have discovered that this error is not occuring when I change line 2245 in db_cam.c:
		if ((ret = __dbc_get(sdbc,
		    &tempskey, &temppkey, rmw | DB_GET_BOTH)) == 0)
			ret = __dbc_del(sdbc, DB_UPDATE_SECONDARY);
		else if (ret == DB_NOTFOUND)
			ret = 0;
		        //ret = __db_secondary_corrupt(dbp);
I know this is not a solution. I have for the moment no idea how to solve that problem.

        EnvironmentConfiguration config;
        config.setEnvHome(envHome);
        config.setTransactional(true);
        config.setTransactionNoSync(true);
        config.setInMemoryLogging(true);
       

        DbDefaultConfiguration primaryConfig; // setting DB_BTREE, DB_CREATE, DB_THREAD
        DbDefaultConfiguration indexConfig;
        indexConfig.setFlags(DB_DUPSORT);

        {
            Environment env(config);

            std::auto_ptr<api::KeyGenerator> keyGenerator(new BerkeleyKeyGenerator(env, "autoincr.seq", KeyRange(0, 4)));

            std::auto_ptr<PrimaryStorage<uint64_t, std::string> > primary(new BerkeleyPrimaryStorage<uint64_t, std::string>(env, primaryConfig, "primary"));
            Index<std::string, uint64_t, std::string> index1(env, indexConfig, "index1", new TestStringExtractor);
            primary->associate(index1);

            std::vector<std::string> values;
            values.push_back("abc");
            values.push_back("def");
            values.push_back("ghi");

            std::auto_ptr<Transaction> txn = env.beginTransaction();
            primary->bulkInsert(*txn, *keyGenerator, values);

            CHECK_EQUAL("abc", primary->get(*txn, 0));
            CHECK_EQUAL("def", primary->get(*txn, 1));
            CHECK_EQUAL("ghi", primary->get(*txn, 2));

            txn->commit();
        }

        {        
            Environment env(config);

            std::auto_ptr<api::KeyGenerator> keyGenerator(new BerkeleyKeyGenerator(env, "autoincr.seq", KeyRange(0, 4)));

            std::auto_ptr<PrimaryStorage<uint64_t, std::string> > primary(new BerkeleyPrimaryStorage<uint64_t, std::string>(env, primaryConfig, "primary"));
            Index<std::string, uint64_t, std::string> index1(env, indexConfig, "index1", new TestStringExtractor);
            Index<std::string, uint64_t, std::string> index2(env, indexConfig, "index2", new TestStringExtractor);

            primary->associate(index1);
            primary->associate(index2);

            std::vector<std::string> values;
            values.push_back("jkl");
            values.push_back("mno");
            values.push_back("pqr");

            std::auto_ptr<Transaction> txn = env.beginTransaction();
            primary->bulkInsert(*txn, *keyGenerator, values);

            CHECK_EQUAL("pqr", primary->get(*txn, 0));
            CHECK_EQUAL("def", primary->get(*txn, 1));
            CHECK_EQUAL("ghi", primary->get(*txn, 2));
            CHECK_EQUAL("jkl", primary->get(*txn, 3));
            CHECK_EQUAL("mno", primary->get(*txn, 4));

            txn->commit();
        }
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 10 2011
Added on Mar 23 2011
11 comments
232 views