Skip to content

Commit 5700064

Browse files
committed
more logging, deal with missing physical indexes
1 parent b314a27 commit 5700064

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

Diff for: cmd/rp-indexer/main.go

+12-10
Original file line numberDiff line numberDiff line change
@@ -55,32 +55,32 @@ func main() {
5555
}
5656
oldIndex := physicalIndex
5757

58-
// doesn't exist or we are rebuilding, create it
59-
if physicalIndex == "" || config.Rebuild {
60-
physicalIndex, err = indexer.CreateNewIndex(config.ElasticURL, config.Index)
61-
if err != nil {
62-
log.WithError(err).Fatal("error creating new index")
58+
for {
59+
// doesn't exist or we are rebuilding, create it
60+
if physicalIndex == "" || config.Rebuild {
61+
physicalIndex, err = indexer.CreateNewIndex(config.ElasticURL, config.Index)
62+
if err != nil {
63+
log.WithError(err).Fatal("error creating new index")
64+
}
65+
log.WithField("index", config.Index).WithField("physicalIndex", physicalIndex).Info("created new physical index")
6366
}
64-
log.WithField("index", config.Index).WithField("physicalIndex", physicalIndex).Info("created new physical index")
65-
}
6667

67-
for {
6868
lastModified, err := indexer.GetLastModified(config.ElasticURL, physicalIndex)
6969
if err != nil {
7070
logError(config.Rebuild, err, "error finding last modified")
7171
continue
7272
}
7373

7474
start := time.Now()
75-
log.WithField("last_modified", lastModified).Info("indexing contacts newer than last modified")
75+
log.WithField("last_modified", lastModified).WithField("index", physicalIndex).Info("indexing contacts newer than last modified")
7676

7777
// now index our docs
7878
indexed, deleted, err := indexer.IndexContacts(db, config.ElasticURL, physicalIndex, lastModified)
7979
if err != nil {
8080
logError(config.Rebuild, err, "error indexing contacts")
8181
continue
8282
}
83-
log.WithField("added", indexed).WithField("deleted", deleted).WithField("elapsed", time.Now().Sub(start)).Info("completed indexing")
83+
log.WithField("added", indexed).WithField("deleted", deleted).WithField("index", physicalIndex).WithField("elapsed", time.Now().Sub(start)).Info("completed indexing")
8484

8585
// if the index didn't previously exist or we are rebuilding, remap to our alias
8686
if oldIndex == "" || config.Rebuild {
@@ -101,6 +101,8 @@ func main() {
101101
log.WithField("physicalIndexes", physicalIndexes).WithField("index", config.Index).Debug("found physical indexes")
102102
if len(physicalIndex) > 0 {
103103
physicalIndex = physicalIndexes[0]
104+
} else {
105+
oldIndex = ""
104106
}
105107
}
106108
}

Diff for: indexer.go

+7
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ func CreateNewIndex(url string, alias string) (string, error) {
5959
// GetLastModified queries our index and finds the last modified contact, returning it
6060
func GetLastModified(url string, index string) (time.Time, error) {
6161
lastModified := time.Time{}
62+
if index == "" {
63+
return lastModified, fmt.Errorf("empty index passed to GetLastModified")
64+
}
6265

6366
// get the newest document on our index
6467
queryResponse := queryResponse{}
@@ -177,6 +180,10 @@ func IndexContacts(db *sql.DB, elasticURL string, index string, lastModified tim
177180
createdCount, deletedCount := 0, 0
178181
processedCount := 0
179182

183+
if index == "" {
184+
return createdCount, deletedCount, fmt.Errorf("empty index passed to IndexContacts")
185+
}
186+
180187
var modifiedOn time.Time
181188
var contactJSON string
182189
var id, orgID int64

0 commit comments

Comments
 (0)