Forum Stats

  • 3,839,879 Users
  • 2,262,546 Discussions


Want to insert records into a primary over RPC w/ secondary update

524300 Member Posts: 340
(Responding to a question posted on comp.databases.berkeley-db):
I'd like to support a simple insert into a primary w/ a secondary key
update over RPC. One should be able to perform this from the
client-side and just wrap both put operations into a transaction. (?)
You can maintain the secondary database manually over RPC by updating the primary and secondary independently. Queries can still use DB->associate with read-only handles to do secondary lookups.
if (secondary_associate_callback_ != NULL)
// reuse Dbt key, data;
Dbt skey;

assert(secondary_associate_callback_(this, &key, &data, &skey) == 0);
assert(secondary_->put(NULL, &skey, &data, 0) == 0);
This is almost right: secondaries store secondary key -> primary key. That is, the secondary update should be:

secondary_->put(NULL, &skey, &key, 0);

Obviously things get more complicated if this isn't an insert: if you are updating an existing record, you may have an old secondary key to remove.

This discussion has been closed.