Skip to content

Commit cb271b7

Browse files
committed
Merge branch 'master' into experiment-any-bson
2 parents 16f3640 + 0c85ece commit cb271b7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+3883
-1753
lines changed

.evergreen/config.yml

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ functions:
195195

196196
run-tests:
197197
- command: subprocess.exec
198-
type: test
199198
params:
200199
binary: bash
201200
env:
@@ -204,6 +203,7 @@ functions:
204203
args: [*task-runner, setup-test]
205204
- command: subprocess.exec
206205
type: test
206+
retry_on_failure: true
207207
params:
208208
binary: bash
209209
args: [*task-runner, "${DEFAULT_TASK}" ]
@@ -285,12 +285,21 @@ functions:
285285
echo "Response Body: $response_body"
286286
echo "HTTP Status: $http_status"
287287
288+
send-perf-pr-comment:
289+
- command: subprocess.exec
290+
type: test
291+
params:
292+
binary: bash
293+
env:
294+
VERSION_ID: ${version_id}
295+
include_expansions_in_env: [PERF_URI_PRIVATE_ENDPOINT]
296+
args: [*task-runner, perf-pr-comment]
297+
288298
run-enterprise-auth-tests:
289299
- command: ec2.assume_role
290300
params:
291301
role_arn: "${aws_test_secrets_role}"
292302
- command: subprocess.exec
293-
type: test
294303
params:
295304
binary: bash
296305
include_expansions_in_env: [AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN]
@@ -299,6 +308,7 @@ functions:
299308
args: [*task-runner, setup-test]
300309
- command: subprocess.exec
301310
type: test
311+
retry_on_failure: true
302312
params:
303313
binary: bash
304314
args: [*task-runner, --silent, evg-test-enterprise-auth]
@@ -308,7 +318,6 @@ functions:
308318
params:
309319
role_arn: "${aws_test_secrets_role}"
310320
- command: subprocess.exec
311-
type: test
312321
params:
313322
binary: bash
314323
include_expansions_in_env: [AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN]
@@ -317,6 +326,7 @@ functions:
317326
args: [*task-runner, setup-test]
318327
- command: subprocess.exec
319328
type: test
329+
retry_on_failure: true
320330
params:
321331
binary: bash
322332
args: [*task-runner, --silent, evg-test-enterprise-auth]
@@ -326,7 +336,6 @@ functions:
326336
params:
327337
role_arn: "${aws_test_secrets_role}"
328338
- command: subprocess.exec
329-
type: test
330339
params:
331340
binary: bash
332341
include_expansions_in_env: [AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN]
@@ -335,13 +344,13 @@ functions:
335344
args: [*task-runner, setup-test]
336345
- command: subprocess.exec
337346
type: test
347+
retry_on_failure: true
338348
params:
339349
binary: bash
340350
args: [*task-runner, test-atlas-connect]
341351

342352
run-ocsp-test:
343353
- command: subprocess.exec
344-
type: test
345354
params:
346355
binary: bash
347356
env:
@@ -352,14 +361,14 @@ functions:
352361
args: [*task-runner, setup-test]
353362
- command: subprocess.exec
354363
type: test
364+
retry_on_failure: true
355365
params:
356366
binary: bash
357367
include_expansions_in_env: [OCSP_TLS_SHOULD_SUCCEED]
358368
args: [*task-runner, evg-test-ocsp]
359369

360370
run-versioned-api-test:
361371
- command: subprocess.exec
362-
type: test
363372
params:
364373
binary: bash
365374
env:
@@ -369,13 +378,13 @@ functions:
369378
args: [*task-runner, setup-test]
370379
- command: subprocess.exec
371380
type: test
381+
retry_on_failure: true
372382
params:
373383
binary: bash
374384
args: [*task-runner, evg-test-versioned-api]
375385

