2222import com .google .common .base .Preconditions ;
2323import java .util .Collections ;
2424import java .util .HashMap ;
25- import java .util .List ;
25+ import java .util .Iterator ;
2626import java .util .Map ;
2727import org .apache .commons .configuration .Configuration ;
2828import org .apache .commons .configuration .PropertiesConfiguration ;
2929import org .apache .pinot .spi .config .instance .InstanceDataManagerConfig ;
3030import org .apache .pinot .spi .config .table .SegmentsValidationAndRetentionConfig ;
3131import org .apache .pinot .spi .config .table .TableConfig ;
3232import org .apache .pinot .spi .config .table .TableType ;
33- import org .apache .pinot .spi .env .CommonsConfigurationUtils ;
3433import org .apache .pinot .spi .utils .builder .TableNameBuilder ;
3534import org .slf4j .Logger ;
3635import org .slf4j .LoggerFactory ;
@@ -50,7 +49,7 @@ public class TableDataManagerConfig {
5049 private static final String TABLE_DATA_MANAGER_AUTH = "auth" ;
5150
5251 private static final String TABLE_DATA_MANAGER_TIER_CONFIGS = "tierConfigs" ;
53- private static final String TABLE_DATA_MANAGER_TIER_NAME = "tierName " ;
52+ private static final String TIER_CONFIGS_TIER_NAMES = "tierNames " ;
5453 private static final String TABLE_DELETED_SEGMENTS_CACHE_SIZE = "deletedSegmentsCacheSize" ;
5554 private static final String TABLE_DELETED_SEGMENTS_CACHE_TTL_MINUTES = "deletedSegmentsCacheTTL" ;
5655 private static final String TABLE_PEER_DOWNLOAD_SCHEME = "peerDownloadScheme" ;
@@ -100,38 +99,28 @@ public Map<String, Map<String, String>> getInstanceTierConfigs() {
10099 }
101100
102101 @ VisibleForTesting
103- static Map <String , Map <String , String >> getTierConfigMaps (Configuration tierCfgs ) {
104- List <String > cfgKeys = CommonsConfigurationUtils .getKeys (tierCfgs );
105- Collections .sort (cfgKeys );
102+ static Map <String , Map <String , String >> getTierConfigMaps (Configuration allTierCfgs ) {
103+ // Note that config names from the instance configs are all lowered cased, e.g.
104+ // - tiernames:[hotTier, coldTier]
105+ // - hottier.datadir:/tmp/multidir_test/hotTier
106+ // - coldtier.datadir:/tmp/multidir_test/coldTier
107+ // And Configuration uses ',' as the list separator to get the list of strings.
108+ // Therefore, the tier name should not contain ',' and must be unique case-insensitive.
109+ String [] tierNames = allTierCfgs .getStringArray (TIER_CONFIGS_TIER_NAMES .toLowerCase ());
110+ if (tierNames == null ) {
111+ LOGGER .debug ("No tierConfigs from instanceConfig" );
112+ return Collections .emptyMap ();
113+ }
106114 Map <String , Map <String , String >> tierCfgMaps = new HashMap <>();
107- // Collect the cfgs for each tier into the tierCfgMaps.
108- Map <String , String > cfgMap = new HashMap <>();
109- String lastIdx = null ;
110- String tierName = null ;
111- for (String key : cfgKeys ) {
112- String value = tierCfgs .getString (key );
113- String cfgIdx = key .substring (0 , key .indexOf ('.' ));
114- if (lastIdx == null ) {
115- lastIdx = cfgIdx ;
116- } else if (!cfgIdx .equals (lastIdx )) {
117- Preconditions .checkNotNull (tierName , "Missing tier name in instance tier configs with index: %s" , lastIdx );
118- tierCfgMaps .put (tierName , cfgMap );
119- // Reset to collect cfgs for the next tier.
120- cfgMap = new HashMap <>();
121- lastIdx = cfgIdx ;
122- tierName = null ;
123- }
124- String cfgName = key .substring (key .indexOf ('.' ) + 1 );
125- cfgMap .put (cfgName , value );
126- // All config names are lower cased while being passed down here.
127- if (cfgName .equalsIgnoreCase (TABLE_DATA_MANAGER_TIER_NAME )) {
128- tierName = value ;
115+ for (String tierName : tierNames ) {
116+ Configuration tierCfgs = allTierCfgs .subset (tierName .toLowerCase ());
117+ for (Iterator <String > cfgKeys = tierCfgs .getKeys (); cfgKeys .hasNext (); ) {
118+ String cfgKey = cfgKeys .next ();
119+ String cfgValue = tierCfgs .getString (cfgKey );
120+ tierCfgMaps .computeIfAbsent (tierName , (k ) -> new HashMap <>()).put (cfgKey , cfgValue );
129121 }
130122 }
131- if (!cfgMap .isEmpty ()) {
132- Preconditions .checkNotNull (tierName , "Missing tier name in instance tier configs with index: %s" , lastIdx );
133- tierCfgMaps .put (tierName , cfgMap );
134- }
123+ LOGGER .debug ("Got tierConfigs: {} from instanceConfig" , tierCfgMaps );
135124 return tierCfgMaps ;
136125 }
137126
0 commit comments