Skip to content

Commit

Permalink
Merge branch 'develop' into dependabot/go_modules/github.com/cosmos/c…
Browse files Browse the repository at this point in the history
…osmos-sdk-0.50.12
  • Loading branch information
shahzadlone authored Feb 22, 2025
2 parents a564c40 + 595b9f5 commit 49741f1
Show file tree
Hide file tree
Showing 25 changed files with 301 additions and 151 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
# Required: the version of golangci-lint is required.
# Note: The version should not pick the patch version as the latest patch
# version is what will always be used.
version: v1.61
version: v1.64

# Optional: working directory, useful for monorepos or if we wanted to run this
# on a non-root directory.
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
if: matrix.os == 'ubuntu-latest'
uses: actions/cache/save@v4
with:
path: dist/linux_amd64_v1
path: dist/linux_amd64
key: linux-${{ env.sha_short }}

- name: Save cache on MacOS
Expand All @@ -81,7 +81,7 @@ jobs:
if: matrix.os == 'windows-latest'
uses: actions/cache/save@v4
with:
path: dist/windows_amd64_v1
path: dist/windows_amd64
key: windows-${{ env.sha_short }}
enableCrossOsArchive: true

Expand Down Expand Up @@ -113,7 +113,7 @@ jobs:
id: restore-linux
uses: actions/cache/restore@v4
with:
path: dist/linux_amd64_v1
path: dist/linux_amd64
key: linux-${{ env.sha_short }}
fail-on-cache-miss: true

Expand All @@ -129,7 +129,7 @@ jobs:
id: restore-windows
uses: actions/cache/restore@v4
with:
path: dist/windows_amd64_v1
path: dist/windows_amd64
key: windows-${{ env.sha_short }}
fail-on-cache-miss: true
enableCrossOsArchive: true
Expand Down
57 changes: 7 additions & 50 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,18 @@ before:
- make deps:playground

builds:
- id: "defradb"
main: ./cmd/defradb
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
# A build with the playground included.
- id: "defradb_playground"
main: ./cmd/defradb
flags:
- -tags=playground
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
# A build with telemetry included.
- id: "defradb_telemetry"
# Minimal build with no extras
- id: "defradb_lite"
main: ./cmd/defradb
flags:
- -tags=telemetry
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
# A build with the playground and telemetry included.
- id: "defradb_playground_telemetry"
# Default build with playground and telemetry
- id: "defradb"
main: ./cmd/defradb
flags:
- -tags=playground,telemetry
Expand All @@ -56,13 +33,13 @@ partial:
by: target

