mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-01 18:00:46 +01:00
fix test errors
This commit is contained in:
1 parent
cce9d8a365
commit
ccd48feefb
9 files changed
+423
-161
No files matched your search
+17
-11
@@ -10,8 +10,8 @@ import (
|
||||
// InMemoryOffsetStorage provides an in-memory implementation of OffsetStorage for testing
|
||||
type InMemoryOffsetStorage struct {
|
||||
mu sync.RWMutex
|
||||
checkpoints map[string]int64 // partition key -> offset
|
||||
records map[string]map[int64]bool // partition key -> offset -> exists
|
||||
checkpoints map[string]int64 // partition key -> offset
|
||||
records map[string]map[int64]bool // partition key -> offset -> exists
|
||||
}
|
||||
|
||||
// NewInMemoryOffsetStorage creates a new in-memory storage
|
||||
@@ -26,7 +26,7 @@ func NewInMemoryOffsetStorage() *InMemoryOffsetStorage {
|
||||
func (s *InMemoryOffsetStorage) SaveCheckpoint(partition *schema_pb.Partition, offset int64) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
|
||||
key := partitionKey(partition)
|
||||
s.checkpoints[key] = offset
|
||||
return nil
|
||||
@@ -36,13 +36,13 @@ func (s *InMemoryOffsetStorage) SaveCheckpoint(partition *schema_pb.Partition, o
|
||||
func (s *InMemoryOffsetStorage) LoadCheckpoint(partition *schema_pb.Partition) (int64, error) {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
|
||||
|
||||
key := partitionKey(partition)
|
||||
offset, exists := s.checkpoints[key]
|
||||
if !exists {
|
||||
return -1, fmt.Errorf("no checkpoint found")
|
||||
}
|
||||
|
||||
|
||||
return offset, nil
|
||||
}
|
||||
|
||||
@@ -50,20 +50,20 @@ func (s *InMemoryOffsetStorage) LoadCheckpoint(partition *schema_pb.Partition) (
|
||||
func (s *InMemoryOffsetStorage) GetHighestOffset(partition *schema_pb.Partition) (int64, error) {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
|
||||
|
||||
key := partitionKey(partition)
|
||||
offsets, exists := s.records[key]
|
||||
if !exists || len(offsets) == 0 {
|
||||
return -1, fmt.Errorf("no records found")
|
||||
}
|
||||
|
||||
|
||||
var highest int64 = -1
|
||||
for offset := range offsets {
|
||||
if offset > highest {
|
||||
highest = offset
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return highest, nil
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ func (s *InMemoryOffsetStorage) GetHighestOffset(partition *schema_pb.Partition)
|
||||
func (s *InMemoryOffsetStorage) AddRecord(partition *schema_pb.Partition, offset int64) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
|
||||
key := partitionKey(partition)
|
||||
if s.records[key] == nil {
|
||||
s.records[key] = make(map[int64]bool)
|
||||
@@ -83,7 +83,7 @@ func (s *InMemoryOffsetStorage) AddRecord(partition *schema_pb.Partition, offset
|
||||
func (s *InMemoryOffsetStorage) GetRecordCount(partition *schema_pb.Partition) int {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
|
||||
|
||||
key := partitionKey(partition)
|
||||
if offsets, exists := s.records[key]; exists {
|
||||
return len(offsets)
|
||||
@@ -95,9 +95,15 @@ func (s *InMemoryOffsetStorage) GetRecordCount(partition *schema_pb.Partition) i
|
||||
func (s *InMemoryOffsetStorage) Clear() {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
|
||||
s.checkpoints = make(map[string]int64)
|
||||
s.records = make(map[string]map[int64]bool)
|
||||
}
|
||||
|
||||
// Reset removes all data (implements resettable interface for shutdown)
|
||||
func (s *InMemoryOffsetStorage) Reset() error {
|
||||
s.Clear()
|
||||
return nil
|
||||
}
|
||||
|
||||
// Note: SQLOffsetStorage is now implemented in sql_storage.go
|
||||
Reference in new issue
Block a user