Skip to content

Commit

Permalink
refactor: Decouple client.DB from net (#2768)
Browse files Browse the repository at this point in the history
## Relevant issue(s)

Resolves #2767 

## Description

This PR make the `net` package no longer dependent on `client.DB`.
Instead, on creation, the peer takes in a rootstore, a blockstore and an
event bus.

The p2p collections and replicators have been moved to `db`. Most of the
code is reused but it now makes use of the event bus to update the
peer's related state (pubsub topics and peer connections).
  • Loading branch information
fredcarle authored Jul 1, 2024
1 parent 204c8ef commit ea77dc2
Show file tree
Hide file tree
Showing 57 changed files with 2,643 additions and 2,229 deletions.
11 changes: 8 additions & 3 deletions client/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ type DB interface {
// can safely operate on it concurrently.
NewConcurrentTxn(context.Context, bool) (datastore.Txn, error)

// Root returns the underlying root store, within which all data managed by DefraDB is held.
Root() datastore.RootStore
// Rootstore returns the underlying root store, within which all data managed by DefraDB is held.
Rootstore() datastore.Rootstore

// Blockstore returns the blockstore, within which all blocks (commits) managed by DefraDB are held.
//
// It sits within the rootstore returned by [Root].
Blockstore() datastore.DAGStore
Blockstore() datastore.Blockstore

// Peerstore returns the peerstore where known host information is stored.
//
Expand Down Expand Up @@ -106,6 +106,11 @@ type Store interface {
// Backup holds the backup related methods that must be implemented by the database.
Backup

// P2P contains functions related to the P2P system.
//
// These functions are only useful if there is a configured network peer.
P2P

// AddSchema takes the provided GQL schema in SDL format, and applies it to the [Store],
// creating the necessary collections, request types, etc.
//
Expand Down
1 change: 1 addition & 0 deletions client/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ var (
ErrCanNotNormalizeValue = errors.New(errCanNotNormalizeValue)
ErrCanNotTurnNormalValueIntoArray = errors.New(errCanNotTurnNormalValueIntoArray)
ErrCanNotMakeNormalNilFromFieldKind = errors.New(errCanNotMakeNormalNilFromFieldKind)
ErrCollectionNotFound = errors.New(errCollectionNotFound)
)

// NewErrFieldNotExist returns an error indicating that the given field does not exist.
Expand Down
Loading

0 comments on commit ea77dc2

Please sign in to comment.