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

All json all the time #277

Merged
merged 9 commits into from
Mar 23, 2020
Merged

All json all the time #277

merged 9 commits into from
Mar 23, 2020

Conversation

asutula
Copy link
Member

@asutula asutula commented Mar 20, 2020

This PR removes the two db modes of normal go mode and json mode. The only mode now is what was called json mode, there is no "mode" nomenclature any more.

Also snuck in an update to better support creating Collections as part of db creation.

The Collection and jsonpatcher apis still take interface{} arguments event though all the data is string and *string. I plan on cleaning that up in the next PR where all methods will explicitly accept and return []byte for json data.

@asutula asutula self-assigned this Mar 20, 2020
Signed-off-by: Aaron Sutula <[email protected]>
Signed-off-by: Aaron Sutula <[email protected]>
// ToDo: Decide how we want to apply instance id requirements
return len(instanceID) > 0
// _, err := uuid.Parse(instanceID)
// return err == nil
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disabled this for now, made the issue #280

}

func newCollectionFromSchema(name string, schema string, d *DB) *Collection {
func newCollection(name string, schema string, d *DB) *Collection {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where we'll want some schema verification of ID

#281

// if _, err := db.NewCollection(cc); err != ErrInvalidCollectionType {
// t.Fatal("the collection should be invalid")
// }
// })
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is disabled until we start verifying that the schema specifies ID, tracking here #281

@@ -114,7 +112,7 @@ func NewDBFromAddr(ctx context.Context, network net.Net, addr ma.Multiaddr, key

// newDB is used directly by a db manager to create new dbs
// with the same config.
func newDB(n net.Net, id thread.ID, config *Config, collections ...CollectionConfig) (*DB, error) {
func newDB(n net.Net, id thread.ID, config *Config) (*DB, error) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CollectionConfigs are now passed in as part of Config

Debug: base.Debug,
EventCodec: base.EventCodec,
Debug: base.Debug,
Collections: append(base.Collections, collections...),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We combine the default collections that the manager was created with (using Options) with any default collections specified in the call to manager.NewDB or manager.NewDBFromAddress.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

EventCodec core.EventCodec
Debug bool
LowMem bool
Collections []CollectionConfig
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default collections are now part of the db config.

sc.Collections = collections
return nil
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Option func for setting collections

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perf!

@@ -0,0 +1,166 @@
package db
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were the old non-json mode query tests. I figured they might cover some use cases not covered by the json mode tests, so I left them here and ported them to json mode.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably some overlap, but cool

Schema: util.SchemaFromInstance(&myCounter{}),
}

d, err := db.NewDBFromAddr(context.Background(), n, writerAddr, key, db.WithRepoPath(repo), db.WithCollections(cc))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heres an example of creating a db from invite and passing in a collection config so the auto start works nicely

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels good 💯 💯 💯

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep!

if err := json.Unmarshal([]byte(s), i); err != nil {
panic(err)
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some utilities for converting between go types and json strings

panic(err)
}
return string(JSON)
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Utility to create a json schema from a go type

@asutula asutula marked this pull request as ready for review March 21, 2020 00:59
Copy link
Contributor

@jsign jsign left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 👍

I'm happy to see that all those ifs distinguishing go-type/JSONMode thing are going away, and most prob some extra reflection things will be stripped off when interface{} params will go away in the future.

I wonder if going all-json might enable using better json-libraries for things in general. I'm not thinking about any particular thing, but making the point. Also, would be good to have @carsonfarmer opinion on how this may enable better/easier/etc things for indexes, considering not having to care about go-type mode.

Debug: base.Debug,
EventCodec: base.EventCodec,
Debug: base.Debug,
Collections: append(base.Collections, collections...),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

Schema: util.SchemaFromInstance(&myCounter{}),
}

d, err := db.NewDBFromAddr(context.Background(), n, writerAddr, key, db.WithRepoPath(repo), db.WithCollections(cc))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels good 💯 💯 💯

@@ -9,6 +9,7 @@ import (
ma "github.com/multiformats/go-multiaddr"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A quick refresher: This e2e_counter was some of the first e2e things that I created when we had a first working version of DB. We have chatted some times to remove this code if may be confusing or adding too much burden to refactors or maintainability. No strong opinion, but just refreshing this since I originally made this example... no feelings with it. If it adds value in some direction, np with leaving this too.

The books example was made roughly at the same time... but feels that example it's much nicer to show somebody a minimal way of using things.

Just leaving al this as a note here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok. If anyone has some strong feeling about removing it, I'm fine with that, but also don't have a strong opinion.

@asutula
Copy link
Member Author

asutula commented Mar 23, 2020

Thanks for the review @jsign. Yea, all that reflect stuff goes away with the removal of interface{} and use of []byte. I have that going on a branch now and it feels good, cleans up the code a lot.

Copy link
Member

@sanderpick sanderpick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 💪 💪

sc.Collections = collections
return nil
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perf!

Schema: util.SchemaFromInstance(&myCounter{}),
}

d, err := db.NewDBFromAddr(context.Background(), n, writerAddr, key, db.WithRepoPath(repo), db.WithCollections(cc))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep!

@asutula asutula merged commit 47c6a7d into master Mar 23, 2020
@asutula asutula deleted the asutula/all-json-all-the-time branch March 23, 2020 20:54
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

Successfully merging this pull request may close these issues.

None yet

3 participants