snapshot of https://github.com/seaweedfs/seaweedfs.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
go: build dev binaries / cleanup (push) Successful in 4s
Codespell / Check for spelling errors (push) Failing after 3s
docker: build dev containers / build-rust-binaries (amd64, x86_64-unknown-linux-musl) (push) Failing after 3s
docker: build dev containers / build-dev-containers (push) Has been skipped
docker: build dev containers / build-rust-binaries (arm64, true, aarch64-unknown-linux-musl) (push) Failing after 3s
End to End / FUSE Mount (push) Failing after 2s
EC Integration Tests / EC Integration Tests (push) Failing after 30s
FUSE DLM Integration Tests / FUSE DLM Integration Tests (push) Failing after 3s
FUSE Volume Server Failover Tests / FUSE Volume Server Failover (push) Failing after 3s
FUSE Integration Tests / FUSE Integration Testing (push) Failing after 2s
FUSE P2P Peer Chunk Sharing Integration Tests / FUSE P2P Peer Chunk Sharing (push) Failing after 3s
go: build binary / Go Vet (push) Failing after 2s
go: build binary / Go Vet 32-bit (push) Failing after 3s
go: build binary / Build (push) Failing after 4s
go: build binary / Build cross-platform (freebsd/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (darwin/arm64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/arm64) (push) Failing after 3s
go: build binary / Test (push) Failing after 2s
go: build binary / Test 32-bit (push) Failing after 3s
helm: lint and test charts / lint-test (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (11) (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (17) (push) Failing after 3s
go: build dev binaries / build_dev_linux_windows (amd64, linux) (push) Failing after 2s
go: build dev binaries / build_dev_linux_windows (amd64, windows) (push) Failing after 3s
go: build dev binaries / build_dev_darwin (amd64, darwin) (push) Has been skipped
go: build dev binaries / build_dev_darwin (arm64, darwin) (push) Has been skipped
Java Client Unit Tests / Java Unit Tests (11) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (17) (push) Failing after 2s
Java Client Unit Tests / Java Unit Tests (21) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (8) (push) Failing after 3s
Kafka Quick Test (Load Test with Schema Registry) / Kafka Client Load Test (Quick) (push) Failing after 3s
Kafka Gateway Tests / Kafka Unit Tests (unit-tests-1) (push) Failing after 11s
Kafka Gateway Tests / Kafka Integration Tests (Critical) (integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka End-to-End Tests (with SMQ) (e2e-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Consumer Group Tests (Highly Isolated) (consumer-group-1) (push) Failing after 2s
Kafka Gateway Tests / Kafka Client Compatibility (with SMQ) (client-compat-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka SMQ Integration Tests (Full Stack) (smq-integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Protocol Tests (Isolated) (protocol-1) (push) Failing after 3s
KMS Tests / KMS Provider Integration Tests (push) Failing after 2s
KMS Tests / S3 KMS End-to-End Tests (push) Failing after 3s
Master Cold Start Tests / Master Cold Start Tests (push) Failing after 4s
Metadata Subscribe Integration Tests / Metadata Subscribe Integration Tests (push) Failing after 3s
Multi-Master Tests / Multi-Master Failover Tests (push) Failing after 3s
Performance / CPU and Heap Profile (push) Failing after 2s
Performance / S3 Read/Write Benchmark (rust volume) (push) Failing after 3s
pjdfstest POSIX Compliance / pjdfstest (push) Failing after 2s
Plugin Worker Integration Tests / Plugin Worker: erasure_coding (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: vacuum (push) Failing after 3s
Rust Volume Server Tests / Rust Integration Tests (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 1) (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 1) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 3) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Distributed Tests (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Performance Tests (push) Failing after 3s
Performance / Throughput Benchmark (go volume) (push) Failing after 3s
Performance / Throughput Benchmark (rust volume) (push) Failing after 2s
Performance / S3 Read/Write Benchmark (go volume) (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: volume_balance (push) Failing after 3s
PostgreSQL Gateway Tests / PostgreSQL Basic Tests (push) Failing after 3s
Rust Volume Server Tests / Rust Unit Tests (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 3) (push) Failing after 3s
Rust Plugin Worker Tests / Rust Plugin Worker Build and Unit Tests (push) Failing after 3s
rust: build dev volume server binaries / cleanup (push) Successful in 3s
S3 ETag and ACL Tests / S3 ETag + ACL Integration Tests (push) Failing after 3s
S3 IAM Integration Tests / IAM Unit Tests (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (advanced) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (basic) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (group) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (policy-enforcement) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (sts) (push) Failing after 4s
S3 Keycloak Integration Tests / S3 Keycloak Integration Tests (push) Failing after 3s
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.11) (push) Failing after 3s
S3 PyArrow Parquet Tests / Go Unit Tests (Implicit Directory) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.12) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-amd64, x86_64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-arm64, aarch64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-linux (linux-amd64, x86_64-unknown-linux-gnu) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.9) (push) Has been cancelled
S3 Proxy Signature Tests / S3 Proxy Signature Verification Tests (push) Has been cancelled
S3 SDK V2 Route Disambiguation Tests / S3 SDK V2 Routing Tests (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (quick) (push) Has been cancelled
S3 SSE Tests / S3 SSE Compatibility Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Metadata Persistence Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Copy Operations Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Multipart Upload Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Performance Test (push) Has been cancelled
S3 SSE Tests / S3 Volume Encryption Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (comprehensive) (push) Has been cancelled
Spark Integration Tests / Spark Integration Tests (push) Failing after 2s
Telemetry Integration Tests / telemetry-integration-test (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 1) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 1) (push) Failing after 3s
Ceph S3 tests / Basic S3 tests (KV store) (push) Has been cancelled
Ceph S3 tests / S3 Versioning & Object Lock tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Unit Tests (push) Failing after 3s
Ceph S3 tests / S3 CORS tests (push) Has been cancelled
Ceph S3 tests / SeaweedFS Custom S3 Copy tests (push) Has been cancelled
Ceph S3 tests / Basic S3 tests (SQL store) (push) Has been cancelled
test s3 over https using aws-cli / awscli-tests (push) Has been cancelled
TLS Rotation Integration Tests / TLS Rotation Integration Tests (push) Has been cancelled
Vacuum Integration Tests / Vacuum Integration Tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Variables Integration Tests (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (advanced-policy) (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (basic-policy) (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (contextual-policy) (push) Failing after 4s
S3 Policy Integration Tests / Trusted Proxy Detection Tests (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Shell Integration Tests (push) Failing after 3s
Samba on FUSE Integration / samba-integration (push) Failing after 2s
SFTP Integration Tests / SFTP Integration Testing (push) Failing after 3s
terraform: validate and test modules / fmt, validate, plan-level tests (push) Failing after 3s
terraform: validate and test modules / local cluster smoke test (real weed) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 3) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 2) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 2) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 3) (push) Failing after 5s
mount: windows conformance / WinFsp conformance (push) Has been cancelled
mount: windows / Mount on Windows (push) Has been cancelled
Some checks failed
go: build dev binaries / cleanup (push) Successful in 4s
Codespell / Check for spelling errors (push) Failing after 3s
docker: build dev containers / build-rust-binaries (amd64, x86_64-unknown-linux-musl) (push) Failing after 3s
docker: build dev containers / build-dev-containers (push) Has been skipped
docker: build dev containers / build-rust-binaries (arm64, true, aarch64-unknown-linux-musl) (push) Failing after 3s
End to End / FUSE Mount (push) Failing after 2s
EC Integration Tests / EC Integration Tests (push) Failing after 30s
FUSE DLM Integration Tests / FUSE DLM Integration Tests (push) Failing after 3s
FUSE Volume Server Failover Tests / FUSE Volume Server Failover (push) Failing after 3s
FUSE Integration Tests / FUSE Integration Testing (push) Failing after 2s
FUSE P2P Peer Chunk Sharing Integration Tests / FUSE P2P Peer Chunk Sharing (push) Failing after 3s
go: build binary / Go Vet (push) Failing after 2s
go: build binary / Go Vet 32-bit (push) Failing after 3s
go: build binary / Build (push) Failing after 4s
go: build binary / Build cross-platform (freebsd/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (darwin/arm64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/arm64) (push) Failing after 3s
go: build binary / Test (push) Failing after 2s
go: build binary / Test 32-bit (push) Failing after 3s
helm: lint and test charts / lint-test (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (11) (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (17) (push) Failing after 3s
go: build dev binaries / build_dev_linux_windows (amd64, linux) (push) Failing after 2s
go: build dev binaries / build_dev_linux_windows (amd64, windows) (push) Failing after 3s
go: build dev binaries / build_dev_darwin (amd64, darwin) (push) Has been skipped
go: build dev binaries / build_dev_darwin (arm64, darwin) (push) Has been skipped
Java Client Unit Tests / Java Unit Tests (11) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (17) (push) Failing after 2s
Java Client Unit Tests / Java Unit Tests (21) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (8) (push) Failing after 3s
Kafka Quick Test (Load Test with Schema Registry) / Kafka Client Load Test (Quick) (push) Failing after 3s
Kafka Gateway Tests / Kafka Unit Tests (unit-tests-1) (push) Failing after 11s
Kafka Gateway Tests / Kafka Integration Tests (Critical) (integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka End-to-End Tests (with SMQ) (e2e-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Consumer Group Tests (Highly Isolated) (consumer-group-1) (push) Failing after 2s
Kafka Gateway Tests / Kafka Client Compatibility (with SMQ) (client-compat-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka SMQ Integration Tests (Full Stack) (smq-integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Protocol Tests (Isolated) (protocol-1) (push) Failing after 3s
KMS Tests / KMS Provider Integration Tests (push) Failing after 2s
KMS Tests / S3 KMS End-to-End Tests (push) Failing after 3s
Master Cold Start Tests / Master Cold Start Tests (push) Failing after 4s
Metadata Subscribe Integration Tests / Metadata Subscribe Integration Tests (push) Failing after 3s
Multi-Master Tests / Multi-Master Failover Tests (push) Failing after 3s
Performance / CPU and Heap Profile (push) Failing after 2s
Performance / S3 Read/Write Benchmark (rust volume) (push) Failing after 3s
pjdfstest POSIX Compliance / pjdfstest (push) Failing after 2s
Plugin Worker Integration Tests / Plugin Worker: erasure_coding (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: vacuum (push) Failing after 3s
Rust Volume Server Tests / Rust Integration Tests (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 1) (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 1) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 3) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Distributed Tests (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Performance Tests (push) Failing after 3s
Performance / Throughput Benchmark (go volume) (push) Failing after 3s
Performance / Throughput Benchmark (rust volume) (push) Failing after 2s
Performance / S3 Read/Write Benchmark (go volume) (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: volume_balance (push) Failing after 3s
PostgreSQL Gateway Tests / PostgreSQL Basic Tests (push) Failing after 3s
Rust Volume Server Tests / Rust Unit Tests (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 3) (push) Failing after 3s
Rust Plugin Worker Tests / Rust Plugin Worker Build and Unit Tests (push) Failing after 3s
rust: build dev volume server binaries / cleanup (push) Successful in 3s
S3 ETag and ACL Tests / S3 ETag + ACL Integration Tests (push) Failing after 3s
S3 IAM Integration Tests / IAM Unit Tests (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (advanced) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (basic) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (group) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (policy-enforcement) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (sts) (push) Failing after 4s
S3 Keycloak Integration Tests / S3 Keycloak Integration Tests (push) Failing after 3s
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.11) (push) Failing after 3s
S3 PyArrow Parquet Tests / Go Unit Tests (Implicit Directory) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.12) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-amd64, x86_64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-arm64, aarch64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-linux (linux-amd64, x86_64-unknown-linux-gnu) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.9) (push) Has been cancelled
S3 Proxy Signature Tests / S3 Proxy Signature Verification Tests (push) Has been cancelled
S3 SDK V2 Route Disambiguation Tests / S3 SDK V2 Routing Tests (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (quick) (push) Has been cancelled
S3 SSE Tests / S3 SSE Compatibility Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Metadata Persistence Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Copy Operations Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Multipart Upload Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Performance Test (push) Has been cancelled
S3 SSE Tests / S3 Volume Encryption Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (comprehensive) (push) Has been cancelled
Spark Integration Tests / Spark Integration Tests (push) Failing after 2s
Telemetry Integration Tests / telemetry-integration-test (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 1) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 1) (push) Failing after 3s
Ceph S3 tests / Basic S3 tests (KV store) (push) Has been cancelled
Ceph S3 tests / S3 Versioning & Object Lock tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Unit Tests (push) Failing after 3s
Ceph S3 tests / S3 CORS tests (push) Has been cancelled
Ceph S3 tests / SeaweedFS Custom S3 Copy tests (push) Has been cancelled
Ceph S3 tests / Basic S3 tests (SQL store) (push) Has been cancelled
test s3 over https using aws-cli / awscli-tests (push) Has been cancelled
TLS Rotation Integration Tests / TLS Rotation Integration Tests (push) Has been cancelled
Vacuum Integration Tests / Vacuum Integration Tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Variables Integration Tests (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (advanced-policy) (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (basic-policy) (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (contextual-policy) (push) Failing after 4s
S3 Policy Integration Tests / Trusted Proxy Detection Tests (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Shell Integration Tests (push) Failing after 3s
Samba on FUSE Integration / samba-integration (push) Failing after 2s
SFTP Integration Tests / SFTP Integration Testing (push) Failing after 3s
terraform: validate and test modules / fmt, validate, plan-level tests (push) Failing after 3s
terraform: validate and test modules / local cluster smoke test (real weed) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 3) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 2) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 2) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 3) (push) Failing after 5s
mount: windows conformance / WinFsp conformance (push) Has been cancelled
mount: windows / Mount on Windows (push) Has been cancelled
This commit is contained in:
355
weed/mq/offset/subscriber.go
Normal file
355
weed/mq/offset/subscriber.go
Normal file
@@ -0,0 +1,355 @@
|
||||
package offset
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/schema_pb"
|
||||
)
|
||||
|
||||
// OffsetSubscriber handles offset-based subscription logic
|
||||
type OffsetSubscriber struct {
|
||||
mu sync.RWMutex
|
||||
offsetRegistry *PartitionOffsetRegistry
|
||||
subscriptions map[string]*OffsetSubscription
|
||||
}
|
||||
|
||||
// OffsetSubscription represents an active offset-based subscription
|
||||
type OffsetSubscription struct {
|
||||
ID string
|
||||
Namespace string
|
||||
TopicName string
|
||||
Partition *schema_pb.Partition
|
||||
StartOffset int64
|
||||
CurrentOffset int64
|
||||
OffsetType schema_pb.OffsetType
|
||||
IsActive bool
|
||||
offsetRegistry *PartitionOffsetRegistry
|
||||
}
|
||||
|
||||
// NewOffsetSubscriber creates a new offset-based subscriber
|
||||
func NewOffsetSubscriber(offsetRegistry *PartitionOffsetRegistry) *OffsetSubscriber {
|
||||
return &OffsetSubscriber{
|
||||
offsetRegistry: offsetRegistry,
|
||||
subscriptions: make(map[string]*OffsetSubscription),
|
||||
}
|
||||
}
|
||||
|
||||
// CreateSubscription creates a new offset-based subscription
|
||||
func (s *OffsetSubscriber) CreateSubscription(
|
||||
subscriptionID string,
|
||||
namespace, topicName string,
|
||||
partition *schema_pb.Partition,
|
||||
offsetType schema_pb.OffsetType,
|
||||
startOffset int64,
|
||||
) (*OffsetSubscription, error) {
|
||||
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
// Check if subscription already exists
|
||||
if _, exists := s.subscriptions[subscriptionID]; exists {
|
||||
return nil, fmt.Errorf("subscription %s already exists", subscriptionID)
|
||||
}
|
||||
|
||||
// Resolve the actual start offset based on type
|
||||
actualStartOffset, err := s.resolveStartOffset(namespace, topicName, partition, offsetType, startOffset)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to resolve start offset: %w", err)
|
||||
}
|
||||
|
||||
subscription := &OffsetSubscription{
|
||||
ID: subscriptionID,
|
||||
Namespace: namespace,
|
||||
TopicName: topicName,
|
||||
Partition: partition,
|
||||
StartOffset: actualStartOffset,
|
||||
CurrentOffset: actualStartOffset,
|
||||
OffsetType: offsetType,
|
||||
IsActive: true,
|
||||
offsetRegistry: s.offsetRegistry,
|
||||
}
|
||||
|
||||
s.subscriptions[subscriptionID] = subscription
|
||||
return subscription, nil
|
||||
}
|
||||
|
||||
// GetSubscription retrieves an existing subscription
|
||||
func (s *OffsetSubscriber) GetSubscription(subscriptionID string) (*OffsetSubscription, error) {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
|
||||
subscription, exists := s.subscriptions[subscriptionID]
|
||||
if !exists {
|
||||
return nil, fmt.Errorf("subscription %s not found", subscriptionID)
|
||||
}
|
||||
|
||||
return subscription, nil
|
||||
}
|
||||
|
||||
// CloseSubscription closes and removes a subscription
|
||||
func (s *OffsetSubscriber) CloseSubscription(subscriptionID string) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
subscription, exists := s.subscriptions[subscriptionID]
|
||||
if !exists {
|
||||
return fmt.Errorf("subscription %s not found", subscriptionID)
|
||||
}
|
||||
|
||||
subscription.IsActive = false
|
||||
delete(s.subscriptions, subscriptionID)
|
||||
return nil
|
||||
}
|
||||
|
||||
// resolveStartOffset resolves the actual start offset based on OffsetType
|
||||
func (s *OffsetSubscriber) resolveStartOffset(
|
||||
namespace, topicName string,
|
||||
partition *schema_pb.Partition,
|
||||
offsetType schema_pb.OffsetType,
|
||||
requestedOffset int64,
|
||||
) (int64, error) {
|
||||
|
||||
switch offsetType {
|
||||
case schema_pb.OffsetType_EXACT_OFFSET:
|
||||
// Validate that the requested offset exists
|
||||
return s.validateAndGetOffset(namespace, topicName, partition, requestedOffset)
|
||||
|
||||
case schema_pb.OffsetType_RESET_TO_OFFSET:
|
||||
// Use the requested offset, even if it doesn't exist yet
|
||||
return requestedOffset, nil
|
||||
|
||||
case schema_pb.OffsetType_RESET_TO_EARLIEST:
|
||||
// Start from offset 0
|
||||
return 0, nil
|
||||
|
||||
case schema_pb.OffsetType_RESET_TO_LATEST:
|
||||
// Start from the current high water mark
|
||||
hwm, err := s.offsetRegistry.GetHighWaterMark(namespace, topicName, partition)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return hwm, nil
|
||||
|
||||
case schema_pb.OffsetType_RESUME_OR_EARLIEST:
|
||||
// Try to resume from a saved position, fallback to earliest
|
||||
// For now, just use earliest (consumer group position tracking will be added later)
|
||||
return 0, nil
|
||||
|
||||
case schema_pb.OffsetType_RESUME_OR_LATEST:
|
||||
// Try to resume from a saved position, fallback to latest
|
||||
// For now, just use latest
|
||||
hwm, err := s.offsetRegistry.GetHighWaterMark(namespace, topicName, partition)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return hwm, nil
|
||||
|
||||
default:
|
||||
return 0, fmt.Errorf("unsupported offset type: %v", offsetType)
|
||||
}
|
||||
}
|
||||
|
||||
// validateAndGetOffset validates that an offset exists and returns it
|
||||
func (s *OffsetSubscriber) validateAndGetOffset(namespace, topicName string, partition *schema_pb.Partition, offset int64) (int64, error) {
|
||||
if offset < 0 {
|
||||
return 0, fmt.Errorf("offset cannot be negative: %d", offset)
|
||||
}
|
||||
|
||||
// Get the current high water mark
|
||||
hwm, err := s.offsetRegistry.GetHighWaterMark(namespace, topicName, partition)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to get high water mark: %w", err)
|
||||
}
|
||||
|
||||
// Check if offset is within valid range
|
||||
if offset >= hwm {
|
||||
return 0, fmt.Errorf("offset %d is beyond high water mark %d", offset, hwm)
|
||||
}
|
||||
|
||||
return offset, nil
|
||||
}
|
||||
|
||||
// SeekToOffset seeks a subscription to a specific offset
|
||||
func (sub *OffsetSubscription) SeekToOffset(offset int64) error {
|
||||
if !sub.IsActive {
|
||||
return fmt.Errorf("subscription is not active")
|
||||
}
|
||||
|
||||
// Validate the offset
|
||||
if offset < 0 {
|
||||
return fmt.Errorf("offset cannot be negative: %d", offset)
|
||||
}
|
||||
|
||||
hwm, err := sub.offsetRegistry.GetHighWaterMark(sub.Namespace, sub.TopicName, sub.Partition)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get high water mark: %w", err)
|
||||
}
|
||||
|
||||
if offset > hwm {
|
||||
return fmt.Errorf("offset %d is beyond high water mark %d", offset, hwm)
|
||||
}
|
||||
|
||||
sub.CurrentOffset = offset
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetNextOffset returns the next offset to read
|
||||
func (sub *OffsetSubscription) GetNextOffset() int64 {
|
||||
return sub.CurrentOffset
|
||||
}
|
||||
|
||||
// AdvanceOffset advances the subscription to the next offset
|
||||
func (sub *OffsetSubscription) AdvanceOffset() {
|
||||
sub.CurrentOffset++
|
||||
}
|
||||
|
||||
// GetLag returns the lag between current position and high water mark
|
||||
func (sub *OffsetSubscription) GetLag() (int64, error) {
|
||||
if !sub.IsActive {
|
||||
return 0, fmt.Errorf("subscription is not active")
|
||||
}
|
||||
|
||||
hwm, err := sub.offsetRegistry.GetHighWaterMark(sub.Namespace, sub.TopicName, sub.Partition)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to get high water mark: %w", err)
|
||||
}
|
||||
|
||||
lag := hwm - sub.CurrentOffset
|
||||
if lag < 0 {
|
||||
lag = 0
|
||||
}
|
||||
|
||||
return lag, nil
|
||||
}
|
||||
|
||||
// IsAtEnd checks if the subscription has reached the end of available data
|
||||
func (sub *OffsetSubscription) IsAtEnd() (bool, error) {
|
||||
if !sub.IsActive {
|
||||
return true, fmt.Errorf("subscription is not active")
|
||||
}
|
||||
|
||||
hwm, err := sub.offsetRegistry.GetHighWaterMark(sub.Namespace, sub.TopicName, sub.Partition)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("failed to get high water mark: %w", err)
|
||||
}
|
||||
|
||||
return sub.CurrentOffset >= hwm, nil
|
||||
}
|
||||
|
||||
// OffsetRange represents a range of offsets
|
||||
type OffsetRange struct {
|
||||
StartOffset int64
|
||||
EndOffset int64
|
||||
Count int64
|
||||
}
|
||||
|
||||
// GetOffsetRange returns a range of offsets for batch reading
|
||||
func (sub *OffsetSubscription) GetOffsetRange(maxCount int64) (*OffsetRange, error) {
|
||||
if !sub.IsActive {
|
||||
return nil, fmt.Errorf("subscription is not active")
|
||||
}
|
||||
|
||||
hwm, err := sub.offsetRegistry.GetHighWaterMark(sub.Namespace, sub.TopicName, sub.Partition)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get high water mark: %w", err)
|
||||
}
|
||||
|
||||
startOffset := sub.CurrentOffset
|
||||
endOffset := startOffset + maxCount - 1
|
||||
|
||||
// Don't go beyond high water mark
|
||||
if endOffset >= hwm {
|
||||
endOffset = hwm - 1
|
||||
}
|
||||
|
||||
// If start is already at or beyond HWM, return empty range
|
||||
if startOffset >= hwm {
|
||||
return &OffsetRange{
|
||||
StartOffset: startOffset,
|
||||
EndOffset: startOffset - 1, // Empty range
|
||||
Count: 0,
|
||||
}, nil
|
||||
}
|
||||
|
||||
count := endOffset - startOffset + 1
|
||||
return &OffsetRange{
|
||||
StartOffset: startOffset,
|
||||
EndOffset: endOffset,
|
||||
Count: count,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// AdvanceOffsetBy advances the subscription by a specific number of offsets
|
||||
func (sub *OffsetSubscription) AdvanceOffsetBy(count int64) {
|
||||
sub.CurrentOffset += count
|
||||
}
|
||||
|
||||
// OffsetSeeker provides utilities for offset-based seeking
|
||||
type OffsetSeeker struct {
|
||||
offsetRegistry *PartitionOffsetRegistry
|
||||
}
|
||||
|
||||
// NewOffsetSeeker creates a new offset seeker
|
||||
func NewOffsetSeeker(offsetRegistry *PartitionOffsetRegistry) *OffsetSeeker {
|
||||
return &OffsetSeeker{
|
||||
offsetRegistry: offsetRegistry,
|
||||
}
|
||||
}
|
||||
|
||||
// SeekToTimestamp finds the offset closest to a given timestamp
|
||||
// This bridges offset-based and timestamp-based seeking
|
||||
func (seeker *OffsetSeeker) SeekToTimestamp(partition *schema_pb.Partition, timestamp int64) (int64, error) {
|
||||
// TODO: This requires integration with the storage layer to map timestamps to offsets
|
||||
// For now, return an error indicating this feature needs implementation
|
||||
return 0, fmt.Errorf("timestamp-to-offset mapping not implemented yet")
|
||||
}
|
||||
|
||||
// ValidateOffsetRange validates that an offset range is valid
|
||||
func (seeker *OffsetSeeker) ValidateOffsetRange(namespace, topicName string, partition *schema_pb.Partition, startOffset, endOffset int64) error {
|
||||
if startOffset < 0 {
|
||||
return fmt.Errorf("start offset cannot be negative: %d", startOffset)
|
||||
}
|
||||
|
||||
if endOffset < startOffset {
|
||||
return fmt.Errorf("end offset %d cannot be less than start offset %d", endOffset, startOffset)
|
||||
}
|
||||
|
||||
hwm, err := seeker.offsetRegistry.GetHighWaterMark(namespace, topicName, partition)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get high water mark: %w", err)
|
||||
}
|
||||
|
||||
if startOffset >= hwm {
|
||||
return fmt.Errorf("start offset %d is beyond high water mark %d", startOffset, hwm)
|
||||
}
|
||||
|
||||
if endOffset >= hwm {
|
||||
return fmt.Errorf("end offset %d is beyond high water mark %d", endOffset, hwm)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetAvailableOffsetRange returns the range of available offsets for a partition
|
||||
func (seeker *OffsetSeeker) GetAvailableOffsetRange(namespace, topicName string, partition *schema_pb.Partition) (*OffsetRange, error) {
|
||||
hwm, err := seeker.offsetRegistry.GetHighWaterMark(namespace, topicName, partition)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get high water mark: %w", err)
|
||||
}
|
||||
|
||||
if hwm == 0 {
|
||||
// No data available
|
||||
return &OffsetRange{
|
||||
StartOffset: 0,
|
||||
EndOffset: -1,
|
||||
Count: 0,
|
||||
}, nil
|
||||
}
|
||||
|
||||
return &OffsetRange{
|
||||
StartOffset: 0,
|
||||
EndOffset: hwm - 1,
|
||||
Count: hwm,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user