-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Remove flush loop and queue from Ingester RF-1 #13538
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,9 @@ const ( | |
) | ||
|
||
var ( | ||
// ErrClosed is returned when the WAL is closed. | ||
ErrClosed = errors.New("WAL is closed") | ||
|
||
// ErrFull is returned when an append fails because the WAL is full. This | ||
// happens when all segments are either in the pending list waiting to be | ||
// flushed, or in the process of being flushed. | ||
|
@@ -111,9 +114,10 @@ type Manager struct { | |
// pending is a list of segments that are waiting to be flushed. Once | ||
// flushed, the segment is reset and moved to the back of the available | ||
// list to accept writes again. | ||
pending *list.List | ||
shutdown chan struct{} | ||
mu sync.Mutex | ||
pending *list.List | ||
|
||
closed bool | ||
mu sync.Mutex | ||
} | ||
|
||
// item is similar to PendingItem, but it is an internal struct used in the | ||
|
@@ -141,7 +145,6 @@ func NewManager(cfg Config, metrics *Metrics) (*Manager, error) { | |
metrics: metrics.ManagerMetrics, | ||
available: list.New(), | ||
pending: list.New(), | ||
shutdown: make(chan struct{}), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed as it wasn't used. |
||
} | ||
m.metrics.NumPending.Set(0) | ||
m.metrics.NumFlushing.Set(0) | ||
|
@@ -162,6 +165,9 @@ func NewManager(cfg Config, metrics *Metrics) (*Manager, error) { | |
func (m *Manager) Append(r AppendRequest) (*AppendResult, error) { | ||
m.mu.Lock() | ||
defer m.mu.Unlock() | ||
if m.closed { | ||
return nil, ErrClosed | ||
} | ||
if m.available.Len() == 0 { | ||
return nil, ErrFull | ||
} | ||
|
@@ -185,9 +191,25 @@ func (m *Manager) Append(r AppendRequest) (*AppendResult, error) { | |
return it.r, nil | ||
} | ||
|
||
func (m *Manager) Close() { | ||
m.mu.Lock() | ||
defer m.mu.Unlock() | ||
m.closed = true | ||
if m.available.Len() > 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is duplicate code. I will refactor it in a follow up PR. But I wanted to show how it works here. |
||
el := m.available.Front() | ||
it := el.Value.(*item) | ||
if it.w.InputSize() > 0 { | ||
m.pending.PushBack(it) | ||
m.metrics.NumPending.Inc() | ||
m.available.Remove(el) | ||
m.metrics.NumAvailable.Dec() | ||
} | ||
} | ||
} | ||
|
||
// NextPending returns the next segment to be flushed. It returns nil if the | ||
// pending list is empty. | ||
func (m *Manager) NextPending() *PendingItem { | ||
// pending list is empty, and ErrClosed if the WAL is closed. | ||
func (m *Manager) NextPending() (*PendingItem, error) { | ||
m.mu.Lock() | ||
defer m.mu.Unlock() | ||
if m.pending.Len() == 0 { | ||
|
@@ -205,15 +227,18 @@ func (m *Manager) NextPending() *PendingItem { | |
} | ||
// If the pending list is still empty return nil. | ||
if m.pending.Len() == 0 { | ||
return nil | ||
if m.closed { | ||
return nil, ErrClosed | ||
} | ||
return nil, nil | ||
} | ||
} | ||
el := m.pending.Front() | ||
it := el.Value.(*item) | ||
m.pending.Remove(el) | ||
m.metrics.NumPending.Dec() | ||
m.metrics.NumFlushing.Inc() | ||
return &PendingItem{Result: it.r, Writer: it.w} | ||
return &PendingItem{Result: it.r, Writer: it.w}, nil | ||
} | ||
|
||
// Put resets the segment and puts it back in the available list to accept | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was concerned this would increase CPU usage, but having tested it in dev it doesn't have much effect at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think next pending should be blocking instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about it too! I'll take a look at how to use
sync.Cond
to achieve this.