Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
orpheuslummis committed Jun 18, 2022
1 parent faa8917 commit 8432d99
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 68 deletions.
3 changes: 3 additions & 0 deletions cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

/*
Package cli provides the command line interface.
*/
package cli

import (
Expand Down
3 changes: 3 additions & 0 deletions cmd/genclidocs/genclidocs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

/*
genclidocs is a tool to generate the command line interface documentation.
*/
package main

import (
Expand Down
9 changes: 4 additions & 5 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func WithBroadcaster(bs corenet.Broadcaster) Option {
}
}

// NewDB creates a new instance of the DB using the given options
// NewDB creates a new instance of the DB using the given options.
func NewDB(ctx context.Context, rootstore ds.Batching, options ...Option) (client.DB, error) {
return newDB(ctx, rootstore, options...)
}
Expand Down Expand Up @@ -132,7 +132,7 @@ func (db *db) Root() ds.Batching {
return db.rootstore
}

// Blockstore returns the internal DAG store which contains IPLD blocks
// Blockstore returns the internal DAG store which contains IPLD blocks.
func (db *db) Blockstore() blockstore.Blockstore {
return db.multistore.DAGstore()
}
Expand All @@ -142,7 +142,7 @@ func (db *db) systemstore() datastore.DSReaderWriter {
}

// Initialize is called when a database is first run and creates all the db global meta data
// like Collection ID counters
// like Collection ID counters.
func (db *db) initialize(ctx context.Context) error {
db.glock.Lock()
defer db.glock.Unlock()
Expand Down Expand Up @@ -197,8 +197,7 @@ func (db *db) GetRelationshipIdField(fieldName, targetType, thisType string) (st
}

// Close is called when we are shutting down the database.
// This is the place for any last minute cleanup or releaseing
// of resources (IE: Badger instance)
// This is the place for any last minute cleanup or releasing of resources (i.e.: Badger instance).
func (db *db) Close(ctx context.Context) {
log.Info(ctx, "Closing DefraDB process...")
err := db.rootstore.Close()
Expand Down
11 changes: 4 additions & 7 deletions merkle/crdt/composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,15 @@ func init() {
}
}

// MerkleCompositeDAG is a MerkleCRDT implementation of the CompositeDAG
// using MerkleClocks
// MerkleCompositeDAG is a MerkleCRDT implementation of the CompositeDAG using MerkleClocks.
type MerkleCompositeDAG struct {
*baseMerkleCRDT
// core.ReplicatedData
reg corecrdt.CompositeDAG
}

// NewMerkleCompositeDAG creates a new instance (or loaded from DB) of a MerkleCRDT
// backed by a CompositeDAG CRDT
// backed by a CompositeDAG CRDT.
func NewMerkleCompositeDAG(
datastore datastore.DSReaderWriter,
headstore datastore.DSReaderWriter,
Expand All @@ -87,9 +86,7 @@ func NewMerkleCompositeDAG(
}
}

// Set sets the values of CompositeDAG.
// The value is always the object from the
// mutation operations.
// Set sets the values of CompositeDAG. The value is always the object from the mutation operations.
func (m *MerkleCompositeDAG) Set(
ctx context.Context,
patch []byte,
Expand All @@ -107,7 +104,7 @@ func (m *MerkleCompositeDAG) Set(
return c, m.Broadcast(ctx, nd, delta)
}

// Value is a no-op for a CompositeDAG
// Value is a no-op for a CompositeDAG.
func (m *MerkleCompositeDAG) Value(ctx context.Context) ([]byte, error) {
return m.reg.Value(ctx)
}
Expand Down
26 changes: 13 additions & 13 deletions merkle/crdt/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ var (
ErrFactoryTypeNoExist = errors.New("No such factory for the given type exists")
)

// MerkleCRDTInitFn instantiates a MerkleCRDT with a given key
// MerkleCRDTInitFn instantiates a MerkleCRDT with a given key.
type MerkleCRDTInitFn func(core.DataStoreKey) MerkleCRDT

// MerkleCRDTFactory instantiates a MerkleCRDTInitFn with a MultiStore
// returns a MerkleCRDTInitFn with all the necessary stores set
// MerkleCRDTFactory instantiates a MerkleCRDTInitFn with a MultiStore.
// Returns a MerkleCRDTInitFn with all the necessary stores set.
type MerkleCRDTFactory func(
mstore datastore.MultiStore,
schemaID string,
Expand All @@ -36,7 +36,7 @@ type MerkleCRDTFactory func(

// Factory is a helper utility for instantiating new MerkleCRDTs.
// It removes some of the overhead of having to coordinate all the various
// store parameters on every single new MerkleCRDT creation
// store parameters on every single new MerkleCRDT creation.
type Factory struct {
crdts map[client.CType]*MerkleCRDTFactory
multistore datastore.MultiStore
Expand All @@ -50,7 +50,7 @@ var (
)

// NewFactory returns a newly instanciated factory object with the assigned stores
// It may be called with all stores set to nil
// It may be called with all stores set to nil.
func NewFactory(multistore datastore.MultiStore) *Factory {
return &Factory{
crdts: make(map[client.CType]*MerkleCRDTFactory),
Expand All @@ -66,7 +66,7 @@ func (factory *Factory) Register(t client.CType, fn *MerkleCRDTFactory) error {
}

// Instance and execute the registered factory function for a given MerkleCRDT type
// supplied with all the current stores (passed in as a datastore.MultiStore object)
// supplied with all the current stores (passed in as a datastore.MultiStore object).
func (factory Factory) Instance(
schemaID string,
bs corenet.Broadcaster,
Expand Down Expand Up @@ -107,48 +107,48 @@ func (factory Factory) getRegisteredFactory(t client.CType) (*MerkleCRDTFactory,
return fn, nil
}

// SetStores sets all the current stores on the Factory in one call
// SetStores sets all the current stores on the Factory in one call.
func (factory *Factory) SetStores(multistore datastore.MultiStore) error {
factory.multistore = multistore
return nil
}

// WithStores returns a new instance of the Factory with all the stores set
// WithStores returns a new instance of the Factory with all the stores set.
func (factory Factory) WithStores(multistore datastore.MultiStore) Factory {
factory.multistore = multistore
return factory
}

// Rootstore impements MultiStore
// Rootstore impements MultiStore.
func (factory Factory) Rootstore() datastore.DSReaderWriter {
return nil
}

// Data implements datastore.MultiStore and returns the current Datastore
// Data implements datastore.MultiStore and returns the current Datastore.
func (factory Factory) Datastore() datastore.DSReaderWriter {
if factory.multistore == nil {
return nil
}
return factory.multistore.Datastore()
}

// Head implements datastore.MultiStore and returns the current Headstore
// Head implements datastore.MultiStore and returns the current Headstore.
func (factory Factory) Headstore() datastore.DSReaderWriter {
if factory.multistore == nil {
return nil
}
return factory.multistore.Headstore()
}

// Head implements datastore.MultiStore and returns the current Headstore
// Head implements datastore.MultiStore and returns the current Headstore.
func (factory Factory) Systemstore() datastore.DSReaderWriter {
if factory.multistore == nil {
return nil
}
return factory.multistore.Systemstore()
}

// Dag implements datastore.MultiStore and returns the current Dagstore
// Dag implements datastore.MultiStore and returns the current Dagstore.
func (factory Factory) DAGstore() datastore.DAGStore {
if factory.multistore == nil {
return nil
Expand Down
11 changes: 5 additions & 6 deletions merkle/crdt/lwwreg.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ func init() {
}
}

// MerkleLWWRegister is a MerkleCRDT implementation of the LWWRegister
// using MerkleClocks
// MerkleLWWRegister is a MerkleCRDT implementation of the LWWRegister using MerkleClocks.
type MerkleLWWRegister struct {
*baseMerkleCRDT
// core.ReplicatedData
Expand All @@ -58,7 +57,7 @@ type MerkleLWWRegister struct {
}

// NewMerkleLWWRegister creates a new instance (or loaded from DB) of a MerkleCRDT
// backed by a LWWRegister CRDT
// backed by a LWWRegister CRDT.
func NewMerkleLWWRegister(
datastore datastore.DSReaderWriter,
headstore datastore.DSReaderWriter,
Expand All @@ -78,7 +77,7 @@ func NewMerkleLWWRegister(
}
}

// Set the value of the register
// Set the value of the register.
func (mlwwreg *MerkleLWWRegister) Set(ctx context.Context, value []byte) (cid.Cid, error) {
// Set() call on underlying LWWRegister CRDT
// persist/publish delta
Expand All @@ -87,13 +86,13 @@ func (mlwwreg *MerkleLWWRegister) Set(ctx context.Context, value []byte) (cid.Ci
return c, err
}

// Value will retrieve the current value from the db
// Value will retrieve the current value from the db.
func (mlwwreg *MerkleLWWRegister) Value(ctx context.Context) ([]byte, error) {
return mlwwreg.reg.Value(ctx)
}

// Merge writes the provided delta to state using a supplied
// merge semantic
// merge semantic.
func (mlwwreg *MerkleLWWRegister) Merge(ctx context.Context, other core.Delta, id string) error {
return mlwwreg.reg.Merge(ctx, other, id)
}
8 changes: 3 additions & 5 deletions merkle/crdt/merklecrdt.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ var (
_ core.ReplicatedData = (*baseMerkleCRDT)(nil)
)

// The baseMerkleCRDT handles the merkle crdt overhead functions
// that aren't CRDT specific like the mutations and state retrieval
// functions. It handles creating and publishing the crdt DAG with
// the help of the MerkleClock
// baseMerkleCRDT handles the MerkleCRDT overhead functions that aren't CRDT specific like the mutations and state
// retrieval functions. It handles creating and publishing the CRDT DAG with the help of the MerkleClock.
type baseMerkleCRDT struct {
clock core.MerkleClock
crdt core.ReplicatedData
Expand Down Expand Up @@ -71,7 +69,7 @@ func (base *baseMerkleCRDT) ID() string {
return base.crdt.ID()
}

// Publishes the delta to state
// Publishes the delta to state.
func (base *baseMerkleCRDT) Publish(
ctx context.Context,
delta core.Delta,
Expand Down
42 changes: 10 additions & 32 deletions net/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,20 @@
// limitations under the License.

/*
Package net provides p2p network functions for the core DefraDB
instance.
Package net provides p2p network functions for the core DefraDB instance.
Notable design descision. All DocKeys (Documents) have their own
respective PubSub topics.
Notable design descision: all DocKeys (Documents) have their own respective PubSub topics.
@todo: Needs review/scrutiny.
Its structured as follows.
We define a Peer object, which encapsulates an instanciated DB
objects, libp2p host object, libp2p DAGService.
- Peer is responsible for storing all network related meta-data,
maintaining open connections, pubsub mechanics, etc.
- Peer object also contains a Server instance
type Peer struct {
config
The Peer object encapsulates an instanciated DB objects, libp2p host object, libp2p DAGService.
Peer is responsible for storing all network related meta-data, maintaining open connections, pubsub mechanics, etc.
The Peer object also contains a Server instance.
DAGService
libp2pHost
The Server object is responsible for all underlying gRPC related functions and as it relates to the pubsub network.
db client.DB
Credit: Some of the base structure of this net package and its types is inspired/inherited from
Textile Threads (github.com/textileio/go-threads). As such, we are omitting copyright on this "net" package
and will release this folder under the Apache 2.0 license as per the header of each file.
context???
}
Server object is responsible for all underlying gRPC related
functions and as it relates to the pubsub network.
Credit: Some of the base structure of this net package and its
types is inspired/inherited from Textile Threads
(github.com/textileio/go-threads). As such, we are omitting
copyright on this "net" package and will release this folder
under the Apache 2.0 license as per the header of each file.
@todo: Needs review/scrutiny.
*/

package net

0 comments on commit 8432d99

Please sign in to comment.