376386
run-load-balancer-tests:
377387
- command: subprocess.exec
378-
type: test
379388
params:
380389
binary: bash
381390
include_expansions_in_env: [SINGLE_MONGOS_LB_URI, MULTI_MONGOS_LB_URI, AUTH, SSL, MONGO_GO_DRIVER_COMPRESSOR]
@@ -384,13 +393,13 @@ functions:
384393
args: [*task-runner, setup-test]
385394
- command: subprocess.exec
386395
type: test
396+
retry_on_failure: true
387397
params:
388398
binary: bash
389399
args: [*task-runner, evg-test-load-balancers]
390400

391401
run-atlas-data-lake-test:
392402
- command: subprocess.exec
393-
type: test
394403
params:
395404
binary: "bash"
396405
env:
@@ -401,6 +410,7 @@ functions:
401410
args: [*task-runner, setup-test]
402411
- command: subprocess.exec
403412
type: test
413+
retry_on_failure: true
404414
params:
405415
binary: "bash"
406416
args: [*task-runner, evg-test-atlas-data-lake]
@@ -572,7 +582,6 @@ functions:
572582

573583
run-kms-tls-test:
574584
- command: subprocess.exec
575-
type: test
576585
params:
577586
binary: "bash"
578587
env:
@@ -582,14 +591,14 @@ functions:
582591
args: [*task-runner, setup-test]
583592
- command: subprocess.exec
584593
type: test
594+
retry_on_failure: true
585595
params:
586596
binary: "bash"
587597
include_expansions_in_env: [KMS_TLS_TESTCASE]
588598
args: [*task-runner, evg-test-kms]
589599

590600
run-kmip-tests:
591601
- command: subprocess.exec
592-
type: test
593602
params:
594603
binary: "bash"
595604
env:
@@ -599,6 +608,7 @@ functions:
599608
args: [*task-runner, setup-test]
600609
- command: subprocess.exec
601610
type: test
611+
retry_on_failure: true
602612
params:
603613
binary: "bash"
604614
env:
@@ -607,7 +617,6 @@ functions:
607617

608618
run-retry-kms-requests:
609619
- command: subprocess.exec
610-
type: test
611620
params:
612621
binary: "bash"
613622
env:
@@ -617,6 +626,7 @@ functions:
617626
args: [*task-runner, setup-test]
618627
- command: subprocess.exec
619628
type: test
629+
retry_on_failure: true
620630
params:
621631
binary: "bash"
622632
env:
@@ -684,6 +694,7 @@ tasks:
684694
binary: bash
685695
args: [*task-runner, driver-benchmark]
686696
- func: send-perf-data
697+
- func: send-perf-pr-comment
687698

688699
- name: test-standalone-noauth-nossl
689700
tags: ["test", "standalone"]

Taskfile.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ tasks:
7070

7171
pr-task: bash etc/pr-task.sh
7272

73+
perf-pr-comment: bash etc/perf-pr-comment.sh
74+
7375
# Lint with various GOOS and GOARCH tasks to catch static analysis failures that may only affect
7476
# specific operating systems or architectures. For example, staticcheck will only check for 64-bit
7577
# alignment of atomically accessed variables on 32-bit architectures (see

