Пример #1
0
void Controller::handlePut(Key& key, shared_ptr<Value> value,
        const Requirements& requirements) {
    Condition condition = prepareCondition(key, value->getSize(), requirements);
    {
        lock_guard<mutex> gurad(infoLock);
        info[key] = KeyInfo{make_unique<Requirements>(requirements),
            value->getSize()};
    }
    double estimatedCost;
    Choice* choice = decider->choose(condition, &estimatedCost);
    if (choice == nullptr) {
        throw NoChoiceAvailableException();
    }
    accountant->recordEstimate(estimatedCost);
    accountant->recordPut(choice->getId(), value->getSize());
    storeInto(key, value, *choice, requirements);
    choice_id old_choice_id = memory->remember(key, choice->getId());
    if (old_choice_id != 0) {
        auto it = choices.find(old_choice_id);
        assert(it != choices.end());
        Choice& old_choice = it->second;
        old_choice.getActor()->del(key, old_choice.getProfile());
    }
    estimator->notifyPut(key, requirements);
    if (enableStat) {
        stat->notifyPut(key);
    }
}
Пример #2
0
void Controller::checkMigration(Key& key, const Choice& current,
        bool extraGet, shared_ptr<Value> valueGot) {
    Requirements requirements;
    size_t size;
    {
        lock_guard<mutex> guard(infoLock);
        if (info.count(key) == 0) return;
        requirements = *info[key].requirements.get();
        size = info[key].size;
    }
    Condition condition = prepareCondition(key, size, requirements);
    double estimatedCost;
    Choice* choice = decider->findBetter(condition, current, extraGet,
            &estimatedCost);
    if (choice != nullptr) {
        Dbg() << "migrating from " << current.desc() << " to " << choice->desc() << endl;
        shared_ptr<Value> value;
        Requirements migrateRequirements;
        if (extraGet) {
            value = current.getActor()->get(key, current.getProfile());
        } else {
            value = valueGot;
        }
        storeInto(key, value, *choice, requirements);
        choice_id old_id = memory->remember(key, choice->getId());
        deleteFrom(key, current);
        accountant->recordMigrate(current.getId(), choice->getId(), size,
                extraGet);
    }
}