Conversation
Signed-off-by: Sander Pick <sanderpick@gmail.com>
Signed-off-by: Sander Pick <sanderpick@gmail.com>
Signed-off-by: Sander Pick <sanderpick@gmail.com>
Signed-off-by: Sander Pick <sanderpick@gmail.com>
Signed-off-by: Sander Pick <sanderpick@gmail.com>
62a30f6 to
e07eb8b
Compare
Signed-off-by: Sander Pick <sanderpick@gmail.com>
Signed-off-by: Sander Pick <sanderpick@gmail.com>
Signed-off-by: Sander Pick <sanderpick@gmail.com>
Signed-off-by: Sander Pick <sanderpick@gmail.com>
Signed-off-by: Sander Pick <sanderpick@gmail.com>
Signed-off-by: Sander Pick <sanderpick@gmail.com>
Signed-off-by: Sander Pick <sanderpick@gmail.com>
Signed-off-by: Sander Pick <sanderpick@gmail.com>
4cffd14 to
330f712
Compare
jsign
left a comment
There was a problem hiding this comment.
LGTM! Very cool and powerful. 🚀
Left some comments but nothing important.
| c, err := db.NewCollection(CollectionConfig{ | ||
| Name: "Dog", | ||
| Schema: util.SchemaFromInstance(&Dog{}, false), | ||
| ReadFilter: ` |
There was a problem hiding this comment.
Oh, it can also mutate the instance. Scary but powerful :P
Now feel ReadFilter might be a bit short in semantics since isn't only deciding to "show/not_show" but possibly changing. I don't have a good candidate name though.
| func (d *DB) HandleNetRecord(rec net.ThreadRecord, key thread.Key, lid peer.ID, timeout time.Duration) error { | ||
| if rec.LogID() == lid { | ||
| return nil // Ignore our own events since DB already dispatches to DB reducers | ||
| func (d *DB) ValidateNetRecordBody(_ context.Context, body format.Node, identity thread.PubKey) error { |
There was a problem hiding this comment.
Nice. With this write validators, we should stress more than ever the single-writer approach.
That is, is very important that write validations relies on the assumption on getting writes in a single log where records are always presented in order. If some validation depends on two logs, depending on the order of processing you might have unwanted consequences. Sharing thoughts to validate mentality.
Maybe under more advanced validators, multi-writers might make sense... but thinking about all possible out of order arrivals to validate or not sounds hard.
| JSONPatch interface{} `json:"json_patch"` | ||
| } | ||
|
|
||
| func (je patchEvent) Marshal() ([]byte, error) { |
There was a problem hiding this comment.
Is this breaking change? Saying: changing the json format in the records?
Thinking about if older code can unmarshal correctly the new json tags? Sorry if confused!
Signed-off-by: Sander Pick <sanderpick@gmail.com>
* db: initial work for validator funcs Signed-off-by: Sander Pick <sanderpick@gmail.com> * db: adds collection read filter Signed-off-by: Sander Pick <sanderpick@gmail.com> * net: track logs by identity Signed-off-by: Sander Pick <sanderpick@gmail.com> * net: fix up tests Signed-off-by: Sander Pick <sanderpick@gmail.com> * net: add back compat for old own logs Signed-off-by: Sander Pick <sanderpick@gmail.com> * db: handle remaining db access Signed-off-by: Sander Pick <sanderpick@gmail.com> * logs: adds clear metadata method Signed-off-by: Sander Pick <sanderpick@gmail.com> * db: fix up tests Signed-off-by: Sander Pick <sanderpick@gmail.com> * net: fix record validation from net Signed-off-by: Sander Pick <sanderpick@gmail.com> * mod: migrate datastore to own namespace Signed-off-by: Sander Pick <sanderpick@gmail.com> * mod: use both go-datastores Signed-off-by: Sander Pick <sanderpick@gmail.com> * logstore: fix up tests Signed-off-by: Sander Pick <sanderpick@gmail.com> * cleanup: typos found during self review Signed-off-by: Sander Pick <sanderpick@gmail.com> * review: address feedback Signed-off-by: Sander Pick <sanderpick@gmail.com>
|
|
||
| type patchEvent struct { | ||
| Timestamp time.Time | ||
| Timestamp int64 |
There was a problem hiding this comment.
@sanderpick FYI this change breaks the backward compatibility with existing logs/dbs...
Not sure if you have an intent to promise this by the moment.
Let me know, I can propose PR to support the old format
There was a problem hiding this comment.
Hrm, okay. Let's see... what do you propose? To add some context, time.Time isn't cbor-serializable since it doesn't export any fields.
There was a problem hiding this comment.
You can try to cbor-serialize the old-format patchEvent(with time.Time) and then try to deserialize it into the new format(with int64) or vice versa. You will get unmarshal error.
Here is the proof to test:
https://gist.github.com/requilence/d80e0eb1e346a8b40403e8593163aabf
output:
=== RUN TestJsonPatcher_Migration
jsonpatcher_test.go:54: malformed stream: invalid appearance of uint token; expected start of map
jsonpatcher_test.go:59: unmarshal error: cannot assign <{:0> to int64 field
There was a problem hiding this comment.
Added a comment to your gist: https://gist.github.com/requilence/d80e0eb1e346a8b40403e8593163aabf#gistcomment-3438857
There was a problem hiding this comment.
@sanderpick thanks, the solution you've proposed seems ok, but still older clients will not be able to read the data created with the newer version.
Personally, I don't like the way these cbor-serialized structs become no-upgradable at all. In case of any struct amend, you need to preserve the old struct and still break the non-upgraded clients that read the same data.
On the other hand, PB-encoded ipld nodes look more solid as it provides the way to add new fields and remove the old ones as far as you don't reuse the same indexes. It also ignores the extra fields, which means compatible with older clients. Maybe you can provide some context why did you prefer cbor?
Anyway, it may be also useful to add some comments on all cbor-encoded structs that it shouldn't be changed
There was a problem hiding this comment.
Sorry for the delay. Coming up for air :) Agreed, the upgrade-ability is poor. IMO, CBOR is much nicer to work with compared to proto nodes in every other way. In any case, it would be an undertaking to migrate to proto nodes. Ideally, we could use any kind of format.Node at the net layer.
We could introduce a Version to the core.Event to make the handling a little cleaner. Still, older nodes are out of luck on this one.
There was a problem hiding this comment.
I ended up going with a simpler solution: #439
Closes #418
Closes #406
Net
Appto validate aRecordbefore it's committed to a log.DB
Misc.
go-libp2ptov0.10.3go.mod, which are cumbersome for downstream projects.