-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve delete performance for clickhouse (#132)
### TL;DR Improved the deletion logic in case of reorgs in ClickHouse by implementing partition-aware deletes and disabling lightweight delete synchronization. ### What changed? - Added `lightweight_deletes_sync` setting (value 0) to ClickHouse configuration. This will make the deletes async, so processing does not need to wait for it to finish - Split generic `deleteBatch` function into specific delete functions for blocks, logs, transactions, and traces, which will improve performance due to having all of the order by keys defined - Implemented two-step deletion process: 1. Query for existing records that need deletion 2. Execute targeted deletes using partition values and primary keys - Added proper error handling and batch processing for deletions ### Why make this change? The previous deletion method was inefficient and could cause performance issues in ClickHouse.
- Loading branch information
Showing
6 changed files
with
265 additions
and
107 deletions.
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package common | ||
|
||
type Set[T comparable] struct { | ||
elements map[T]struct{} | ||
} | ||
|
||
// NewSet creates a new set | ||
func NewSet[T comparable]() *Set[T] { | ||
return &Set[T]{ | ||
elements: make(map[T]struct{}), | ||
} | ||
} | ||
|
||
// Add inserts an element into the set | ||
func (s *Set[T]) Add(value T) { | ||
s.elements[value] = struct{}{} | ||
} | ||
|
||
// Remove deletes an element from the set | ||
func (s *Set[T]) Remove(value T) { | ||
delete(s.elements, value) | ||
} | ||
|
||
// Contains checks if an element is in the set | ||
func (s *Set[T]) Contains(value T) bool { | ||
_, found := s.elements[value] | ||
return found | ||
} | ||
|
||
// Size returns the number of elements in the set | ||
func (s *Set[T]) Size() int { | ||
return len(s.elements) | ||
} | ||
|
||
// List returns all elements in the set as a slice | ||
func (s *Set[T]) List() []T { | ||
keys := make([]T, 0, len(s.elements)) | ||
for key := range s.elements { | ||
keys = append(keys, key) | ||
} | ||
return keys | ||
} |
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
Oops, something went wrong.