-
Notifications
You must be signed in to change notification settings - Fork 3
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
Mongo7 upgrade #394
Merged
Merged
Mongo7 upgrade #394
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,9 +107,10 @@ public void startUpWith2ConfigDocs() throws Exception { | |
|
||
final Pattern errorPattern = Pattern.compile( | ||
"Failed to create index: Write failed with error code 11000 and error message " + | ||
"'(exception: )?E11000 duplicate key error (index|collection): " + | ||
"'(exception: )?(.*)E11000 duplicate key error (index|collection): " + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is captured by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
"startUpWith2ConfigDocs.config( index: |\\.\\$)schema_1\\s+dup key: " + | ||
"\\{ : \"schema\" \\}'"); | ||
"(\\{ schema: \"schema\" \\}'|\\{ : \"schema\" \\}')"); | ||
|
||
try { | ||
new MongoGroupsStorage(db, set()); | ||
fail("started mongo with bad config"); | ||
|
@@ -188,27 +189,21 @@ public void checkCollectionNames() throws Exception { | |
|
||
@Test | ||
public void indexesConfig() { | ||
final Set<Document> indexes = new HashSet<>(); | ||
manager.db.getCollection("config").listIndexes() | ||
.forEach((Consumer<Document>) indexes::add); | ||
final Set<Document> indexes = getAndNormalizeIndexes("config"); | ||
assertThat("incorrect indexes", indexes, is(set( | ||
new Document("v", manager.indexVer) | ||
.append("unique", true) | ||
.append("key", new Document("schema", 1)) | ||
.append("name", "schema_1") | ||
.append("ns", "test_mongogroupsstorage.config"), | ||
.append("name", "schema_1"), | ||
new Document("v", manager.indexVer) | ||
.append("key", new Document("_id", 1)) | ||
.append("name", "_id_") | ||
.append("ns", "test_mongogroupsstorage.config") | ||
))); | ||
} | ||
|
||
@Test | ||
public void indexesGroups() { | ||
final Set<Document> indexes = new HashSet<>(); | ||
manager.db.getCollection("groups").listIndexes() | ||
.forEach((Consumer<Document>) indexes::add); | ||
final Set<Document> indexes = getAndNormalizeIndexes("groups"); | ||
assertThat("incorrect indexes", indexes, is(getDefaultGroupsIndexes())); | ||
} | ||
|
||
|
@@ -218,28 +213,22 @@ private Set<Document> getDefaultGroupsIndexes() { | |
new Document("v", manager.indexVer) | ||
.append("unique", true) | ||
.append("key", new Document("id", 1)) | ||
.append("name", "id_1") | ||
.append("ns", col), | ||
.append("name", "id_1"), | ||
new Document("v", manager.indexVer) | ||
.append("key", new Document("own", 1).append("id", 1)) | ||
.append("name", "own_1_id_1") | ||
.append("ns", col), | ||
.append("name", "own_1_id_1"), | ||
new Document("v", manager.indexVer) | ||
.append("key", new Document("admin", 1).append("id", 1)) | ||
.append("name", "admin_1_id_1") | ||
.append("ns", col), | ||
.append("name", "admin_1_id_1"), | ||
new Document("v", manager.indexVer) | ||
.append("key", new Document("_id", 1)) | ||
.append("name", "_id_") | ||
.append("ns", col), | ||
.append("name", "_id_"), | ||
new Document("v", manager.indexVer) | ||
.append("key", new Document("priv", 1).append("id", 1)) | ||
.append("name", "priv_1_id_1") | ||
.append("ns", col), | ||
.append("name", "priv_1_id_1"), | ||
new Document("v", manager.indexVer) | ||
.append("key", new Document("memb.user", 1).append("id", 1)) | ||
.append("name", "memb.user_1_id_1") | ||
.append("ns", col) | ||
); | ||
} | ||
|
||
|
@@ -250,10 +239,8 @@ public void indexesGroupsWithResourceTypes() throws Exception { | |
try { | ||
new MongoGroupsStorage( | ||
manager.db, Arrays.asList(new ResourceType("t1"), new ResourceType("t2"))); | ||
final Set<Document> indexes = new HashSet<>(); | ||
manager.db.getCollection("groups").listIndexes() | ||
.forEach((Consumer<Document>) indexes::add); | ||
|
||
final Set<Document> indexes = getAndNormalizeIndexes("groups"); | ||
|
||
final String col = "test_mongogroupsstorage.groups"; | ||
final Set<Document> expected = getDefaultGroupsIndexes(); | ||
for (final String t: set("t1", "t2")) { | ||
|
@@ -263,19 +250,16 @@ public void indexesGroupsWithResourceTypes() throws Exception { | |
.append("key", new Document(resKey, 1) | ||
.append("own", 1) | ||
.append("id", 1)) | ||
.append("name", resKey + "_1_own_1_id_1") | ||
.append("ns", col), | ||
.append("name", resKey + "_1_own_1_id_1"), | ||
new Document("v", manager.indexVer) | ||
.append("key", new Document(resKey, 1) | ||
.append("id", 1)) | ||
.append("name", resKey + "_1_id_1") | ||
.append("ns", col), | ||
.append("name", resKey + "_1_id_1"), | ||
new Document("v", manager.indexVer) | ||
.append("key", new Document(resKey, 1) | ||
.append("priv", 1) | ||
.append("id", 1)) | ||
.append("name", resKey + "_1_priv_1_id_1") | ||
.append("ns", col) | ||
)); | ||
} | ||
assertThat("incorrect indexes", indexes, is(expected)); | ||
|
@@ -287,116 +271,113 @@ public void indexesGroupsWithResourceTypes() throws Exception { | |
|
||
@Test | ||
public void indexesRequests() { | ||
final Set<Document> indexes = new HashSet<>(); | ||
manager.db.getCollection("requests").listIndexes() | ||
.forEach((Consumer<Document>) indexes::add); | ||
final Set<Document> indexes = getAndNormalizeIndexes("requests"); | ||
final String col = "test_mongogroupsstorage.requests"; | ||
assertThat("incorrect indexes", indexes, is(set( | ||
new Document("v", manager.indexVer) | ||
.append("unique", true) | ||
.append("key", new Document("id", 1)) | ||
.append("name", "id_1") | ||
.append("ns", col), | ||
.append("name", "id_1"), | ||
new Document("v", manager.indexVer) | ||
.append("key", new Document("gid", 1).append("type", 1).append("mod", 1)) | ||
.append("name", "gid_1_type_1_mod_1") | ||
.append("ns", col), | ||
.append("name", "gid_1_type_1_mod_1"), | ||
new Document("v", manager.indexVer) | ||
.append("key", new Document("gid", 1) | ||
.append("status", 1) | ||
.append("type", 1) | ||
.append("mod", 1)) | ||
.append("name", "gid_1_status_1_type_1_mod_1") | ||
.append("ns", col), | ||
.append("name", "gid_1_status_1_type_1_mod_1"), | ||
new Document("v", manager.indexVer) | ||
.append("key", new Document("requester", 1).append("mod", 1)) | ||
.append("name", "requester_1_mod_1") | ||
.append("ns", col), | ||
.append("name", "requester_1_mod_1"), | ||
new Document("v", manager.indexVer) | ||
.append("key", new Document("requester", 1) | ||
.append("status", 1) | ||
.append("mod", 1)) | ||
.append("name", "requester_1_status_1_mod_1") | ||
.append("ns", col), | ||
.append("name", "requester_1_status_1_mod_1"), | ||
new Document("v", manager.indexVer) | ||
.append("key", new Document("resaid", 1) | ||
.append("restype", 1) | ||
.append("type", 1) | ||
.append("mod", 1)) | ||
.append("name", "resaid_1_restype_1_type_1_mod_1") | ||
.append("ns", col), | ||
.append("name", "resaid_1_restype_1_type_1_mod_1"), | ||
new Document("v", manager.indexVer) | ||
.append("key", new Document("resaid", 1) | ||
.append("restype", 1) | ||
.append("status", 1) | ||
.append("type", 1) | ||
.append("mod", 1)) | ||
.append("name", "resaid_1_restype_1_status_1_type_1_mod_1") | ||
.append("ns", col), | ||
.append("name", "resaid_1_restype_1_status_1_type_1_mod_1"), | ||
new Document("v", manager.indexVer) | ||
.append("key", new Document("resrid", 1) | ||
.append("restype", 1) | ||
.append("type", 1) | ||
.append("mod", 1)) | ||
.append("name", "resrid_1_restype_1_type_1_mod_1") | ||
.append("ns", col), | ||
.append("name", "resrid_1_restype_1_type_1_mod_1"), | ||
new Document("v", manager.indexVer) | ||
.append("key", new Document("resrid", 1) | ||
.append("restype", 1) | ||
.append("status", 1) | ||
.append("type", 1) | ||
.append("mod", 1)) | ||
.append("name", "resrid_1_restype_1_status_1_type_1_mod_1") | ||
.append("ns", col), | ||
.append("name", "resrid_1_restype_1_status_1_type_1_mod_1"), | ||
new Document("v", manager.indexVer) | ||
.append("key", new Document("resrid", 1) | ||
.append("requester", 1) | ||
.append("restype", 1) | ||
.append("type", 1) | ||
.append("mod", 1)) | ||
.append("name", "resrid_1_requester_1_restype_1_type_1_mod_1") | ||
.append("ns", col), | ||
.append("name", "resrid_1_requester_1_restype_1_type_1_mod_1"), | ||
new Document("v", manager.indexVer) | ||
.append("key", new Document("resrid", 1) | ||
.append("requester", 1) | ||
.append("restype", 1) | ||
.append("status", 1) | ||
.append("type", 1) | ||
.append("mod", 1)) | ||
.append("name", "resrid_1_requester_1_restype_1_status_1_type_1_mod_1") | ||
.append("ns", col), | ||
.append("name", "resrid_1_requester_1_restype_1_status_1_type_1_mod_1"), | ||
new Document("v", manager.indexVer) | ||
.append("key", new Document("resrid", 1) | ||
.append("gid", 1) | ||
.append("restype", 1) | ||
.append("type", 1) | ||
.append("mod", 1)) | ||
.append("name", "resrid_1_gid_1_restype_1_type_1_mod_1") | ||
.append("ns", col), | ||
.append("name", "resrid_1_gid_1_restype_1_type_1_mod_1"), | ||
new Document("v", manager.indexVer) | ||
.append("key", new Document("resrid", 1) | ||
.append("gid", 1) | ||
.append("restype", 1) | ||
.append("status", 1) | ||
.append("type", 1) | ||
.append("mod", 1)) | ||
.append("name", "resrid_1_gid_1_restype_1_status_1_type_1_mod_1") | ||
.append("ns", col), | ||
.append("name", "resrid_1_gid_1_restype_1_status_1_type_1_mod_1"), | ||
|
||
new Document("v", manager.indexVer) | ||
.append("key", new Document("expire", 1)) | ||
.append("name", "expire_1") | ||
.append("ns", col), | ||
.append("name", "expire_1"), | ||
new Document("v", manager.indexVer) | ||
.append("unique", true) | ||
.append("sparse", true) | ||
.append("key", new Document("charstr", 1)) | ||
.append("name", "charstr_1") | ||
.append("ns", col), | ||
.append("name", "charstr_1"), | ||
new Document("v", manager.indexVer) | ||
.append("key", new Document("_id", 1)) | ||
.append("name", "_id_") | ||
.append("ns", col) | ||
))); | ||
} | ||
|
||
private Set<Document> getAndNormalizeIndexes(final String collectionName) { | ||
final Set<Document> indexes = new HashSet<>(); | ||
for (Document index: manager.db.getCollection(collectionName).listIndexes()) { | ||
// In MongoDB 4.4, the listIndexes and the mongo shell helper method db.collection.getIndexes() | ||
// no longer returns the namespace ns field in the index specification documents. | ||
index.remove("ns"); | ||
// some versions of Mongo return ints, some longs. Convert all to longs. | ||
if (index.containsKey("expireAfterSeconds")) { | ||
index.put("expireAfterSeconds", ((Number) index.get("expireAfterSeconds")).longValue()); | ||
} | ||
indexes.add(index); | ||
} | ||
return indexes; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're going to need the retryWrites parameter as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding the retryWrites parameter will be included in the next PR.