From efffa39c2c0c751aa6eccff0ea02ea50fa766a3d Mon Sep 17 00:00:00 2001 From: Travis Date: Fri, 17 Jan 2020 11:42:21 -0600 Subject: [PATCH] check foreign index on field open --- field.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/field.go b/field.go index 149ae65c3..86cf50b64 100644 --- a/field.go +++ b/field.go @@ -526,6 +526,14 @@ func (f *Field) Open() error { return errors.Wrap(err, "applying translate store") } + // If the field has a foreign index, make sure the index + // exists. + if f.options.ForeignIndex != "" { + if err := f.holder.checkForeignIndex(f); err != nil { + return errors.Wrap(err, "checking foreign index") + } + } + return nil }(); err != nil { f.Close() @@ -548,6 +556,14 @@ func (f *Field) applyTranslateStore() error { return nil } +// applyForeignIndex used to set the field's translateStore to +// that of the foreign index, but since moving to partitioned +// translate stores on indexes, that doesn't happen anymore. +// So now all this method does is check that the foreign index +// actually exists. If we decided this was unnecessary (which +// it kind of is), we could remove the field.holder and all +// the logic which does this check on holder open after all +// indexes have opened. func (f *Field) applyForeignIndex() error { foreignIndex := f.holder.Index(f.options.ForeignIndex) if foreignIndex == nil {