aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2018-12-22 11:52:58 -0800
committerChris Lu <chris.lu@gmail.com>2018-12-22 11:52:58 -0800
commit141d302492ba73ca5b20ee0ee98da9ca061efa42 (patch)
treec38acd49c6d80f6d9d576247e54609f0bf3dfa12
parentd3839fe2793eb2729785d0534d4f1643541b0836 (diff)
downloadseaweedfs-141d302492ba73ca5b20ee0ee98da9ca061efa42.tar.xz
seaweedfs-141d302492ba73ca5b20ee0ee98da9ca061efa42.zip
fix binarySearchCompactSection
-rw-r--r--weed/storage/needle/compact_map.go30
1 files changed, 20 insertions, 10 deletions
diff --git a/weed/storage/needle/compact_map.go b/weed/storage/needle/compact_map.go
index 2182f3bf3..4816e0098 100644
--- a/weed/storage/needle/compact_map.go
+++ b/weed/storage/needle/compact_map.go
@@ -165,19 +165,29 @@ func (cm *CompactMap) Get(key NeedleId) (*NeedleValue, bool) {
return cm.list[x].Get(key)
}
func (cm *CompactMap) binarySearchCompactSection(key NeedleId) int {
- if len(cm.list) == 0 {
- return -1
+ l, h := 0, len(cm.list)-1
+ if h < 0 {
+ return -5
}
- x := sort.Search(len(cm.list), func(i int) bool {
- return cm.list[i].start >= key
- })
- if len(cm.list) == x {
- return -1
+ if cm.list[h].start <= key {
+ if cm.list[h].counter < batch || key <= cm.list[h].end {
+ return h
+ }
+ return -4
}
- if cm.list[x].start == key {
- return x
+ for l <= h {
+ m := (l + h) / 2
+ if key < cm.list[m].start {
+ h = m - 1
+ } else { // cm.list[m].start <= key
+ if cm.list[m+1].start <= key {
+ l = m + 1
+ } else {
+ return m
+ }
+ }
}
- return x - 1
+ return -3
}
// Visit visits all entries or stop if any error when visiting