|
7 | 7 | "encoding/hex" |
8 | 8 | "errors" |
9 | 9 | "fmt" |
10 | | - "math" |
11 | 10 | "os" |
12 | 11 | "path/filepath" |
13 | 12 | "reflect" |
@@ -312,8 +311,8 @@ func (s *RoSnapshots) BlocksAvailable() uint64 { |
312 | 311 | func (s *RoSnapshots) LogStat(label string) { |
313 | 312 | var m runtime.MemStats |
314 | 313 | dbg.ReadMemStats(&m) |
315 | | - s.logger.Info(fmt.Sprintf("[snapshots:%s] Blocks Stat", label), |
316 | | - "blocks", fmt.Sprintf("%dk", (s.BlocksAvailable()+1)/1000), |
| 314 | + s.logger.Info(fmt.Sprintf("[snapshots:%s] Stat", label), |
| 315 | + "blocks", fmt.Sprintf("%dk", (s.SegmentsMax()+1)/1000), |
317 | 316 | "indices", fmt.Sprintf("%dk", (s.IndicesMax()+1)/1000), |
318 | 317 | "alloc", common2.ByteCount(m.Alloc), "sys", common2.ByteCount(m.Sys)) |
319 | 318 | } |
@@ -386,29 +385,46 @@ func (s *RoSnapshots) EnableMadvNormal() *RoSnapshots { |
386 | 385 | return s |
387 | 386 | } |
388 | 387 |
|
| 388 | +// minimax of existing indices |
389 | 389 | func (s *RoSnapshots) idxAvailability() uint64 { |
390 | | - _max := make([]uint64, len(s.Types())) |
391 | | - i := 0 |
| 390 | + // Use-Cases: |
| 391 | + // 1. developers can add new types in future. and users will not have files of this type |
| 392 | + // 2. some types are network-specific. example: borevents exists only on Bor-consensus networks |
| 393 | + // 3. user can manually remove 1 .idx file: `rm snapshots/v1-type1-0000-1000.idx` |
| 394 | + // 4. user can manually remove all .idx files of given type: `rm snapshots/*type1*.idx` |
| 395 | + // 5. file-types may have different height: 10 headers, 10 bodies, 9 trancasctions (for example if `kill -9` came during files building/merge). still need index all 3 types. |
| 396 | + amount := 0 |
| 397 | + s.segments.Scan(func(segtype snaptype.Enum, value *segments) bool { |
| 398 | + if len(value.segments) == 0 || !s.HasType(segtype.Type()) { |
| 399 | + return true |
| 400 | + } |
| 401 | + amount++ |
| 402 | + return true |
| 403 | + }) |
392 | 404 |
|
| 405 | + maximums := make([]uint64, amount) |
| 406 | + var i int |
393 | 407 | s.segments.Scan(func(segtype snaptype.Enum, value *segments) bool { |
| 408 | + if len(value.segments) == 0 || !s.HasType(segtype.Type()) { |
| 409 | + return true |
| 410 | + } |
| 411 | + |
394 | 412 | for _, seg := range value.segments { |
395 | 413 | if !seg.IsIndexed() { |
396 | 414 | break |
397 | 415 | } |
398 | 416 |
|
399 | | - _max[i] = seg.to - 1 |
| 417 | + maximums[i] = seg.to - 1 |
400 | 418 | } |
401 | 419 |
|
402 | 420 | i++ |
403 | 421 | return true |
404 | 422 | }) |
405 | 423 |
|
406 | | - var _min uint64 = math.MaxUint64 |
407 | | - for _, maxEl := range _max { |
408 | | - _min = cmp.Min(_min, maxEl) |
| 424 | + if len(maximums) == 0 { |
| 425 | + return 0 |
409 | 426 | } |
410 | | - |
411 | | - return _min |
| 427 | + return slices.Min(maximums) |
412 | 428 | } |
413 | 429 |
|
414 | 430 | // OptimisticReopenWithDB - optimistically open snapshots (ignoring error), useful at App startup because: |
|
0 commit comments