@@ -303,23 +303,29 @@ protected Multimap<Long, Long> getNormalReplicaBackendPathMapCloud(String beEndp
303
303
(rep , be ) -> ((CloudReplica ) rep ).getBackendId (be ));
304
304
}
305
305
306
+ // When a BE reports a missing version, lastFailedVersion is set. When a write fails on a replica,
307
+ // lastFailedVersion is set.
306
308
// for query
307
309
public List <Replica > getQueryableReplicas (long visibleVersion , Map <Long , Set <Long >> backendAlivePathHashs ,
308
- boolean allowFailedVersion ) {
310
+ boolean allowMissingVersion ) {
309
311
List <Replica > allQueryableReplica = Lists .newArrayListWithCapacity (replicas .size ());
310
312
List <Replica > auxiliaryReplica = Lists .newArrayListWithCapacity (replicas .size ());
311
313
List <Replica > deadPathReplica = Lists .newArrayList ();
314
+ List <Replica > mayMissingVersionReplica = Lists .newArrayList ();
315
+ List <Replica > notCatchupReplica = Lists .newArrayList ();
316
+
312
317
for (Replica replica : replicas ) {
313
318
if (replica .isBad ()) {
314
319
continue ;
315
320
}
316
321
317
- // Skip the missing version replica
318
- if ( replica . getLastFailedVersion () > 0 && ! allowFailedVersion ) {
322
+ if ( replica . getLastFailedVersion () > 0 ) {
323
+ mayMissingVersionReplica . add ( replica );
319
324
continue ;
320
325
}
321
326
322
327
if (!replica .checkVersionCatchUp (visibleVersion , false )) {
328
+ notCatchupReplica .add (replica );
323
329
continue ;
324
330
}
325
331
@@ -345,6 +351,15 @@ public List<Replica> getQueryableReplicas(long visibleVersion, Map<Long, Set<Lon
345
351
allQueryableReplica = deadPathReplica ;
346
352
}
347
353
354
+ if (allQueryableReplica .isEmpty ()) {
355
+ // If be misses a version, be would report failure.
356
+ allQueryableReplica = mayMissingVersionReplica ;
357
+ }
358
+
359
+ if (allQueryableReplica .isEmpty () && allowMissingVersion ) {
360
+ allQueryableReplica = notCatchupReplica ;
361
+ }
362
+
348
363
if (Config .skip_compaction_slower_replica && allQueryableReplica .size () > 1 ) {
349
364
long minVersionCount = allQueryableReplica .stream ().mapToLong (Replica ::getVisibleVersionCount )
350
365
.filter (count -> count != -1 ).min ().orElse (Long .MAX_VALUE );
0 commit comments