mirror of
https://github.com/rustfs/rustfs.git
synced 2026-11-23 16:38:49 +00:00
9e57f83885
* perf(ecstore): reduce allocations for bounded bitrot frames * test(s3): cover dynamic block layouts over HTTP * perf: measure quantized range read shape * chore: checkpoint quantized read metrics draft Save work in progress for collaboration. Counts omit retired readers and transient or cancelled hedges. Frame semantics, async recorder coverage and disabled-metrics overhead remain unresolved; these counters are not ready for performance conclusions. Validation: rustfmt and ecstore check passed; io-metrics 120, quantized 4 and hashed-read 3 tests passed. No new live or performance validation. * perf(ecstore): reduce dynamic layout read overhead * fix(ecstore): avoid prefetching conservative short range tails * perf(ecstore): compact deferred shard reader state * perf(ecstore): include shard checksums in file buffer cap * fix(ecstore): preserve bounded quantum frames during heal * perf(ecstore): reuse owned quantized frame batches * perf(ecstore): batch q reads and retain shared copy framing * fix(ecstore): preserve typed quantized read errors * perf(ecstore): avoid zero-fill and serial copies in local batch reads The local batch reader zero-initialized every window at a nonzero offset before reading it, and copied every shard serially inside one blocking task. Two-segment q-window range reads (cross-shard, cross-block) pay both costs twice per request. Read each window with a positioned read into uninitialized Vec capacity, and dispatch each shard separately when every window is at least 512 KiB, where copies dominate blocking-pool round trips. Smaller windows keep one coalesced dispatch. * perf(ecstore): keep readahead pipelined for local batch windows A single window-sized pread on cold pages waits on each kernel readahead chunk in turn. Seek to the window start and fill the buffer with read_to_end over a length-limited reader instead: it still reads into uninitialized spare capacity, but its growing sequential reads keep readahead pipelined. Warm windows cost the same. * Revert "perf(ecstore): keep readahead pipelined for local batch windows" This reverts commitc252fca525. On the ESSD-backed cloud footprint, the growing read_to_end reads were slower than one window-sized positioned read for cold windows at nonzero offsets (cross-block -27% on 4 MiB layouts, cross-shard -21% on 64 KiB layouts versus the previous batch reader). The local benchmark that motivated the change ran on a WSL virtual disk and did not represent the target storage. Keep the single positioned read into spare capacity and the per-shard dispatch for large windows. * perf(ecstore): choose the batch read method by window size Measured on ESSD-backed cloud storage, a cold window of about 1 MiB is fastest as one positioned read, which completes as a single device request, while windows of 2 MiB and more are faster with growing sequential reads that keep readahead pipelined (one large read waits on each readahead chunk in turn). Use one positioned read up to 1.5 MiB and a seek plus length-limited read_to_end above it. Both paths read into uninitialized spare capacity; per-shard dispatch for large windows is unchanged. * perf(ecstore): read local batch windows with an exact readahead hint Kernel readahead sizes its first request from the read size. A cold 16 KiB window at offset 0 pulled 64-128 KiB, and a single 2 MiB read was split into serial readahead chunks that cached almost twice the window, which is why neither the single positioned read nor growing sequential reads won for every window size on block storage. Announce each window with POSIX_FADV_WILLNEED, which submits exactly the window at once, and then fill the exact spare capacity with positioned reads. This replaces the size-based choice between the two read methods. The hint is advisory and its failure does not fail the read. A residency test checks that cold reads cache only their window; it failed with the hint disabled (a 5-page window cached 32 pages). * perf(ecstore): use half-shard read quantum at 1 MiB EC layout * revert(release): defer certification rollout for 1.0.5 (#9254) Reverte5563e6004only on release/1.0.5. Its trusted verifier workflow and immutable-candidate integration are not available yet. Restore the previous publication path under the approved release policy; retain the completed product regression and preview acceptance requirements. * fix(ecstore): preserve legacy full-shard framing for default 1 MiB layout * perf(ecstore): enable direct-memory GET and coalesce cross-shard range reads for bounded-quantum blocks * chore(ecstore): remove unused schedule_bitrot_reader_task wrapper * fix(ecstore): run delete-recovery discovery off the metadata lane Bucket-wide delete-recovery discovery starts with the server and walks the whole bucket tree in pages of up to 4096 entries, one lstat per entry. Each page ran on the per-disk namespace queue's foreground lane, which has a single worker and also serves GET metadata reads. On a cold tree a page holds that worker for hundreds of milliseconds, so every GET on the disk waits behind it until the walk finishes. Run the page on the queue's sync lane instead, as the delete-transaction inspection already does for the same reason. The namespace lease and the page bounds are unchanged. The regression test occupies the foreground lane and requires a discovery page to complete within ten seconds; it times out without this change. * test(ecstore): align read_appending rollback assertions on error * fix: align multipart and EC read paths with current workspace APIs --------- Co-authored-by: Xiaoyang Han <lux1an@qq.com> Co-authored-by: Chris An <anzhengchao@gmail.com>
382 lines
13 KiB
Python
382 lines
13 KiB
Python
#!/usr/bin/env python3
|
|
"""Verify RustFS dynamic EC block hints against a disposable S3 endpoint.
|
|
|
|
Requires boto3 and AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY. See
|
|
docs/testing/dynamic-block-size.md for rollout and restart probes.
|
|
"""
|
|
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import os
|
|
import re
|
|
import uuid
|
|
|
|
import boto3
|
|
from botocore.config import Config
|
|
from botocore.exceptions import ClientError
|
|
|
|
MIB = 1024 * 1024
|
|
CANDIDATES = (64 * 1024, 256 * 1024, MIB, 4 * MIB)
|
|
HINT = "rustfs-ec-block-size-hint"
|
|
ACTUAL = "x-rustfs-effective-ec-block-size"
|
|
STATUS = "x-rustfs-layout-hint-status"
|
|
REASON = "x-rustfs-layout-hint-reason"
|
|
SIZE = 4 * MIB + 123
|
|
PART_SIZES = (5 * MIB + 123, MIB + 77)
|
|
|
|
|
|
def require(condition, message):
|
|
if not condition:
|
|
raise AssertionError(message)
|
|
|
|
|
|
def headers(response):
|
|
return response["ResponseMetadata"]["HTTPHeaders"]
|
|
|
|
|
|
def check_layout(response, expected, label, status=None, reason=None):
|
|
values = headers(response)
|
|
require(
|
|
values.get(ACTUAL) == str(expected),
|
|
f"{label}: actual B {values.get(ACTUAL)!r}, expected {expected}",
|
|
)
|
|
require(
|
|
values.get(STATUS) == status,
|
|
f"{label}: hint status {values.get(STATUS)!r}, expected {status!r}",
|
|
)
|
|
require(
|
|
values.get(REASON) == reason,
|
|
f"{label}: hint reason {values.get(REASON)!r}, expected {reason!r}",
|
|
)
|
|
require(
|
|
not any("internal-ec-read-quantum" in key for key in values),
|
|
f"{label}: internal q leaked over S3",
|
|
)
|
|
|
|
|
|
def payload(key, size):
|
|
return hashlib.shake_256(key.encode()).digest(size)
|
|
|
|
|
|
def sha256_argument(value):
|
|
if re.fullmatch(r"[0-9a-fA-F]{64}", value) is None:
|
|
raise argparse.ArgumentTypeError(
|
|
"SHA-256 must contain exactly 64 hexadecimal characters"
|
|
)
|
|
return value.lower()
|
|
|
|
|
|
def read_body(response):
|
|
try:
|
|
return response["Body"].read()
|
|
finally:
|
|
response["Body"].close()
|
|
|
|
|
|
def verify_object(client, bucket, key, expected, block_size, part_boundary=None):
|
|
head = client.head_object(Bucket=bucket, Key=key)
|
|
check_layout(head, block_size, f"HEAD {key}")
|
|
require(head["ContentLength"] == len(expected), f"HEAD {key}: size mismatch")
|
|
full = client.get_object(Bucket=bucket, Key=key)
|
|
check_layout(full, block_size, f"GET {key}")
|
|
require(read_body(full) == expected, f"GET {key}: payload mismatch")
|
|
ranges = []
|
|
if expected:
|
|
ranges.extend(
|
|
[
|
|
(0, min(122, len(expected) - 1)),
|
|
(max(0, len(expected) - 123), len(expected) - 1),
|
|
]
|
|
)
|
|
if len(expected) > block_size:
|
|
ranges.append((block_size - 37, min(block_size + 85, len(expected) - 1)))
|
|
if part_boundary is not None:
|
|
ranges.append((part_boundary - 37, min(part_boundary + 85, len(expected) - 1)))
|
|
for start, end in ranges:
|
|
response = client.get_object(
|
|
Bucket=bucket, Key=key, Range=f"bytes={start}-{end}"
|
|
)
|
|
check_layout(response, block_size, f"Range {key} {start}-{end}")
|
|
require(
|
|
response["ResponseMetadata"]["HTTPStatusCode"] == 206,
|
|
f"Range {key}: expected HTTP 206",
|
|
)
|
|
require(
|
|
response["ContentRange"] == f"bytes {start}-{end}/{len(expected)}",
|
|
f"Range {key}: content-range mismatch",
|
|
)
|
|
require(
|
|
read_body(response) == expected[start : end + 1],
|
|
f"Range {key}: payload mismatch",
|
|
)
|
|
print(
|
|
json.dumps(
|
|
{
|
|
"key": key,
|
|
"actual_b": block_size,
|
|
"size": len(expected),
|
|
"range_checks": len(ranges),
|
|
"result": "passed",
|
|
}
|
|
)
|
|
)
|
|
|
|
|
|
def ensure_absent(client, bucket, key):
|
|
try:
|
|
client.head_object(Bucket=bucket, Key=key)
|
|
except ClientError as error:
|
|
if error.response["ResponseMetadata"]["HTTPStatusCode"] == 404:
|
|
return
|
|
raise
|
|
raise RuntimeError(f"refusing to overwrite existing object {bucket}/{key}")
|
|
|
|
|
|
def put_multipart(client, bucket, key, block_size, status, reason):
|
|
initiated = client.create_multipart_upload(
|
|
Bucket=bucket, Key=key, Metadata={HINT: str(block_size)}
|
|
)
|
|
upload_id = initiated["UploadId"]
|
|
parts = []
|
|
committed = False
|
|
try:
|
|
check_layout(
|
|
initiated,
|
|
block_size if status == "applied" else MIB,
|
|
f"MPU initiate {key}",
|
|
status,
|
|
reason,
|
|
)
|
|
for number, size in enumerate(PART_SIZES, 1):
|
|
response = client.upload_part(
|
|
Bucket=bucket,
|
|
Key=key,
|
|
UploadId=upload_id,
|
|
PartNumber=number,
|
|
Body=payload(f"{key}:{number}", size),
|
|
)
|
|
parts.append({"PartNumber": number, "ETag": response["ETag"]})
|
|
completed = client.complete_multipart_upload(
|
|
Bucket=bucket, Key=key, UploadId=upload_id, MultipartUpload={"Parts": parts}
|
|
)
|
|
committed = True
|
|
check_layout(
|
|
completed, block_size if status == "applied" else MIB, f"MPU complete {key}"
|
|
)
|
|
except BaseException:
|
|
if not committed:
|
|
client.abort_multipart_upload(Bucket=bucket, Key=key, UploadId=upload_id)
|
|
raise
|
|
|
|
|
|
def cases(policy):
|
|
status = "applied" if policy == "applied" else "ignored"
|
|
reason = None if status == "applied" else policy
|
|
for block_size in CANDIDATES:
|
|
actual = block_size if status == "applied" else MIB
|
|
yield f"put-{block_size}", block_size, actual, status, reason, False
|
|
yield f"mpu-{block_size}", block_size, actual, status, reason, True
|
|
yield "put-default", None, MIB, None, None, False
|
|
yield (
|
|
"put-unsupported",
|
|
131072,
|
|
MIB,
|
|
"ignored",
|
|
"unsupported-size" if policy == "applied" else policy,
|
|
False,
|
|
)
|
|
|
|
|
|
def verify_external(client, args):
|
|
require(
|
|
args.external_block_size is not None,
|
|
"--external-prefix requires --external-block-size",
|
|
)
|
|
found = 0
|
|
for page in client.get_paginator("list_objects_v2").paginate(
|
|
Bucket=args.bucket, Prefix=args.external_prefix
|
|
):
|
|
for item in page.get("Contents", []):
|
|
key = item["Key"]
|
|
response = client.get_object(Bucket=args.bucket, Key=key)
|
|
expected = read_body(response)
|
|
require(
|
|
len(expected) == item["Size"],
|
|
f"external {key}: full GET length mismatch",
|
|
)
|
|
if args.external_size is not None:
|
|
require(
|
|
len(expected) == args.external_size,
|
|
f"external {key}: intended payload size mismatch",
|
|
)
|
|
if args.external_sha256 is not None:
|
|
require(
|
|
hashlib.sha256(expected).hexdigest() == args.external_sha256,
|
|
f"external {key}: intended payload checksum mismatch",
|
|
)
|
|
verify_object(client, args.bucket, key, expected, args.external_block_size)
|
|
found += 1
|
|
require(found > 0, f"no external objects found under {args.external_prefix!r}")
|
|
print(json.dumps({"external_objects": found, "result": "passed"}))
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--endpoint", required=True)
|
|
parser.add_argument("--bucket", help="Disposable bucket; generated by default")
|
|
parser.add_argument("--prefix", default="dynamic-block-e2e/")
|
|
parser.add_argument(
|
|
"--write-policy",
|
|
choices=("applied", "disabled", "fleet-unconfirmed"),
|
|
default="applied",
|
|
help="Policy during object creation, including when verifying after restart",
|
|
)
|
|
parser.add_argument(
|
|
"--keep",
|
|
action="store_true",
|
|
help="Keep this script's bucket and objects for restart verification",
|
|
)
|
|
parser.add_argument(
|
|
"--verify-only",
|
|
action="store_true",
|
|
help="Read previously written objects; never delete them",
|
|
)
|
|
parser.add_argument(
|
|
"--external-prefix",
|
|
help="Only verify objects written by a client such as BrewFS",
|
|
)
|
|
parser.add_argument("--external-block-size", type=int, choices=CANDIDATES)
|
|
parser.add_argument(
|
|
"--external-size",
|
|
type=int,
|
|
help="Expected size in bytes of every external object",
|
|
)
|
|
parser.add_argument(
|
|
"--external-sha256",
|
|
type=sha256_argument,
|
|
help="Expected SHA-256 of every external object",
|
|
)
|
|
args = parser.parse_args()
|
|
if not os.environ.get("AWS_ACCESS_KEY_ID") or not os.environ.get(
|
|
"AWS_SECRET_ACCESS_KEY"
|
|
):
|
|
parser.error(
|
|
"set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY for the disposable endpoint"
|
|
)
|
|
if (args.verify_only or args.external_prefix is not None) and not args.bucket:
|
|
parser.error("--verify-only and --external-prefix require --bucket")
|
|
if args.external_prefix is not None and not args.external_prefix:
|
|
parser.error("--external-prefix must identify a nonempty task prefix")
|
|
if args.external_size is not None and args.external_size < 0:
|
|
parser.error("--external-size must be nonnegative")
|
|
if (
|
|
args.external_size is not None or args.external_sha256 is not None
|
|
) and args.external_prefix is None:
|
|
parser.error("--external-size and --external-sha256 require --external-prefix")
|
|
args.bucket = args.bucket or "dynamic-block-" + uuid.uuid4().hex[:20]
|
|
client = boto3.client(
|
|
"s3",
|
|
endpoint_url=args.endpoint,
|
|
region_name="us-east-1",
|
|
config=Config(
|
|
s3={"addressing_style": "path"},
|
|
signature_version="s3v4",
|
|
proxies={},
|
|
connect_timeout=5,
|
|
read_timeout=120,
|
|
retries={"total_max_attempts": 1},
|
|
request_checksum_calculation="when_required",
|
|
response_checksum_validation="when_required",
|
|
),
|
|
)
|
|
created = []
|
|
created_bucket = False
|
|
try:
|
|
if args.external_prefix is not None:
|
|
verify_external(client, args)
|
|
return
|
|
if not args.verify_only:
|
|
try:
|
|
client.head_bucket(Bucket=args.bucket)
|
|
except ClientError as error:
|
|
require(
|
|
error.response["ResponseMetadata"]["HTTPStatusCode"] == 404,
|
|
"test bucket lookup failed",
|
|
)
|
|
else:
|
|
raise RuntimeError(f"refusing to reuse existing bucket {args.bucket}")
|
|
client.create_bucket(Bucket=args.bucket)
|
|
created_bucket = True
|
|
for name, hint, actual, status, reason, multipart in cases(args.write_policy):
|
|
key = args.prefix + name
|
|
if multipart:
|
|
expected = b"".join(
|
|
payload(f"{key}:{number}", size)
|
|
for number, size in enumerate(PART_SIZES, 1)
|
|
)
|
|
else:
|
|
expected = payload(key, SIZE)
|
|
if not args.verify_only:
|
|
ensure_absent(client, args.bucket, key)
|
|
created.append(key)
|
|
if multipart:
|
|
put_multipart(client, args.bucket, key, hint, status, reason)
|
|
else:
|
|
response = client.put_object(
|
|
Bucket=args.bucket,
|
|
Key=key,
|
|
Body=expected,
|
|
Metadata={} if hint is None else {HINT: str(hint)},
|
|
)
|
|
check_layout(response, actual, f"PUT {key}", status, reason)
|
|
verify_object(
|
|
client,
|
|
args.bucket,
|
|
key,
|
|
expected,
|
|
actual,
|
|
PART_SIZES[0] if multipart else None,
|
|
)
|
|
if not args.verify_only and args.write_policy == "applied":
|
|
key = args.prefix + "invalid-hint"
|
|
ensure_absent(client, args.bucket, key)
|
|
try:
|
|
client.put_object(
|
|
Bucket=args.bucket,
|
|
Key=key,
|
|
Body=b"invalid-hint-probe",
|
|
Metadata={HINT: "+65536"},
|
|
)
|
|
except ClientError as error:
|
|
require(
|
|
error.response["Error"]["Code"] == "InvalidArgument",
|
|
"malformed hint must fail with InvalidArgument",
|
|
)
|
|
else:
|
|
created.append(key)
|
|
raise AssertionError("malformed hint unexpectedly succeeded")
|
|
print(
|
|
json.dumps(
|
|
{
|
|
"bucket": args.bucket,
|
|
"prefix": args.prefix,
|
|
"write_policy": args.write_policy,
|
|
"verify_only": args.verify_only,
|
|
"objects": 10,
|
|
"result": "passed",
|
|
}
|
|
)
|
|
)
|
|
finally:
|
|
if not args.keep and not args.verify_only and args.external_prefix is None:
|
|
for key in created:
|
|
client.delete_object(Bucket=args.bucket, Key=key)
|
|
if created_bucket:
|
|
client.delete_bucket(Bucket=args.bucket)
|
|
client.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|