Skip to content

Commit

Permalink
removed unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
kelindar committed Oct 19, 2019
1 parent df3cee6 commit d5c716d
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 80 deletions.
63 changes: 1 addition & 62 deletions internal/provider/storage/ssd.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,10 @@ package storage

import (
"context"
enc "encoding/binary"
"io"
"os"
"time"

"github.com/dgraph-io/badger"
"github.com/dgraph-io/badger/protos"
"github.com/dgraph-io/badger/y"
"github.com/emitter-io/emitter/internal/async"
"github.com/emitter-io/emitter/internal/message"
"github.com/emitter-io/emitter/internal/provider/logging"
Expand Down Expand Up @@ -71,9 +67,7 @@ func (s *SSD) Configure(config map[string]interface{}) error {
}

// Create the options
opts := badger.DefaultOptions
opts.Dir = dir
opts.ValueDir = opts.Dir
opts := badger.DefaultOptions(dir)
opts.SyncWrites = false
opts.Truncate = true

Expand Down Expand Up @@ -228,62 +222,7 @@ func loadMessage(item *badger.Item) (message.Message, error) {
return message.DecodeMessage(data)
}

// Restore loads a previous snapshot
func (s *SSD) Restore(reader io.Reader) error {
logging.LogAction("ssd", "reading from snapshot")
return s.db.Load(reader)
}

// GC runs the garbage collection on the storage
func (s *SSD) GC() {
s.db.RunValueLogGC(0.50)
}

// Backup creates a snaphshot of the store.
func (s *SSD) Backup(writer io.Writer) error {

// Run GC before backing up
s.GC()

// This is a copy of badger backup except it doesn't write any
// deleted or expired items in the snapshot.
logging.LogAction("ssd", "writing a snapshot")
return s.db.View(func(txn *badger.Txn) error {
it := txn.NewIterator(badger.DefaultIteratorOptions)
defer it.Close()

for it.Rewind(); it.Valid(); it.Next() {
item := it.Item()
valCopy, err := item.ValueCopy(nil)
if err != nil {
continue
}

entry := &protos.KVPair{
Key: y.Copy(item.Key()),
Value: valCopy,
UserMeta: []byte{item.UserMeta()},
Version: item.Version(),
ExpiresAt: item.ExpiresAt(),
}

// Write entries to disk
if err := writeTo(entry, writer); err != nil {
return err
}
}
return nil
})
}

func writeTo(entry *protos.KVPair, w io.Writer) error {
if err := enc.Write(w, binary.LittleEndian, uint64(entry.Size())); err != nil {
return err
}
buf, err := entry.Marshal()
if err != nil {
return err
}
_, err = w.Write(buf)
return err
}
18 changes: 0 additions & 18 deletions internal/provider/storage/ssd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package storage

import (
"bytes"
"context"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -326,20 +325,3 @@ func benchmarkQuery(b *testing.B, store *SSD, last int, m *stats.Metric) {

time.Sleep(5 * time.Second)
}

func TestBackup(t *testing.T) {
runSSDTest(func(store *SSD) {
err := store.storeFrame(getNTestMessages(10))
assert.NoError(t, err)

// Do the backup
buffer := bytes.NewBuffer(nil)
err = store.Backup(buffer)
assert.NoError(t, err)

// Restore the backup
reader := bytes.NewReader(buffer.Bytes())
err = store.Restore(reader)
assert.NoError(t, err)
})
}

0 comments on commit d5c716d

Please sign in to comment.