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

docs: Document client interfaces in client/db.go #1305

Merged
merged 29 commits into from
Apr 6, 2023

Conversation

AndrewSisley
Copy link
Contributor

@AndrewSisley AndrewSisley commented Apr 6, 2023

Relevant issue(s)

Resolves #1303

Description

Adds basic documentation for the client interfaces in client/db.go.

Some oddities are noted in the commit message bodies, but I see changing them as out of scope - happy to tweak the easy ones here if people feel otherwise though.

@AndrewSisley AndrewSisley added documentation Improvements or additions to documentation area/api Related to the external API component action/no-benchmark Skips the action that runs the benchmark. labels Apr 6, 2023
@AndrewSisley AndrewSisley added this to the DefraDB v0.5 milestone Apr 6, 2023
@AndrewSisley AndrewSisley requested a review from a team April 6, 2023 17:12
@AndrewSisley AndrewSisley self-assigned this Apr 6, 2023
@AndrewSisley AndrewSisley changed the title doc: Document client interfaces in client/db.go docs: Document client interfaces in client/db.go Apr 6, 2023
Copy link
Member

@shahzadlone shahzadlone left a comment

Choose a reason for hiding this comment

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

Appreciate you taking the time to add documentation. LGTM, pointed some minor typos.

client/db.go Outdated
@@ -19,30 +19,75 @@ import (
"github.com/sourcenetwork/defradb/events"
)

// DB is the primary public programatic access point to the local Defra instance.
Copy link
Member

Choose a reason for hiding this comment

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

todo:

Suggested change
// DB is the primary public programatic access point to the local Defra instance.
// DB is the primary public programmatic access point to the local Defra instance.

Copy link
Contributor Author

@AndrewSisley AndrewSisley Apr 6, 2023

Choose a reason for hiding this comment

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

Cheers :)

  • programatic => programmatic

client/db.go Outdated
@@ -19,30 +19,75 @@ import (
"github.com/sourcenetwork/defradb/events"
)

// DB is the primary public programatic access point to the local Defra instance.
Copy link
Member

Choose a reason for hiding this comment

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

todo:

Suggested change
// DB is the primary public programatic access point to the local Defra instance.
// DB is the primary public programatic access point to the local DefraDB instance.

Copy link
Contributor Author

@AndrewSisley AndrewSisley Apr 6, 2023

Choose a reason for hiding this comment

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

I guess it should be :)

  • DefraDB (change all instances of this)

client/db.go Outdated
@@ -19,30 +19,75 @@ import (
"github.com/sourcenetwork/defradb/events"
)

// DB is the primary public programatic access point to the local Defra instance.
//
// It should be contructed via the [db] package, via the [db.NewDB] function.
Copy link
Member

Choose a reason for hiding this comment

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

todo:

Suggested change
// It should be contructed via the [db] package, via the [db.NewDB] function.
// It should be constructed via the [db] package, via the [db.NewDB] function.

Copy link
Contributor Author

@AndrewSisley AndrewSisley Apr 6, 2023

Choose a reason for hiding this comment

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

cheers

  • contructed => constructed

