Introduce Comparator interface (#88016)
* Introduce Comparator interface * Add compare implementation everywhere * Add comment explaining what Compare should do * Lint
This commit is contained in:
@@ -35,6 +35,8 @@ type Storage interface {
|
||||
rest.CreaterUpdater
|
||||
rest.GracefulDeleter
|
||||
rest.CollectionDeleter
|
||||
// Compare asserts on the equality of objects returned from both stores (object storage and legacy storage)
|
||||
Compare(storageObj, legacyObj runtime.Object) bool
|
||||
}
|
||||
|
||||
// LegacyStorage is a storage implementation that writes to the Grafana SQL database.
|
||||
@@ -91,18 +93,18 @@ func NewDualWriter(mode DualWriterMode, legacy LegacyStorage, storage Storage) D
|
||||
switch mode {
|
||||
case Mode1:
|
||||
// read and write only from legacy storage
|
||||
return NewDualWriterMode1(legacy, storage)
|
||||
return newDualWriterMode1(legacy, storage)
|
||||
case Mode2:
|
||||
// write to both, read from storage but use legacy as backup
|
||||
return NewDualWriterMode2(legacy, storage)
|
||||
return newDualWriterMode2(legacy, storage)
|
||||
case Mode3:
|
||||
// write to both, read from storage only
|
||||
return NewDualWriterMode3(legacy, storage)
|
||||
return newDualWriterMode3(legacy, storage)
|
||||
case Mode4:
|
||||
// read and write only from storage
|
||||
return NewDualWriterMode4(legacy, storage)
|
||||
return newDualWriterMode4(legacy, storage)
|
||||
default:
|
||||
return NewDualWriterMode1(legacy, storage)
|
||||
return newDualWriterMode1(legacy, storage)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ const mode1Str = "1"
|
||||
|
||||
// NewDualWriterMode1 returns a new DualWriter in mode 1.
|
||||
// Mode 1 represents writing to and reading from LegacyStorage.
|
||||
func NewDualWriterMode1(legacy LegacyStorage, storage Storage) *DualWriterMode1 {
|
||||
func newDualWriterMode1(legacy LegacyStorage, storage Storage) *DualWriterMode1 {
|
||||
metrics := &dualWriterMetrics{}
|
||||
metrics.init()
|
||||
return &DualWriterMode1{Legacy: legacy, Storage: storage, Log: klog.NewKlogr().WithName("DualWriterMode1"), dualWriterMetrics: metrics}
|
||||
@@ -236,3 +236,7 @@ func (d *DualWriterMode1) NewList() runtime.Object {
|
||||
func (d *DualWriterMode1) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1.Table, error) {
|
||||
return d.Legacy.ConvertToTable(ctx, object, tableOptions)
|
||||
}
|
||||
|
||||
func (d *DualWriterMode1) Compare(storageObj, legacyObj runtime.Object) bool {
|
||||
return d.Storage.Compare(storageObj, legacyObj)
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ const mode2Str = "2"
|
||||
|
||||
// NewDualWriterMode2 returns a new DualWriter in mode 2.
|
||||
// Mode 2 represents writing to LegacyStorage and Storage and reading from LegacyStorage.
|
||||
func NewDualWriterMode2(legacy LegacyStorage, storage Storage) *DualWriterMode2 {
|
||||
func newDualWriterMode2(legacy LegacyStorage, storage Storage) *DualWriterMode2 {
|
||||
metrics := &dualWriterMetrics{}
|
||||
metrics.init()
|
||||
return &DualWriterMode2{Legacy: legacy, Storage: storage, Log: klog.NewKlogr().WithName("DualWriterMode2"), dualWriterMetrics: metrics}
|
||||
@@ -310,6 +310,10 @@ func (d *DualWriterMode2) ConvertToTable(ctx context.Context, object runtime.Obj
|
||||
return d.Storage.ConvertToTable(ctx, object, tableOptions)
|
||||
}
|
||||
|
||||
func (d *DualWriterMode2) Compare(storageObj, legacyObj runtime.Object) bool {
|
||||
return d.Storage.Compare(storageObj, legacyObj)
|
||||
}
|
||||
|
||||
func parseList(legacyList []runtime.Object) (metainternalversion.ListOptions, map[string]int, error) {
|
||||
options := metainternalversion.ListOptions{}
|
||||
originKeys := []string{}
|
||||
|
||||
@@ -18,9 +18,9 @@ type DualWriterMode3 struct {
|
||||
Log klog.Logger
|
||||
}
|
||||
|
||||
// NewDualWriterMode3 returns a new DualWriter in mode 3.
|
||||
// newDualWriterMode3 returns a new DualWriter in mode 3.
|
||||
// Mode 3 represents writing to LegacyStorage and Storage and reading from Storage.
|
||||
func NewDualWriterMode3(legacy LegacyStorage, storage Storage) *DualWriterMode3 {
|
||||
func newDualWriterMode3(legacy LegacyStorage, storage Storage) *DualWriterMode3 {
|
||||
metrics := &dualWriterMetrics{}
|
||||
metrics.init()
|
||||
return &DualWriterMode3{Legacy: legacy, Storage: storage, Log: klog.NewKlogr().WithName("DualWriterMode3"), dualWriterMetrics: metrics}
|
||||
@@ -157,3 +157,7 @@ func (d *DualWriterMode3) NewList() runtime.Object {
|
||||
func (d *DualWriterMode3) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1.Table, error) {
|
||||
return d.Storage.ConvertToTable(ctx, object, tableOptions)
|
||||
}
|
||||
|
||||
func (d *DualWriterMode3) Compare(storageObj, legacyObj runtime.Object) bool {
|
||||
return d.Storage.Compare(storageObj, legacyObj)
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ type DualWriterMode4 struct {
|
||||
Log klog.Logger
|
||||
}
|
||||
|
||||
// NewDualWriterMode4 returns a new DualWriter in mode 4.
|
||||
// newDualWriterMode4 returns a new DualWriter in mode 4.
|
||||
// Mode 4 represents writing and reading from Storage.
|
||||
func NewDualWriterMode4(legacy LegacyStorage, storage Storage) *DualWriterMode4 {
|
||||
func newDualWriterMode4(legacy LegacyStorage, storage Storage) *DualWriterMode4 {
|
||||
metrics := &dualWriterMetrics{}
|
||||
metrics.init()
|
||||
return &DualWriterMode4{Legacy: legacy, Storage: storage, Log: klog.NewKlogr().WithName("DualWriterMode4"), dualWriterMetrics: metrics}
|
||||
@@ -85,3 +85,7 @@ func (d *DualWriterMode4) NewList() runtime.Object {
|
||||
func (d *DualWriterMode4) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1.Table, error) {
|
||||
return d.Storage.ConvertToTable(ctx, object, tableOptions)
|
||||
}
|
||||
|
||||
func (d *DualWriterMode4) Compare(storageObj, legacyObj runtime.Object) bool {
|
||||
return d.Storage.Compare(storageObj, legacyObj)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user