Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concurrent issue with MySQL table sharding #113

Open
chenchunan opened this issue Sep 10, 2019 · 1 comment
Open

Concurrent issue with MySQL table sharding #113

chenchunan opened this issue Sep 10, 2019 · 1 comment

Comments

@chenchunan
Copy link

We are trying to do table sharding with following code

` [HttpGet("test/{flag}")]
public string test(string flag)
{
var _repository = _unitOfWork.GetRepository();

        Comment _data;

        if (flag.Equals("0"))
        {
            _repository.ChangeTable("Comment_0");
            _data = new Comment();
            _data.Title = "0";
            _data.Content = "0";
        }
        else
        {
            _repository.ChangeTable("Comment_1");
            _data = new Comment();
            _data.Title = "1";
            _data.Content = "1";
        }

        _repository.Insert(_data);

        _unitOfWork.SaveChanges();

        return $"is:{flag}";
    }`

Http client would send some requests with parameter 1 and 0 at the sam time. And the result shows that some rows of 1s go to table "Comment_0" and some rows of 0s go to table "Comment_1". It looks like a concurrency problem to me. Anyone can help?

Thanks!

@rigofunc
Copy link
Member

Using AddScoped<T, T>?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants