Ejemplo n.º 1
0
//##############################################################################
//##############################################################################
ChangeList
BerkeleyDBCXXDb::read_changelist() const
{
    RANGE_LOG_FUNCTION();
    std::string buf = this->get_record(record_type::GRAPH_META, "changelist");
    ChangeList changes;
    if(!buf.empty()) {
        changes.ParseFromString(buf);
        if(!changes.IsInitialized()) {
            THROW_STACK(DatabaseVersioningError("Changelist cannot be initialized"));
        }
        return changes;
    }
    changes.set_current_version(0);
    changes.mutable_change();
    changes.mutable_unknown_fields();
    return changes;
    //THROW_STACK(DatabaseVersioningError("Changelist cannot be read"));
}
Ejemplo n.º 2
0
//##############################################################################
//##############################################################################
void
BerkeleyDB::add_new_range_version()
{
    RANGE_LOG_FUNCTION();
    this->init_info();
    auto lock = info_->write_lock(record_type::GRAPH_META, "graph_list");

    std::string buf = info_->get_record(record_type::GRAPH_META,
            "range_changelist");
    ChangeList changes;
    if(!buf.empty()) {
        changes.ParseFromString(buf);
    }

    std::unordered_map<std::string, uint64_t> vermap;
    for (auto &gname : listGraphInstances()) {
        auto ginst = getGraphInstance(gname);
        vermap[gname] = ginst->version();
    }

    ChangeList_Change *c = changes.add_change();

    for(auto &verinfo : vermap) {
        auto item = c->add_items();
        item->set_key(verinfo.first);
        item->set_version(verinfo.second);
    }

    struct timeval cur_time;
    gettimeofday(&cur_time, NULL);

    auto ts = c->mutable_timestamp();
    ts->set_seconds(cur_time.tv_sec);
    ts->set_msec(cur_time.tv_usec / 1000);

    changes.set_current_version(changes.current_version() + 1);
    info_->commit_record(std::make_tuple(record_type::GRAPH_META, "range_changelist", 0, changes.SerializeAsString()));
}