Skip to content

Commit 3b6b263

Browse files
committed
add comments
1 parent 2ffc6fc commit 3b6b263

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

catalogd/internal/storage/index.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,25 @@ import (
1212
"github.com/operator-framework/operator-registry/alpha/declcfg"
1313
)
1414

15+
// index is an index of sections of an FBC file used to lookup FBC blobs that
16+
// match any combination of their schema, package, and name fields.
17+
18+
// This index strikes a balance between space and performance. It indexes each field
19+
// separately, and performs logical set intersections at lookup time in order to implement
20+
// a multi-parameter query.
21+
//
22+
// Note: it is permissible to change the indexing algorithm later if it is necessary to
23+
// tune the space / performance tradeoff. However care should be taken to ensure
24+
// that the actual content returned by the index remains identical, as users of the index
25+
// may be sensitive to differences introduced by index algorithm changes (e.g. if the
26+
// order of the returned sections changes).
1527
type index struct {
1628
BySchema map[string][]section `json:"by_schema"`
1729
ByPackage map[string][]section `json:"by_package"`
1830
ByName map[string][]section `json:"by_name"`
1931
}
2032

33+
// A section is the byte offset and length of an FBC blob within the file.
2134
type section struct {
2235
offset int64
2336
length int64

catalogd/internal/storage/localdir.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,22 @@ import (
2222

2323
// LocalDirV1 is a storage Instance. When Storing a new FBC contained in
2424
// fs.FS, the content is first written to a temporary file, after which
25-
// it is copied to its final destination in RootDir/catalogName/. This is
26-
// done so that clients accessing the content stored in RootDir/catalogName have
27-
// atomic view of the content for a catalog.
25+
// it is copied to its final destination in RootDir/<catalogName>.jsonl. This is
26+
// done so that clients accessing the content stored in RootDir/<catalogName>.json1
27+
// have an atomic view of the content for a catalog.
2828
type LocalDirV1 struct {
2929
RootDir string
3030
RootURL *url.URL
3131
EnableQueryHandler bool
3232

33-
m sync.RWMutex
33+
m sync.RWMutex
34+
// this singleflight Group is used in `getIndex()`` to handle concurrent HTTP requests
35+
// optimally. With the use of this slightflight group, the index is loaded from disk
36+
// once per concurrent group of HTTP requests being handled by the query handler.
37+
// The single flight instance gives us a way to load the index from disk exactly once
38+
// per concurrent group of callers, and then let every concurrent caller have access to
39+
// the loaded index. This avoids lots of unnecessary open/decode/close cycles when concurrent
40+
// requests are being handled, which improves overall performance and decreases response latency.
3441
sf singleflight.Group
3542
}
3643

0 commit comments

Comments
 (0)