Skip to content

Commit

Permalink
Ensure index clean up runs before index creation (#6634) (#6643)
Browse files Browse the repository at this point in the history
Move the code from the migration to the constructor.
This avoids a race between our asynchronously executed migration and the
DBProcessingStatusService.

Fixes #6383

(cherry picked from commit 6fbf78f)
  • Loading branch information
bernd authored and mpfz0r committed Oct 24, 2019
1 parent 4b87171 commit b7a2986
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 51 deletions.
Expand Up @@ -40,6 +40,5 @@ protected void configure() {
addMigration(V20190705071400_AddEventIndexSetsMigration.class);
addMigration(V20190730100900_AddAlertsManagerRole.class);
addMigration(V20190730000000_CreateDefaultEventsConfiguration.class);
addMigration(V20190905114400_RemoveOldProcessingStatusIndex.class);
}
}

This file was deleted.

Expand Up @@ -20,6 +20,7 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.mongodb.BasicDBObject;
import com.mongodb.MongoException;
import org.bson.types.ObjectId;
import org.graylog.scheduler.clock.JobSchedulerClock;
import org.graylog2.bindings.providers.MongoJackObjectMapperProvider;
Expand Down Expand Up @@ -76,6 +77,18 @@ public DBProcessingStatusService(MongoConnection mongoConnection,
mapper.get());

db.createIndex(new BasicDBObject(ProcessingStatusDto.FIELD_NODE_ID, 1), new BasicDBObject("unique", true));

// Remove the old (3.1.0) index before creating the new one. This is needed, because mongodb >= 4.2 won't allow
// the creation of identical indices with a different name. We don't use a migration,
// because it can race with the code below that creates the same index with a shorter name.
// TODO remove this in a future release (maybe at 3.5)
final String OLD_INDEX_NAME = "updated_at_1_input_journal.uncommitted_entries_1_input_journal.written_messages_1m_rate_1";
try {
db.dropIndex(OLD_INDEX_NAME);
} catch (MongoException ignored) {
// index was either never created or already deleted
}

// Use a custom index name to avoid the automatically generated index name which will be pretty long and
// might cause errors due to the 127 character index name limit. (e.g. when using a long database name)
// See: https://github.com/Graylog2/graylog2-server/issues/6322
Expand Down

0 comments on commit b7a2986

Please sign in to comment.