-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add size limit for storing in the DB #71
base: main
Are you sure you want to change the base?
Conversation
98d310b
to
bce21f6
Compare
1b43d0f
to
47a1633
Compare
47a1633
to
f46c09f
Compare
runtime/plaid/src/executor/mod.rs
Outdated
@@ -104,6 +104,10 @@ pub struct Env { | |||
pub api: Arc<Api>, | |||
// A handle to the storage system if one is configured | |||
pub storage: Option<Arc<Storage>>, | |||
// Number of bytes the module is currently saving in persistent storage | |||
pub storage_current: Arc<RwLock<u64>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mutex might be faster here. The critical section for these kinds of checks are going to be super short. RWLock isn't a problem but worth looking into.
// Note: we _substract_ the size of existing data. If we were to insert the new data, the old data would be overwritten. | ||
let used_storage = match env_data.storage_current.read() { | ||
Ok(data) => *data, | ||
Err(_) => panic!(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should never panic. This needs to be surfaced and handled in some way.
9ad02f3
to
3114c37
Compare
This PR adds an optional size limit that modules must respect when storing data in the permanent storage (e.g., DB).
If a module tries to store more than it is allowed, the insertion will fail.
Modules can also be given (by default or through overrides)
Unlimited
storage in the DB, in which case we will still count how many bytes they are storing, but we will not fail the insert.When counting what is stored, we take into account the byte length of the key and the values.
Breaking changes
The configuration needs a new section that looks like