This commit is contained in:
Matheus Lima 2023-07-17 21:42:11 -05:00 committed by GitHub
commit 99c351cf48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 72 additions and 10 deletions

View File

@ -3,11 +3,12 @@ package com.twitter.search.earlybird.factory;
import com.twitter.decider.Decider; import com.twitter.decider.Decider;
import com.twitter.search.common.schema.earlybird.EarlybirdCluster; import com.twitter.search.common.schema.earlybird.EarlybirdCluster;
import com.twitter.search.earlybird.EarlybirdIndexConfig; import com.twitter.search.earlybird.EarlybirdIndexConfig;
import com.twitter.search.earlybird.RealtimeEarlybirdIndexConfig;
import com.twitter.search.earlybird.archive.ArchiveOnDiskEarlybirdIndexConfig;
import com.twitter.search.earlybird.archive.ArchiveSearchPartitionManager; import com.twitter.search.earlybird.archive.ArchiveSearchPartitionManager;
import com.twitter.search.earlybird.common.config.EarlybirdConfig; import com.twitter.search.earlybird.common.config.EarlybirdConfig;
import com.twitter.search.earlybird.exception.CriticalExceptionHandler; import com.twitter.search.earlybird.exception.CriticalExceptionHandler;
import com.twitter.search.earlybird.factory.configStrategy.ArchiveOnDiskEarlybirdIndexConfigStrategy;
import com.twitter.search.earlybird.factory.configStrategy.EarlybirdIndexConfigContext;
import com.twitter.search.earlybird.factory.configStrategy.RealtimeEarlybirdIndexConfigStrategy;
import com.twitter.search.earlybird.partition.SearchIndexingMetricSet; import com.twitter.search.earlybird.partition.SearchIndexingMetricSet;
public final class EarlybirdIndexConfigUtil { public final class EarlybirdIndexConfigUtil {
@ -20,19 +21,17 @@ public final class EarlybirdIndexConfigUtil {
public static EarlybirdIndexConfig createEarlybirdIndexConfig( public static EarlybirdIndexConfig createEarlybirdIndexConfig(
Decider decider, SearchIndexingMetricSet searchIndexingMetricSet, Decider decider, SearchIndexingMetricSet searchIndexingMetricSet,
CriticalExceptionHandler criticalExceptionHandler) { CriticalExceptionHandler criticalExceptionHandler) {
EarlybirdIndexConfigContext context = new EarlybirdIndexConfigContext();
if (isArchiveSearch()) { if (isArchiveSearch()) {
return new ArchiveOnDiskEarlybirdIndexConfig(decider, searchIndexingMetricSet, context.setStrategy(new ArchiveOnDiskEarlybirdIndexConfigStrategy());
criticalExceptionHandler);
} else if (isProtectedSearch()) { } else if (isProtectedSearch()) {
return new RealtimeEarlybirdIndexConfig( context.setStrategy(new RealtimeEarlybirdIndexConfigStrategy(EarlybirdCluster.PROTECTED));
EarlybirdCluster.PROTECTED, decider, searchIndexingMetricSet, criticalExceptionHandler);
} else if (isRealtimeCG()) { } else if (isRealtimeCG()) {
return new RealtimeEarlybirdIndexConfig( context.setStrategy(new RealtimeEarlybirdIndexConfigStrategy(EarlybirdCluster.REALTIME_CG));
EarlybirdCluster.REALTIME_CG, decider, searchIndexingMetricSet, criticalExceptionHandler);
} else { } else {
return new RealtimeEarlybirdIndexConfig( context.setStrategy(new RealtimeEarlybirdIndexConfigStrategy(EarlybirdCluster.REALTIME));
EarlybirdCluster.REALTIME, decider, searchIndexingMetricSet, criticalExceptionHandler);
} }
return context.createEarlybirdIndexConfig(decider, searchIndexingMetricSet, criticalExceptionHandler);
} }
public static boolean isArchiveSearch() { public static boolean isArchiveSearch() {

View File

@ -0,0 +1,19 @@
package com.twitter.search.earlybird.factory.configStrategy;
import com.twitter.search.earlybird.EarlybirdIndexConfig;
import com.twitter.search.earlybird.exception.CriticalExceptionHandler;
import com.twitter.search.earlybird.partition.SearchIndexingMetricSet;
public class EarlybirdIndexConfigContext {
private EarlybirdIndexConfigStrategy strategy;
public void setStrategy(EarlybirdIndexConfigStrategy strategy) {
this.strategy = strategy;
}
public EarlybirdIndexConfig createEarlybirdIndexConfig(
Decider decider, SearchIndexingMetricSet searchIndexingMetricSet,
CriticalExceptionHandler criticalExceptionHandler) {
return strategy.createEarlybirdIndexConfig(decider, searchIndexingMetricSet, criticalExceptionHandler);
}
}

View File

@ -0,0 +1,21 @@
package com.twitter.search.earlybird.factory.configStrategy;
import com.twitter.search.earlybird.EarlybirdIndexConfig;
import com.twitter.search.earlybird.archive.ArchiveOnDiskEarlybirdIndexConfig;
import com.twitter.search.earlybird.exception.CriticalExceptionHandler;
import com.twitter.search.earlybird.partition.SearchIndexingMetricSet;
public interface EarlybirdIndexConfigStrategy {
EarlybirdIndexConfig createEarlybirdIndexConfig(
Decider decider, SearchIndexingMetricSet searchIndexingMetricSet,
CriticalExceptionHandler criticalExceptionHandler);
}
public class ArchiveOnDiskEarlybirdIndexConfigStrategy implements EarlybirdIndexConfigStrategy {
@Override
public EarlybirdIndexConfig createEarlybirdIndexConfig(
Decider decider, SearchIndexingMetricSet searchIndexingMetricSet,
CriticalExceptionHandler criticalExceptionHandler) {
return new ArchiveOnDiskEarlybirdIndexConfig(decider, searchIndexingMetricSet, criticalExceptionHandler);
}
}

View File

@ -0,0 +1,23 @@
package com.twitter.search.earlybird.factory.configStrategy;
import com.twitter.search.common.schema.earlybird.EarlybirdCluster;
import com.twitter.search.earlybird.EarlybirdIndexConfig;
import com.twitter.search.earlybird.RealtimeEarlybirdIndexConfig;
import com.twitter.search.earlybird.exception.CriticalExceptionHandler;
import com.twitter.search.earlybird.partition.SearchIndexingMetricSet;
public class RealtimeEarlybirdIndexConfigStrategy implements EarlybirdIndexConfigStrategy {
private EarlybirdCluster earlybirdCluster;
public RealtimeEarlybirdIndexConfigStrategy(EarlybirdCluster earlybirdCluster) {
this.earlybirdCluster = earlybirdCluster;
}
@Override
public EarlybirdIndexConfig createEarlybirdIndexConfig(
Decider decider, SearchIndexingMetricSet searchIndexingMetricSet,
CriticalExceptionHandler criticalExceptionHandler) {
return new RealtimeEarlybirdIndexConfig(
earlybirdCluster, decider, searchIndexingMetricSet, criticalExceptionHandler);
}
}