Skip to content

Commit

Permalink
GODRIVER-2859 [master] Add search index management helpers (#1396)
Browse files Browse the repository at this point in the history
Co-authored-by: Qingyang Hu <103950869+qingyang-hu@users.noreply.github.com>
  • Loading branch information
blink1073 and qingyang-hu authored Sep 25, 2023
1 parent d8f19ab commit 738d3bb
Show file tree
Hide file tree
Showing 24 changed files with 2,504 additions and 8 deletions.
71 changes: 67 additions & 4 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,17 @@ functions:
params:
file: lb-expansion.yml

run-search-index-tests:
- command: shell.exec
type: test
params:
shell: "bash"
working_dir: src/go.mongodb.org/mongo-driver
script: |
${PREPARE_SHELL}
TEST_INDEX_URI="${TEST_INDEX_URI}" \
make evg-test-search-index
stop-load-balancer:
- command: shell.exec
params:
Expand Down Expand Up @@ -2259,6 +2270,14 @@ tasks:
${PREPARE_SHELL}
./.evergreen/run-deployed-lambda-aws-tests.sh
- name: "test-search-index"
commands:
- func: "bootstrap-mongo-orchestration"
vars:
VERSION: "latest"
TOPOLOGY: "replica_set"
- func: "run-search-index-tests"

axes:
- id: version
display_name: MongoDB Version
Expand Down Expand Up @@ -2314,7 +2333,7 @@ axes:
VENV_BIN_DIR: "Scripts"
- id: "rhel87-64-go-1-20"
display_name: "RHEL 8.7"
run_on: rhel8.7-large
run_on: rhel8.7-large
variables:
GO_DIST: "/opt/golang/go1.20"
- id: "macos11-go-1-20"
Expand Down Expand Up @@ -2618,6 +2637,44 @@ task_groups:
tasks:
- test-aws-lambda-deployed

- name: test-search-index-task-group
setup_group:
- func: fetch-source
- func: prepare-resources
- command: subprocess.exec
params:
working_dir: src/go.mongodb.org/mongo-driver
binary: bash
add_expansions_to_env: true
env:
MONGODB_VERSION: "7.0"
args:
- ${DRIVERS_TOOLS}/.evergreen/atlas/setup-atlas-cluster.sh
- command: expansions.update
params:
file: src/go.mongodb.org/mongo-driver/atlas-expansion.yml
- command: shell.exec
params:
working_dir: src/go.mongodb.org/mongo-driver
shell: bash
script: |-
echo "TEST_INDEX_URI: ${MONGODB_URI}" > atlas-expansion.yml
- command: expansions.update
params:
file: src/go.mongodb.org/mongo-driver/atlas-expansion.yml
teardown_group:
- command: subprocess.exec
params:
working_dir: src/go.mongodb.org/mongo-driver
binary: bash
add_expansions_to_env: true
args:
- ${DRIVERS_TOOLS}/.evergreen/atlas/teardown-atlas-cluster.sh
setup_group_can_fail_task: true
setup_group_timeout_secs: 1800
tasks:
- test-search-index

buildvariants:
- name: static-analysis
display_name: "Static Analysis"
Expand Down Expand Up @@ -2645,11 +2702,11 @@ buildvariants:
GO_DIST: "/opt/golang/go1.20"
tasks:
- name: ".compile-check"

- name: atlas-test
display_name: "Atlas test"
run_on:
- rhel8.7-large
- rhel8.7-large
expansions:
GO_DIST: "/opt/golang/go1.20"
tasks:
Expand All @@ -2658,7 +2715,7 @@ buildvariants:
- name: atlas-data-lake-test
display_name: "Atlas Data Lake Test"
run_on:
- rhel8.7-large
- rhel8.7-large
expansions:
GO_DIST: "/opt/golang/go1.20"
tasks:
Expand Down Expand Up @@ -2766,6 +2823,12 @@ buildvariants:
tasks:
- test-aws-lambda-task-group

- matrix_name: "searchindex-test"
matrix_spec: { version: ["7.0"], os-faas-80: ["rhel87-large-go-1-20"] }
display_name: "Search Index ${version} ${os-faas-80}"
tasks:
- test-search-index-task-group

- name: testgcpkms-variant
display_name: "GCP KMS"
run_on:
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ evg-test-load-balancers:
go test $(BUILD_TAGS) ./mongo/integration -run TestLoadBalancerSupport -v -timeout $(TEST_TIMEOUT)s >> test.suite
go test $(BUILD_TAGS) ./mongo/integration/unified -run TestUnifiedSpec -v -timeout $(TEST_TIMEOUT)s >> test.suite

.PHONY: evg-test-search-index
evg-test-search-index:
go test ./mongo/integration -run TestSearchIndexProse -v -timeout $(TEST_TIMEOUT)s >> test.suite

.PHONY: evg-test-ocsp
evg-test-ocsp:
go test -v ./mongo -run TestOCSP $(OCSP_TLS_SHOULD_SUCCEED) >> test.suite
Expand Down
11 changes: 9 additions & 2 deletions bson/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,19 @@ func (r Raw) LookupErr(key ...string) (RawValue, error) {
// elements. If the document is not valid, the elements up to the invalid point will be returned
// along with an error.
func (r Raw) Elements() ([]RawElement, error) {
elems, err := bsoncore.Document(r).Elements()
doc := bsoncore.Document(r)
if len(doc) == 0 {
return nil, nil
}
elems, err := doc.Elements()
if err != nil {
return nil, err
}
relems := make([]RawElement, 0, len(elems))
for _, elem := range elems {
relems = append(relems, RawElement(elem))
}
return relems, err
return relems, nil
}

// Values returns this document as a slice of values. The returned slice will contain valid values.
Expand Down
7 changes: 7 additions & 0 deletions mongo/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -1773,6 +1773,13 @@ func (coll *Collection) Indexes() IndexView {
return IndexView{coll: coll}
}

// SearchIndexes returns a SearchIndexView instance that can be used to perform operations on the search indexes for the collection.
func (coll *Collection) SearchIndexes() SearchIndexView {
return SearchIndexView{
coll: coll,
}
}

// Drop drops the collection on the server. This method ignores "namespace not found" errors so it is safe to drop
// a collection that does not exist on the server.
func (coll *Collection) Drop(ctx context.Context) error {
Expand Down
Loading

0 comments on commit 738d3bb

Please sign in to comment.