// ApplySnapshot applies the snapshot of the computation's persisted state func (p *LevelDBPersister) ApplySnapshot(compID StreamID, snapshot []byte) error { batch := new(leveldb.Batch) log.Println("[persister] Applying snapshot") //, snapshot) // clear data for this computation keyPrefix := compID iter := p.db.NewIterator(util.BytesPrefix([]byte(keyPrefix)), nil) defer iter.Release() for iter.Next() { batch.Delete(iter.Key()) } err := p.db.Write(batch, nil) if err != nil { return err } batch.Reset() err = batch.Load(snapshot) if err != nil { return err } return p.db.Write(batch, nil) }