事务处理的示例 [英] Example of Transaction Processing

查看:74
本文介绍了事务处理的示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释一下这段代码到底发生了什么吗?它旨在找到所有可能的操作安排。详细分解和解释将不胜感激。非常感谢。



Can someone please explain exactly what is happening in this code? It is intended to find all the possible arrangements of operations. A detailed breakdown and explanation would be appreciated. Thanks much.

/** Recursion for enumeration of all possible transaction schedules */
void gen_all_sch_r(const xa_coll_t& xa_coll,
    vector<xa_t::const_iterator>& xac_pos,
    vector<xa_op_t>& sch)
{
    size_t num_xa = xa_coll.size();

    //if(xac_pos.empty())
    //{
    //    xac_pos = vector<xa_coll_t::const_iterator>(num_xa);
    //}

    /*
    vector<size_t> v(4);
    iota(v.begin(), v.end(), 0);
    print_coll(cout, v.begin(), v.end(), " ", "\n");
    while(next_permutation(v.begin(), v.end()))
    {
        print_coll(cout, v.begin(), v.end(), " ", "\n");
    }
    //copy(v.begin(), v.end(), ostream_iterator<int>(cout, " "));
    */

    // Have all transaction operations been added to the schedule?
    bool all_xa_op_used = true;
    for(size_t i = 0; i < num_xa; i++)
    {
        if(xac_pos[i] != xa_coll[i].end())
        {
            all_xa_op_used = false;
        }
    }

    if(all_xa_op_used)
    {
        // We have found another schedule
        cout << "SCHEDULE" << endl;
        cout << sch;

        // TODO: Is this schedule serializable? Use graphs and cycles.
    }
    else
    {
        // Still need to recurse one level lower to continue filling
        // the schedule
        for(size_t i = 0; i < num_xa; i++)
        {
            if(xac_pos[i] != xa_coll[i].end())
            {
                sch.push_back(*xac_pos[i]);
                xac_pos[i]++;
                gen_all_sch_r(xa_coll, xac_pos, sch);
                xac_pos[i]--;
                sch.pop_back();
            }
        }
    }

}

void gen_all_sch(const xa_coll_t& xa_coll)
{
    vector<xa_op_t> sch;
    vector<xa_t::const_iterator> xac_pos(xa_coll.size());

    for(size_t pos = 0; pos < xa_coll.size(); pos++)
    {
        xac_pos[pos] = xa_coll[pos].cbegin();
    }

    gen_all_sch_r(xa_coll, xac_pos, sch);
}

推荐答案

您是否知道逐行解释代码的工作量是多少?

每一行都需要一段解释!例如:

Do you have any idea how much work explaining code line by line is?
Every single line needs a paragraph of explanation! For example:
int next = r.Next();



创建一个名为next的新变量,它可以包含一个整数值。从先前声明的Random实例r,调用Next方法获取一个新的随机数,并将其分配给next变量。



可以你想象我们需要多长时间才能解释一个像你的例子一样的非常短的代码片段,一行一行?



不会发生这种情况。如果您有特定问题,请询问有关它的问题。但首先考虑一下 - 您是否希望坐下45分钟并且没有充分的理由输入逐行描述?


Create a new variable called "next" which can hold a integer value. From the previously declared Random instance "r", call the "Next" method to get a new random number, and assign it to the "next" variable.

Can you imagine how long it would take us to explain even a very short code fragment like your example, line by line?

No. It is not going to happen. If you have a specific problem, then ask a question about it. But think first - would you want to sit down for 45 minutes and type up a line-by-line description for no good reason?


这篇关于事务处理的示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