Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure index clean up runs before index creation #6634

Merged
merged 1 commit into from Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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