DATAMONGO-2572 - Remove usage of Oppressive Language.
Replaced blacklist with denylist and introduce meta keyword SECONDARY_READS as we no longer use MongoDB API with the initial replication concept. Original Pull Request: #870
This commit is contained in:
committed by
Christoph Strobl
parent
8b36617752
commit
a6aa174ff5
@@ -1178,7 +1178,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
|
||||
/**
|
||||
* Prepare the collection before any processing is done using it. This allows a convenient way to apply settings like
|
||||
* slaveOk() etc. Can be overridden in sub-classes.
|
||||
* withCodecRegistry() etc. Can be overridden in sub-classes.
|
||||
*
|
||||
* @param collection
|
||||
*/
|
||||
@@ -3260,6 +3260,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
case PARTIAL:
|
||||
cursorToUse = cursorToUse.partial(true);
|
||||
break;
|
||||
case SECONDARY_READS:
|
||||
case SLAVE_OK:
|
||||
break;
|
||||
default:
|
||||
@@ -3277,7 +3278,8 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
|
||||
@Override
|
||||
public ReadPreference getReadPreference() {
|
||||
return query.getMeta().getFlags().contains(CursorOption.SLAVE_OK) ? ReadPreference.primaryPreferred() : null;
|
||||
return (query.getMeta().getFlags().contains(CursorOption.SECONDARY_READS)
|
||||
|| query.getMeta().getFlags().contains(CursorOption.SLAVE_OK)) ? ReadPreference.primaryPreferred() : null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2682,7 +2682,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
|
||||
/**
|
||||
* Prepare the collection before any processing is done using it. This allows a convenient way to apply settings like
|
||||
* slaveOk() etc. Can be overridden in sub-classes.
|
||||
* withCodecRegistry() etc. Can be overridden in sub-classes.
|
||||
*
|
||||
* @param collection
|
||||
*/
|
||||
@@ -3295,7 +3295,8 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
|
||||
@Override
|
||||
public ReadPreference getReadPreference() {
|
||||
return query.getMeta().getFlags().contains(CursorOption.SLAVE_OK) ? ReadPreference.primaryPreferred() : null;
|
||||
return (query.getMeta().getFlags().contains(CursorOption.SECONDARY_READS)
|
||||
|| query.getMeta().getFlags().contains(CursorOption.SLAVE_OK)) ? ReadPreference.primaryPreferred() : null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.lang.Nullable;
|
||||
* {@link AggregationOperationContext} implementation prefixing non-command keys on root level with the given prefix.
|
||||
* Useful when mapping fields to domain specific types while having to prefix keys for query purpose.
|
||||
* <p />
|
||||
* Fields to be excluded from prefixing my be added to a {@literal blacklist}.
|
||||
* Fields to be excluded from prefixing my be added to a {@literal denylist}.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
@@ -41,18 +41,18 @@ public class PrefixingDelegatingAggregationOperationContext implements Aggregati
|
||||
|
||||
private final AggregationOperationContext delegate;
|
||||
private final String prefix;
|
||||
private final Set<String> blacklist;
|
||||
private final Set<String> denylist;
|
||||
|
||||
public PrefixingDelegatingAggregationOperationContext(AggregationOperationContext delegate, String prefix) {
|
||||
this(delegate, prefix, Collections.emptySet());
|
||||
}
|
||||
|
||||
public PrefixingDelegatingAggregationOperationContext(AggregationOperationContext delegate, String prefix,
|
||||
Collection<String> blacklist) {
|
||||
Collection<String> denylist) {
|
||||
|
||||
this.delegate = delegate;
|
||||
this.prefix = prefix;
|
||||
this.blacklist = new HashSet<>(blacklist);
|
||||
this.denylist = new HashSet<>(denylist);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -121,7 +121,7 @@ public class PrefixingDelegatingAggregationOperationContext implements Aggregati
|
||||
}
|
||||
|
||||
private String prefixKey(String key) {
|
||||
return (key.startsWith("$") || isBlacklisted(key)) ? key : (prefix + "." + key);
|
||||
return (key.startsWith("$") || isDenied(key)) ? key : (prefix + "." + key);
|
||||
}
|
||||
|
||||
private Object prefixCollection(Collection<Object> sourceCollection) {
|
||||
@@ -139,9 +139,9 @@ public class PrefixingDelegatingAggregationOperationContext implements Aggregati
|
||||
return prefixed;
|
||||
}
|
||||
|
||||
private boolean isBlacklisted(String key) {
|
||||
private boolean isDenied(String key) {
|
||||
|
||||
if (blacklist.contains(key)) {
|
||||
if (denylist.contains(key)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -149,8 +149,8 @@ public class PrefixingDelegatingAggregationOperationContext implements Aggregati
|
||||
return false;
|
||||
}
|
||||
|
||||
for (String blacklisted : blacklist) {
|
||||
if (key.startsWith(blacklisted + ".")) {
|
||||
for (String denied : denylist) {
|
||||
if (key.startsWith(denied + ".")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ import com.mongodb.client.model.changestream.FullDocument;
|
||||
*/
|
||||
class ChangeStreamTask extends CursorReadingTask<ChangeStreamDocument<Document>, Object> {
|
||||
|
||||
private final Set<String> blacklist = new HashSet<>(
|
||||
private final Set<String> denylist = new HashSet<>(
|
||||
Arrays.asList("operationType", "fullDocument", "documentKey", "updateDescription", "ns"));
|
||||
|
||||
private final QueryMapper queryMapper;
|
||||
@@ -178,7 +178,7 @@ class ChangeStreamTask extends CursorReadingTask<ChangeStreamDocument<Document>,
|
||||
template.getConverter().getMappingContext(), queryMapper)
|
||||
: Aggregation.DEFAULT_CONTEXT;
|
||||
|
||||
return agg.toPipeline(new PrefixingDelegatingAggregationOperationContext(context, "fullDocument", blacklist));
|
||||
return agg.toPipeline(new PrefixingDelegatingAggregationOperationContext(context, "fullDocument", denylist));
|
||||
}
|
||||
|
||||
if (filter instanceof List) {
|
||||
|
||||
@@ -284,9 +284,21 @@ public class Meta {
|
||||
*/
|
||||
EXHAUST,
|
||||
|
||||
/** Allows querying of a replica slave. */
|
||||
/**
|
||||
* Allows querying of a replica.
|
||||
*
|
||||
* @deprecated since 3.0.2, use {@link #SECONDARY_READS} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
SLAVE_OK,
|
||||
|
||||
/**
|
||||
* Allows querying of a replica.
|
||||
*
|
||||
* @since 3.0.2
|
||||
*/
|
||||
SECONDARY_READS,
|
||||
|
||||
/**
|
||||
* Sets the cursor to return partial data from a query against a sharded cluster in which some shards do not respond
|
||||
* rather than throwing an error.
|
||||
|
||||
@@ -411,18 +411,33 @@ public class Query {
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows querying of a replica slave.
|
||||
* Allows querying of a replica.
|
||||
*
|
||||
* @return this.
|
||||
* @see org.springframework.data.mongodb.core.query.Meta.CursorOption#SLAVE_OK
|
||||
* @since 1.10
|
||||
* @deprecated since 3.0.2, use {@link #allowSecondaryReads()}.
|
||||
*/
|
||||
@Deprecated
|
||||
public Query slaveOk() {
|
||||
|
||||
meta.addFlag(Meta.CursorOption.SLAVE_OK);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows querying of a replica.
|
||||
*
|
||||
* @return this.
|
||||
* @see org.springframework.data.mongodb.core.query.Meta.CursorOption#SECONDARY_READS
|
||||
* @since 3.0.2
|
||||
*/
|
||||
public Query allowSecondaryReads() {
|
||||
|
||||
meta.addFlag(Meta.CursorOption.SECONDARY_READS);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return this.
|
||||
* @see org.springframework.data.mongodb.core.query.Meta.CursorOption#PARTIAL
|
||||
|
||||
@@ -434,7 +434,7 @@ This controls whether or not to fsync. The 'fsync' option to the getlasterror c
|
||||
<xsd:attribute name="slave-ok" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
This controls if the driver is allowed to read from secondaries or slaves. Defaults to false.
|
||||
This controls if the driver is allowed to read from secondaries or replicas. Defaults to false.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
|
||||
@@ -432,7 +432,7 @@ This controls whether or not to fsync. The 'fsync' option to the getlasterror c
|
||||
<xsd:attribute name="slave-ok" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
This controls if the driver is allowed to read from secondaries or slaves. Defaults to false.
|
||||
This controls if the driver is allowed to read from secondaries or replicas. Defaults to false.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
|
||||
@@ -531,7 +531,7 @@ This controls whether or not to fsync. The 'fsync' option to the getlasterror c
|
||||
<xsd:attribute name="slave-ok" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
This controls if the driver is allowed to read from secondaries or slaves. Defaults to false.
|
||||
This controls if the driver is allowed to read from secondaries or replicas. Defaults to false.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
|
||||
@@ -531,7 +531,7 @@ This controls whether or not to fsync. The 'fsync' option to the getlasterror c
|
||||
<xsd:attribute name="slave-ok" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
This controls if the driver is allowed to read from secondaries or slaves. Defaults to false.
|
||||
This controls if the driver is allowed to read from secondaries or replicas. Defaults to false.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
|
||||
@@ -447,7 +447,7 @@ This controls whether or not to fsync. The 'fsync' option to the getlasterror c
|
||||
<xsd:attribute name="slave-ok" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
This controls if the driver is allowed to read from secondaries or slaves. Defaults to false.
|
||||
This controls if the driver is allowed to read from secondaries or replicas. Defaults to false.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
|
||||
@@ -462,7 +462,7 @@ This controls whether or not to fsync. The 'fsync' option to the getlasterror c
|
||||
<xsd:attribute name="slave-ok" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
This controls if the driver is allowed to read from secondaries or slaves. Defaults to false.
|
||||
This controls if the driver is allowed to read from secondaries or replicas. Defaults to false.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
|
||||
@@ -480,7 +480,7 @@ This controls whether or not to fsync. The 'fsync' option to the getlasterror c
|
||||
<xsd:attribute name="slave-ok" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
This controls if the driver is allowed to read from secondaries or slaves. Defaults to false.
|
||||
This controls if the driver is allowed to read from secondaries or replicas. Defaults to false.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
|
||||
@@ -498,7 +498,7 @@ This controls whether or not to fsync. The 'fsync' option to the getlasterror c
|
||||
<xsd:attribute name="slave-ok" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
This controls if the driver is allowed to read from secondaries or slaves. Defaults to false.
|
||||
This controls if the driver is allowed to read from secondaries or replicas. Defaults to false.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
|
||||
@@ -531,7 +531,7 @@ This controls whether or not to fsync. The 'fsync' option to the getlasterror c
|
||||
<xsd:attribute name="slave-ok" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
This controls if the driver is allowed to read from secondaries or slaves. Defaults to false.
|
||||
This controls if the driver is allowed to read from secondaries or replicas. Defaults to false.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
|
||||
@@ -537,7 +537,7 @@ This controls whether or not to fsync. The 'fsync' option to the getlasterror c
|
||||
<xsd:attribute name="slave-ok" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
This controls if the driver is allowed to read from secondaries or slaves. Defaults to false.
|
||||
This controls if the driver is allowed to read from secondaries or replicas. Defaults to false.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
|
||||
@@ -1162,7 +1162,7 @@ public class MongoTemplateTests {
|
||||
assertThat(p5.getFirstName()).isEqualTo("Mark");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test // DATAMONGO-2572
|
||||
public void testUsingReadPreference() throws Exception {
|
||||
this.template.execute("readPref", new CollectionCallback<Object>() {
|
||||
public Object doInCollection(MongoCollection<org.bson.Document> collection)
|
||||
@@ -1173,9 +1173,9 @@ public class MongoTemplateTests {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
MongoTemplate slaveTemplate = new MongoTemplate(factory);
|
||||
slaveTemplate.setReadPreference(ReadPreference.secondary());
|
||||
slaveTemplate.execute("readPref", new CollectionCallback<Object>() {
|
||||
MongoTemplate secondaryTemplate = new MongoTemplate(factory);
|
||||
secondaryTemplate.setReadPreference(ReadPreference.secondary());
|
||||
secondaryTemplate.execute("readPref", new CollectionCallback<Object>() {
|
||||
public Object doInCollection(MongoCollection<org.bson.Document> collection)
|
||||
throws MongoException, DataAccessException {
|
||||
assertThat(collection.getReadPreference()).isEqualTo(ReadPreference.secondary());
|
||||
|
||||
@@ -1714,34 +1714,34 @@ public class MongoTemplateUnitTests extends MongoOperationsUnitTests {
|
||||
Assertions.assertThat(ReflectionTestUtils.getField(template, "entityCallbacks")).isSameAs(callbacks);
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2344
|
||||
void slaveOkQueryOptionShouldApplyPrimaryPreferredReadPreferenceForFind() {
|
||||
@Test // DATAMONGO-2344, DATAMONGO-2572
|
||||
void allowSecondaryReadsQueryOptionShouldApplyPrimaryPreferredReadPreferenceForFind() {
|
||||
|
||||
template.find(new Query().slaveOk(), AutogenerateableId.class);
|
||||
template.find(new Query().allowSecondaryReads(), AutogenerateableId.class);
|
||||
|
||||
verify(collection).withReadPreference(eq(ReadPreference.primaryPreferred()));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2344
|
||||
void slaveOkQueryOptionShouldApplyPrimaryPreferredReadPreferenceForFindOne() {
|
||||
@Test // DATAMONGO-2344, DATAMONGO-2572
|
||||
void allowSecondaryReadsQueryOptionShouldApplyPrimaryPreferredReadPreferenceForFindOne() {
|
||||
|
||||
template.findOne(new Query().slaveOk(), AutogenerateableId.class);
|
||||
template.findOne(new Query().allowSecondaryReads(), AutogenerateableId.class);
|
||||
|
||||
verify(collection).withReadPreference(eq(ReadPreference.primaryPreferred()));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2344
|
||||
void slaveOkQueryOptionShouldApplyPrimaryPreferredReadPreferenceForFindDistinct() {
|
||||
@Test // DATAMONGO-2344, DATAMONGO-2572
|
||||
void allowSecondaryReadsQueryOptionShouldApplyPrimaryPreferredReadPreferenceForFindDistinct() {
|
||||
|
||||
template.findDistinct(new Query().slaveOk(), "name", AutogenerateableId.class, String.class);
|
||||
template.findDistinct(new Query().allowSecondaryReads(), "name", AutogenerateableId.class, String.class);
|
||||
|
||||
verify(collection).withReadPreference(eq(ReadPreference.primaryPreferred()));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2344
|
||||
void slaveOkQueryOptionShouldApplyPrimaryPreferredReadPreferenceForStream() {
|
||||
@Test // DATAMONGO-2344, DATAMONGO-2572
|
||||
void allowSecondaryReadsQueryOptionShouldApplyPrimaryPreferredReadPreferenceForStream() {
|
||||
|
||||
template.stream(new Query().slaveOk(), AutogenerateableId.class);
|
||||
template.stream(new Query().allowSecondaryReads(), AutogenerateableId.class);
|
||||
verify(collection).withReadPreference(eq(ReadPreference.primaryPreferred()));
|
||||
}
|
||||
|
||||
|
||||
@@ -896,26 +896,26 @@ public class ReactiveMongoTemplateUnitTests {
|
||||
Assertions.assertThat(ReflectionTestUtils.getField(template, "entityCallbacks")).isSameAs(callbacks);
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2344
|
||||
void slaveOkQueryOptionShouldApplyPrimaryPreferredReadPreferenceForFind() {
|
||||
@Test // DATAMONGO-2344, DATAMONGO-2572
|
||||
void allowSecondaryReadsQueryOptionShouldApplyPrimaryPreferredReadPreferenceForFind() {
|
||||
|
||||
template.find(new Query().slaveOk(), AutogenerateableId.class).subscribe();
|
||||
template.find(new Query().allowSecondaryReads(), AutogenerateableId.class).subscribe();
|
||||
|
||||
verify(collection).withReadPreference(eq(ReadPreference.primaryPreferred()));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2344
|
||||
void slaveOkQueryOptionShouldApplyPrimaryPreferredReadPreferenceForFindOne() {
|
||||
@Test // DATAMONGO-2344, DATAMONGO-2572
|
||||
void allowSecondaryReadsQueryOptionShouldApplyPrimaryPreferredReadPreferenceForFindOne() {
|
||||
|
||||
template.findOne(new Query().slaveOk(), AutogenerateableId.class).subscribe();
|
||||
template.findOne(new Query().allowSecondaryReads(), AutogenerateableId.class).subscribe();
|
||||
|
||||
verify(collection).withReadPreference(eq(ReadPreference.primaryPreferred()));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2344
|
||||
void slaveOkQueryOptionShouldApplyPrimaryPreferredReadPreferenceForFindDistinct() {
|
||||
@Test // DATAMONGO-2344, DATAMONGO-2572
|
||||
void allowSecondaryReadsQueryOptionShouldApplyPrimaryPreferredReadPreferenceForFindDistinct() {
|
||||
|
||||
template.findDistinct(new Query().slaveOk(), "name", AutogenerateableId.class, String.class).subscribe();
|
||||
template.findDistinct(new Query().allowSecondaryReads(), "name", AutogenerateableId.class, String.class).subscribe();
|
||||
|
||||
verify(collection).withReadPreference(eq(ReadPreference.primaryPreferred()));
|
||||
}
|
||||
|
||||
@@ -297,14 +297,14 @@ class QueryTests {
|
||||
.isNotEqualTo(source.getFieldsObject());
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1783
|
||||
@Test // DATAMONGO-1783, DATAMONGO-2572
|
||||
void clonedQueryShouldNotDependOnMetaFromSource() {
|
||||
|
||||
Query source = new Query().maxTimeMsec(100);
|
||||
Query target = Query.of(source);
|
||||
|
||||
compareQueries(target, source);
|
||||
source.slaveOk();
|
||||
source.allowSecondaryReads();
|
||||
|
||||
Meta meta = new Meta();
|
||||
meta.setMaxTimeMsec(100);
|
||||
|
||||
@@ -194,7 +194,7 @@ public class MongoQueryMethodUnitTests {
|
||||
.contains(org.springframework.data.mongodb.core.query.Meta.CursorOption.NO_TIMEOUT);
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1480
|
||||
@Test // DATAMONGO-1480, DATAMONGO-2572
|
||||
public void createsMongoQueryMethodWithMultipleFlagsCorrectly() throws Exception {
|
||||
|
||||
MongoQueryMethod method = queryMethod(PersonRepository.class, "metaWithMultipleFlags");
|
||||
@@ -202,7 +202,7 @@ public class MongoQueryMethodUnitTests {
|
||||
assertThat(method.hasQueryMetaAttributes()).isTrue();
|
||||
assertThat(method.getQueryMetaAttributes().getFlags()).contains(
|
||||
org.springframework.data.mongodb.core.query.Meta.CursorOption.NO_TIMEOUT,
|
||||
org.springframework.data.mongodb.core.query.Meta.CursorOption.SLAVE_OK);
|
||||
org.springframework.data.mongodb.core.query.Meta.CursorOption.SECONDARY_READS);
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1266
|
||||
@@ -273,7 +273,7 @@ public class MongoQueryMethodUnitTests {
|
||||
List<User> metaWithNoCursorTimeout();
|
||||
|
||||
@Meta(flags = { org.springframework.data.mongodb.core.query.Meta.CursorOption.NO_TIMEOUT,
|
||||
org.springframework.data.mongodb.core.query.Meta.CursorOption.SLAVE_OK })
|
||||
org.springframework.data.mongodb.core.query.Meta.CursorOption.SECONDARY_READS })
|
||||
List<User> metaWithMultipleFlags();
|
||||
|
||||
// DATAMONGO-1266
|
||||
|
||||
Reference in New Issue
Block a user