-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Before this change, the SOCI snapshotter would verify files on read. After this change, SOCI will verify all files after the background fetcher is done, whether their read or not. Signed-off-by: Kern Walster <walster@amazon.com>
- Loading branch information
Showing
8 changed files
with
172 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
Copyright The Soci Snapshotter Authors. | ||
Licensed 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 reader | ||
|
||
import ( | ||
"errors" | ||
"sync" | ||
|
||
"github.com/containerd/log" | ||
) | ||
|
||
var ErrNotReader = errors.New("reader is not a *reader.reader") | ||
|
||
type Verifier struct { | ||
queue chan *reader | ||
|
||
closedMu sync.Mutex | ||
closed bool | ||
closedC chan struct{} | ||
} | ||
|
||
func NewVerifier(maxQueueSize int) *Verifier { | ||
return &Verifier{ | ||
queue: make(chan *reader, maxQueueSize), | ||
closedMu: sync.Mutex{}, | ||
closed: false, | ||
closedC: make(chan struct{}), | ||
} | ||
} | ||
|
||
func (v *Verifier) Add(r Reader) error { | ||
switch r := r.(type) { | ||
case *reader: | ||
go func() { | ||
select { | ||
case <-r.spanManager.DownloadedC: | ||
v.queue <- r | ||
case <-v.closedC: | ||
case <-r.closedC: | ||
} | ||
}() | ||
return nil | ||
default: | ||
return ErrNotReader | ||
} | ||
} | ||
|
||
func (v *Verifier) Run() { | ||
for { | ||
select { | ||
case r := <-v.queue: | ||
if !r.isClosed() { | ||
l := log.L.WithField("layer", r.layerSha) | ||
err := r.Verify() | ||
if err == nil { | ||
l.Debug("verified reader") | ||
} else { | ||
l.WithError(err).Error("failed to verify reader") | ||
} | ||
|
||
} | ||
case <-v.closedC: | ||
} | ||
} | ||
} | ||
|
||
func (v *Verifier) Close() { | ||
v.closedMu.Lock() | ||
if !v.closed { | ||
v.closed = true | ||
close(v.closedC) | ||
} | ||
v.closedMu.Unlock() | ||
} |
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