archives:
- id: defradb_playground
- id: defradb_lite
builds:
- defradb_playground
- defradb_lite
formats: [binary]
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
{{ .Binary }}_playground_{{ .Version }}_{{ .Os }}_
{{ .Binary }}_lite_{{ .Version }}_{{ .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
Expand All @@ -76,26 +53,6 @@ archives:
{{- if eq .Arch "amd64" }}x86_64
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
- id: defradb_telemetry
builds:
- defradb_telemetry
formats: [binary]
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
{{ .Binary }}_telemetry_{{ .Version }}_{{ .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
- id: defradb_playground_telemetry
builds:
- defradb_playground_telemetry
formats: [binary]
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
{{ .Binary }}_playground_telemetry_{{ .Version }}_{{ .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
release:
target_commitish: '{{ .Commit }}'
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ client\:add-schema:

.PHONY: deps\:lint-go
deps\:lint-go:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.64

.PHONY: deps\:lint-yaml
deps\:lint-yaml:
Expand Down
18 changes: 9 additions & 9 deletions cli/collection_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,13 @@ func MakeCollectionUpdateCommand() *cobra.Command {
var filter string
var updater string
var cmd = &cobra.Command{
Use: "update [-i --identity] [--filter <filter> --docID <docID> --updater <updater>] <document>",
Use: "update [-i --identity] [--filter <filter> --docID <docID>] --updater <updater>",
Short: "Update documents by docID or filter.",
Long: `Update documents by docID or filter.
Example: update from string:
defradb client collection update --name User --docID bae-123 '{ "name": "Bob" }'
Example: update by filter:
defradb client collection update --name User \
--filter '{ "_gte": { "points": 100 } }' --updater '{ "verified": true }'
--filter '{ "points": { "_gte": 100 } }' --updater '{ "verified": true }'
Example: update by docID:
defradb client collection update --name User \
Expand All @@ -42,15 +39,18 @@ Example: update private docID, with identity:
defradb client collection update -i 028d53f37a19afb9a0dbc5b4be30c65731479ee8cfa0c9bc8f8bf198cc3c075f --name User \
--docID bae-123 --updater '{ "verified": true }'
`,
Args: cobra.RangeArgs(0, 1),
RunE: func(cmd *cobra.Command, args []string) error {
col, ok := tryGetContextCollection(cmd)
if !ok {
return cmd.Usage()
}

if updater == "" {
return NewErrMissingRequiredFlag("updater")
}

switch {
case filter != "" || updater != "":
case filter != "":
var filterValue any
if err := json.Unmarshal([]byte(filter), &filterValue); err != nil {
return err
Expand All @@ -60,7 +60,7 @@ Example: update private docID, with identity:
return err
}
return writeJSON(cmd, res)
case argDocID != "" && len(args) == 1:
case argDocID != "":
docID, err := client.NewDocIDFromString(argDocID)
if err != nil {
return err
Expand All @@ -69,7 +69,7 @@ Example: update private docID, with identity:
if err != nil {
return err
}
if err := doc.SetWithJSON([]byte(args[0])); err != nil {
if err := doc.SetWithJSON([]byte(updater)); err != nil {
return err
}
return col.Update(cmd.Context(), doc)
Expand Down
5 changes: 5 additions & 0 deletions cli/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
errInvalidAscensionOrder string = "invalid order: expected ASC or DESC"
errInvalidInxedFieldDescription string = "invalid or malformed field description"
errEmptySchemaString string = "schema cannot be empty"
errMissingRequiredFlag string = "missing required flag"
)

var (
Expand Down Expand Up @@ -79,3 +80,7 @@ func NewErrFailedToReadSchemaFromStdin(inner error) error {
func NewErrFailedToAddSchema(inner error) error {
return errors.Wrap("failed to add schema", inner)
}

func NewErrMissingRequiredFlag(flag string) error {
return errors.New(errMissingRequiredFlag, errors.NewKV("Flag", flag))
}
2 changes: 2 additions & 0 deletions docs/data_format_changes/i3477-version-query-consistency.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Consistent version query semantics
Updated semantics for commit/version/time-travel queries when using both DocID and CID.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ Update documents by docID or filter.
### Synopsis

Update documents by docID or filter.

Example: update from string:
defradb client collection update --name User --docID bae-123 '{ "name": "Bob" }'

Example: update by filter:
defradb client collection update --name User \
--filter '{ "_gte": { "points": 100 } }' --updater '{ "verified": true }'
--filter '{ "points": { "_gte": 100 } }' --updater '{ "verified": true }'

Example: update by docID:
defradb client collection update --name User \
Expand All @@ -23,7 +20,7 @@ Example: update private docID, with identity:


```
defradb client collection update [-i --identity] [--filter <filter> --docID <docID> --updater <updater>] <document> [flags]
defradb client collection update [-i --identity] [--filter <filter> --docID <docID>] --updater <updater> [flags]
```

### Options
Expand Down
2 changes: 2 additions & 0 deletions internal/db/collection_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ func (c *collection) makeSelectionPlan(
}
case immutable.Option[request.Filter]:
f = fval
case map[string]any:
f = immutable.Some(request.Filter{Conditions: fval})
default:
return nil, ErrInvalidFilter
}
Expand Down
51 changes: 40 additions & 11 deletions internal/planner/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/client/request"
"github.com/sourcenetwork/defradb/errors"
"github.com/sourcenetwork/defradb/internal/core"
coreblock "github.com/sourcenetwork/defradb/internal/core/block"
"github.com/sourcenetwork/defradb/internal/db/fetcher"
Expand Down Expand Up @@ -84,7 +85,11 @@ func (n *dagScanNode) Init() error {
}
}

return n.fetcher.Start(n.planner.ctx, n.planner.txn, n.prefix, n.commitSelect.FieldID)
// only need the head fetcher for non cid specific queries
if !n.commitSelect.Cid.HasValue() {
return n.fetcher.Start(n.planner.ctx, n.planner.txn, n.prefix, n.commitSelect.FieldID)
}
return nil
}

func (n *dagScanNode) Start() error {
Expand Down Expand Up @@ -123,7 +128,10 @@ func (n *dagScanNode) Prefixes(prefixes []keys.Walkable) {
}

func (n *dagScanNode) Close() error {
return n.fetcher.Close()
if !n.commitSelect.Cid.HasValue() {
return n.fetcher.Close()
}
return nil
}

func (n *dagScanNode) Source() planNode { return nil }
Expand Down Expand Up @@ -183,7 +191,14 @@ func (n *dagScanNode) Next() (bool, error) {
if len(n.queuedCids) > 0 {
currentCid = n.queuedCids[0]
n.queuedCids = n.queuedCids[1:(len(n.queuedCids))]
} else {
} else if n.commitSelect.Cid.HasValue() && len(n.visitedNodes) == 0 {
cid, err := cid.Parse(n.commitSelect.Cid.Value())
if err != nil {
return false, err
}

currentCid = &cid
} else if !n.commitSelect.Cid.HasValue() {
cid, err := n.fetcher.FetchNext()
if err != nil || cid == nil {
return false, err
Expand All @@ -192,6 +207,8 @@ func (n *dagScanNode) Next() (bool, error) {
currentCid = cid
// Reset the depthVisited for each head yielded by headset
n.depthVisited = 0
} else {
return false, nil
}

// skip already visited CIDs
Expand All @@ -207,7 +224,7 @@ func (n *dagScanNode) Next() (bool, error) {
// clear the cid after
block, err := store.Get(n.planner.ctx, *currentCid)
if err != nil {
return false, err
return false, errors.Join(ErrMissingCID, err)
}

dagBlock, err := coreblock.GetFromBytes(block.RawData())
Expand All @@ -220,6 +237,18 @@ func (n *dagScanNode) Next() (bool, error) {
return false, err
}

// if this is a time travel query or a latestCommits
// (cid + undefined depth + docId) then we need to make sure the
// target block actually belongs to the doc, since we are
// bypassing the HeadFetcher for the first cid
currentDocID := n.commitSelect.DocumentMapping.FirstOfName(currentValue, request.DocIDArgName)
if n.commitSelect.Cid.HasValue() &&
len(n.visitedNodes) == 0 &&
n.commitSelect.DocID.HasValue() &&
currentDocID != n.commitSelect.DocID.Value() {
return false, ErrIncorrectCIDForDocId
}

// the dagscan node can traverse into the merkle dag
// based on the specified depth limit.
// The default query operation 'latestCommit' only cares about
Expand All @@ -230,7 +259,13 @@ func (n *dagScanNode) Next() (bool, error) {
// HEAD paths.
n.depthVisited++
n.visitedNodes[currentCid.String()] = true // mark the current node as "visited"
if !n.commitSelect.Depth.HasValue() || n.depthVisited < n.commitSelect.Depth.Value() {

// the default behavior for depth is:
// doc ID, max depth
// just doc ID + CID, 0 depth
// doc ID + CID + depth, use depth
if (!n.commitSelect.Depth.HasValue() && !n.commitSelect.Cid.HasValue()) ||
(n.commitSelect.Depth.HasValue() && n.depthVisited < n.commitSelect.Depth.Value()) {
// Insert the newly fetched cids into the slice of queued items, in reverse order
// so that the last new cid will be at the front of the slice
n.queuedCids = append(make([]*cid.Cid, len(dagBlock.Heads)), n.queuedCids...)
Expand All @@ -240,12 +275,6 @@ func (n *dagScanNode) Next() (bool, error) {
}
}

if n.commitSelect.Cid.HasValue() && currentCid.String() != n.commitSelect.Cid.Value() {
// If a specific cid has been requested, and the current item does not
// match, keep searching.
return n.Next()
}

n.currentValue = currentValue
return true, nil
}
Expand Down
2 changes: 2 additions & 0 deletions internal/planner/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ var (
ErrUnknownExplainRequestType = errors.New("can not explain request of unknown type")
ErrUpsertMultipleDocuments = errors.New("cannot upsert multiple matching documents")
ErrMismatchLengthOnSimilarity = errors.New("source and vector must be of the same length")
ErrIncorrectCIDForDocId = errors.New("cid does not belong to document")
ErrMissingCID = errors.New("missing cid")
)

func NewErrUnknownDependency(name string) error {
Expand Down
1 change: 1 addition & 0 deletions internal/planner/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var (
_ explainablePlanNode = (*typeIndexJoin)(nil)
_ explainablePlanNode = (*updateNode)(nil)
_ explainablePlanNode = (*upsertNode)(nil)
_ explainablePlanNode = (*similarityNode)(nil)
)

const (
Expand Down
Loading

0 comments on commit 49741f1

Please sign in to comment.