// ReportSnapshot reports snapshot status to underlying raft node.
// Part of transport.Raft interface.
511306
func (n *Node) ReportSnapshot(id uint64, status raft.SnapshotStatus) {
	n.raftNode.ReportSnapshot(id, status)
}
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()
}
1358346
func (c *HeapProfiler) TakeHeapSnapshot(reportProgress bool) (*gcdmessage.ChromeResponse, error) {
	var v HeapProfilerTakeHeapSnapshotParams
	v.ReportProgress = reportProgress
	return c.TakeHeapSnapshotWithParams(&v)
}
1291336
func (s *StateStore) Snapshot() (*StateSnapshot, error) {
	snap := &StateSnapshot{
		StateStore: StateStore{
			logger: s.logger,
			config: s.config,
			db:     s.db.Snapshot(),
		},
	}
	return snap, nil
}
678473
func (v *DeviceMapperVolume) isInvalidSnapshot(rawLabel string) bool {
	reader, err := v.ReadMetadata(rawLabel, ".SNAPSHOTINFO")
	if err != nil {
		return true
	}
	reader.Close()
	return false
}
1309868
func (s *Store) Snapshot() (raft.FSMSnapshot, error) {
	s.restoreMu.RLock()
	defer s.restoreMu.RUnlock()

	// Snapshots are not permitted while any connection has a transaction
	// in progress, because it's not possible (not without a lot of extra
	// code anyway) to capture the state of a connection during a transaction
	// on that connection. Since only during Apply() can a connection change
	// its transaction state, and Apply() is never called concurrently with
	// this call, it's safe to check transaction state here across all connections.
	if err := func() error {
		s.connsMu.Lock()
		defer s.connsMu.Unlock()
		for _, c := range s.conns {
			if c.TransactionActive() {
				stats.Add(numSnaphotsBlocked, 1)
				return ErrTransactionActive
			}
		}
		return nil
	}(); err != nil {
		return nil, err
	}

	// Copy the database.
	fsm := &fsmSnapshot{}
	var buf bytes.Buffer
	var err error
	err = s.database(false, &buf)
	if err != nil {
		s.logger.Printf("failed to read database for snapshot: %s", err.Error())
		return nil, err
	}
	fsm.database = buf.Bytes()

	// Copy the node metadata.
	fsm.meta, err = json.Marshal(s.meta)
	if err != nil {
		s.logger.Printf("failed to encode meta for snapshot: %s", err.Error())
		return nil, err
	}

	// Copy the active connections.
	fsm.connections, err = json.Marshal(s.conns)
	if err != nil {
		s.logger.Printf("failed to encode connections for snapshot: %s", err.Error())
		return nil, err
	}
	stats.Add(numSnaphots, 1)

	return fsm, nil
}
1168465
func (c *Cloud) DescribeSnapshot(snapshotID string) (status string, isCompleted bool, err error) {
	request := &ec2.DescribeSnapshotsInput{
		SnapshotIds: []*string{
			aws.String(snapshotID),
		},
	}
	result, err := c.ec2.DescribeSnapshots(request)
	if err != nil {
		return "", false, err
	}
	if len(result) != 1 {
		return "", false, fmt.Errorf("wrong result from DescribeSnapshots: %#v", result)
	}
	if result[0].State == nil {
		return "", false, fmt.Errorf("missing state from DescribeSnapshots: %#v", result)
	}
	if *result[0].State == ec2.SnapshotStateCompleted {
		return *result[0].State, true, nil
	}
	if *result[0].State == ec2.SnapshotStateError {
		return *result[0].State, false, fmt.Errorf("snapshot state is error: %s", *result[0].StateMessage)
	}
	if *result[0].State == ec2.SnapshotStatePending {
		return *result[0].State, false, nil
	}
	return *result[0].State, false, fmt.Errorf("unknown state")
}
232612
func (c *Client) LoadSnapshot(snap *Snapshot) error {
	return c.Post("/snapshot", snap, nil)
}
1117220
func (s *server) TakeSnapshot() error {
	if s.stateMachine == nil {
		return errors.New("Snapshot: Cannot create snapshot. Missing state machine.")
	}

	// Shortcut without lock
	// Exit if the server is currently creating a snapshot.
	if s.pendingSnapshot != nil {
		return errors.New("Snapshot: Last snapshot is not finished.")
	}

	// TODO: acquire the lock and no more committed is allowed
	// This will be done after finishing refactoring heartbeat
	s.debugln("take.snapshot")

	lastIndex, lastTerm := s.log.commitInfo()

	// check if there is log has been committed since the
	// last snapshot.
	if lastIndex == s.log.startIndex {
		return nil
	}

	path := s.SnapshotPath(lastIndex, lastTerm)
	// Attach snapshot to pending snapshot and save it to disk.
	s.pendingSnapshot = &Snapshot{lastIndex, lastTerm, nil, nil, path}

	state, err := s.stateMachine.Save()
	if err != nil {
		return err
	}

	// Clone the list of peers.
	peers := make([]*Peer, 0, len(s.peers)+1)
	for _, peer := range s.peers {
		peers = append(peers, peer.clone())
	}
	peers = append(peers, &Peer{Name: s.Name(), ConnectionString: s.connectionString})

	// Attach snapshot to pending snapshot and save it to disk.
	s.pendingSnapshot.Peers = peers
	s.pendingSnapshot.State = state
	s.saveSnapshot()

	// We keep some log entries after the snapshot.
	// We do not want to send the whole snapshot to the slightly slow machines
	if lastIndex-s.log.startIndex > NumberOfLogEntriesAfterSnapshot {
		compactIndex := lastIndex - NumberOfLogEntriesAfterSnapshot
		compactTerm := s.log.getEntry(compactIndex).Term()
		s.log.compact(compactIndex, compactTerm)
	}

	return 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
}
419723
func (c *OpenChannel) Snapshot() *ChannelSnapshot {
	c.RLock()
	defer c.RUnlock()

	localCommit := c.LocalCommitment
	snapshot := &ChannelSnapshot{
		RemoteIdentity:    *c.IdentityPub,
		ChannelPoint:      c.FundingOutpoint,
		Capacity:          c.Capacity,
		TotalMSatSent:     c.TotalMSatSent,
		TotalMSatReceived: c.TotalMSatReceived,
		ChainHash:         c.ChainHash,
		ChannelCommitment: ChannelCommitment{
			LocalBalance:  localCommit.LocalBalance,
			RemoteBalance: localCommit.RemoteBalance,
			CommitHeight:  localCommit.CommitHeight,
			CommitFee:     localCommit.CommitFee,
		},
	}

	// Copy over the current set of HTLCs to ensure the caller can't mutate
	// our internal state.
	snapshot.Htlcs = make([]HTLC, len(localCommit.Htlcs))
	for i, h := range localCommit.Htlcs {
		snapshot.Htlcs[i] = h.Copy()
	}

	return snapshot
}
135460
func (c *ServicedCli) printSnapshotsFirst(ctx *cli.Context) {
	if len(ctx.Args()) > 0 {
		return
	}

	for _, s := range c.snapshots("") {
		fmt.Println(s)
	}
}
163283
func (s *SnapshotGetService) Snapshot(snapshots ...string) *SnapshotGetService {
	s.snapshot = append(s.snapshot, snapshots...)
	return s
}
680161
func (m *collection) newSnapshotLOCKED() (Snapshot, error) {
	if m.isClosed() {
		return nil, ErrClosed
	}

	atomic.AddUint64(&m.stats.TotSnapshotBeg, 1)

	rv, _, _, _, _ := m.snapshot(0, nil, true) // collection lock already held.

	atomic.AddUint64(&m.stats.TotSnapshotEnd, 1)

	return rv, nil
}
860528
func (d *destination) snapshot() *seesaw.Destination {
	return &seesaw.Destination{
		Backend:     d.backend,
		Name:        d.name(),
		VserverName: d.service.vserver.String(),
		Stats:       d.stats,
		Enabled:     d.backend.Enabled,
		Weight:      d.weight,
		Healthy:     d.healthy,
		Active:      d.active,
	}
}
759535
func (c *Cloud) FindSnapshot(tags map[string]string) ([]string, []string, error) {
	request := &ec2.DescribeSnapshotsInput{}
	for k, v := range tags {
		filter := &ec2.Filter{}
		filter.SetName(k)
		filter.SetValues([]*string{&v})

		request.Filters = append(request.Filters, filter)
	}

	result, err := c.ec2.DescribeSnapshots(request)
	if err != nil {
		return nil, nil, err
	}
	var snapshotIDs, statuses []string
	for _, snapshot := range result {
		id := *snapshot.SnapshotId
		status := *snapshot.State
		glog.Infof("found %s, status %s", id, status)
		snapshotIDs = append(snapshotIDs, id)
		statuses = append(statuses, status)
	}
	return snapshotIDs, statuses, nil
}
503125
func (cs *ConnStats) Snapshot() *ConnStats {
	cs.lock.Lock()
	snapshot := *cs
	cs.lock.Unlock()

	snapshot.lock = sync.Mutex{}
	return &snapshot
}