-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Relevant issue(s) Resolves #2893 This change adds ACP to pubsub KMS. A new event `MergeComplete` was introduced in order to make it correspond to `MergeCompleteName`. This is necessary to notify listeners that the merge was executed on decrypted blocks. Upon granting access to a document via `AddDocActorRelationship` we publish not `Update` event so that the actors that being given access to can now request a document anew. In testing framework `WaitForSync` is extended to allow specifying documents that should be received in decrypted state.
- Loading branch information
1 parent
6d6c9f2
commit 2f53878
Showing
18 changed files
with
972 additions
and
81 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
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,80 @@ | ||
// 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 db | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/sourcenetwork/immutable" | ||
|
||
"github.com/sourcenetwork/defradb/client" | ||
"github.com/sourcenetwork/defradb/internal/db/description" | ||
) | ||
|
||
// collectionRetriever is a helper struct that retrieves a collection from a document ID. | ||
type collectionRetriever struct { | ||
db client.DB | ||
} | ||
|
||
// NewCollectionRetriever creates a new CollectionRetriever. | ||
func NewCollectionRetriever(db client.DB) collectionRetriever { | ||
return collectionRetriever{ | ||
db: db, | ||
} | ||
} | ||
|
||
// RetrieveCollectionFromDocID retrieves a collection from a document ID. | ||
func (r collectionRetriever) RetrieveCollectionFromDocID( | ||
ctx context.Context, | ||
docID string, | ||
) (client.Collection, error) { | ||
ctx, txn, err := ensureContextTxn(ctx, r.db, false) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer txn.Discard(ctx) | ||
|
||
headIterator, err := NewHeadBlocksIteratorFromTxn(ctx, txn, docID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
hasValue, err := headIterator.Next() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if !hasValue { | ||
return nil, NewErrDocIDNotFound(docID) | ||
} | ||
|
||
schema, err := description.GetSchemaVersion(ctx, txn, headIterator.CurrentBlock().Delta.GetSchemaVersionID()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
cols, err := r.db.GetCollections( | ||
ctx, | ||
client.CollectionFetchOptions{ | ||
SchemaRoot: immutable.Some(schema.Root), | ||
}, | ||
) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if len(cols) == 0 { | ||
return nil, NewErrCollectionWithSchemaRootNotFound(schema.Root) | ||
} | ||
|
||
return cols[0], nil | ||
} |
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,104 @@ | ||
// 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 db | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ipfs/go-cid" | ||
|
||
"github.com/sourcenetwork/defradb/datastore" | ||
"github.com/sourcenetwork/defradb/internal/core" | ||
coreblock "github.com/sourcenetwork/defradb/internal/core/block" | ||
"github.com/sourcenetwork/defradb/internal/keys" | ||
"github.com/sourcenetwork/defradb/internal/merkle/clock" | ||
) | ||
|
||
// DocHeadBlocksIterator is an iterator that iterates over the head blocks of a document. | ||
type DocHeadBlocksIterator struct { | ||
ctx context.Context | ||
blockstore datastore.Blockstore | ||
cids []cid.Cid | ||
|
||
currentCid cid.Cid | ||
currentBlock *coreblock.Block | ||
currentRawBlock []byte | ||
} | ||
|
||
// NewHeadBlocksIterator creates a new DocHeadBlocksIterator. | ||
func NewHeadBlocksIterator( | ||
ctx context.Context, | ||
headstore datastore.DSReaderWriter, | ||
blockstore datastore.Blockstore, | ||
docID string, | ||
) (*DocHeadBlocksIterator, error) { | ||
headStoreKey := keys.HeadStoreKey{ | ||
DocID: docID, | ||
FieldID: core.COMPOSITE_NAMESPACE, | ||
} | ||
headset := clock.NewHeadSet(headstore, headStoreKey) | ||
cids, _, err := headset.List(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &DocHeadBlocksIterator{ | ||
ctx: ctx, | ||
blockstore: blockstore, | ||
cids: cids, | ||
}, nil | ||
} | ||
|
||
// NewHeadBlocksIteratorFromTxn creates a new DocHeadBlocksIterator from a transaction. | ||
func NewHeadBlocksIteratorFromTxn( | ||
ctx context.Context, | ||
txn datastore.Txn, | ||
docID string, | ||
) (*DocHeadBlocksIterator, error) { | ||
return NewHeadBlocksIterator(ctx, txn.Headstore(), txn.Blockstore(), docID) | ||
} | ||
|
||
// Next advances the iterator to the next block. | ||
func (h *DocHeadBlocksIterator) Next() (bool, error) { | ||
if len(h.cids) == 0 { | ||
return false, nil | ||
} | ||
nextCid := h.cids[0] | ||
h.cids = h.cids[1:] | ||
|
||
rawBlock, err := h.blockstore.Get(h.ctx, nextCid) | ||
if err != nil { | ||
return false, err | ||
} | ||
blk, err := coreblock.GetFromBytes(rawBlock.RawData()) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
h.currentCid = nextCid | ||
h.currentBlock = blk | ||
h.currentRawBlock = rawBlock.RawData() | ||
return true, nil | ||
} | ||
|
||
// CurrentCid returns the CID of the current block. | ||
func (h *DocHeadBlocksIterator) CurrentCid() cid.Cid { | ||
return h.currentCid | ||
} | ||
|
||
// CurrentBlock returns the current block. | ||
func (h *DocHeadBlocksIterator) CurrentBlock() *coreblock.Block { | ||
return h.currentBlock | ||
} | ||
|
||
// CurrentRawBlock returns the raw data of the current block. | ||
func (h *DocHeadBlocksIterator) CurrentRawBlock() []byte { | ||
return h.currentRawBlock | ||
} |
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.