void DatabaseImpl::storeOwnership()

in glean/rocksdb/rocksdb.cpp [1236:1275]


void DatabaseImpl::storeOwnership(ComputedOwnership &ownership) {
  container_.requireOpen();

  if (ownership.sets_.size() > 0) {
    auto t = makeAutoTimer("storeOwnership(sets)");
    rocksdb::WriteBatch batch;

    uint32_t id = ownership.firstId_;
    for (auto &exp : ownership.sets_) {
      if ((id % 1000000) == 0) {
        VLOG(1) << "storeOwnership: " << id;
      }
      putOwnerSet(batch, id, exp.op, exp.set);
      id++;
    }
    VLOG(1) << "storeOwnership: writing sets (" <<
      ownership.sets_.size() << ")";
    check(container_.db->Write(container_.writeOptions, &batch));
  }

  // ToDo: just update usets_, don't load the whole thing
  usets_ = loadOwnershipSets();

  if (ownership.facts_.size() > 0) {
    auto t = makeAutoTimer("storeOwnership(facts)");
    rocksdb::WriteBatch batch;
    for (uint64_t i = 0; i < ownership.facts_.size(); i++) {
      auto id = ownership.facts_[i].first;
      auto usetid = ownership.facts_[i].second;
      EncodedNat key(id.toWord());
      EncodedNat val(usetid);
      check(batch.Put(container_.family(Family::factOwners),
                      slice(key.byteRange()),
                      slice(val.byteRange())));
    }
    VLOG(1) << "storeOwnership: writing facts: " <<
      ownership.facts_.size() << " intervals";
    check(container_.db->Write(container_.writeOptions, &batch));
  }
}