-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add page iterator (LPI) for local pagination
* part four, prev. commit: 693ff5c Signed-off-by: Alex Aizman <[email protected]>
- Loading branch information
1 parent
9f2ecbd
commit 8109466
Showing
11 changed files
with
232 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Package lpi: local page iterator | ||
/* | ||
* Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. | ||
*/ | ||
package lpi | ||
|
||
import ( | ||
"github.com/NVIDIA/aistore/api/apc" | ||
"github.com/NVIDIA/aistore/cmn" | ||
"github.com/NVIDIA/aistore/cmn/cos" | ||
"github.com/NVIDIA/aistore/cmn/debug" | ||
"github.com/NVIDIA/aistore/cmn/nlog" | ||
"github.com/NVIDIA/aistore/fs" | ||
) | ||
|
||
type ( | ||
milpi struct { | ||
page Page | ||
it *Iter | ||
mi *fs.Mountpath | ||
} | ||
Lpis struct { | ||
a []milpi | ||
bck *cmn.Bck | ||
} | ||
) | ||
|
||
func (lpis *Lpis) Init(bck *cmn.Bck, prefix string) { | ||
var ( | ||
avail = fs.GetAvail() | ||
) | ||
{ | ||
lpis.a = make([]milpi, 0, len(avail)) | ||
lpis.bck = bck | ||
} | ||
for _, mi := range avail { | ||
it, err := New(mi.MakePathPrefix(bck, fs.ObjectType, prefix)) | ||
debug.AssertNoErr(err) | ||
milpi := milpi{ | ||
page: make(Page), | ||
it: it, | ||
mi: mi, | ||
} | ||
lpis.a = append(lpis.a, milpi) | ||
} | ||
} | ||
|
||
// TODO: consider jogger-per-mountpath | ||
|
||
func (lpis *Lpis) Do(lastPage cmn.LsoEntries, outPage *cmn.LsoRes, tag string) { | ||
var ( | ||
lastName string | ||
eop = AllPages | ||
num = len(lastPage) // num entries | ||
) | ||
if num > 0 { | ||
lastName = lastPage[num-1].Name | ||
} | ||
// 1. all mountpaths: next page | ||
for _, milpi := range lpis.a { | ||
if milpi.it.Pos() == "" { | ||
// iterated to the end, exhausted local content | ||
milpi.it.Clear() | ||
continue | ||
} | ||
if lastName != "" { | ||
eop = milpi.mi.MakePathPrefix(lpis.bck, fs.ObjectType, lastName) | ||
} | ||
|
||
// next local page "until" | ||
lpiMsg := Msg{EOP: eop} | ||
if err := milpi.it.Next(lpiMsg, milpi.page); err != nil { | ||
if cmn.Rom.FastV(4, cos.SmoduleXs) { | ||
nlog.Warningln(tag, err) | ||
} | ||
} | ||
} | ||
|
||
// 2. last page as a map | ||
lastPageMap := allocPage() | ||
for _, en := range lastPage { | ||
lastPageMap[en.Name] = struct{}{} | ||
} | ||
|
||
// 3. find and add 'remotely-deleted' | ||
for _, milpi := range lpis.a { | ||
for lname := range milpi.page { | ||
if _, ok := lastPageMap[lname]; ok { | ||
delete(milpi.page, lname) | ||
continue | ||
} | ||
en := &cmn.LsoEnt{Name: lname} | ||
en.SetFlag(apc.EntryVerRemoved | apc.EntryIsCached) | ||
outPage.Entries = append(outPage.Entries, en) | ||
} | ||
} | ||
freePage(lastPageMap) | ||
} |
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,83 @@ | ||
// Package lpi_test: local page iterator | ||
/* | ||
* Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. | ||
*/ | ||
package lpi_test | ||
|
||
import ( | ||
"strconv" | ||
"sync" | ||
"testing" | ||
) | ||
|
||
func _clr(m map[int]struct{}) { | ||
for k := range m { | ||
delete(m, k) | ||
} | ||
} | ||
|
||
func BenchClear(b *testing.B) { | ||
b.RunParallel(func(pb *testing.PB) { | ||
m := make(map[int]struct{}) | ||
for pb.Next() { | ||
for i := range 1000 { | ||
m[i] = struct{}{} | ||
} | ||
clear(m) | ||
} | ||
}) | ||
} | ||
|
||
func BenchManualClear(b *testing.B) { | ||
b.RunParallel(func(pb *testing.PB) { | ||
m := make(map[int]struct{}) | ||
for pb.Next() { | ||
for i := range 1000 { | ||
m[i] = struct{}{} | ||
} | ||
_clr(m) | ||
} | ||
}) | ||
} | ||
|
||
// init | ||
var keys []string | ||
|
||
func init() { | ||
keys = make([]string, 1000) | ||
for i := range 1000 { | ||
keys[i] = "key-" + strconv.Itoa(i) | ||
} | ||
} | ||
|
||
var pool = sync.Pool{ | ||
New: func() interface{} { | ||
return make(map[string]struct{}, 1000) | ||
}, | ||
} | ||
|
||
func BenchmarkPool(b *testing.B) { | ||
b.RunParallel(func(pb *testing.PB) { | ||
for pb.Next() { | ||
m := pool.Get().(map[string]struct{}) | ||
for i := range 1000 { | ||
k := keys[i] | ||
m[k] = struct{}{} | ||
} | ||
clear(m) | ||
pool.Put(m) | ||
} | ||
}) | ||
} | ||
|
||
func BenchmarkNoPool(b *testing.B) { | ||
b.RunParallel(func(pb *testing.PB) { | ||
for pb.Next() { | ||
m := make(map[string]struct{}, 1000) | ||
for i := range 1000 { | ||
k := keys[i] | ||
m[k] = struct{}{} | ||
} | ||
} | ||
}) | ||
} |
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 was deleted.
Oops, something went wrong.
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,22 @@ | ||
// Package lpi: local page iterator | ||
/* | ||
* Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. | ||
*/ | ||
package lpi | ||
|
||
import "sync" | ||
|
||
var pool sync.Pool | ||
|
||
func allocPage() Page { | ||
v := pool.Get() | ||
if v != nil { | ||
return v.(Page) | ||
} | ||
return make(Page, 1000) | ||
} | ||
|
||
func freePage(v Page) { | ||
clear(v) | ||
pool.Put(v) | ||
} |
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