forked from milvus-io/milvus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhance: make delegator delete buffer holding all delete from cp (mil…
…vus-io#29626) (milvus-io#35074) See also milvus-io#29625 pr: milvus-io#29626 This PR: - Add a new implemention of `DeleteBuffer`: listDeleteBuffer - holds cacheBlock slice - `Put` method append new delete data into last block - when a block is full, append a new block into the list - Add `TryDiscard` method for `DeleteBuffer` interface - For doubleCacheBuffer, do nothing - For listDeleteBuffer, try to evict "old" blocks, which are blocks before the first block whose start ts is behind provided ts - Add checkpoint field for `UpdateVersion` sync action, which shall be used to discard old cache delete block --------- Signed-off-by: Wei Liu <[email protected]> Co-authored-by: congqixia <[email protected]>
- Loading branch information
1 parent
d8bfc07
commit e5681e5
Showing
12 changed files
with
263 additions
and
31 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
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
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
94 changes: 94 additions & 0 deletions
94
internal/querynodev2/delegator/deletebuffer/list_delete_buffer.go
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,94 @@ | ||
// Licensed to the LF AI & Data foundation under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package deletebuffer | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/cockroachdb/errors" | ||
) | ||
|
||
func NewListDeleteBuffer[T timed](startTs uint64, sizePerBlock int64) DeleteBuffer[T] { | ||
return &listDeleteBuffer[T]{ | ||
safeTs: startTs, | ||
sizePerBlock: sizePerBlock, | ||
list: []*cacheBlock[T]{newCacheBlock[T](startTs, sizePerBlock)}, | ||
} | ||
} | ||
|
||
// listDeleteBuffer implements DeleteBuffer with a list. | ||
// head points to the earliest block. | ||
// tail points to the latest block which shall be written into. | ||
type listDeleteBuffer[T timed] struct { | ||
mut sync.RWMutex | ||
|
||
list []*cacheBlock[T] | ||
|
||
safeTs uint64 | ||
sizePerBlock int64 | ||
} | ||
|
||
func (b *listDeleteBuffer[T]) Put(entry T) { | ||
b.mut.Lock() | ||
defer b.mut.Unlock() | ||
|
||
tail := b.list[len(b.list)-1] | ||
err := tail.Put(entry) | ||
if errors.Is(err, errBufferFull) { | ||
b.list = append(b.list, newCacheBlock[T](entry.Timestamp(), b.sizePerBlock, entry)) | ||
} | ||
} | ||
|
||
func (b *listDeleteBuffer[T]) ListAfter(ts uint64) []T { | ||
b.mut.RLock() | ||
defer b.mut.RUnlock() | ||
|
||
var result []T | ||
for _, block := range b.list { | ||
result = append(result, block.ListAfter(ts)...) | ||
} | ||
return result | ||
} | ||
|
||
func (b *listDeleteBuffer[T]) SafeTs() uint64 { | ||
b.mut.RLock() | ||
defer b.mut.RUnlock() | ||
return b.safeTs | ||
} | ||
|
||
func (b *listDeleteBuffer[T]) TryDiscard(ts uint64) { | ||
b.mut.Lock() | ||
defer b.mut.Unlock() | ||
if len(b.list) == 1 { | ||
return | ||
} | ||
var nextHead int | ||
for idx := len(b.list) - 1; idx >= 0; idx-- { | ||
block := b.list[idx] | ||
if block.headTs <= ts { | ||
nextHead = idx | ||
break | ||
} | ||
} | ||
|
||
if nextHead > 0 { | ||
for idx := 0; idx < nextHead; idx++ { | ||
b.list[idx] = nil | ||
} | ||
b.list = b.list[nextHead:] | ||
} | ||
} |
Oops, something went wrong.