Browse Source

Unify LevelDB.*Options.

We have seven different types all called like LevelDB.*Options.  One
of them is the plain LevelDBOptions. All others are just wrapping that
type without adding anything except clunkier handling.

If there ever was a plan to add more specific options to the various
LevelDB.*Options types, history has proven that nothing like that is
going to happen anytime soon.

To keep the code a bit shorter and more focused on the real (quite
significant) complexities we have to deal with here, this commit
reduces all uses of LevelDBOptions to the actual LevelDBOptions type.

1576 fewer characters to read...

Change-Id: I3d7a2b7ffed78b337aa37f812c53c058329ecaa6
changes/28/128/2
Bjoern Rabenstein 11 years ago
parent
commit
e11e8c7a23
  1. 36
      storage/metric/index.go
  2. 46
      storage/metric/leveldb.go
  3. 24
      storage/metric/processor_test.go
  4. 18
      storage/metric/watermark.go

36
storage/metric/index.go

@ -46,11 +46,6 @@ type LevelDBFingerprintMetricIndex struct {
*leveldb.LevelDBPersistence *leveldb.LevelDBPersistence
} }
// LevelDBFingerprintMetricIndexOptions just wraps leveldb.LevelDBOptions.
type LevelDBFingerprintMetricIndexOptions struct {
leveldb.LevelDBOptions
}
// IndexBatch implements FingerprintMetricIndex. // IndexBatch implements FingerprintMetricIndex.
func (i *LevelDBFingerprintMetricIndex) IndexBatch(mapping FingerprintMetricMapping) error { func (i *LevelDBFingerprintMetricIndex) IndexBatch(mapping FingerprintMetricMapping) error {
b := leveldb.NewBatch() b := leveldb.NewBatch()
@ -90,8 +85,8 @@ func (i *LevelDBFingerprintMetricIndex) Lookup(f *clientmodel.Fingerprint) (m cl
// NewLevelDBFingerprintMetricIndex returns a LevelDBFingerprintMetricIndex // NewLevelDBFingerprintMetricIndex returns a LevelDBFingerprintMetricIndex
// object ready to use. // object ready to use.
func NewLevelDBFingerprintMetricIndex(o LevelDBFingerprintMetricIndexOptions) (*LevelDBFingerprintMetricIndex, error) { func NewLevelDBFingerprintMetricIndex(o leveldb.LevelDBOptions) (*LevelDBFingerprintMetricIndex, error) {
s, err := leveldb.NewLevelDBPersistence(o.LevelDBOptions) s, err := leveldb.NewLevelDBPersistence(o)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -175,15 +170,10 @@ func (i *LevelDBLabelNameFingerprintIndex) Has(l clientmodel.LabelName) (ok bool
}) })
} }
// LevelDBLabelNameFingerprintIndexOptions just wraps leveldb.LevelDBOptions.
type LevelDBLabelNameFingerprintIndexOptions struct {
leveldb.LevelDBOptions
}
// NewLevelLabelNameFingerprintIndex returns a LevelDBLabelNameFingerprintIndex // NewLevelLabelNameFingerprintIndex returns a LevelDBLabelNameFingerprintIndex
// ready to use. // ready to use.
func NewLevelLabelNameFingerprintIndex(o LevelDBLabelNameFingerprintIndexOptions) (*LevelDBLabelNameFingerprintIndex, error) { func NewLevelLabelNameFingerprintIndex(o leveldb.LevelDBOptions) (*LevelDBLabelNameFingerprintIndex, error) {
s, err := leveldb.NewLevelDBPersistence(o.LevelDBOptions) s, err := leveldb.NewLevelDBPersistence(o)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -215,11 +205,6 @@ type LevelDBLabelPairFingerprintIndex struct {
*leveldb.LevelDBPersistence *leveldb.LevelDBPersistence
} }
// LevelDBLabelSetFingerprintIndexOptions just wraps leveldb.LevelDBOptions.
type LevelDBLabelSetFingerprintIndexOptions struct {
leveldb.LevelDBOptions
}
// IndexBatch implements LabelPairFingerprintMapping. // IndexBatch implements LabelPairFingerprintMapping.
func (i *LevelDBLabelPairFingerprintIndex) IndexBatch(m LabelPairFingerprintMapping) error { func (i *LevelDBLabelPairFingerprintIndex) IndexBatch(m LabelPairFingerprintMapping) error {
batch := leveldb.NewBatch() batch := leveldb.NewBatch()
@ -283,8 +268,8 @@ func (i *LevelDBLabelPairFingerprintIndex) Has(p *LabelPair) (ok bool, err error
// NewLevelDBLabelSetFingerprintIndex returns a LevelDBLabelPairFingerprintIndex // NewLevelDBLabelSetFingerprintIndex returns a LevelDBLabelPairFingerprintIndex
// object ready to use. // object ready to use.
func NewLevelDBLabelSetFingerprintIndex(o LevelDBLabelSetFingerprintIndexOptions) (*LevelDBLabelPairFingerprintIndex, error) { func NewLevelDBLabelSetFingerprintIndex(o leveldb.LevelDBOptions) (*LevelDBLabelPairFingerprintIndex, error) {
s, err := leveldb.NewLevelDBPersistence(o.LevelDBOptions) s, err := leveldb.NewLevelDBPersistence(o)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -332,15 +317,10 @@ func (i *LevelDBMetricMembershipIndex) Has(m clientmodel.Metric) (ok bool, err e
return i.LevelDBPersistence.Has(k) return i.LevelDBPersistence.Has(k)
} }
// LevelDBMetricMembershipIndexOptions just wraps leveldb.LevelDBOptions
type LevelDBMetricMembershipIndexOptions struct {
leveldb.LevelDBOptions
}
// NewLevelDBMetricMembershipIndex returns a LevelDBMetricMembershipIndex object // NewLevelDBMetricMembershipIndex returns a LevelDBMetricMembershipIndex object
// ready to use. // ready to use.
func NewLevelDBMetricMembershipIndex(o LevelDBMetricMembershipIndexOptions) (*LevelDBMetricMembershipIndex, error) { func NewLevelDBMetricMembershipIndex(o leveldb.LevelDBOptions) (*LevelDBMetricMembershipIndex, error) {
s, err := leveldb.NewLevelDBPersistence(o.LevelDBOptions) s, err := leveldb.NewLevelDBPersistence(o)
if err != nil { if err != nil {
return nil, err return nil, err
} }

46
storage/metric/leveldb.go

@ -122,14 +122,14 @@ func NewLevelDBMetricPersistence(baseDirectory string) (*LevelDBMetricPersistenc
"Label Names and Value Pairs by Fingerprint", "Label Names and Value Pairs by Fingerprint",
func() { func() {
var err error var err error
emission.FingerprintToMetrics, err = NewLevelDBFingerprintMetricIndex(LevelDBFingerprintMetricIndexOptions{ emission.FingerprintToMetrics, err = NewLevelDBFingerprintMetricIndex(
LevelDBOptions: leveldb.LevelDBOptions{ leveldb.LevelDBOptions{
Name: "Metrics by Fingerprint", Name: "Metrics by Fingerprint",
Purpose: "Index", Purpose: "Index",
Path: baseDirectory + "/label_name_and_value_pairs_by_fingerprint", Path: baseDirectory + "/label_name_and_value_pairs_by_fingerprint",
CacheSizeBytes: *fingerprintsToLabelPairCacheSize, CacheSizeBytes: *fingerprintsToLabelPairCacheSize,
}, },
}) )
workers.MayFail(err) workers.MayFail(err)
}, },
}, },
@ -150,13 +150,14 @@ func NewLevelDBMetricPersistence(baseDirectory string) (*LevelDBMetricPersistenc
"High Watermarks by Fingerprint", "High Watermarks by Fingerprint",
func() { func() {
var err error var err error
emission.MetricHighWatermarks, err = NewLevelDBHighWatermarker(LevelDBHighWatermarkerOptions{ emission.MetricHighWatermarks, err = NewLevelDBHighWatermarker(
LevelDBOptions: leveldb.LevelDBOptions{ leveldb.LevelDBOptions{
Name: "High Watermarks", Name: "High Watermarks",
Purpose: "The youngest sample in the database per metric.", Purpose: "The youngest sample in the database per metric.",
Path: baseDirectory + "/high_watermarks_by_fingerprint", Path: baseDirectory + "/high_watermarks_by_fingerprint",
CacheSizeBytes: *highWatermarkCacheSize, CacheSizeBytes: *highWatermarkCacheSize,
}}) },
)
workers.MayFail(err) workers.MayFail(err)
}, },
}, },
@ -164,14 +165,14 @@ func NewLevelDBMetricPersistence(baseDirectory string) (*LevelDBMetricPersistenc
"Fingerprints by Label Name", "Fingerprints by Label Name",
func() { func() {
var err error var err error
emission.LabelNameToFingerprints, err = NewLevelLabelNameFingerprintIndex(LevelDBLabelNameFingerprintIndexOptions{ emission.LabelNameToFingerprints, err = NewLevelLabelNameFingerprintIndex(
LevelDBOptions: leveldb.LevelDBOptions{ leveldb.LevelDBOptions{
Name: "Fingerprints by Label Name", Name: "Fingerprints by Label Name",
Purpose: "Index", Purpose: "Index",
Path: baseDirectory + "/fingerprints_by_label_name", Path: baseDirectory + "/fingerprints_by_label_name",
CacheSizeBytes: *labelNameToFingerprintsCacheSize, CacheSizeBytes: *labelNameToFingerprintsCacheSize,
}, },
}) )
workers.MayFail(err) workers.MayFail(err)
}, },
}, },
@ -179,14 +180,14 @@ func NewLevelDBMetricPersistence(baseDirectory string) (*LevelDBMetricPersistenc
"Fingerprints by Label Name and Value Pair", "Fingerprints by Label Name and Value Pair",
func() { func() {
var err error var err error
emission.LabelPairToFingerprints, err = NewLevelDBLabelSetFingerprintIndex(LevelDBLabelSetFingerprintIndexOptions{ emission.LabelPairToFingerprints, err = NewLevelDBLabelSetFingerprintIndex(
LevelDBOptions: leveldb.LevelDBOptions{ leveldb.LevelDBOptions{
Name: "Fingerprints by Label Pair", Name: "Fingerprints by Label Pair",
Purpose: "Index", Purpose: "Index",
Path: baseDirectory + "/fingerprints_by_label_name_and_value_pair", Path: baseDirectory + "/fingerprints_by_label_name_and_value_pair",
CacheSizeBytes: *labelPairToFingerprintsCacheSize, CacheSizeBytes: *labelPairToFingerprintsCacheSize,
}, },
}) )
workers.MayFail(err) workers.MayFail(err)
}, },
}, },
@ -195,14 +196,13 @@ func NewLevelDBMetricPersistence(baseDirectory string) (*LevelDBMetricPersistenc
func() { func() {
var err error var err error
emission.MetricMembershipIndex, err = NewLevelDBMetricMembershipIndex( emission.MetricMembershipIndex, err = NewLevelDBMetricMembershipIndex(
LevelDBMetricMembershipIndexOptions{ leveldb.LevelDBOptions{
LevelDBOptions: leveldb.LevelDBOptions{ Name: "Metric Membership",
Name: "Metric Membership", Purpose: "Index",
Purpose: "Index", Path: baseDirectory + "/metric_membership_index",
Path: baseDirectory + "/metric_membership_index", CacheSizeBytes: *metricMembershipIndexCacheSize,
CacheSizeBytes: *metricMembershipIndexCacheSize, },
}, )
})
workers.MayFail(err) workers.MayFail(err)
}, },
}, },
@ -210,14 +210,14 @@ func NewLevelDBMetricPersistence(baseDirectory string) (*LevelDBMetricPersistenc
"Sample Curation Remarks", "Sample Curation Remarks",
func() { func() {
var err error var err error
emission.CurationRemarks, err = NewLevelDBCurationRemarker(LevelDBCurationRemarkerOptions{ emission.CurationRemarks, err = NewLevelDBCurationRemarker(
LevelDBOptions: leveldb.LevelDBOptions{ leveldb.LevelDBOptions{
Name: "Sample Curation Remarks", Name: "Sample Curation Remarks",
Purpose: "Ledger of Progress for Various Curators", Purpose: "Ledger of Progress for Various Curators",
Path: baseDirectory + "/curation_remarks", Path: baseDirectory + "/curation_remarks",
CacheSizeBytes: *curationRemarksCacheSize, CacheSizeBytes: *curationRemarksCacheSize,
}, },
}) )
workers.MayFail(err) workers.MayFail(err)
}, },
}, },

24
storage/metric/processor_test.go

@ -849,20 +849,20 @@ func TestCuratorCompactionProcessor(t *testing.T) {
sampleDirectory := fixture.NewPreparer(t).Prepare("sample", fixture.NewCassetteFactory(scenario.in.sampleGroups)) sampleDirectory := fixture.NewPreparer(t).Prepare("sample", fixture.NewCassetteFactory(scenario.in.sampleGroups))
defer sampleDirectory.Close() defer sampleDirectory.Close()
curatorStates, err := NewLevelDBCurationRemarker(LevelDBCurationRemarkerOptions{ curatorStates, err := NewLevelDBCurationRemarker(
LevelDBOptions: leveldb.LevelDBOptions{ leveldb.LevelDBOptions{
Path: curatorDirectory.Path(), Path: curatorDirectory.Path(),
}, },
}) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
watermarkStates, err := NewLevelDBHighWatermarker(LevelDBHighWatermarkerOptions{ watermarkStates, err := NewLevelDBHighWatermarker(
LevelDBOptions: leveldb.LevelDBOptions{ leveldb.LevelDBOptions{
Path: watermarkDirectory.Path(), Path: watermarkDirectory.Path(),
}, },
}) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -1379,21 +1379,21 @@ func TestCuratorDeletionProcessor(t *testing.T) {
sampleDirectory := fixture.NewPreparer(t).Prepare("sample", fixture.NewCassetteFactory(scenario.in.sampleGroups)) sampleDirectory := fixture.NewPreparer(t).Prepare("sample", fixture.NewCassetteFactory(scenario.in.sampleGroups))
defer sampleDirectory.Close() defer sampleDirectory.Close()
curatorStates, err := NewLevelDBCurationRemarker(LevelDBCurationRemarkerOptions{ curatorStates, err := NewLevelDBCurationRemarker(
LevelDBOptions: leveldb.LevelDBOptions{ leveldb.LevelDBOptions{
Path: curatorDirectory.Path(), Path: curatorDirectory.Path(),
}, },
}) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer curatorStates.Close() defer curatorStates.Close()
watermarkStates, err := NewLevelDBHighWatermarker(LevelDBHighWatermarkerOptions{ watermarkStates, err := NewLevelDBHighWatermarker(
LevelDBOptions: leveldb.LevelDBOptions{ leveldb.LevelDBOptions{
Path: watermarkDirectory.Path(), Path: watermarkDirectory.Path(),
}, },
}) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

18
storage/metric/watermark.go

@ -104,14 +104,9 @@ func (w *LevelDBHighWatermarker) UpdateBatch(m FingerprintHighWatermarkMapping)
return w.LevelDBPersistence.Commit(batch) return w.LevelDBPersistence.Commit(batch)
} }
// LevelDBHighWatermarkerOptions just wraps leveldb.LevelDBOptions.
type LevelDBHighWatermarkerOptions struct {
leveldb.LevelDBOptions
}
// NewLevelDBHighWatermarker returns a LevelDBHighWatermarker ready to use. // NewLevelDBHighWatermarker returns a LevelDBHighWatermarker ready to use.
func NewLevelDBHighWatermarker(o LevelDBHighWatermarkerOptions) (*LevelDBHighWatermarker, error) { func NewLevelDBHighWatermarker(o leveldb.LevelDBOptions) (*LevelDBHighWatermarker, error) {
s, err := leveldb.NewLevelDBPersistence(o.LevelDBOptions) s, err := leveldb.NewLevelDBPersistence(o)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -136,11 +131,6 @@ type LevelDBCurationRemarker struct {
*leveldb.LevelDBPersistence *leveldb.LevelDBPersistence
} }
// LevelDBCurationRemarkerOptions just wraps leveldb.LevelDBOptions.
type LevelDBCurationRemarkerOptions struct {
leveldb.LevelDBOptions
}
// Get implements CurationRemarker. // Get implements CurationRemarker.
func (w *LevelDBCurationRemarker) Get(c *curationKey) (t clientmodel.Timestamp, ok bool, err error) { func (w *LevelDBCurationRemarker) Get(c *curationKey) (t clientmodel.Timestamp, ok bool, err error) {
k := &dto.CurationKey{} k := &dto.CurationKey{}
@ -166,8 +156,8 @@ func (w *LevelDBCurationRemarker) Update(pair *curationKey, t clientmodel.Timest
} }
// NewLevelDBCurationRemarker returns a LevelDBCurationRemarker ready to use. // NewLevelDBCurationRemarker returns a LevelDBCurationRemarker ready to use.
func NewLevelDBCurationRemarker(o LevelDBCurationRemarkerOptions) (*LevelDBCurationRemarker, error) { func NewLevelDBCurationRemarker(o leveldb.LevelDBOptions) (*LevelDBCurationRemarker, error) {
s, err := leveldb.NewLevelDBPersistence(o.LevelDBOptions) s, err := leveldb.NewLevelDBPersistence(o)
if err != nil { if err != nil {
return nil, err return nil, err
} }

Loading…
Cancel
Save