bson/buffered_byte_src.go

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// Copyright (C) MongoDB, Inc. 2025-present.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
// not use this file except in compliance with the License. You may obtain
5+
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
package bson
8+
9+
import (
10+
"bytes"
11+
"io"
12+
)
13+
14+
// bufferedByteSrc implements the low-level byteSrc interface by reading
15+
// directly from an in-memory byte slice. It provides efficient, zero-copy
16+
// access for parsing BSON when the entire document is buffered in memory.
17+
type bufferedByteSrc struct {
18+
buf []byte // entire BSON document
19+
offset int64 // Current read index into buf
20+
}
21+
22+
var _ byteSrc = (*bufferedByteSrc)(nil)
23+
24+
// Read reads up to len(p) bytes from the in-memory buffer, advancing the offset
25+
// by the number of bytes read.
26+
func (b *bufferedByteSrc) readExact(p []byte) (int, error) {
27+
if b.offset >= int64(len(b.buf)) {
28+
return 0, io.EOF
29+
}
30+
n := copy(p, b.buf[b.offset:])
31+
b.offset += int64(n)
32+
return n, nil
33+
}
34+
35+
// ReadByte returns the single byte at buf[offset] and advances offset by 1.
36+
func (b *bufferedByteSrc) ReadByte() (byte, error) {
37+
if b.offset >= int64(len(b.buf)) {
38+
return 0, io.EOF
39+
}
40+
b.offset++
41+
return b.buf[b.offset-1], nil
42+
}
43+
44+
// peek returns buf[offset:offset+n] without advancing offset.
45+
func (b *bufferedByteSrc) peek(n int) ([]byte, error) {
46+
// Ensure we don't read past the end of the buffer.
47+
if int64(n)+b.offset > int64(len(b.buf)) {
48+
return b.buf[b.offset:], io.EOF
49+
}
50+
51+
// Return the next n bytes without advancing the offset
52+
return b.buf[b.offset : b.offset+int64(n)], nil
53+
}
54+
55+
// discard advances offset by n bytes, returning the number of bytes discarded.
56+
func (b *bufferedByteSrc) discard(n int) (int, error) {
57+
// Ensure we don't read past the end of the buffer.
58+
if int64(n)+b.offset > int64(len(b.buf)) {
59+
// If we have exceeded the buffer length, discard only up to the end.
60+
left := len(b.buf) - int(b.offset)
61+
b.offset = int64(len(b.buf))
62+
63+
return left, io.EOF
64+
}
65+
66+
// Advance the read position
67+
b.offset += int64(n)
68+
return n, nil
69+
}
70+
71+
// readSlice scans buf[offset:] for the first occurrence of delim, returns
72+
// buf[offset:idx+1], and advances offset past it; errors if delim not found.
73+
func (b *bufferedByteSrc) readSlice(delim byte) ([]byte, error) {
74+
// Ensure we don't read past the end of the buffer.
75+
if b.offset >= int64(len(b.buf)) {
76+
return nil, io.EOF
77+
}
78+
79+
// Look for the delimiter in the remaining bytes
80+
rem := b.buf[b.offset:]
81+
idx := bytes.IndexByte(rem, delim)
82+
if idx < 0 {
83+
return nil, io.EOF
84+
}
85+
86+
// Build the result slice up through the delimiter.
87+
result := rem[:idx+1]
88+
89+
// Advance the offset past the delimiter.
90+
b.offset += int64(idx + 1)
91+
92+
return result, nil
93+
}
94+
95+
// pos returns the current read position in the buffer.
96+
func (b *bufferedByteSrc) pos() int64 {
97+
return b.offset
98+
}
99+
100+
// regexLength will return the total byte length of a BSON regex value.
101+
func (b *bufferedByteSrc) regexLength() (int32, error) {
102+
rem := b.buf[b.offset:]
103+
104+
// Find end of the first C-string (pattern).
105+
i := bytes.IndexByte(rem, 0x00)
106+
if i < 0 {
107+
return 0, io.EOF
108+
}
109+
110+
// Find end of second C-string (options).
111+
j := bytes.IndexByte(rem[i+1:], 0x00)
112+
if j < 0 {
113+
return 0, io.EOF
114+
}
115+
116+
// Total length = first C-string length (pattern) + second C-string length
117+
// (options) + 2 null terminators
118+
return int32(i + j + 2), nil
119+
}
120+
121+
func (*bufferedByteSrc) streamable() bool {
122+
return false
123+
}
124+
125+
func (b *bufferedByteSrc) reset() {
126+
b.buf = nil
127+
b.offset = 0
128+
}

0 commit comments

Comments
 (0)