client/db.go Outdated
type DB interface {
// Store contains Defra database functions protected by an internal, short-lived, transaction, allowing safe
Copy link
Member

Choose a reason for hiding this comment

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

todo:

Suggested change
// Store contains Defra database functions protected by an internal, short-lived, transaction, allowing safe
// Store contains DefraDB functions protected by an internal, short-lived, transaction, allowing safe

Copy link
Contributor Author

@AndrewSisley AndrewSisley Apr 6, 2023

Choose a reason for hiding this comment

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

Will do

  • Defra database => DefraDB

client/db.go Outdated
// WithTxn returns a new [client.Store] that respects the given transaction.
WithTxn(datastore.Txn) Store

// Root returns the underlying root store, within which all data managed by Defra is held.
Copy link
Member

Choose a reason for hiding this comment

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

todo:

Suggested change
// Root returns the underlying root store, within which all data managed by Defra is held.
// Root returns the underlying root store, within which all data managed by DefraDB is held.

client/db.go Outdated
Root() datastore.RootStore

// Blockstore returns the blockstore, within which all blocks (commits) managed by Defra are held.
Copy link
Member

Choose a reason for hiding this comment

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

todo:

Suggested change
// Blockstore returns the blockstore, within which all blocks (commits) managed by Defra are held.
// Blockstore returns the blockstore, within which all blocks (commits) managed by DefraDB are held.

Comment on lines +57 to +60
// It does not explicitly clear any data from persisted storage, and a new [DB] instance may typically
// be created after calling this to resume operations on the prior data - this is however dependant on
// the behaviour of the rootstore provided on database instance creation, as this function will Close
// the provided rootstore.
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: idk if we care lol but I realize this is just American vs UK spelling diffs at this point.

Suggested change
// It does not explicitly clear any data from persisted storage, and a new [DB] instance may typically
// be created after calling this to resume operations on the prior data - this is however dependant on
// the behaviour of the rootstore provided on database instance creation, as this function will Close
// the provided rootstore.
// It does not explicitly clear any data from persisted storage, and a new [DB] instance may typically
// be created after calling this to resume operations on the prior data - this is however dependent on
// the behavior of the rootstore provided on database instance creation, as this function will Close
// the provided rootstore.

Copy link
Contributor Author

@AndrewSisley AndrewSisley Apr 6, 2023

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

UK English always. Not sure why Americans need to try to be special with everything...

Comment on lines +63 to +66
// Events returns the database event queue.
//
// It may be used to monitor database events - a new event will be yielded for each mutation.
// Note: it does not copy the queue, just the reference to it.
Copy link
Member

Choose a reason for hiding this comment

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

praise: useful note

client/db.go Outdated
PrintDump(ctx context.Context) error
}

// Store contains the core Defra read-write operations.
Copy link
Member

Choose a reason for hiding this comment

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

todo:

Suggested change
// Store contains the core Defra read-write operations.
// Store contains the core DefraDB read-write operations.

client/db.go Show resolved Hide resolved
@AndrewSisley AndrewSisley force-pushed the sisley/doc/I1303-client-docs branch from cfe2c8f to 35009e9 Compare April 6, 2023 18:02
Comment on lines +89 to +90
// All schema types provided must not exist prior to calling this, and they may not reference existing
// types previously defined.
Copy link
Collaborator

Choose a reason for hiding this comment

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

thought(out of scope): Reading this I realize that we should probably allow new schema to reference existing ones. For example, I may want to add an Image schema that references the User collection (images are owned by users).

Comment on lines +109 to 113
// CreateCollection creates a new collection using the given description.
//
// WARNING: It does not currently update the GQL types, and as such a database restart is required after
// calling this if use of the new collection via GQL is desired (for example via [ExecRequest]).
CreateCollection(context.Context, CollectionDescription) (Collection, error)
Copy link
Collaborator

Choose a reason for hiding this comment

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

though: Seeing this warning makes me think that maybe this function shouldn't be exposed publicly. Unless I'm missing something, we don't use this function anywhere internally. We only use the private version of it for the adding schemas. It feels like giving users a chance to do something they may not want to.

Copy link
Contributor Author

@AndrewSisley AndrewSisley Apr 6, 2023

Choose a reason for hiding this comment

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

I think it is still nominally useful, and my preference long term is to fix both this and UpdateCollection so that they do actually update the GQL types.

That said, I think the lack of references might be quite new - I think they were referenced until the client txn rework, but I'm not 100% sure.

I have just spotted that UpdateCollection is missing this warning and should have it too

  • Add warning to UpdateCollection

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we remove them until they do update the GQL types?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I dont really think so, they will still work (on restart) and leaving them in documented like this should cause no harm IMO.

Can even be fixed in 0.5.1 if we want I think, as it wouldnt quite be a breaking change IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've merged, but happy to remove these if that is what we decide upon

client/db.go Show resolved Hide resolved
client/db.go Outdated
GQL GQLResult

// Pub contains a pointer to an events stream which channels any subscription results
Copy link
Collaborator

