casbin / redis-watcher

Redis WatcherEx for Casbin

Home Page:https://github.com/casbin/casbin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

use SavePolicy in multi pod will cause data lost

WRAllen opened this issue · comments

commented

i use redis-watcher in my service, but i found SavePolicy in multi pod will cause data lost in concurrent request。(i use gorm as a adpter)

because i found NewEnforcer will select exist policy into memry, SavePolicy will truncate casbin_rule table and insert policy from memry, in three pod with concurrent request first, I found same case will cause casbin_rule data lost.

Thanks for your report, can you give a code sample that simulates the error? This helps us understand and try to solve the problem.

commented

Thanks for your report, can you give a code sample that simulates the error? This helps us understand and try to solve the problem.

sorry i can't give the sample code ,because it not sample, the data lost case must trigger in multi pod with concurrent request.

but the SavePolicy code show , when i use db as adpter(gorm, use mysql as db), casbin.NewEnforcer will select policy from db, and SavePolicy will truncate casbin_rule and use policy from memry insert into db.

on concurrent request there has same time will truncate data, like this

pod1: select policy from db -> truncate casbin table -> insert into db with memry policy
pod2:                                                                               select policy from db -> policy is empty

after pod1 truncate casbin table , pod2 casbin.NewEnforcer with a empty policy from db

I roughly understand your situation, do you expect (truncate casbin table -> insert into db with memory policy) to be an atomic operation? Then, other pods will not encounter an intermediate state with an empty policy

commented

I roughly understand your situation, do you expect (truncate casbin table -> insert into db with memory policy) to be an atomic operation? Then, other pods will not encounter an intermediate state with an empty policy

yes!

Ok, I'll try to fix this in the next few days.

@WRAllen
By the way, do you have this problem with gorm-adapter or redis-adapter, or both? Can you give a link to the Github repository of the adapter you are using, as we may have multiple adapters of the same type.

According to your description, you use gorm-adapter (mysql database), but submitted an issue in redis-watcher, is there any relationship between them?

I think this issue is better submitted to the adapter's GitHub repository.

commented

@WRAllen By the way, do you have this problem with gorm-adapter or redis-adapter, or both? Can you give a link to the Github repository of the adapter you are using, as we may have multiple adapters of the same type.

According to your description, you use gorm-adapter (mysql database), but submitted an issue in redis-watcher, is there any relationship between them?

I think this issue is better submitted to the adapter's GitHub repository.

OK~thinks you,I will