Ejemplo n.º 1
0
// Create a view on the given GCS object generation. If rl is non-nil, it must
// contain a lease for the contents of the object and will be used when
// possible instead of re-reading the object.
//
// If the object is larger than the given chunk size, we will only read
// and cache portions of it at a time.
func NewReadProxy(
	o *gcs.Object,
	rl lease.ReadLease,
	chunkSize uint64,
	leaser lease.FileLeaser,
	bucket gcs.Bucket) (rp lease.ReadProxy) {
	// Sanity check: the read lease's size should match the object's size if it
	// is present.
	if rl != nil && uint64(rl.Size()) != o.Size {
		panic(fmt.Sprintf(
			"Read lease size %d doesn't match object size %d",
			rl.Size(),
			o.Size))
	}

	// Special case: don't bring in the complication of a multi-read proxy if we
	// have only one refresher.
	refreshers := makeRefreshers(chunkSize, o, bucket)
	if len(refreshers) == 1 {
		rp = lease.NewReadProxy(leaser, refreshers[0], rl)
	} else {
		rp = lease.NewMultiReadProxy(leaser, refreshers, rl)
	}

	return
}
Ejemplo n.º 2
0
// Recreate refreshers using makeRefreshers and reset the proxy to use them and
// t.initialLease.
func (t *MultiReadProxyTest) resetProxy() {
	t.proxy = &checkingReadProxy{
		Wrapped: lease.NewMultiReadProxy(
			t.leaser,
			t.makeRefreshers(),
			t.initialLease),
	}
}