-
Notifications
You must be signed in to change notification settings - Fork 303
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
Fbaetens/bump sqlite kv limit & improve error reporting #2724
Conversation
336f99c
to
5c476b5
Compare
This also has an internal PR |
5c476b5
to
321fab6
Compare
kj::Array<byte> buffer = serializeV8Value(js, field.value); | ||
ActorStorageLimits::checkMaxValueSize(field.name, buffer); |
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.
Hmm, by doing this means that if we get a giant value we're going to keep it around until the check kicks in later. I guess this is probably safe, if only because if the value were too huge, the isolate would have run out of memory before we got here.
src/workerd/util/sqlite-kv.h
Outdated
// of KJ exceptions which become internal errors. | ||
class SqliteKvRegulator: public SqliteDatabase::Regulator { | ||
void onError(kj::StringPtr message) const override { | ||
JSG_ASSERT(false, Error, message); |
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.
This implementation will throw JSG errors for all possible SQLite errors. Almost everything about this class is under our control so every error EXCEPT the TOOBIG error should be an internal error. Is it possible to report only TOOBIG errors this way?
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.
Yes, but not without either doing matching on the string message (bad), or changing the onError API (out of scope for now).
What I'll do now is only pass the regulator to the put query, so only sql errors for put get passed through. Or would you prefer I do string matching as a temporary kludge here?
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.
Changed it to only report errors on the put query. Let me know your thoughts on that. I acknowledge it's a bit of a hack, but I think its a low consequence change here. Reporting an SQLite error that's actually our fault to the user doesn't seem like a massive issue for sqlite here.
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.
Hmm, including the error code in the onError doesn't seem that difficult actually. I'll try to get something out based on that.
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.
Pushed a fixup commit passing the error code to onError. Let me know what you think of that, and I'll squash it if you think it's a good approach here.
9ef86fa
to
46c544d
Compare
ab70a64
to
3453abb
Compare
@@ -3,6 +3,7 @@ | |||
// https://opensource.org/licenses/Apache-2.0 | |||
|
|||
#include "pyodide.h" | |||
|
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.
This got in from running the formatter.
src/workerd/util/sqlite-kv.h
Outdated
@@ -15,8 +17,22 @@ namespace { | |||
// In this case we just customize the error reporting to emit JSG user visible errors instead | |||
// of KJ exceptions which become internal errors. | |||
class SqliteKvRegulator: public SqliteDatabase::Regulator { | |||
void onError(kj::StringPtr message) const override { | |||
JSG_ASSERT(false, Error, message); | |||
void onError(kj::Maybe<int> sqliteErrorCode, kj::StringPtr message) const override { |
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.
I like this approach of taking in the error code. However, it would be better if you put the definition of onError
in the C++ file. Doing so means that we wouldn't need to #include <sqlite3.h>
in this header file, which means that other headers won't have to include sqlite3.h
, which means @sqlite3
can remain an implementation_dep
, which means builds should not slow down.
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.
Done this now, I had put it in the header file to be able to put it in an anonymous namespace, but I suppose that doesn't matter much.
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.
FYI for future reference, don't put anonymous namespaces in headers. This causes everything that includes the header to compile its own copy of the stuff in the anonymous namespace. This bloats the binary and could lead to ODR violations.
3453abb
to
8935dba
Compare
8935dba
to
2983b60
Compare
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.
I think the code itself is in good shape, but we're missing a test in sqlite-kv-test.c++.
Or is there a reason that we shouldn't include a test?
I tested this in the internal PR, but I'll add a test there too then. |
327f419
to
e63c2ba
Compare
No description provided.