// Snapshot returns a read-only copy of the timer.
175531
func (t *StandardTimer) Snapshot() Timer {
	t.mutex.Lock()
	defer t.mutex.Unlock()
	return &TimerSnapshot{
		histogram: t.histogram.Snapshot().(*HistogramSnapshot),
		meter:     t.meter.Snapshot().(*MeterSnapshot),
	}
}
115006
func (c *dbCache) Snapshot() (*dbCacheSnapshot, error) {
	dbSnapshot, err := c.ldb.GetSnapshot()
	if err != nil {
		str := "failed to open transaction"
		return nil, convertErr(str, err)
	}

	// Since the cached keys to be added and removed use an immutable treap,
	// a snapshot is simply obtaining the root of the tree under the lock
	// which is used to atomically swap the root.
	c.cacheLock.RLock()
	cacheSnapshot := &dbCacheSnapshot{
		dbSnapshot:    dbSnapshot,
		pendingKeys:   c.cachedKeys,
		pendingRemove: c.cachedRemove,
	}
	c.cacheLock.RUnlock()
	return cacheSnapshot, nil
}
240719
func takeSnapshot(i ...interface{}) string {
	snapshot := &bytes.Buffer{}
	for _, v := range i {
		switch vt := v.(type) {
		case string:
			snapshot.WriteString(vt)
			snapshot.WriteString("\n")
		case []byte:
			snapshot.Write(vt)
			snapshot.WriteString("\n")
		default:
			spewConfig.Fdump(snapshot, v)
		}
	}

	return snapshot.String()
}
362031
func (s *Snapshotter) updateClock() {
	lastSeen := s.clock.Time() - 1
	if lastSeen > s.lastClock {
		s.lastClock = lastSeen
		s.tryAppend(fmt.Sprintf("clock: %d\n", s.lastClock))
	}
}
1027695
func (v *RsyncVolume) Snapshots() ([]string, error) {
	glog.Infof("Snapshots()")
	v.Lock()
	defer v.Unlock()
	return v.getSnapshotList()
}
1141108
func (dfs *DistributedFilesystem) Snapshot(data SnapshotInfo, spaceFactor int) (string, error) {
	label := generateSnapshotLabel()
	vol, err := dfs.disk.Get(data.TenantID)

	if volume.DriverTypeDeviceMapper == dfs.disk.DriverType() {
		freeSpace, err := ensureFreeSpace(vol, dfs, spaceFactor)
		if err != nil {
			glog.Errorf("Could not determine freespace on devicemapper device %s", err)
			return "", err
		}
		if !freeSpace {
			return "", errors.New("There is not enough diskspace to complete your request. You should enlarge your thin pool using LVM tools and/or delete some snapshots")
		}
	}
	if err != nil {
		glog.Errorf("Could not get volume for tenant %s: %s", data.TenantID, err)
		return "", err
	}
	// relabel all registry tags for this snapshot
	images := make([]string, len(data.Images))
	for i, image := range data.Images {
		rImage, err := dfs.index.FindImage(image)
		if err != nil {
			glog.Errorf("Could not find image %s for snapshot: %s", image, err)
			return "", err
		}

		// make sure we actually have the image locally before changing the tag and triggering a push
		if _, err := dfs.reg.FindImage(rImage); err != nil {
			glog.Errorf("Could not find image %s locally for snapshot:  %s", rImage.String(), err)
			return "", err
		}

		rImage.Tag = label
		if err := dfs.index.PushImage(rImage.String(), rImage.UUID, rImage.Hash); err != nil {
			glog.Errorf("Could not retag image %s for snapshot: %s", image, err)
			return "", err
		}
		fullImagePath, err := dfs.reg.ImagePath(rImage.String())
		if err != nil {
			glog.Errorf("Could not get the full image path for image %s: %s", image, err)
			return "", err
		}
		images[i] = fullImagePath
	}
	// write snapshot metadata
	w, err := vol.WriteMetadata(label, ImagesMetadataFile)
	if err != nil {
		glog.Errorf("Could not create image metadata file for tenant %s: %s", data.TenantID, err)
		return "", err
	}
	if err := exportJSON(w, images); err != nil {
		glog.Errorf("Could not write service metadata file for tenant %s: %s", data.TenantID, err)
		return "", err
	}
	w, err = vol.WriteMetadata(label, ServicesMetadataFile)
	if err != nil {
		glog.Errorf("Could not create service metadata file for tenant %s: %s", data.TenantID, err)
		return "", err
	}
	if err := exportJSON(w, data.Services); err != nil {
		glog.Errorf("Could not write service metadata file for tenant %s: %s", data.TenantID, err)
		return "", err
	}
	// snapshot the volume
	if err := vol.Snapshot(label, data.Message, data.Tags); err != nil {
		glog.Errorf("Could not snapshot volume for tenant %s: %s", data.TenantID, err)
		return "", err
	}
	info, err := vol.SnapshotInfo(label)
	if err != nil {
		glog.Errorf("Could not get info for snapshot %s of tenant %s: %s", label, data.TenantID, err)
		return "", err
	}
	return info.Name, nil
}
1287646
func (s *service) snapshot() *seesaw.Service {
	ss := &seesaw.Service{
		ServiceKey: seesaw.ServiceKey{
			AF:    s.af,
			Proto: s.proto,
			Port:  s.port,
		},
		Mode:          s.ventry.Mode,
		Scheduler:     s.ventry.Scheduler,
		OnePacket:     s.ventry.OnePacket,
		Persistence:   s.ventry.Persistence,
		IP:            s.ip.IP(),
		Healthy:       s.healthy,
		Enabled:       s.vserver.enabled,
		Active:        s.active,
		Stats:         s.stats,
		Destinations:  make(map[string]*seesaw.Destination),
		LowWatermark:  s.ventry.LowWatermark,
		HighWatermark: s.ventry.HighWatermark,
	}
	for _, d := range s.dests {
		sd := d.snapshot()
		ss.Destinations[sd.Backend.Hostname] = sd
	}

	numBackends := 0
	numHealthyDests := 0
	for _, d := range s.dests {
		if d.backend.InService {
			numBackends++
		}
		if d.healthy {
			numHealthyDests++
		}
	}
	if numBackends > 0 {
		ss.CurrentWatermark = float32(numHealthyDests) / float32(numBackends)
	}

	return ss
}
232612
func (c *Client) LoadSnapshot(snap *Snapshot) error {
	return c.Post("/snapshot", snap, nil)
}
1330683
func (s *RevokeSnapshotAccessOutput) SetSnapshot(v *Snapshot) *RevokeSnapshotAccessOutput {
	s.Snapshot = v
	return s
}
1237244
func WithSnapshot(value fab.EventSnapshot) options.Opt {
	return func(p options.Params) {
		if setter, ok := p.(snapshotSetter); ok {
			err := setter.SetSnapshot(value)
			if err != nil {
				logger.Errorf("Unable to set snapshot: %s", err)
			}
		}
	}
}
796098
func (f *FSM) Snapshot() (raft.FSMSnapshot, error) {
	f.mu.Lock()

	entries := make(map[SnapshotKey]SnapshotEntry)
	for _, group := range f.groups {
		for key, entry := range group {
			entries[SnapshotKey{
				Namespace: key.Namespace,
				ModelUUID: key.ModelUUID,
				Lease:     key.Lease,
			}] = SnapshotEntry{
				Holder:   entry.holder,
				Start:    entry.start,
				Duration: entry.duration,
			}
		}
	}

	pinned := make(map[SnapshotKey][]string)
	for key, entities := range f.pinned {
		if entities.IsEmpty() {
			continue
		}
		pinned[SnapshotKey{
			Namespace: key.Namespace,
			ModelUUID: key.ModelUUID,
			Lease:     key.Lease,
		}] = entities.SortedValues()
	}

	f.mu.Unlock()

	return &Snapshot{
		Version:    SnapshotVersion,
		Entries:    entries,
		Pinned:     pinned,
		GlobalTime: f.globalTime,
	}, nil
}
248162
func (kvm *Clone) Snapshot(wr io.Writer) error {
	kvm.mu.RLock()
	defer kvm.mu.RUnlock()
	data, err := json.Marshal(kvm.keys)
	if err != nil {
		return err
	}
	if _, err := wr.Write(data); err != nil {
		return err
	}
	return nil
}
705587
func (c *Cache) Snapshot() (*Cache, error) {
	c.mu.Lock()
	defer c.mu.Unlock()

	if c.snapshotting {
		return nil, ErrSnapshotInProgress
	}

	c.snapshotting = true
	c.tracker.IncSnapshotsActive() // increment the number of times we tried to do this

	// If no snapshot exists, create a new one, otherwise update the existing snapshot
	if c.snapshot == nil {
		c.snapshot = &Cache{
			store:   newRing(),
			tracker: newCacheTracker(c.tracker.metrics, c.tracker.labels),
		}
	}

	// Did a prior snapshot exist that failed?  If so, return the existing
	// snapshot to retry.
	if c.snapshot.Size() > 0 {
		return c.snapshot, nil
	}

	c.snapshot.store, c.store = c.store, c.snapshot.store
	snapshotSize := c.Size()

	c.snapshot.tracker.SetSnapshotSize(snapshotSize) // Save the size of the snapshot on the snapshot cache
	c.tracker.SetSnapshotSize(snapshotSize)          // Save the size of the snapshot on the live cache

	// Reset the cache's store.
	c.store.reset()
	c.tracker.SetCacheSize(0)
	c.lastSnapshot = time.Now()

	c.tracker.AddSnapshottedBytes(snapshotSize) // increment the number of bytes added to the snapshot
	c.tracker.SetDiskBytes(0)
	c.tracker.SetSnapshotsActive(0)

	return c.snapshot, nil
}
39553
func (d *driver) Snapshot(volumeID string, readonly bool, locator *api.VolumeLocator, noRetry bool) (string, error) {
	vols, err := d.Inspect([]string{volumeID})
	if err != nil {
		return "", err
	}
	if len(vols) != 1 {
		return "", fmt.Errorf("Failed to inspect %v len %v", volumeID, len(vols))
	}
	snapID := uuid.New()
	vols[0].Id = snapID
	vols[0].Source = &api.Source{Parent: volumeID}
	vols[0].Locator = locator
	vols[0].Ctime = prototime.Now()

	if err := d.CreateVol(vols[0]); err != nil {
		return "", err
	}
	chaos.Now(koStrayCreate)
	err = d.btrfs.Create(snapID, volumeID, "", nil)
	if err != nil {
		return "", err
	}
	return vols[0].Id, nil
}
317395
func (m *MockVolumeDriver) Snapshot(arg0 string, arg1 bool, arg2 *api.VolumeLocator, arg3 bool) (string, error) {
	ret := m.ctrl.Call(m, "Snapshot", arg0, arg1, arg2, arg3)
	ret0, _ := ret[0].(string)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}
651198
func (self *StateDB) Snapshot() int {
	id := self.nextRevisionId
	self.nextRevisionId++
	self.validRevisions = append(self.validRevisions, revision{id, self.journal.length()})
	return id
}
872032
func (ops *vsphereOps) Snapshot(volumeID string, readonly bool) (interface{}, error) {
	return nil, storageops.ErrNotSupported
}