-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for branchable collections (#3216)
## Relevant issue(s) Resolves #3038 ## Description Adds support for branchable collections. Does not add support for syncing the collection level commits via the P2P system (broken out, lots of people working in the space, significant changes required, I'm not so familiar with that part of the code so will take longer). This does mean that the somewhat surprising (to me at least) implementation of `Collection.Merge` is currently untested. Commits are queriable via the `commits` GQL queries. Time travel queries do not work due to an existing bug: #3214 - once that bug is fixed I expect there to be some more work (definitely testing) in order to get it to work with branchable collections. This is a breaking change due to the moving/namespacing of the existing document headstore keys.
- Loading branch information
1 parent
2f53878
commit 85bbdc0
Showing
49 changed files
with
1,718 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Add support for branchable collections | ||
|
||
The existing keys in the headstore gained a '/d' prefix in order to accommodate new types of keys within the headstore. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright 2024 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package crdt | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/sourcenetwork/defradb/internal/core" | ||
"github.com/sourcenetwork/defradb/internal/keys" | ||
) | ||
|
||
// Collection is a simple CRDT type that tracks changes to the contents of a | ||
// collection in a similar way to a document composite commit, only simpler, | ||
// without the need to track status and a simpler [Merge] function. | ||
type Collection struct { | ||
// schemaVersionKey is the schema version datastore key at the time of commit. | ||
// | ||
// It can be used to identify the collection datastructure state at the time of commit. | ||
schemaVersionKey keys.CollectionSchemaVersionKey | ||
} | ||
|
||
var _ core.ReplicatedData = (*Collection)(nil) | ||
|
||
func NewCollection(schemaVersionKey keys.CollectionSchemaVersionKey) *Collection { | ||
return &Collection{ | ||
schemaVersionKey: schemaVersionKey, | ||
} | ||
} | ||
|
||
func (c *Collection) Merge(ctx context.Context, other core.Delta) error { | ||
// Collection merges don't actually need to do anything, as the delta is empty, | ||
// and doc-level merges are handled by the document commits. | ||
return nil | ||
} | ||
|
||
func (c *Collection) NewDelta() *CollectionDelta { | ||
return &CollectionDelta{ | ||
SchemaVersionID: c.schemaVersionKey.SchemaVersionID, | ||
} | ||
} | ||
|
||
type CollectionDelta struct { | ||
Priority uint64 | ||
|
||
// As we do not yet have a global collection id we temporarily rely on the schema | ||
// version id for tracking which collection this belongs to. See: | ||
// https://github.com/sourcenetwork/defradb/issues/3215 | ||
SchemaVersionID string | ||
} | ||
|
||
var _ core.Delta = (*CollectionDelta)(nil) | ||
|
||
func (delta *CollectionDelta) IPLDSchemaBytes() []byte { | ||
return []byte(` | ||
type CollectionDelta struct { | ||
priority Int | ||
schemaVersionID String | ||
}`) | ||
} | ||
|
||
func (d *CollectionDelta) GetPriority() uint64 { | ||
return d.Priority | ||
} | ||
|
||
func (d *CollectionDelta) SetPriority(priority uint64) { | ||
d.Priority = priority | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.