mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
Merge pull request #362 from yabinmeng/main
Ignore message out-of-order and duplicate check for Shared and Key_Shared
This commit is contained in:
commit
3b67498320
@ -401,11 +401,6 @@ public class PulsarSpace {
|
|||||||
SubscriptionType subscriptionType = getEffectiveSubscriptionType(cycleSubscriptionType);
|
SubscriptionType subscriptionType = getEffectiveSubscriptionType(cycleSubscriptionType);
|
||||||
String consumerName = getEffectiveConsumerName(cycleConsumerName);
|
String consumerName = getEffectiveConsumerName(cycleConsumerName);
|
||||||
|
|
||||||
if ( subscriptionType.equals(SubscriptionType.Exclusive) && (activityDef.getThreads() > 1) ) {
|
|
||||||
throw new RuntimeException("Consumer:: trying to create multiple consumers of " +
|
|
||||||
"\"Exclusive\" subscription type under the same subscription name to the same topic!");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (StringUtils.isAnyBlank(cycleTopicName, subscriptionName)) {
|
if (StringUtils.isAnyBlank(cycleTopicName, subscriptionName)) {
|
||||||
throw new RuntimeException("Consumer:: must specify a topic name and a subscription name");
|
throw new RuntimeException("Consumer:: must specify a topic name and a subscription name");
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ public class PulsarConsumerMapper extends PulsarTransactOpMapper {
|
|||||||
|
|
||||||
private final LongFunction<Consumer<?>> consumerFunc;
|
private final LongFunction<Consumer<?>> consumerFunc;
|
||||||
private final LongFunction<Boolean> topicMsgDedupFunc;
|
private final LongFunction<Boolean> topicMsgDedupFunc;
|
||||||
|
private final LongFunction<String> subscriptionTypeFunc;
|
||||||
private final boolean e2eMsProc;
|
private final boolean e2eMsProc;
|
||||||
|
|
||||||
public PulsarConsumerMapper(CommandTemplate cmdTpl,
|
public PulsarConsumerMapper(CommandTemplate cmdTpl,
|
||||||
@ -42,10 +43,12 @@ public class PulsarConsumerMapper extends PulsarTransactOpMapper {
|
|||||||
LongFunction<Supplier<Transaction>> transactionSupplierFunc,
|
LongFunction<Supplier<Transaction>> transactionSupplierFunc,
|
||||||
LongFunction<Boolean> topicMsgDedupFunc,
|
LongFunction<Boolean> topicMsgDedupFunc,
|
||||||
LongFunction<Consumer<?>> consumerFunc,
|
LongFunction<Consumer<?>> consumerFunc,
|
||||||
|
LongFunction<String> subscriptionTypeFunc,
|
||||||
boolean e2eMsgProc) {
|
boolean e2eMsgProc) {
|
||||||
super(cmdTpl, clientSpace, pulsarActivity, asyncApiFunc, useTransactionFunc, seqTrackingFunc, transactionSupplierFunc);
|
super(cmdTpl, clientSpace, pulsarActivity, asyncApiFunc, useTransactionFunc, seqTrackingFunc, transactionSupplierFunc);
|
||||||
this.consumerFunc = consumerFunc;
|
this.consumerFunc = consumerFunc;
|
||||||
this.topicMsgDedupFunc = topicMsgDedupFunc;
|
this.topicMsgDedupFunc = topicMsgDedupFunc;
|
||||||
|
this.subscriptionTypeFunc = subscriptionTypeFunc;
|
||||||
this.e2eMsProc = e2eMsgProc;
|
this.e2eMsProc = e2eMsgProc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,6 +60,7 @@ public class PulsarConsumerMapper extends PulsarTransactOpMapper {
|
|||||||
boolean seqTracking = seqTrackingFunc.apply(value);
|
boolean seqTracking = seqTrackingFunc.apply(value);
|
||||||
Supplier<Transaction> transactionSupplier = transactionSupplierFunc.apply(value);
|
Supplier<Transaction> transactionSupplier = transactionSupplierFunc.apply(value);
|
||||||
boolean topicMsgDedup = topicMsgDedupFunc.apply(value);
|
boolean topicMsgDedup = topicMsgDedupFunc.apply(value);
|
||||||
|
String subscriptionType = subscriptionTypeFunc.apply(value);
|
||||||
|
|
||||||
return new PulsarConsumerOp(
|
return new PulsarConsumerOp(
|
||||||
pulsarActivity,
|
pulsarActivity,
|
||||||
@ -66,6 +70,7 @@ public class PulsarConsumerMapper extends PulsarTransactOpMapper {
|
|||||||
transactionSupplier,
|
transactionSupplier,
|
||||||
topicMsgDedup,
|
topicMsgDedup,
|
||||||
consumer,
|
consumer,
|
||||||
|
subscriptionType,
|
||||||
clientSpace.getPulsarSchema(),
|
clientSpace.getPulsarSchema(),
|
||||||
clientSpace.getPulsarClientConf().getConsumerTimeoutSeconds(),
|
clientSpace.getPulsarClientConf().getConsumerTimeoutSeconds(),
|
||||||
value,
|
value,
|
||||||
|
@ -31,6 +31,7 @@ public class PulsarConsumerOp implements PulsarOp {
|
|||||||
|
|
||||||
private final boolean topicMsgDedup;
|
private final boolean topicMsgDedup;
|
||||||
private final Consumer<?> consumer;
|
private final Consumer<?> consumer;
|
||||||
|
private final String subscriptionType;
|
||||||
private final Schema<?> pulsarSchema;
|
private final Schema<?> pulsarSchema;
|
||||||
private final int timeoutSeconds;
|
private final int timeoutSeconds;
|
||||||
private final boolean e2eMsgProc;
|
private final boolean e2eMsgProc;
|
||||||
@ -54,6 +55,7 @@ public class PulsarConsumerOp implements PulsarOp {
|
|||||||
Supplier<Transaction> transactionSupplier,
|
Supplier<Transaction> transactionSupplier,
|
||||||
boolean topicMsgDedup,
|
boolean topicMsgDedup,
|
||||||
Consumer<?> consumer,
|
Consumer<?> consumer,
|
||||||
|
String subscriptionType,
|
||||||
Schema<?> schema,
|
Schema<?> schema,
|
||||||
int timeoutSeconds,
|
int timeoutSeconds,
|
||||||
long curCycleNum,
|
long curCycleNum,
|
||||||
@ -68,6 +70,7 @@ public class PulsarConsumerOp implements PulsarOp {
|
|||||||
|
|
||||||
this.topicMsgDedup = topicMsgDedup;
|
this.topicMsgDedup = topicMsgDedup;
|
||||||
this.consumer = consumer;
|
this.consumer = consumer;
|
||||||
|
this.subscriptionType = subscriptionType;
|
||||||
this.pulsarSchema = schema;
|
this.pulsarSchema = schema;
|
||||||
this.timeoutSeconds = timeoutSeconds;
|
this.timeoutSeconds = timeoutSeconds;
|
||||||
this.curCycleNum = curCycleNum;
|
this.curCycleNum = curCycleNum;
|
||||||
@ -149,17 +152,28 @@ public class PulsarConsumerOp implements PulsarOp {
|
|||||||
// normal case: message sequence id is monotonically increasing by 1
|
// normal case: message sequence id is monotonically increasing by 1
|
||||||
if ((curMsgSeqId - prevMsgSeqId) != 1) {
|
if ((curMsgSeqId - prevMsgSeqId) != 1) {
|
||||||
// abnormal case: out of ordering
|
// abnormal case: out of ordering
|
||||||
|
// - for any subscription type, this check should always hold
|
||||||
if (curMsgSeqId < prevMsgSeqId) {
|
if (curMsgSeqId < prevMsgSeqId) {
|
||||||
throw new PulsarMsgOutOfOrderException(
|
throw new PulsarMsgOutOfOrderException(
|
||||||
false, curCycleNum, curMsgSeqId, prevMsgSeqId);
|
false, curCycleNum, curMsgSeqId, prevMsgSeqId);
|
||||||
}
|
}
|
||||||
// abnormal case: message loss
|
// - this sequence based message loss and message duplicate check can't be used for
|
||||||
else if ((curMsgSeqId - prevMsgSeqId) > 1) {
|
// "Shared" subscription (ignore this check)
|
||||||
throw new PulsarMsgLossException(
|
// - TODO: for Key_Shared subscription type, this logic needs to be improved on
|
||||||
false, curCycleNum, curMsgSeqId, prevMsgSeqId);
|
// per-key basis
|
||||||
} else if (topicMsgDedup && (curMsgSeqId == prevMsgSeqId)) {
|
else {
|
||||||
throw new PulsarMsgDuplicateException(
|
if ( !StringUtils.equalsAnyIgnoreCase(subscriptionType,
|
||||||
false, curCycleNum, curMsgSeqId, prevMsgSeqId);
|
PulsarActivityUtil.SUBSCRIPTION_TYPE.Shared.label,
|
||||||
|
PulsarActivityUtil.SUBSCRIPTION_TYPE.Key_Shared.label)) {
|
||||||
|
// abnormal case: message loss
|
||||||
|
if ((curMsgSeqId - prevMsgSeqId) > 1) {
|
||||||
|
throw new PulsarMsgLossException(
|
||||||
|
false, curCycleNum, curMsgSeqId, prevMsgSeqId);
|
||||||
|
} else if (topicMsgDedup && (curMsgSeqId == prevMsgSeqId)) {
|
||||||
|
throw new PulsarMsgDuplicateException(
|
||||||
|
false, curCycleNum, curMsgSeqId, prevMsgSeqId);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -249,17 +263,28 @@ public class PulsarConsumerOp implements PulsarOp {
|
|||||||
// normal case: message sequence id is monotonically increasing by 1
|
// normal case: message sequence id is monotonically increasing by 1
|
||||||
if ((curMsgSeqId - prevMsgSeqId) != 1) {
|
if ((curMsgSeqId - prevMsgSeqId) != 1) {
|
||||||
// abnormal case: out of ordering
|
// abnormal case: out of ordering
|
||||||
|
// - for any subscription type, this check should always hold
|
||||||
if (curMsgSeqId < prevMsgSeqId) {
|
if (curMsgSeqId < prevMsgSeqId) {
|
||||||
throw new PulsarMsgOutOfOrderException(
|
throw new PulsarMsgOutOfOrderException(
|
||||||
true, curCycleNum, curMsgSeqId, prevMsgSeqId);
|
false, curCycleNum, curMsgSeqId, prevMsgSeqId);
|
||||||
}
|
}
|
||||||
// abnormal case: message loss
|
// - this sequence based message loss and message duplicate check can't be used for
|
||||||
else if ((curMsgSeqId - prevMsgSeqId) > 1) {
|
// "Shared" subscription (ignore this check)
|
||||||
throw new PulsarMsgLossException(
|
// - TODO: for Key_Shared subscription type, this logic needs to be improved on
|
||||||
true, curCycleNum, curMsgSeqId, prevMsgSeqId);
|
// per-key basis
|
||||||
} else if (topicMsgDedup && (curMsgSeqId == prevMsgSeqId)) {
|
else {
|
||||||
throw new PulsarMsgDuplicateException(
|
if ( !StringUtils.equalsAnyIgnoreCase(subscriptionType,
|
||||||
true, curCycleNum, curMsgSeqId, prevMsgSeqId);
|
PulsarActivityUtil.SUBSCRIPTION_TYPE.Shared.label,
|
||||||
|
PulsarActivityUtil.SUBSCRIPTION_TYPE.Key_Shared.label)) {
|
||||||
|
// abnormal case: message loss
|
||||||
|
if ((curMsgSeqId - prevMsgSeqId) > 1) {
|
||||||
|
throw new PulsarMsgLossException(
|
||||||
|
false, curCycleNum, curMsgSeqId, prevMsgSeqId);
|
||||||
|
} else if (topicMsgDedup && (curMsgSeqId == prevMsgSeqId)) {
|
||||||
|
throw new PulsarMsgDuplicateException(
|
||||||
|
false, curCycleNum, curMsgSeqId, prevMsgSeqId);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,8 +108,8 @@ public class PulsarProducerMapper extends PulsarTransactOpMapper {
|
|||||||
// simulate message out of order
|
// simulate message out of order
|
||||||
else if ( simulateMsgOutofOrder ) {
|
else if ( simulateMsgOutofOrder ) {
|
||||||
int rndmOffset = 2;
|
int rndmOffset = 2;
|
||||||
if (value > rndmOffset)
|
msgProperties.put(PulsarActivityUtil.MSG_SEQUENCE_ID,
|
||||||
msgProperties.put(PulsarActivityUtil.MSG_SEQUENCE_ID, String.valueOf(value-rndmOffset));
|
String.valueOf((value > rndmOffset) ? (value-rndmOffset) : value));
|
||||||
}
|
}
|
||||||
// simulate message duplication
|
// simulate message duplication
|
||||||
else {
|
else {
|
||||||
|
@ -497,6 +497,7 @@ public class ReadyPulsarOp implements OpDispenser<PulsarOp> {
|
|||||||
transactionSupplierFunc,
|
transactionSupplierFunc,
|
||||||
topicMsgDedupFunc,
|
topicMsgDedupFunc,
|
||||||
consumerFunc,
|
consumerFunc,
|
||||||
|
subscription_type_func,
|
||||||
e2eMsgProc);
|
e2eMsgProc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -586,6 +587,7 @@ public class ReadyPulsarOp implements OpDispenser<PulsarOp> {
|
|||||||
// e.g. pulsarAdmin.getPulsarAdmin().topics().getDeduplicationStatus(message.getTopicName())
|
// e.g. pulsarAdmin.getPulsarAdmin().topics().getDeduplicationStatus(message.getTopicName())
|
||||||
brokerMsgDupFunc,
|
brokerMsgDupFunc,
|
||||||
mtConsumerFunc,
|
mtConsumerFunc,
|
||||||
|
subscription_type_func,
|
||||||
false);
|
false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user