Example #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
}
Example #2
0
// Upgrade the supplied lease or panic.
func upgrade(rl lease.ReadLease) (rwl lease.ReadWriteLease) {
	var err error
	defer panicIf(&err)

	// Attempt to upgrade.
	rwl, err = rl.Upgrade()

	return
}