Does unackTime creates a race condition?
/**
*
* @param quorumConn Dyno connection with dc_quorum enabled
* @param nonQuorumConn Dyno connection to local Redis
* @param redisKeyPrefix prefix applied to the Redis keys
* @param shardSupplier Provider for the shards for the queues created
* @param unackTime Time in millisecond within which a message needs to be acknowledged by the client, after which the message is re-queued.
* @param unackHandlerIntervalInMS Time in millisecond at which the un-acknowledgement processor runs
*/
public RedisQueues(JedisCommands quorumConn, JedisCommands nonQuorumConn, String redisKeyPrefix, ShardSupplier shardSupplier, int unackTime,
int unackHandlerIntervalInMS) {
this.quorumConn = quorumConn;
this.nonQuorumConn = nonQuorumConn;
this.redisKeyPrefix = redisKeyPrefix;
this.allShards = shardSupplier.getQueueShards();
this.shardName = shardSupplier.getCurrentShard();
this.unackTime = unackTime;
this.unackHandlerIntervalInMS = unackHandlerIntervalInMS;
this.queues = new ConcurrentHashMap<>();
}
unackTime Time in millisecond within which a message needs to be acknowledged by the client, after which the message is re-queued. We pass 60 seconds as unackTime
what happens if the client do a batch poll with 100 as messageCount? The pop method will query the redis database and pops 100 messages. Now, the client process one message at a time and it has execute some backend logic and takes substantial amount of time. The unackTime kicks off and resets the messages available as below
https://github.com/Netflix/dyno-queues/blob/9232b8df5051886e4f3ea8be9fc338963dd205ce/dyno-queues-redis/src/main/java/com/netflix/dyno/queues/redis/RedisDynoQueue.java#L561-L562
Now, the next available worker can poll the same message resulting in a race condition. I didn't test this race condition, but I want to hear from @v1r3n and @cyzhao on their inputs
The execute method of the worker will only be called after the message is ack'ed, keep in mind that ack happens after the task is received by the client and before it is processed by the worker, its purpose is to acknowledge Conductor that the task is received by the client. After worker completes the processing of the task, WorkflowTaskCoordinator then makes another call to Conductor to update the task.
Note that currently client ack the task after the task is picked up after executionService, so it is possible that the ack call may fail because of unack timeout, in this case WorkflowTaskCoordinator would return task back to Conductor without proceeding so the task can be picked up by another client, i.e. the task won't get lost.