Choose a reason for hiding this comment

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

nitpick: Here I think events should be singular event as a stream implies multiple events coming one at a time. It's not a stream of events block.

Note: I don't have an english major so I may be wrong here but that is my interpretation of it.

Copy link
Contributor Author

@AndrewSisley AndrewSisley Apr 6, 2023

Choose a reason for hiding this comment

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

cheers - will change

  • events => event

@AndrewSisley AndrewSisley force-pushed the sisley/doc/I1303-client-docs branch from 177b952 to a52060f Compare April 6, 2023 19:50
@codecov
Copy link

codecov bot commented Apr 6, 2023

Codecov Report

Merging #1305 (177b952) into develop (055e2ea) will decrease coverage by 0.08%.
The diff coverage is n/a.

❗ Current head 177b952 differs from pull request most recent head a52060f. Consider uploading reports for the commit a52060f to get more accurate results

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1305      +/-   ##
===========================================
- Coverage    70.47%   70.39%   -0.08%     
===========================================
  Files          184      184              
  Lines        17825    17825              
===========================================
- Hits         12562    12548      -14     
- Misses        4311     4321      +10     
- Partials       952      956       +4     
Impacted Files Coverage Δ
client/value.go 100.00% <ø> (ø)
db/txn_db.go 46.26% <ø> (ø)

... and 5 files with indirect coverage changes

@AndrewSisley AndrewSisley merged commit b08fe6f into develop Apr 6, 2023
@AndrewSisley AndrewSisley deleted the sisley/doc/I1303-client-docs branch April 6, 2023 19:59
shahzadlone pushed a commit that referenced this pull request Apr 13, 2023
* Document client.DB

* Document client.DB.Store

* Document client.DB.NewTxn functions

* Document client.DB.Root

* Document client.DB.Blockstore

* Document client.DB.Close

Note: Upon writing this I do not actually think this function should close the rootstore, as Defra does not own it - it is an input parameter and should only be closed by the thing that created it.

* Document client.DB.Events

* Document client.DB.MaxTxnRetries

* Document client.DB.PrintDump

* Document client.Store

* Document client.Store.AddSchema

Uses the existing internal documentation as a starting point, expands it and then backports the changes to the internal functions.

* Document client.Store.CreateCollection

* Document client.Store.GetCollectionByName

* Document client.Store.GetCollectionBySchemaID

* Document client.Store.GetCollectionByVersionID

* Document client.Store.GetAllCollections

* Document client.Store.ExecRequest

* Document client.GQLResult

* Document client.GQLResult.Errors

* Document client.GQLResult.Data

* Document client.RequestResult

* Document client.RequestResult.GQL

Note: I think the naming of this and its type is not ideal.

* Document client.RequestResult.Pub

* Remove commented out code
shahzadlone pushed a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
* Document client.DB

* Document client.DB.Store

* Document client.DB.NewTxn functions

* Document client.DB.Root

* Document client.DB.Blockstore

* Document client.DB.Close

Note: Upon writing this I do not actually think this function should close the rootstore, as Defra does not own it - it is an input parameter and should only be closed by the thing that created it.

* Document client.DB.Events

* Document client.DB.MaxTxnRetries

* Document client.DB.PrintDump

* Document client.Store

* Document client.Store.AddSchema

Uses the existing internal documentation as a starting point, expands it and then backports the changes to the internal functions.

* Document client.Store.CreateCollection

* Document client.Store.GetCollectionByName

* Document client.Store.GetCollectionBySchemaID

* Document client.Store.GetCollectionByVersionID

* Document client.Store.GetAllCollections

* Document client.Store.ExecRequest

* Document client.GQLResult

* Document client.GQLResult.Errors

* Document client.GQLResult.Data

* Document client.RequestResult

* Document client.RequestResult.GQL

Note: I think the naming of this and its type is not ideal.

* Document client.RequestResult.Pub

* Remove commented out code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/no-benchmark Skips the action that runs the benchmark. area/api Related to the external API component documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document client interfaces in client/db.go
3 participants