Levigo -> LevelDB in terminology and references.

This commit is contained in:
Matt T. Proud 2012-11-28 20:22:49 +01:00
parent 2450cb3b1c
commit c1f0d8aefd
10 changed files with 90 additions and 89 deletions

View file

@ -28,6 +28,7 @@ clean:
$(MAKE) -C model clean
-find . -type f -iname '*~' -exec rm '{}' ';'
-find . -type f -iname '*#' -exec rm '{}' ';'
-find . -type f -iname '.#*' -exec rm '{}' ';'
format:
find . -iname '*.go' | grep -v generated | xargs -n1 gofmt -w

View file

@ -20,7 +20,7 @@ import (
)
func main() {
m, _ := leveldb.NewLevigoMetricPersistence("/tmp/metrics")
m, _ := leveldb.NewLevelDBMetricPersistence("/tmp/metrics")
s := &MetricsService{
persistence: m,
}

View file

@ -22,7 +22,7 @@ import (
type MetricsService struct {
gorest.RestService `root:"/" consumes:"application/json" produces:"application/json"`
persistence *leveldb.LevigoMetricPersistence
persistence *leveldb.LevelDBMetricPersistence
listLabels gorest.EndPoint `method:"GET" path:"/labels/" output:"[]string"`
listLabelPairs gorest.EndPoint `method:"GET" path:"/label-pairs/" output:"[]model.LabelPairs"`

View file

@ -19,5 +19,5 @@ import (
)
func TestInterfaceAdherence(t *testing.T) {
var _ metric.MetricPersistence = &LevigoMetricPersistence{}
var _ metric.MetricPersistence = &LevelDBMetricPersistence{}
}

View file

@ -29,20 +29,20 @@ import (
"sort"
)
type LevigoMetricPersistence struct {
fingerprintHighWaterMarks *storage.LevigoPersistence
fingerprintLabelPairs *storage.LevigoPersistence
fingerprintLowWaterMarks *storage.LevigoPersistence
fingerprintSamples *storage.LevigoPersistence
labelNameFingerprints *storage.LevigoPersistence
labelPairFingerprints *storage.LevigoPersistence
metricMembershipIndex *index.LevigoMembershipIndex
type LevelDBMetricPersistence struct {
fingerprintHighWaterMarks *storage.LevelDBPersistence
fingerprintLabelPairs *storage.LevelDBPersistence
fingerprintLowWaterMarks *storage.LevelDBPersistence
fingerprintSamples *storage.LevelDBPersistence
labelNameFingerprints *storage.LevelDBPersistence
labelPairFingerprints *storage.LevelDBPersistence
metricMembershipIndex *index.LevelDBMembershipIndex
}
type levigoOpener func()
type leveldbOpener func()
func (l *LevigoMetricPersistence) Close() error {
log.Printf("Closing LevigoPersistence storage containers...")
func (l *LevelDBMetricPersistence) Close() error {
log.Printf("Closing LevelDBPersistence storage containers...")
var persistences = []struct {
name string
@ -85,11 +85,11 @@ func (l *LevigoMetricPersistence) Close() error {
closer := persistence.closer
if closer != nil {
log.Printf("Closing LevigoPersistence storage container: %s\n", name)
log.Printf("Closing LevelDBPersistence storage container: %s\n", name)
closingError := closer.Close()
if closingError != nil {
log.Printf("Could not close a LevigoPersistence storage container; inconsistencies are possible: %q\n", closingError)
log.Printf("Could not close a LevelDBPersistence storage container; inconsistencies are possible: %q\n", closingError)
}
errorChannel <- closingError
@ -106,27 +106,27 @@ func (l *LevigoMetricPersistence) Close() error {
}
}
log.Printf("Successfully closed all LevigoPersistence storage containers.")
log.Printf("Successfully closed all LevelDBPersistence storage containers.")
return nil
}
func NewLevigoMetricPersistence(baseDirectory string) (*LevigoMetricPersistence, error) {
log.Printf("Opening LevigoPersistence storage containers...")
func NewLevelDBMetricPersistence(baseDirectory string) (*LevelDBMetricPersistence, error) {
log.Printf("Opening LevelDBPersistence storage containers...")
errorChannel := make(chan error, 7)
emission := &LevigoMetricPersistence{}
emission := &LevelDBMetricPersistence{}
var subsystemOpeners = []struct {
name string
opener levigoOpener
opener leveldbOpener
}{
{
"High-Water Marks by Fingerprint",
func() {
var anomaly error
emission.fingerprintHighWaterMarks, anomaly = storage.NewLevigoPersistence(baseDirectory+"/high_water_marks_by_fingerprint", 1000000, 10)
emission.fingerprintHighWaterMarks, anomaly = storage.NewLevelDBPersistence(baseDirectory+"/high_water_marks_by_fingerprint", 1000000, 10)
errorChannel <- anomaly
},
},
@ -134,7 +134,7 @@ func NewLevigoMetricPersistence(baseDirectory string) (*LevigoMetricPersistence,
"Label Names and Value Pairs by Fingerprint",
func() {
var anomaly error
emission.fingerprintLabelPairs, anomaly = storage.NewLevigoPersistence(baseDirectory+"/label_name_and_value_pairs_by_fingerprint", 1000000, 10)
emission.fingerprintLabelPairs, anomaly = storage.NewLevelDBPersistence(baseDirectory+"/label_name_and_value_pairs_by_fingerprint", 1000000, 10)
errorChannel <- anomaly
},
},
@ -142,7 +142,7 @@ func NewLevigoMetricPersistence(baseDirectory string) (*LevigoMetricPersistence,
"Low-Water Marks by Fingerprint",
func() {
var anomaly error
emission.fingerprintLowWaterMarks, anomaly = storage.NewLevigoPersistence(baseDirectory+"/low_water_marks_by_fingerprint", 1000000, 10)
emission.fingerprintLowWaterMarks, anomaly = storage.NewLevelDBPersistence(baseDirectory+"/low_water_marks_by_fingerprint", 1000000, 10)
errorChannel <- anomaly
},
},
@ -150,7 +150,7 @@ func NewLevigoMetricPersistence(baseDirectory string) (*LevigoMetricPersistence,
"Samples by Fingerprint",
func() {
var anomaly error
emission.fingerprintSamples, anomaly = storage.NewLevigoPersistence(baseDirectory+"/samples_by_fingerprint", 1000000, 10)
emission.fingerprintSamples, anomaly = storage.NewLevelDBPersistence(baseDirectory+"/samples_by_fingerprint", 1000000, 10)
errorChannel <- anomaly
},
},
@ -158,7 +158,7 @@ func NewLevigoMetricPersistence(baseDirectory string) (*LevigoMetricPersistence,
"Fingerprints by Label Name",
func() {
var anomaly error
emission.labelNameFingerprints, anomaly = storage.NewLevigoPersistence(baseDirectory+"/fingerprints_by_label_name", 1000000, 10)
emission.labelNameFingerprints, anomaly = storage.NewLevelDBPersistence(baseDirectory+"/fingerprints_by_label_name", 1000000, 10)
errorChannel <- anomaly
},
},
@ -166,7 +166,7 @@ func NewLevigoMetricPersistence(baseDirectory string) (*LevigoMetricPersistence,
"Fingerprints by Label Name and Value Pair",
func() {
var anomaly error
emission.labelPairFingerprints, anomaly = storage.NewLevigoPersistence(baseDirectory+"/fingerprints_by_label_name_and_value_pair", 1000000, 10)
emission.labelPairFingerprints, anomaly = storage.NewLevelDBPersistence(baseDirectory+"/fingerprints_by_label_name_and_value_pair", 1000000, 10)
errorChannel <- anomaly
},
},
@ -174,7 +174,7 @@ func NewLevigoMetricPersistence(baseDirectory string) (*LevigoMetricPersistence,
"Metric Membership Index",
func() {
var anomaly error
emission.metricMembershipIndex, anomaly = index.NewLevigoMembershipIndex(baseDirectory+"/metric_membership_index", 1000000, 10)
emission.metricMembershipIndex, anomaly = index.NewLevelDBMembershipIndex(baseDirectory+"/metric_membership_index", 1000000, 10)
errorChannel <- anomaly
},
},
@ -184,7 +184,7 @@ func NewLevigoMetricPersistence(baseDirectory string) (*LevigoMetricPersistence,
name := subsystem.name
opener := subsystem.opener
log.Printf("Opening LevigoPersistence storage container: %s\n", name)
log.Printf("Opening LevelDBPersistence storage container: %s\n", name)
go opener()
}
@ -194,13 +194,13 @@ func NewLevigoMetricPersistence(baseDirectory string) (*LevigoMetricPersistence,
if openingError != nil {
log.Printf("Could not open a LevigoPersistence storage container: %q\n", openingError)
log.Printf("Could not open a LevelDBPersistence storage container: %q\n", openingError)
return nil, openingError
}
}
log.Printf("Successfully opened all LevigoPersistence storage containers.\n")
log.Printf("Successfully opened all LevelDBPersistence storage containers.\n")
return emission, nil
}
@ -269,12 +269,12 @@ func fingerprintDDOFromByteArray(fingerprint []byte) *data.FingerprintDDO {
return fingerprintDDO
}
func (l *LevigoMetricPersistence) hasIndexMetric(ddo *data.MetricDDO) (bool, error) {
func (l *LevelDBMetricPersistence) hasIndexMetric(ddo *data.MetricDDO) (bool, error) {
ddoKey := coding.NewProtocolBufferEncoder(ddo)
return l.metricMembershipIndex.Has(ddoKey)
}
func (l *LevigoMetricPersistence) indexMetric(ddo *data.MetricDDO) error {
func (l *LevelDBMetricPersistence) indexMetric(ddo *data.MetricDDO) error {
ddoKey := coding.NewProtocolBufferEncoder(ddo)
return l.metricMembershipIndex.Put(ddoKey)
}
@ -292,17 +292,17 @@ func fingerprintDDOForMessage(message proto.Message) (*data.FingerprintDDO, erro
return nil, errors.New("Unknown error in generating FingerprintDDO from message.")
}
func (l *LevigoMetricPersistence) HasLabelPair(ddo *data.LabelPairDDO) (bool, error) {
func (l *LevelDBMetricPersistence) HasLabelPair(ddo *data.LabelPairDDO) (bool, error) {
ddoKey := coding.NewProtocolBufferEncoder(ddo)
return l.labelPairFingerprints.Has(ddoKey)
}
func (l *LevigoMetricPersistence) HasLabelName(ddo *data.LabelNameDDO) (bool, error) {
func (l *LevelDBMetricPersistence) HasLabelName(ddo *data.LabelNameDDO) (bool, error) {
ddoKey := coding.NewProtocolBufferEncoder(ddo)
return l.labelNameFingerprints.Has(ddoKey)
}
func (l *LevigoMetricPersistence) GetLabelPairFingerprints(ddo *data.LabelPairDDO) (*data.FingerprintCollectionDDO, error) {
func (l *LevelDBMetricPersistence) GetLabelPairFingerprints(ddo *data.LabelPairDDO) (*data.FingerprintCollectionDDO, error) {
ddoKey := coding.NewProtocolBufferEncoder(ddo)
if get, getError := l.labelPairFingerprints.Get(ddoKey); getError == nil {
value := &data.FingerprintCollectionDDO{}
@ -317,7 +317,7 @@ func (l *LevigoMetricPersistence) GetLabelPairFingerprints(ddo *data.LabelPairDD
return nil, errors.New("Unknown error while getting label name and value pair fingerprints.")
}
func (l *LevigoMetricPersistence) GetLabelNameFingerprints(ddo *data.LabelNameDDO) (*data.FingerprintCollectionDDO, error) {
func (l *LevelDBMetricPersistence) GetLabelNameFingerprints(ddo *data.LabelNameDDO) (*data.FingerprintCollectionDDO, error) {
ddoKey := coding.NewProtocolBufferEncoder(ddo)
if get, getError := l.labelNameFingerprints.Get(ddoKey); getError == nil {
value := &data.FingerprintCollectionDDO{}
@ -333,19 +333,19 @@ func (l *LevigoMetricPersistence) GetLabelNameFingerprints(ddo *data.LabelNameDD
return nil, errors.New("Unknown error while getting label name fingerprints.")
}
func (l *LevigoMetricPersistence) setLabelPairFingerprints(labelPair *data.LabelPairDDO, fingerprints *data.FingerprintCollectionDDO) error {
func (l *LevelDBMetricPersistence) setLabelPairFingerprints(labelPair *data.LabelPairDDO, fingerprints *data.FingerprintCollectionDDO) error {
labelPairEncoded := coding.NewProtocolBufferEncoder(labelPair)
fingerprintsEncoded := coding.NewProtocolBufferEncoder(fingerprints)
return l.labelPairFingerprints.Put(labelPairEncoded, fingerprintsEncoded)
}
func (l *LevigoMetricPersistence) setLabelNameFingerprints(labelName *data.LabelNameDDO, fingerprints *data.FingerprintCollectionDDO) error {
func (l *LevelDBMetricPersistence) setLabelNameFingerprints(labelName *data.LabelNameDDO, fingerprints *data.FingerprintCollectionDDO) error {
labelNameEncoded := coding.NewProtocolBufferEncoder(labelName)
fingerprintsEncoded := coding.NewProtocolBufferEncoder(fingerprints)
return l.labelNameFingerprints.Put(labelNameEncoded, fingerprintsEncoded)
}
func (l *LevigoMetricPersistence) appendLabelPairFingerprint(labelPair *data.LabelPairDDO, fingerprint *data.FingerprintDDO) error {
func (l *LevelDBMetricPersistence) appendLabelPairFingerprint(labelPair *data.LabelPairDDO, fingerprint *data.FingerprintDDO) error {
if has, hasError := l.HasLabelPair(labelPair); hasError == nil {
var fingerprints *data.FingerprintCollectionDDO
if has {
@ -368,7 +368,7 @@ func (l *LevigoMetricPersistence) appendLabelPairFingerprint(labelPair *data.Lab
return errors.New("Unknown error when appending fingerprint to label name and value pair.")
}
func (l *LevigoMetricPersistence) appendLabelNameFingerprint(labelPair *data.LabelPairDDO, fingerprint *data.FingerprintDDO) error {
func (l *LevelDBMetricPersistence) appendLabelNameFingerprint(labelPair *data.LabelPairDDO, fingerprint *data.FingerprintDDO) error {
labelName := &data.LabelNameDDO{
Name: labelPair.Name,
}
@ -395,7 +395,7 @@ func (l *LevigoMetricPersistence) appendLabelNameFingerprint(labelPair *data.Lab
return errors.New("Unknown error when appending fingerprint to label name and value pair.")
}
func (l *LevigoMetricPersistence) appendFingerprints(ddo *data.MetricDDO) error {
func (l *LevelDBMetricPersistence) appendFingerprints(ddo *data.MetricDDO) error {
if fingerprintDDO, fingerprintDDOError := fingerprintDDOForMessage(ddo); fingerprintDDOError == nil {
labelPairCollectionDDO := &data.LabelPairCollectionDDO{
Member: ddo.LabelPair,
@ -446,7 +446,7 @@ func (l *LevigoMetricPersistence) appendFingerprints(ddo *data.MetricDDO) error
return errors.New("Unknown error in appending label pairs to fingerprint.")
}
func (l *LevigoMetricPersistence) AppendSample(sample *model.Sample) error {
func (l *LevelDBMetricPersistence) AppendSample(sample *model.Sample) error {
fmt.Printf("Sample: %q\n", sample)
metricDDO := ddoFromSample(sample)
@ -494,7 +494,7 @@ func (l *LevigoMetricPersistence) AppendSample(sample *model.Sample) error {
return nil
}
func (l *LevigoMetricPersistence) GetLabelNames() ([]string, error) {
func (l *LevelDBMetricPersistence) GetLabelNames() ([]string, error) {
if getAll, getAllError := l.labelNameFingerprints.GetAll(); getAllError == nil {
result := make([]string, 0, len(getAll))
labelNameDDO := &data.LabelNameDDO{}
@ -516,7 +516,7 @@ func (l *LevigoMetricPersistence) GetLabelNames() ([]string, error) {
return nil, errors.New("Unknown error encountered when querying label names.")
}
func (l *LevigoMetricPersistence) GetLabelPairs() ([]model.LabelPairs, error) {
func (l *LevelDBMetricPersistence) GetLabelPairs() ([]model.LabelPairs, error) {
if getAll, getAllError := l.labelPairFingerprints.GetAll(); getAllError == nil {
result := make([]model.LabelPairs, 0, len(getAll))
labelPairDDO := &data.LabelPairDDO{}
@ -541,7 +541,7 @@ func (l *LevigoMetricPersistence) GetLabelPairs() ([]model.LabelPairs, error) {
return nil, errors.New("Unknown error encountered when querying label pairs.")
}
func (l *LevigoMetricPersistence) GetMetrics() ([]model.LabelPairs, error) {
func (l *LevelDBMetricPersistence) GetMetrics() ([]model.LabelPairs, error) {
log.Printf("GetMetrics()\n")
if getAll, getAllError := l.labelPairFingerprints.GetAll(); getAllError == nil {
@ -596,7 +596,7 @@ func (l *LevigoMetricPersistence) GetMetrics() ([]model.LabelPairs, error) {
return nil, errors.New("Unknown error encountered when querying metrics.")
}
func (l *LevigoMetricPersistence) GetWatermarksForMetric(metric model.Metric) (*model.Interval, int, error) {
func (l *LevelDBMetricPersistence) GetWatermarksForMetric(metric model.Metric) (*model.Interval, int, error) {
metricDDO := ddoFromMetric(metric)
if fingerprintDDO, fingerprintDDOErr := fingerprintDDOForMessage(metricDDO); fingerprintDDOErr == nil {
@ -670,7 +670,7 @@ func (l *LevigoMetricPersistence) GetWatermarksForMetric(metric model.Metric) (*
// TODO(mtp): Holes in the data!
func (l *LevigoMetricPersistence) GetSamplesForMetric(metric model.Metric, interval model.Interval) ([]model.Samples, error) {
func (l *LevelDBMetricPersistence) GetSamplesForMetric(metric model.Metric, interval model.Interval) ([]model.Samples, error) {
metricDDO := ddoFromMetric(metric)
if fingerprintDDO, fingerprintDDOErr := fingerprintDDOForMessage(metricDDO); fingerprintDDOErr == nil {

View file

@ -28,7 +28,7 @@ import (
)
func TestBasicLifecycle(t *testing.T) {
temporaryDirectory, temporaryDirectoryErr := ioutil.TempDir("", "levigo_metric_persistence_test")
temporaryDirectory, temporaryDirectoryErr := ioutil.TempDir("", "leveldb_metric_persistence_test")
if temporaryDirectoryErr != nil {
t.Errorf("Could not create test directory: %q\n", temporaryDirectoryErr)
@ -41,26 +41,26 @@ func TestBasicLifecycle(t *testing.T) {
}
}()
persistence, openErr := NewLevigoMetricPersistence(temporaryDirectory)
persistence, openErr := NewLevelDBMetricPersistence(temporaryDirectory)
if openErr != nil {
t.Errorf("Could not create Levigo Metric Persistence: %q\n", openErr)
t.Errorf("Could not create LevelDB Metric Persistence: %q\n", openErr)
}
if persistence == nil {
t.Errorf("Received nil Levigo Metric Persistence.\n")
t.Errorf("Received nil LevelDB Metric Persistence.\n")
return
}
closeErr := persistence.Close()
if closeErr != nil {
t.Errorf("Could not close Levigo Metric Persistence: %q\n", closeErr)
t.Errorf("Could not close LevelDB Metric Persistence: %q\n", closeErr)
}
}
func TestReadEmpty(t *testing.T) {
temporaryDirectory, _ := ioutil.TempDir("", "levigo_metric_persistence_test")
temporaryDirectory, _ := ioutil.TempDir("", "leveldb_metric_persistence_test")
defer func() {
if removeAllErr := os.RemoveAll(temporaryDirectory); removeAllErr != nil {
@ -68,7 +68,7 @@ func TestReadEmpty(t *testing.T) {
}
}()
persistence, _ := NewLevigoMetricPersistence(temporaryDirectory)
persistence, _ := NewLevelDBMetricPersistence(temporaryDirectory)
defer func() {
persistence.Close()
@ -167,7 +167,7 @@ func TestReadEmpty(t *testing.T) {
}
func TestAppendSampleAsPureSparseAppend(t *testing.T) {
temporaryDirectory, _ := ioutil.TempDir("", "levigo_metric_persistence_test")
temporaryDirectory, _ := ioutil.TempDir("", "leveldb_metric_persistence_test")
defer func() {
if removeAllErr := os.RemoveAll(temporaryDirectory); removeAllErr != nil {
@ -175,7 +175,7 @@ func TestAppendSampleAsPureSparseAppend(t *testing.T) {
}
}()
persistence, _ := NewLevigoMetricPersistence(temporaryDirectory)
persistence, _ := NewLevelDBMetricPersistence(temporaryDirectory)
defer func() {
persistence.Close()
@ -199,7 +199,7 @@ func TestAppendSampleAsPureSparseAppend(t *testing.T) {
}
func TestAppendSampleAsSparseAppendWithReads(t *testing.T) {
temporaryDirectory, _ := ioutil.TempDir("", "levigo_metric_persistence_test")
temporaryDirectory, _ := ioutil.TempDir("", "leveldb_metric_persistence_test")
defer func() {
if removeAllErr := os.RemoveAll(temporaryDirectory); removeAllErr != nil {
@ -207,7 +207,7 @@ func TestAppendSampleAsSparseAppendWithReads(t *testing.T) {
}
}()
persistence, _ := NewLevigoMetricPersistence(temporaryDirectory)
persistence, _ := NewLevelDBMetricPersistence(temporaryDirectory)
defer func() {
persistence.Close()
@ -292,7 +292,7 @@ func TestAppendSampleAsSparseAppendWithReads(t *testing.T) {
}
func TestAppendSampleAsPureSingleEntityAppend(t *testing.T) {
temporaryDirectory, _ := ioutil.TempDir("", "levigo_metric_persistence_test")
temporaryDirectory, _ := ioutil.TempDir("", "leveldb_metric_persistence_test")
defer func() {
if removeAllErr := os.RemoveAll(temporaryDirectory); removeAllErr != nil {
@ -300,7 +300,7 @@ func TestAppendSampleAsPureSingleEntityAppend(t *testing.T) {
}
}()
persistence, _ := NewLevigoMetricPersistence(temporaryDirectory)
persistence, _ := NewLevelDBMetricPersistence(temporaryDirectory)
defer func() {
persistence.Close()
@ -333,7 +333,7 @@ func TestStochastic(t *testing.T) {
numberOfSamples := random.Intn(1024) + 2
numberOfRangeScans := random.Intn(3)
temporaryDirectory, _ := ioutil.TempDir("", "levigo_metric_persistence_test")
temporaryDirectory, _ := ioutil.TempDir("", "leveldb_metric_persistence_test")
defer func() {
if removeAllErr := os.RemoveAll(temporaryDirectory); removeAllErr != nil {
@ -341,7 +341,7 @@ func TestStochastic(t *testing.T) {
}
}()
persistence, _ := NewLevigoMetricPersistence(temporaryDirectory)
persistence, _ := NewLevelDBMetricPersistence(temporaryDirectory)
defer func() {
persistence.Close()

View file

@ -19,5 +19,5 @@ import (
)
func TestInterfaceAdherence(t *testing.T) {
var _ index.MembershipIndex = &LevigoMembershipIndex{}
var _ index.MembershipIndex = &LevelDBMembershipIndex{}
}

View file

@ -23,36 +23,36 @@ var (
existenceValue = coding.NewProtocolBufferEncoder(&data.MembershipIndexValueDDO{})
)
type LevigoMembershipIndex struct {
persistence *leveldb.LevigoPersistence
type LevelDBMembershipIndex struct {
persistence *leveldb.LevelDBPersistence
}
func (l *LevigoMembershipIndex) Close() error {
func (l *LevelDBMembershipIndex) Close() error {
return l.persistence.Close()
}
func (l *LevigoMembershipIndex) Has(key coding.Encoder) (bool, error) {
func (l *LevelDBMembershipIndex) Has(key coding.Encoder) (bool, error) {
return l.persistence.Has(key)
}
func (l *LevigoMembershipIndex) Drop(key coding.Encoder) error {
func (l *LevelDBMembershipIndex) Drop(key coding.Encoder) error {
return l.persistence.Drop(key)
}
func (l *LevigoMembershipIndex) Put(key coding.Encoder) error {
func (l *LevelDBMembershipIndex) Put(key coding.Encoder) error {
return l.persistence.Put(key, existenceValue)
}
func NewLevigoMembershipIndex(storageRoot string, cacheCapacity, bitsPerBloomFilterEncoded int) (*LevigoMembershipIndex, error) {
var levigoPersistence *leveldb.LevigoPersistence
var levigoPersistenceError error
func NewLevelDBMembershipIndex(storageRoot string, cacheCapacity, bitsPerBloomFilterEncoded int) (*LevelDBMembershipIndex, error) {
var leveldbPersistence *leveldb.LevelDBPersistence
var persistenceError error
if levigoPersistence, levigoPersistenceError = leveldb.NewLevigoPersistence(storageRoot, cacheCapacity, bitsPerBloomFilterEncoded); levigoPersistenceError == nil {
levigoMembershipIndex := &LevigoMembershipIndex{
persistence: levigoPersistence,
if leveldbPersistence, persistenceError = leveldb.NewLevelDBPersistence(storageRoot, cacheCapacity, bitsPerBloomFilterEncoded); persistenceError == nil {
leveldbMembershipIndex := &LevelDBMembershipIndex{
persistence: leveldbPersistence,
}
return levigoMembershipIndex, nil
return leveldbMembershipIndex, nil
}
return nil, levigoPersistenceError
return nil, persistenceError
}

View file

@ -19,5 +19,5 @@ import (
)
func TestInterfaceAdherence(t *testing.T) {
var _ raw.Persistence = &LevigoPersistence{}
var _ raw.Persistence = &LevelDBPersistence{}
}

View file

@ -20,7 +20,7 @@ import (
"io"
)
type LevigoPersistence struct {
type LevelDBPersistence struct {
cache *levigo.Cache
filterPolicy *levigo.FilterPolicy
options *levigo.Options
@ -36,7 +36,7 @@ type iteratorCloser struct {
storage *levigo.DB
}
func NewLevigoPersistence(storageRoot string, cacheCapacity, bitsPerBloomFilterEncoded int) (*LevigoPersistence, error) {
func NewLevelDBPersistence(storageRoot string, cacheCapacity, bitsPerBloomFilterEncoded int) (*LevelDBPersistence, error) {
options := levigo.NewOptions()
options.SetCreateIfMissing(true)
options.SetParanoidChecks(true)
@ -53,7 +53,7 @@ func NewLevigoPersistence(storageRoot string, cacheCapacity, bitsPerBloomFilterE
writeOptions := levigo.NewWriteOptions()
writeOptions.SetSync(true)
emission := &LevigoPersistence{
emission := &LevelDBPersistence{
cache: cache,
filterPolicy: filterPolicy,
options: options,
@ -65,7 +65,7 @@ func NewLevigoPersistence(storageRoot string, cacheCapacity, bitsPerBloomFilterE
return emission, openErr
}
func (l *LevigoPersistence) Close() error {
func (l *LevelDBPersistence) Close() error {
if l.storage != nil {
l.storage.Close()
}
@ -103,7 +103,7 @@ func (l *LevigoPersistence) Close() error {
return nil
}
func (l *LevigoPersistence) Get(value coding.Encoder) ([]byte, error) {
func (l *LevelDBPersistence) Get(value coding.Encoder) ([]byte, error) {
if key, keyError := value.Encode(); keyError == nil {
return l.storage.Get(l.readOptions, key)
} else {
@ -113,7 +113,7 @@ func (l *LevigoPersistence) Get(value coding.Encoder) ([]byte, error) {
panic("unreachable")
}
func (l *LevigoPersistence) Has(value coding.Encoder) (bool, error) {
func (l *LevelDBPersistence) Has(value coding.Encoder) (bool, error) {
if value, getError := l.Get(value); getError != nil {
return false, getError
} else if value == nil {
@ -123,7 +123,7 @@ func (l *LevigoPersistence) Has(value coding.Encoder) (bool, error) {
return true, nil
}
func (l *LevigoPersistence) Drop(value coding.Encoder) error {
func (l *LevelDBPersistence) Drop(value coding.Encoder) error {
if key, keyError := value.Encode(); keyError == nil {
if deleteError := l.storage.Delete(l.writeOptions, key); deleteError != nil {
@ -136,7 +136,7 @@ func (l *LevigoPersistence) Drop(value coding.Encoder) error {
return nil
}
func (l *LevigoPersistence) Put(key, value coding.Encoder) error {
func (l *LevelDBPersistence) Put(key, value coding.Encoder) error {
if keyEncoded, keyError := key.Encode(); keyError == nil {
if valueEncoded, valueError := value.Encode(); valueError == nil {
@ -153,7 +153,7 @@ func (l *LevigoPersistence) Put(key, value coding.Encoder) error {
return nil
}
func (l *LevigoPersistence) GetAll() ([]raw.Pair, error) {
func (l *LevelDBPersistence) GetAll() ([]raw.Pair, error) {
snapshot := l.storage.NewSnapshot()
defer l.storage.ReleaseSnapshot(snapshot)
readOptions := levigo.NewReadOptions()
@ -203,7 +203,7 @@ func (i *iteratorCloser) Close() error {
return nil
}
func (l *LevigoPersistence) GetIterator() (*levigo.Iterator, io.Closer, error) {
func (l *LevelDBPersistence) GetIterator() (*levigo.Iterator, io.Closer, error) {
snapshot := l.storage.NewSnapshot()
readOptions := levigo.NewReadOptions()
readOptions.SetSnapshot(snapshot)