// ClearSnapshot removes the snapshot cache from the list of flushing caches and
// adjusts the size.
767204
func (c *Cache) ClearSnapshot(success bool) {
	c.mu.RLock()
	snapStore := c.snapshot.store
	c.mu.RUnlock()

	// reset the snapshot store outside of the write lock
	if success {
		snapStore.reset()
	}

	c.mu.Lock()
	defer c.mu.Unlock()

	c.snapshotting = false

	if success {
		snapshotSize := c.tracker.SnapshotSize()
		c.tracker.SetSnapshotsActive(0)
		c.tracker.SubMemBytes(snapshotSize) // decrement the number of bytes in cache

		// Reset the snapshot to a fresh Cache.
		c.snapshot = &Cache{
			store:   c.snapshot.store,
			tracker: newCacheTracker(c.tracker.metrics, c.tracker.labels),
		}

		c.tracker.SetSnapshotSize(0)
		c.tracker.SetDiskBytes(0)
		c.tracker.SetSnapshotsActive(0)
	}
}
1237245
func (client *Client) DeleteSnapshot(snapshotId string) error {
	args := DeleteSnapshotArgs{SnapshotId: snapshotId}
	response := DeleteSnapshotResponse{}

	return client.Invoke("DeleteSnapshot", &args, &response)
}
398275
func (d Ploop) DeleteSnapshot(uuid string) error {
	return ploop("snapshot-delete", "-u", uuid, d.dd)
}
647622
func (c *ServicedCli) initSnapshot() {
	c.app.Commands = append(c.app.Commands, cli.Command{
		Name:        "snapshot",
		Usage:       "Administers environment snapshots",
		Description: "",
		Subcommands: []cli.Command{
			{
				Name:         "list",
				Usage:        "Lists all snapshots",
				Description:  "serviced snapshot list [SERVICEID]",
				BashComplete: c.printServicesFirst,
				Action:       c.cmdSnapshotList,
				Flags: []cli.Flag{
					cli.BoolFlag{
						Name:  "show-tags, t",
						Usage: "shows tags associated with each snapshot",
					},
				},
			}, {
				Name:         "add",
				Usage:        "Take a snapshot of an existing service",
				Description:  "serviced snapshot add SERVICEID",
				BashComplete: c.printServicesFirst,
				Action:       c.cmdSnapshotAdd,
				Flags: []cli.Flag{
					cli.StringFlag{
						Name:  "description, d",
						Value: "",
						Usage: "a description of the snapshot",
					},
					cli.StringFlag{
						Name:  "tag, t",
						Value: "",
						Usage: "a unique tag for the snapshot",
					},
				},
			}, {
				Name:         "remove",
				ShortName:    "rm",
				Usage:        "Removes an existing snapshot",
				Description:  "serviced snapshot remove [SNAPSHOTID | SERVICED TAG-NAME]",
				BashComplete: c.printServicesFirst,
				Action:       c.cmdSnapshotRemove,
				Flags: []cli.Flag{
					cli.BoolFlag{
						Name:  "force, f",
						Usage: "required for deleting all snapshots",
					},
				},
			}, {
				Name:        "commit",
				Usage:       "Snapshots and commits a given service instance",
				Description: "serviced snapshot commit DOCKERID",
				Action:      c.cmdSnapshotCommit,
			}, {
				Name:        "rollback",
				Usage:       "Restores the environment to the state of the given snapshot",
				Description: "serviced snapshot rollback SNAPSHOTID",
				Flags: []cli.Flag{
					cli.BoolFlag{
						Name:  "force-restart",
						Usage: "restarts running services during rollback",
					},
				},
				BashComplete: c.printSnapshotsFirst,
				Action:       c.cmdSnapshotRollback,
			}, {
				Name:         "tag",
				Usage:        "Tags an existing snapshot with TAG-NAME",
				Description:  "serviced snapshot tag SNAPSHOTID TAG-NAME",
				BashComplete: c.printSnapshotsFirst,
				Action:       c.cmdSnapshotTag,
			}, {
				Name:         "untag",
				Usage:        "Removes a tag from an existing snapshot",
				Description:  "serviced snapshot untag SERVICEID TAG-NAME",
				BashComplete: c.printServicesFirst,
				Action:       c.cmdSnapshotRemoveTag,
			},
		},
	})
}
1169874
func (smap *syncedMap) Clear() {
	smap.Lock()
	defer smap.Unlock()

	smap.data = make(map[interface{}]interface{})
}
751968
func (s *server) saveSnapshot() error {
	if s.pendingSnapshot == nil {
		return errors.New("pendingSnapshot.is.nil")
	}

	// Write snapshot to disk.
	if err := s.pendingSnapshot.save(); err != nil {
		return err
	}

	// Swap the current and last snapshots.
	tmp := s.snapshot
	s.snapshot = s.pendingSnapshot

	// Delete the previous snapshot if there is any change
	if tmp != nil && !(tmp.LastIndex == s.snapshot.LastIndex && tmp.LastTerm == s.snapshot.LastTerm) {
		tmp.remove()
	}
	s.pendingSnapshot = nil

	return nil
}
171731
func (s *Scorch) LoadSnapshot(epoch uint64) (rv *IndexSnapshot, err error) {
	err = s.rootBolt.View(func(tx *bolt.Tx) error {
		snapshots := tx.Bucket(boltSnapshotsBucket)
		if snapshots == nil {
			return nil
		}
		snapshotKey := segment.EncodeUvarintAscending(nil, epoch)
		snapshot := snapshots.Bucket(snapshotKey)
		if snapshot == nil {
			return fmt.Errorf("snapshot with epoch: %v - doesn't exist", epoch)
		}
		rv, err = s.loadSnapshot(snapshot)
		return err
	})
	if err != nil {
		return nil, err
	}
	return rv, nil
}
1313907
func (s *CreateSnapshotOutput) SetSnapshot(v *Snapshot) *CreateSnapshotOutput {
	s.Snapshot = v
	return s
}
122792
func (s *AuthorizeSnapshotAccessOutput) SetSnapshot(v *Snapshot) *AuthorizeSnapshotAccessOutput {
	s.Snapshot = v
	return s
}
609295
func (cache *schedulerCache) Snapshot() *Snapshot {
	cache.mu.RLock()
	defer cache.mu.RUnlock()

	nodes := make(map[string]*schedulernodeinfo.NodeInfo, len(cache.nodes))
	for k, v := range cache.nodes {
		nodes[k] = v.info.Clone()
	}

	assumedPods := make(map[string]bool, len(cache.assumedPods))
	for k, v := range cache.assumedPods {
		assumedPods[k] = v
	}

	return &Snapshot{
		Nodes:       nodes,
		AssumedPods: assumedPods,
	}
}
1027695
func (v *RsyncVolume) Snapshots() ([]string, error) {
	glog.Infof("Snapshots()")
	v.Lock()
	defer v.Unlock()
	return v.getSnapshotList()
}
438622
func (m *SnapshotMetadata) RemoveSnapshot(snapshot string) error {
	m.Lock()
	defer m.Unlock()
	delete(m.snapshotMetadata.Snapshots, snapshot)
	return m.save()
}
941096
func (db *DB) newSnapshot() *Snapshot {
	snap := &Snapshot{
		db:   db,
		elem: db.acquireSnapshot(),
	}
	atomic.AddInt32(&db.aliveSnaps, 1)
	runtime.SetFinalizer(snap, (*Snapshot).Release)
	return snap
}
996265
func (t *compactionTracker) SnapshotAttempted(success bool, reason CacheStatus, duration time.Duration) {
	t.Attempted(0, success, reason.String(), duration)
}
404744
func (v VirtualMachine) RemoveSnapshot(ctx context.Context, name string, removeChildren bool, consolidate *bool) (*Task, error) {
	snapshot, err := v.FindSnapshot(ctx, name)
	if err != nil {
		return nil, err
	}

	req := types.RemoveSnapshot_Task{
		This:           snapshot.Reference(),
		RemoveChildren: removeChildren,
		Consolidate:    consolidate,
	}

	res, err := methods.RemoveSnapshot_Task(ctx, v.c, &req)
	if err != nil {
		return nil, err
	}

	return NewTask(v.c, res.Returnval), nil
}
1345159
func (d *DeviceMapperDriver) cleanUpSnapshots() {
	snapshotsOnDisk, err := d.getSnapshotsOnDisk()
	if err != nil || snapshotsOnDisk == nil {
		return
	}

	glog.V(2).Infof("Snapshots on disk: %v", snapshotsOnDisk)

	snapshotsInMetadata, err := d.getSnapshotsFromMetadata()
	if err != nil || snapshotsInMetadata == nil {
		return
	}

	glog.V(2).Infof("Snapshots in metadata: %v", snapshotsInMetadata)

	for _, snapshotOnDisk := range snapshotsOnDisk {
		if _, ok := snapshotsInMetadata[snapshotOnDisk]; !ok {
			glog.V(2).Infof("Removing Snapshot: %v", snapshotOnDisk)
			os.RemoveAll(filepath.Join(d.MetadataDir(), snapshotOnDisk))
		} else {
			// Remove the snapshot on disk since it was found in the metadata map.  This
			// will leave the snapshotsInMetadata map with only snapshots that are in metadata but
			// not on disk, so they should all be removed from the metadata.
			delete(snapshotsInMetadata, snapshotOnDisk)
		}
	}

	for snapshotInMetadata, volumeName := range snapshotsInMetadata {
		glog.V(2).Infof("Removing Snapshot from metadata: %v", snapshotInMetadata)
		v, err := d.getVolume(volumeName, false)
		if err != nil {
			continue
		}

		v.Lock()
		defer v.Unlock()

		deviceHash, err := v.Metadata.LookupSnapshotDevice(snapshotInMetadata)
		if err != nil {
			glog.Errorf("Error removing snapshot: %v", err)
			continue
		}

		// Remove the snapshot info from the volume metadata
		if err := v.Metadata.RemoveSnapshot(snapshotInMetadata); err != nil {
			glog.Errorf("Error removing snapshot: %v", err)
			continue
		}

		glog.V(2).Infof("Deactivating snapshot device %s", deviceHash)
		v.driver.DeviceSet.Lock()
		err = v.driver.DeactivateDevice(deviceHash)
		v.driver.DeviceSet.Unlock()
		if err != nil {
			glog.Errorf("Error deactivating device (%s): %s", deviceHash, err)
			continue
		}
		if err := v.driver.deleteDevice(deviceHash, false); err != nil {
			glog.Errorf("Error removing snapshot: %v", err)
			continue
		}
	}
}
1370863
func (v *BtrfsVolume) RemoveSnapshot(label string) error {
	if exists, err := v.snapshotExists(label); err != nil || !exists {
		if err != nil {
			return err
		} else {
			return volume.ErrSnapshotDoesNotExist
		}
	}

	v.Lock()
	defer v.Unlock()
	_, err := volume.RunBtrFSCmd(v.sudoer, "subvolume", "delete", v.snapshotPath(label))
	if err != nil {
		glog.Errorf("could not remove snapshot: %s", err)
		return volume.ErrRemovingSnapshot
	}
	return nil
}